Skip to content

Commit

Permalink
Merge pull request #49 from TheJacksonLaboratory/enhancement/schema-s…
Browse files Browse the repository at this point in the history
…earch

Enhancement/schema search
  • Loading branch information
iimpulse authored Mar 13, 2024
2 parents 12b44c9 + da015ec commit 15eedc2
Show file tree
Hide file tree
Showing 39 changed files with 951 additions and 124 deletions.
21 changes: 19 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
plugins {
id("groovy")
id("groovy")
id("com.github.johnrengelman.shadow") version "8.1.1"
id("io.micronaut.application") version "4.1.0"
id("io.micronaut.test-resources") version "4.1.0"
id("jacoco")
}

version = "0.5.8"
version = "0.5.9"
group = "org.jacksonlaboratory"

repositories {
Expand Down Expand Up @@ -103,5 +104,21 @@ tasks.withType(JavaCompile) {
options.forkOptions.jvmArgs << "-Dmicronaut.openapi.views.spec=swagger-ui.enabled=true,swagger-ui.theme=flattop,swagger-ui.js.url=/api/${System.env.ONTOLOGY}/docs/res/,swagger-ui.theme.url=/api/${System.env.ONTOLOGY}/docs/,swagger-ui.spec.url=/api/${System.env.ONTOLOGY}/${project.name}-${System.env.ONTOLOGY}-${project.version}.yml".toString()
}

test {
finalizedBy("jacocoTestReport")
}

jacocoTestReport {
dependsOn("test")
afterEvaluate {
classDirectories.setFrom(files(classDirectories.files.collect {
fileTree(dir: it, exclude: [
"org/jacksonlaboratory/view/*",
"org/jacksonlaboratory/Application.class"
])
}))
}
}



2 changes: 1 addition & 1 deletion src/main/java/org/jacksonlaboratory/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
info = @Info(
title = "ontology-service-${ontology}",
description = "A restful service for the ${ontology} ontology.",
version = "0.5.8",
version = "0.5.9",
contact = @Contact(name = "Michael Gargano", email = "[email protected]")
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ public SearchController(TermService termService) {
public SearchDto search(
@QueryValue("q") @Schema(minLength = 3, maxLength = 250, type = "string", pattern = ".*") String query,
@QueryValue(value = "page", defaultValue = "0") @Schema(maxLength = 1000, type = "number") int page,
@QueryValue(value = "limit", defaultValue = "10") @Schema(maxLength = 1, type = "number") int limit
@QueryValue(value = "limit", defaultValue = "10") @Schema(maxLength = 1000, type = "number") int limit
) {
page = page * limit;
List<OntologyTerm> terms = this.termService.searchOntologyTerm(query);
if (limit == -1) {
return new SearchDto(terms, terms.size());
} else {
page = page * limit;
return new SearchDto(terms.stream().skip(page).limit(limit).collect(Collectors.toList()), terms.size());
}
}
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/org/jacksonlaboratory/controller/TermController.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,15 @@ public List<SimpleOntologyTerm> children(@Schema(minLength = 1, maxLength = 20,
return this.graphService.getChildren(termId);
}

/**
* Get the descendants of the ontology id
* @param id The ontology term id
* @return The descendants of the term id
*/
@Get(uri="/{id}/descendants", produces="application/json")
public List<SimpleOntologyTerm> descendants(@Schema(minLength = 1, maxLength = 20, type = "string", pattern = ".*") @PathVariable String id){
TermId termId = TermId.of(id);
return this.graphService.getDescendants(termId);
}

}
3 changes: 3 additions & 0 deletions src/main/java/org/jacksonlaboratory/ingest/BabelonData.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

import java.util.List;

/**
* A container of term and its babelon (translation) lines
*/
public class BabelonData {
private final TermId id;
private final List<BabelonLine> babelonLines;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.nio.file.Path;
import java.util.zip.GZIPInputStream;


public interface BabelonIngestor {

public static BabelonIngestor of() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
import java.util.function.Function;
import java.util.stream.Collectors;

/**
* The default implementation of a babelon file file
*/
public class BabelonIngestorDefault implements BabelonIngestor {
private static final Logger LOGGER = LoggerFactory.getLogger(BabelonIngestorDefault.class);

Expand Down
3 changes: 3 additions & 0 deletions src/main/java/org/jacksonlaboratory/ingest/BabelonLine.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@

import java.util.Objects;

/**
* A representation of a line in a babelon (translation) file
*/
public class BabelonLine {

private final Language source_language;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
import java.util.*;
import java.util.stream.Collectors;

/**
* An access class for getting BabelonData
*/
public class BabelonNavigator {

private final List<BabelonData> babelonData;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package org.jacksonlaboratory.ingest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import java.util.Objects;

/**
* This builds the data directory path and validates required files exist
*/
public class OntologyDataResolver {
private static final Logger LOGGER = LoggerFactory.getLogger(OntologyDataResolver.class);

private final Path dataDirectory;
private final String ontology;

public static OntologyDataResolver of(Path dataDirectory, String ontology) throws RuntimeException {
return new OntologyDataResolver(dataDirectory, ontology);
}

private OntologyDataResolver(Path dataDirectory, String ontology) throws RuntimeException {
Objects.requireNonNull(dataDirectory, "Data directory must not be null!");
Objects.requireNonNull(ontology, "Ontology must be defined.");
this.dataDirectory = dataDirectory;
this.ontology = ontology;
validateHpoFiles();
}

private void validateHpoFiles() throws RuntimeException {
boolean error = false;
List<Path> requiredFiles = List.of(ontologyJson());
for (Path file : requiredFiles) {
if (!Files.isRegularFile(file)) {
LOGGER.error("Missing required file `{}` in `{}`.", file.toFile().getName(), dataDirectory.toAbsolutePath());
error = true;
}
}
if (error) {
throw new RuntimeException("Missing one or more required files in OntologyAnnotationNetwork data directory!");
}
}


public Path dataDirectory() {
return dataDirectory;
}

public Path ontologyJson(){
return dataDirectory.resolve(String.format("%s-base.json", ontology));
}

public Path babelonFile(){
return dataDirectory.resolve(String.format("%s-all.babelon.tsv", ontology));
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
import java.util.*;
import java.util.stream.Collectors;

/**
* Create translations from babelon file
*/
public class TranslationProcessor {

/**
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/org/jacksonlaboratory/model/dto/SearchDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.jacksonlaboratory.model.entity.OntologyTerm;

import java.util.List;
import java.util.Objects;

public class SearchDto {
private final List<OntologyTerm> terms;
Expand All @@ -20,4 +21,17 @@ public List<OntologyTerm> getTerms() {
public int getTotalCount() {
return totalCount;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
SearchDto searchDto = (SearchDto) o;
return totalCount == searchDto.totalCount && Objects.equals(terms, searchDto.terms);
}

@Override
public int hashCode() {
return Objects.hash(terms, totalCount);
}
}
41 changes: 16 additions & 25 deletions src/main/java/org/jacksonlaboratory/model/entity/OntologyTerm.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,12 @@
import io.swagger.v3.oas.annotations.media.ArraySchema;
import jakarta.persistence.*;
import org.jacksonlaboratory.model.converter.TermIdAttributeConverter;
import org.monarchinitiative.phenol.ontology.data.Dbxref;
import org.monarchinitiative.phenol.ontology.data.Term;
import org.monarchinitiative.phenol.ontology.data.TermId;
import org.monarchinitiative.phenol.ontology.data.TermSynonym;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.function.Predicate;
import java.util.stream.Collectors;

@NamedNativeQuery(
name="searchQuery",
Expand Down Expand Up @@ -48,28 +43,31 @@ public class OntologyTerm {
private String xrefs;

@Column(columnDefinition = "int")
private int nDescendants;
private int descendantCount;

@Transient
private List<Translation> translations;

@Creator
public OntologyTerm(TermId id, String name, String definition, String comment) {
public OntologyTerm(TermId id, String name, String definition, String comment, String synonyms, String xrefs, int descendantCount) {
this.id = id;
this.name = name;
this.definition = definition;
this.comment = comment;
this.synonyms = null;
this.xrefs = null;
this.synonyms = synonyms;
this.xrefs = xrefs;
this.descendantCount = descendantCount;
}

public OntologyTerm(Term term) {
this.id = term.id();
this.name = term.getName();
this.definition = term.getDefinition();
this.comment = term.getComment();
this.synonyms = term.getSynonyms().stream().filter(Predicate.not(TermSynonym::isObsoleteSynonym)).map(TermSynonym::getValue).collect(Collectors.joining(";"));
this.xrefs = term.getXrefs().stream().map(Dbxref::getName).collect(Collectors.joining(";"));
public OntologyTerm(TermId id, String name, String definition, String comment, String synonyms, String xrefs, int descendantCount, List<Translation> translations) {
this.id = id;
this.name = name;
this.definition = definition;
this.comment = comment;
this.synonyms = synonyms;
this.xrefs = xrefs;
this.descendantCount = descendantCount;
this.translations = translations;
}

public OntologyTerm() {
Expand Down Expand Up @@ -106,7 +104,7 @@ public String getComment() {
}

public int getDescendantCount() {
return nDescendants;
return descendantCount;
}

@ArraySchema(maxItems = 25)
Expand All @@ -133,14 +131,6 @@ public List<Translation> getTranslations() {
return translations;
}

public void setTranslation(List<Translation> translations) {
this.translations = translations;
}

public void setDescendantCount(int count) {
this.nDescendants = count;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
Expand All @@ -153,4 +143,5 @@ public boolean equals(Object o) {
public int hashCode() {
return Objects.hash(uid, id, name, definition, comment, synonyms, xrefs, translations);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package org.jacksonlaboratory.model.entity;

import org.monarchinitiative.phenol.ontology.data.TermId;

import java.util.List;

public class OntologyTermBuilder {
private TermId id;
private String name;
private String definition;
private String comment;
private String synonyms;
private String xrefs;
private int nDescendants;
private List<Translation> translations;

public OntologyTermBuilder setId(TermId id) {
this.id = id;
return this;
}

public OntologyTermBuilder setName(String name) {
this.name = name;
return this;
}

public OntologyTermBuilder setDefinition(String definition) {
this.definition = definition;
return this;
}

public OntologyTermBuilder setComment(String comment) {
this.comment = comment;
return this;
}

public OntologyTermBuilder setSynonyms(String synonyms) {
this.synonyms = synonyms;
return this;
}

public OntologyTermBuilder setXrefs(String xrefs) {
this.xrefs = xrefs;
return this;
}

public OntologyTermBuilder setDescendantCount(int nDescendants) {
this.nDescendants = nDescendants;
return this;
}

public OntologyTermBuilder setTranslations(List<Translation> translations) {
this.translations = translations;
return this;
}

public OntologyTerm createOntologyTerm() {
return new OntologyTerm(id, name, definition, comment, synonyms, xrefs, nDescendants, translations);
}

public OntologyTermBuilder fromOntologyTerm(OntologyTerm term) {
this.id = term.getTermId();
this.name = term.getName();
this.definition = term.getDefinition();
this.comment = term.getComment();
this.synonyms = String.join(";", term.getSynonyms());
this.xrefs = String.join(";", term.getXrefs());
this.nDescendants = term.getDescendantCount();
this.translations = term.getTranslations();
return this;
}
}
Loading

0 comments on commit 15eedc2

Please sign in to comment.