Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.alliancegenome.api.entity.GeneGeneticInteractionDocument;
import org.alliancegenome.api.entity.GeneMolecularInteractionDocument;
import org.alliancegenome.api.entity.GeneToGeneParalogyDocument;
import org.alliancegenome.api.entity.GeneToGeneOrthologyDocument;
import org.alliancegenome.api.rest.interfaces.GeneRESTInterface;
import org.alliancegenome.api.service.*;
import org.alliancegenome.api.service.helper.APIServiceHelper;
Expand Down Expand Up @@ -56,6 +57,9 @@ public class GeneController implements GeneRESTInterface {
@Inject
ExpressionCacheRepository expressionCacheRepository;

@Inject
OrthologyESService orthologyESService;

@Inject
DiseaseService diseaseService;

Expand Down Expand Up @@ -628,7 +632,7 @@ private JsonResultResponse<DiseaseAnnotation> getEmpiricalDiseaseAnnotation(Stri
}

@Override
public JsonResultResponse<HomologView> getGeneOrthology(String id,
public JsonResultResponse<GeneToGeneOrthologyDocument> getGeneOrthology(String id,
List<String> geneIDs,
String geneLister,
String stringencyFilter,
Expand All @@ -652,7 +656,7 @@ public JsonResultResponse<HomologView> getGeneOrthology(String id,
pagination.addFieldFilter(FieldFilter.STRINGENCY, stringencyFilter);
pagination.addFieldFilter(FieldFilter.ORTHOLOGY_METHOD, method);
pagination.addFieldFilter(FieldFilter.ORTHOLOGY_TAXON, taxonID);
final JsonResultResponse<HomologView> response = orthologyCacheService.getOrthologyMultiGeneJson(geneList, pagination);
final JsonResultResponse<GeneToGeneOrthologyDocument> response = orthologyESService.getOrthologyList(id, pagination);
response.setHttpServletRequest(null);
return response;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,6 @@ public JsonResultResponse<HomologView> getMultiSpeciesOrthology(List<String> tax
return response;
}

@Override
public JsonResultResponse<HomologView> getMultiGeneOrthology(List<String> geneIDs, String geneList, String stringencyFilter, String method, Integer rows, Integer page) {
// controller.setRequest(request);
return controller.getGeneOrthology(null, geneIDs, geneList, stringencyFilter, null, method, rows, page);
}

@Override
public JsonResultResponse<OrthoAlgorithm> getAllMethodsCalculations() {
LocalDateTime startDate = LocalDateTime.now();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.alliancegenome.api.entity.GeneMolecularInteractionDocument;
import org.alliancegenome.api.entity.GeneToGeneParalogyDocument;
import org.alliancegenome.api.entity.GenePhenotypeAnnotationDocument;
import org.alliancegenome.api.entity.GeneToGeneOrthologyDocument;
import org.alliancegenome.cache.repository.helper.JsonResultResponse;
import org.alliancegenome.neo4j.entity.DiseaseAnnotation;
import org.alliancegenome.neo4j.entity.DiseaseSummary;
Expand Down Expand Up @@ -406,10 +407,9 @@ JsonResultResponse<PrimaryAnnotatedEntity> getPrimaryAnnotatedEntityForModel(

@GET
@Path("/{id}/orthologs")
@JsonView(value = {View.Homology.class})
@Operation(summary = "Download homology records.")
@Operation(summary = "Get orthology records.")
@APIResponses(value = { @APIResponse(responseCode = "200", content = @Content(mediaType = "application/json", schema = @Schema(implementation = Null.class))) })
JsonResultResponse<HomologView> getGeneOrthology(
JsonResultResponse<GeneToGeneOrthologyDocument> getGeneOrthology(
@Parameter(in = ParameterIn.PATH, name = "id", description = "Source Gene ID: the gene for which you are searching homologous gene, e.g. 'MGI:109583'", required = true, schema = @Schema(type = SchemaType.STRING))
@PathParam("id") String id,
@Parameter(in = ParameterIn.QUERY, name = "geneId", description = "List of additional source gene IDs for which homology is retrieved.", schema = @Schema(type = SchemaType.STRING))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,19 +69,6 @@ JsonResultResponse<HomologView> getSingleSpeciesOrthology(
JsonResultResponse<HomologView> getMultiSpeciesOrthology(@QueryParam("taxonID") List<String> taxonID, @QueryParam("taxonIdList") String taxonIdList, @QueryParam("stringencyFilter") String stringencyFilter, @QueryParam("methods") String methods,
@DefaultValue("20") @QueryParam("rows") Integer rows, @DefaultValue("1") @QueryParam("start") Integer start) throws IOException;

@GET
@Path("/geneMap")
@JsonView(value = { View.Homology.class })
@Operation(summary = "Retrieve homologous gene records for given list of geneMap")
@APIResponses(value = { @APIResponse(responseCode = "200", content = @Content(mediaType = "application/json", schema = @Schema(implementation = Null.class))) })
JsonResultResponse<HomologView> getMultiGeneOrthology(
@Parameter(in = ParameterIn.QUERY, name = "geneID", description = "List of geneMap (specified by their ID) for which homology is retrieved, e.g. 'MGI:109583'", schema = @Schema(type = SchemaType.STRING)) @QueryParam("geneID") List<String> geneID,
@Parameter(in = ParameterIn.QUERY, name = "geneIdList", description = "List of additional source gene IDs for which homology is retrieved in a comma-delimited list, e.g. 'MGI:109583,RGD:2129,MGI:97570", schema = @Schema(type = SchemaType.STRING)) @QueryParam("geneIdList") String geneList,
@Parameter(in = ParameterIn.QUERY, name = "filter.stringency", description = "apply stringency containsFilterValue", schema = @Schema(type = SchemaType.STRING)) @DefaultValue("stringent") @QueryParam("filter.stringency") String stringency,
@Parameter(in = ParameterIn.QUERY, name = "filter.method", description = "calculation methods", schema = @Schema(type = SchemaType.STRING)) @QueryParam("filter.method") String method,
@Parameter(in = ParameterIn.QUERY, name = "limit", description = "Number of rows returned", schema = @Schema(type = SchemaType.INTEGER)) @DefaultValue("20") @QueryParam("limit") Integer limit,
@Parameter(in = ParameterIn.QUERY, name = "page", description = "Page number", schema = @Schema(type = SchemaType.INTEGER)) @DefaultValue("1") @QueryParam("page") Integer page) throws IOException;

@GET
@Path("/methods")
@JsonView(value = { View.OrthologyMethod.class })
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package org.alliancegenome.api.service;

import java.util.ArrayList;
import java.util.List;

import static org.elasticsearch.index.query.QueryBuilders.boolQuery;

import org.alliancegenome.api.entity.GeneToGeneOrthologyDocument;
import org.alliancegenome.cache.repository.helper.JsonResultResponse;
import org.alliancegenome.cache.repository.helper.OrthologyFiltering;
import org.alliancegenome.core.api.service.FilterService;
import org.alliancegenome.es.model.query.Pagination;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.TermQueryBuilder;
import org.elasticsearch.search.SearchHit;

import jakarta.enterprise.context.RequestScoped;

@RequestScoped
public class OrthologyESService extends ESService {

public JsonResultResponse<GeneToGeneOrthologyDocument> getOrthologyList(String geneID, Pagination pagination) {
BoolQueryBuilder bool = boolQuery();
bool.filter(new TermQueryBuilder("geneToGeneOrthologyGenerated.subjectGene.primaryExternalId.keyword", geneID));

SearchResponse searchResponse = getSearchResponse(bool, pagination, null, false);

JsonResultResponse<GeneToGeneOrthologyDocument> response = new JsonResultResponse<>();
response.setTotal((int) searchResponse.getHits().getTotalHits().value);

List<GeneToGeneOrthologyDocument> list = new ArrayList<>();

for (SearchHit searchHit : searchResponse.getHits().getHits()) {
try {
String source = searchHit.getSourceAsString();
GeneToGeneOrthologyDocument object = mapper.readValue(source, GeneToGeneOrthologyDocument.class);
list.add(object);
} catch (Exception e) {
e.printStackTrace();
}
}

FilterService<GeneToGeneOrthologyDocument> filterService = new FilterService<>(new OrthologyFiltering());
List<GeneToGeneOrthologyDocument> gene2GeneOrthoFiltered = filterService.filterAnnotations(list, pagination.getFieldFilterValueMap());

response.setResults(gene2GeneOrthoFiltered);
return response;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.alliancegenome.api.dto.ExpressionSummary;
import org.alliancegenome.api.dto.ExpressionSummaryGroup;
import org.alliancegenome.api.dto.ExpressionSummaryGroupTerm;
import org.alliancegenome.api.entity.GeneToGeneOrthologyDocument;
import org.alliancegenome.api.service.GeneService;
import org.alliancegenome.cache.repository.helper.JsonResultResponse;
import org.alliancegenome.core.ExpressionDetail;
Expand Down Expand Up @@ -98,15 +99,15 @@ public void checkOrthologyAPIWithFilter() {

GeneController controller = new GeneController();
String[] geneIDs = {"RGD:2129"};
JsonResultResponse<HomologView> response = controller.getGeneOrthology("MGI:109583", asList(geneIDs), null, "stringENT", null, null, 20, 1);
JsonResultResponse<GeneToGeneOrthologyDocument> response = controller.getGeneOrthology("MGI:109583", asList(geneIDs), null, "stringENT", null, null, 20, 1);
assertThat("Matches found for containsFilterValue 'stringent", response.getTotal(), greaterThan(0));
}

@Test
public void checkOrthologyForListOfGenes() {

GeneController controller = new GeneController();
JsonResultResponse<HomologView> response = controller.getGeneOrthology("MGI:109583", null, null, "stringENT", null, null, 20, 1);
JsonResultResponse<GeneToGeneOrthologyDocument> response = controller.getGeneOrthology("MGI:109583", null, null, "stringENT", null, null, 20, 1);
assertThat("Matches found for containsFilterValue 'stringent", response.getTotal(), greaterThan(0));
}

Expand All @@ -122,7 +123,7 @@ public void checkOrthologyForSingleSpecies() throws IOException {
public void checkOrthologyAPIWithSpecies() {

GeneController controller = new GeneController();
JsonResultResponse<HomologView> response = controller.getGeneOrthology("MGI:109583", null, null, "stringent", null, null, 20, 1);
JsonResultResponse<GeneToGeneOrthologyDocument> response = controller.getGeneOrthology("MGI:109583", null, null, "stringent", null, null, 20, 1);
assertThat("No matches found for species 'NCBITaxon:10115", response.getTotal(), greaterThan(5));

String taxonArray = "NCBITaxon:10116";
Expand All @@ -147,7 +148,7 @@ public void checkOrthologyAPIWithMethods() {

GeneController controller = new GeneController();
String methods = "ZFIN";
JsonResultResponse<HomologView> response = controller.getGeneOrthology("MGI:109583", null, null, null, null, methods, 20, 1);
JsonResultResponse<GeneToGeneOrthologyDocument> response = controller.getGeneOrthology("MGI:109583", null, null, null, null, methods, 20, 1);
assertThat("No match against method 'ZFIN'", response.getTotal(), greaterThan(0));

methods = "OrthoFinder";
Expand All @@ -167,7 +168,7 @@ public void checkOrthologyAPIWithMethods() {
public void checkOrthologyAPINoFilters() {

GeneController controller = new GeneController();
JsonResultResponse<HomologView> response = controller.getGeneOrthology("MGI:109583", null, null, null, null, null, 20, 1);
JsonResultResponse<GeneToGeneOrthologyDocument> response = controller.getGeneOrthology("MGI:109583", null, null, null, null, null, 20, 1);
assertThat("matches found for gene MGI:109583'", response.getTotal(), greaterThan(0));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.alliancegenome.indexer.indexers.curation.GeneToGeneParalogyIndexer;
import org.alliancegenome.indexer.indexers.curation.PhenotypeAnnotationCurationIndexer;
import org.alliancegenome.indexer.indexers.curation.ReleaseInfoIndexer;
import org.alliancegenome.indexer.indexers.curation.GeneToGeneOrthologyIndexer;

public enum IndexerConfig {

Expand All @@ -32,6 +33,7 @@ public enum IndexerConfig {
ParalogyIndexer("paralogy", GeneToGeneParalogyIndexer.class, 4, 5000, 5000, 8, 1),
PhenotypeAnnotationIndexer("phenotypeAnnotation", PhenotypeAnnotationCurationIndexer.class, 4, 1500, 1500, 2, 1),
ReleaseInfoIndexer("release", ReleaseInfoIndexer.class, 1, 1, 1, 1, 1),
GeneToGeneOrthologyIndexer("geneToGeneOrthology", GeneToGeneOrthologyIndexer.class, 4, 1426, 1426, 8, 1)
;


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
package org.alliancegenome.indexer.indexers.curation;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.LinkedBlockingDeque;

import org.alliancegenome.api.entity.GeneToGeneOrthologyDocument;
import org.alliancegenome.curation_api.model.entities.Gene;
import org.alliancegenome.curation_api.model.entities.orthology.GeneToGeneOrthologyGenerated;
import org.alliancegenome.curation_api.response.SearchResponse;
import org.alliancegenome.indexer.RestConfig;
import org.alliancegenome.indexer.config.IndexerConfig;
import org.alliancegenome.indexer.indexers.Indexer;
import org.alliancegenome.indexer.indexers.curation.service.GeneToGeneOrthologyService;
import org.apache.commons.collections4.CollectionUtils;

import com.fasterxml.jackson.databind.ObjectMapper;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class GeneToGeneOrthologyIndexer extends Indexer {

private GeneToGeneOrthologyService service = new GeneToGeneOrthologyService();

public GeneToGeneOrthologyIndexer(IndexerConfig config) {
super(config);
}

@Override
public void index() {
try {
log.info("Getting orthologs");

SearchResponse<GeneToGeneOrthologyGenerated> orthologyResponse = service.getGeneToGeneOrthology(0, 0);

log.info("GeneToGeneParalogy count: " + orthologyResponse.getTotalResults());

int totalPages = (int) (orthologyResponse.getTotalResults() / indexerConfig.getBufferSize());

LinkedBlockingDeque<String> queue = new LinkedBlockingDeque<>();
for (int i = 0; i <= totalPages; i++) {
queue.add(String.valueOf(i));
}

initiateThreading(queue);

} catch (Exception e) {
e.printStackTrace();
}

}

@Override
protected ObjectMapper customizeObjectMapper(ObjectMapper objectMapper) {
return RestConfig.config.getJacksonObjectMapperFactory().createObjectMapper();
}

protected void startSingleThread(LinkedBlockingDeque<String> queue) {
while (true) {
try {
if (queue.isEmpty()) {
return;
}
String page = queue.takeFirst();
SearchResponse<GeneToGeneOrthologyGenerated> resp = service
.getGeneToGeneOrthology(Integer.valueOf(page), indexerConfig.getBufferSize());
List<GeneToGeneOrthologyDocument> docs = createGeneToGeneOrthologyDocuments(resp.getResults());

indexDocuments(docs);
} catch (Exception e) {
log.error("Error while indexing...", e);
System.exit(-1);
return;
}
}
}

private List<GeneToGeneOrthologyDocument> createGeneToGeneOrthologyDocuments(
List<GeneToGeneOrthologyGenerated> g2gOrthoList) {
List<GeneToGeneOrthologyDocument> documents = new ArrayList<>();
for (GeneToGeneOrthologyGenerated g2gOrtho : g2gOrthoList) {
GeneToGeneOrthologyDocument document = new GeneToGeneOrthologyDocument();

document.setGeneToGeneOrthologyGenerated(g2gOrtho);
createStringencyFilter(g2gOrtho, document);
createGeneAnnotations(g2gOrtho, document);
removeAnnotationLists(document);

documents.add(document);
}
return documents;
}

private void createStringencyFilter(GeneToGeneOrthologyGenerated g2gOrtho, GeneToGeneOrthologyDocument document) {
if (Boolean.TRUE.equals(g2gOrtho.getStrictFilter())) {
document.setStringencyFilter("stringent");
} else if (Boolean.TRUE.equals(g2gOrtho.getModerateFilter())) {
document.setStringencyFilter("moderate");
}
}

private void createGeneAnnotations(GeneToGeneOrthologyGenerated g2gOrtho, GeneToGeneOrthologyDocument document) {
Map<String, Object> map = new HashMap<>();
putGeneInfo(map, g2gOrtho.getSubjectGene());
putGeneInfo(map, g2gOrtho.getObjectGene());
document.setGeneAnnotations(map);
}

private void putGeneInfo(Map<String, Object> map, Gene gene) {
Map<String, Object> data = new HashMap<>();
data.put("hasExpressionAnnotations", hasExpressionAnnotations(gene));
data.put("hasDiseaseAnnotations", hasDiseaseAnnotations(gene));
map.put(gene.getIdentifier(), data);
}

private boolean hasDiseaseAnnotations(Gene gene) {
return CollectionUtils.isNotEmpty(gene.getGeneDiseaseAnnotations());
}

private boolean hasExpressionAnnotations(Gene gene) {
return CollectionUtils.isNotEmpty(gene.getGeneExpressionAnnotations());
}

private void removeAnnotationLists(GeneToGeneOrthologyDocument document) {
document.getGeneToGeneOrthologyGenerated().getSubjectGene().setGeneDiseaseAnnotations(null);
document.getGeneToGeneOrthologyGenerated().getSubjectGene().setGeneExpressionAnnotations(null);
document.getGeneToGeneOrthologyGenerated().getObjectGene().setGeneDiseaseAnnotations(null);
document.getGeneToGeneOrthologyGenerated().getObjectGene().setGeneExpressionAnnotations(null);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,12 @@ SearchResponse<GeneToGeneOrthologyGenerated> findForPublic(
@DefaultValue("0") @QueryParam("page") Integer page,
@DefaultValue("10") @QueryParam("limit") Integer limit,
HashMap<String, Object> params);

@POST
@Path("/findForPublic")
SearchResponse<GeneToGeneOrthologyGenerated> findForPublic(
@DefaultValue("0") @QueryParam("page") Integer page,
@DefaultValue("10") @QueryParam("limit") Integer limit,
@DefaultValue("ForPublic") @QueryParam("view") String view,
HashMap<String, Object> params);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package org.alliancegenome.indexer.indexers.curation.service;

import java.util.HashMap;

import org.alliancegenome.core.config.ConfigHelper;
import org.alliancegenome.curation_api.model.entities.orthology.GeneToGeneOrthologyGenerated;
import org.alliancegenome.curation_api.response.SearchResponse;
import org.alliancegenome.indexer.RestConfig;
import org.alliancegenome.indexer.indexers.curation.interfaces.GeneToGeneOrthologyGeneratedInterface;

import si.mazi.rescu.RestProxyFactory;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class GeneToGeneOrthologyService {
private final GeneToGeneOrthologyGeneratedInterface orthologyApi = RestProxyFactory.createProxy(GeneToGeneOrthologyGeneratedInterface.class, ConfigHelper.getCurationApiUrl(), RestConfig.config);

public SearchResponse<GeneToGeneOrthologyGenerated> getGeneToGeneOrthology(Integer page, Integer limit) {

HashMap<String, Object> params = new HashMap<>();
params.put("internal", false);
params.put("obsolete", false);

return orthologyApi.findForPublic(page, limit, "GeneToGeneOrthologyForIndexer", params);
}
}
Loading
Loading