Skip to content

Commit

Permalink
Merge pull request #1748 from alliance-genome/SCRUM-4447
Browse files Browse the repository at this point in the history
SCRUM-4447 Add gene/phenotypes xrefs
  • Loading branch information
markquintontulloch authored Dec 5, 2024
2 parents 4037159 + fcf17ed commit de97af9
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ public List<CrossReference> getMergedFmsXrefList(List<CrossReferenceFmsDTO> fmsC

@Transactional
public List<CrossReference> getUpdatedXrefList(List<CrossReference> incomingXrefs, List<CrossReference> existingXrefs) {
return getUpdatedXrefList(incomingXrefs, existingXrefs, false);
}

@Transactional
public List<CrossReference> getUpdatedXrefList(List<CrossReference> incomingXrefs, List<CrossReference> existingXrefs, Boolean keepAllExisting) {
Map<String, CrossReference> existingXrefMap = new HashMap<>();
if (CollectionUtils.isNotEmpty(existingXrefs)) {
for (CrossReference existingXref : existingXrefs) {
Expand All @@ -71,6 +76,11 @@ public List<CrossReference> getUpdatedXrefList(List<CrossReference> incomingXref

List<CrossReference> finalXrefs = new ArrayList<>();
List<String> addedXrefUniqueIds = new ArrayList<>();

if (keepAllExisting && CollectionUtils.isNotEmpty(existingXrefs)) {
incomingXrefs.addAll(existingXrefs);
}

if (CollectionUtils.isNotEmpty(incomingXrefs)) {
for (CrossReference incomingXref : incomingXrefs) {
String incomingXrefUniqueId = getCrossReferenceUniqueId(incomingXref);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ protected <D extends BaseSQLDAO<?>> List<Long> getAnnotationIdsByDataProvider(D
return annotationIds;
}

@Transactional
public Long upsertPrimaryAnnotation(PhenotypeFmsDTO dto, BackendBulkDataProvider dataProvider) throws ValidationException {
if (StringUtils.isBlank(dto.getObjectId())) {
throw new ObjectValidationException(dto, "objectId - " + ValidationConstants.REQUIRED_MESSAGE);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package org.alliancegenome.curation_api.services.helpers.annotations;

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

import org.alliancegenome.curation_api.dao.GeneDAO;
import org.alliancegenome.curation_api.enums.BackendBulkDataProvider;
import org.alliancegenome.curation_api.model.entities.CrossReference;
import org.alliancegenome.curation_api.model.entities.Gene;
import org.alliancegenome.curation_api.model.entities.ResourceDescriptorPage;
import org.alliancegenome.curation_api.services.CrossReferenceService;
import org.alliancegenome.curation_api.services.ResourceDescriptorPageService;

import jakarta.enterprise.context.RequestScoped;
import jakarta.inject.Inject;
import jakarta.transaction.Transactional;

@RequestScoped
public class GenePhenotypeAnnotationXrefHelper {

@Inject ResourceDescriptorPageService rdpService;
@Inject CrossReferenceService xrefService;
@Inject GeneDAO geneDAO;

@Transactional
public Gene addGenePhenotypeCrossReference(BackendBulkDataProvider dataProvider, Gene gene) {

if (Objects.equals("HUMAN", dataProvider.name()) || gene.getIdentifier().startsWith("HGNC:")) {
return gene;
}

CrossReference xref = new CrossReference();

String[] geneCurieParts = gene.getIdentifier().split(":");
String prefix = geneCurieParts[0];
String pageName = Objects.equals("MGI", prefix) ? "gene_phenotypes_impc" : "gene/phenotypes";

ResourceDescriptorPage rdp = rdpService.getPageForResourceDescriptor(prefix, pageName);
xref.setDisplayName(prefix);
xref.setReferencedCurie(gene.getIdentifier());
xref.setResourceDescriptorPage(rdp);

List<CrossReference> updatedXrefs = xrefService.getUpdatedXrefList(List.of(xref), gene.getCrossReferences());

if (gene.getCrossReferences() != null) {
gene.getCrossReferences().clear();
}
if (updatedXrefs != null) {
if (gene.getCrossReferences() == null) {
gene.setCrossReferences(new ArrayList<>());
}
gene.getCrossReferences().addAll(updatedXrefs);
}

return geneDAO.persist(gene);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.alliancegenome.curation_api.services.GenomicEntityService;
import org.alliancegenome.curation_api.services.PhenotypeAnnotationService;
import org.alliancegenome.curation_api.services.helpers.annotations.AnnotationUniqueIdHelper;
import org.alliancegenome.curation_api.services.helpers.annotations.GenePhenotypeAnnotationXrefHelper;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;

Expand All @@ -33,6 +34,7 @@ public class AGMPhenotypeAnnotationFmsDTOValidator extends PhenotypeAnnotationFm
@Inject AGMPhenotypeAnnotationDAO agmPhenotypeAnnotationDAO;
@Inject GenomicEntityService genomicEntityService;
@Inject PhenotypeAnnotationService phenotypeAnnotationService;
@Inject GenePhenotypeAnnotationXrefHelper xrefHelper;

public AGMPhenotypeAnnotation validatePrimaryAnnotation(AffectedGenomicModel subject, PhenotypeFmsDTO dto, BackendBulkDataProvider dataProvider) throws ObjectValidationException {

Expand Down Expand Up @@ -104,15 +106,16 @@ public List<AGMPhenotypeAnnotation> validateInferredOrAssertedEntities(AffectedG
if (inferredOrAssertedEntity == null) {
apaResponse.addErrorMessage("objectId", ValidationConstants.INVALID_MESSAGE + " (" + dto.getObjectId() + ")");
} else if (inferredOrAssertedEntity instanceof Gene) {
Gene inferredOrAssertedGene = xrefHelper.addGenePhenotypeCrossReference(dataProvider, (Gene) inferredOrAssertedEntity);
for (AGMPhenotypeAnnotation primaryAnnotation : primaryAnnotations) {
if (dataProvider.hasInferredGenePhenotypeAnnotations) {
primaryAnnotation.setInferredGene((Gene) inferredOrAssertedEntity);
primaryAnnotation.setInferredGene(inferredOrAssertedGene);
} else if (dataProvider.hasAssertedGenePhenotypeAnnotations) {
List<Gene> assertedGenes = primaryAnnotation.getAssertedGenes();
if (assertedGenes == null) {
assertedGenes = new ArrayList<>();
}
assertedGenes.add((Gene) inferredOrAssertedEntity);
assertedGenes.add(inferredOrAssertedGene);
primaryAnnotation.setAssertedGenes(assertedGenes);
} else {
apaResponse.addErrorMessage("objectId", ValidationConstants.INVALID_MESSAGE + " (" + dto.getObjectId() + ")");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.alliancegenome.curation_api.services.GenomicEntityService;
import org.alliancegenome.curation_api.services.PhenotypeAnnotationService;
import org.alliancegenome.curation_api.services.helpers.annotations.AnnotationUniqueIdHelper;
import org.alliancegenome.curation_api.services.helpers.annotations.GenePhenotypeAnnotationXrefHelper;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;

Expand All @@ -32,6 +33,7 @@ public class AllelePhenotypeAnnotationFmsDTOValidator extends PhenotypeAnnotatio
@Inject AllelePhenotypeAnnotationDAO allelePhenotypeAnnotationDAO;
@Inject GenomicEntityService genomicEntityService;
@Inject PhenotypeAnnotationService phenotypeAnnotationService;
@Inject GenePhenotypeAnnotationXrefHelper xrefHelper;

public AllelePhenotypeAnnotation validatePrimaryAnnotation(Allele subject, PhenotypeFmsDTO dto, BackendBulkDataProvider dataProvider) throws ObjectValidationException {

Expand Down Expand Up @@ -102,15 +104,16 @@ public List<AllelePhenotypeAnnotation> validateInferredOrAssertedEntities(Allele
if (inferredOrAssertedEntity == null) {
apaResponse.addErrorMessage("objectId", ValidationConstants.INVALID_MESSAGE + " (" + dto.getObjectId() + ")");
} else if (inferredOrAssertedEntity instanceof Gene) {
Gene inferredOrAssertedGene = xrefHelper.addGenePhenotypeCrossReference(dataProvider, (Gene) inferredOrAssertedEntity);
for (AllelePhenotypeAnnotation primaryAnnotation : primaryAnnotations) {
if (dataProvider.hasInferredGenePhenotypeAnnotations) {
primaryAnnotation.setInferredGene((Gene) inferredOrAssertedEntity);
primaryAnnotation.setInferredGene(inferredOrAssertedGene);
} else if (dataProvider.hasAssertedGenePhenotypeAnnotations) {
List<Gene> assertedGenes = primaryAnnotation.getAssertedGenes();
if (assertedGenes == null) {
assertedGenes = new ArrayList<>();
}
assertedGenes.add((Gene) inferredOrAssertedEntity);
assertedGenes.add(inferredOrAssertedGene);
primaryAnnotation.setAssertedGenes(assertedGenes);
} else {
apaResponse.addErrorMessage("objectId", ValidationConstants.INVALID_MESSAGE + " (" + dto.getObjectId() + ")");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,21 @@
import org.alliancegenome.curation_api.services.GenomicEntityService;
import org.alliancegenome.curation_api.services.PhenotypeAnnotationService;
import org.alliancegenome.curation_api.services.helpers.annotations.AnnotationUniqueIdHelper;
import org.alliancegenome.curation_api.services.helpers.annotations.GenePhenotypeAnnotationXrefHelper;

import jakarta.enterprise.context.RequestScoped;
import jakarta.inject.Inject;
import jakarta.transaction.Transactional;

@RequestScoped
public class GenePhenotypeAnnotationFmsDTOValidator extends PhenotypeAnnotationFmsDTOValidator {

@Inject GenePhenotypeAnnotationDAO genePhenotypeAnnotationDAO;
@Inject GenomicEntityService genomicEntityService;
@Inject PhenotypeAnnotationService phenotypeAnnotationService;

@Inject GenePhenotypeAnnotationXrefHelper xrefHelper;

@Transactional
public GenePhenotypeAnnotation validatePrimaryAnnotation(Gene subject, PhenotypeFmsDTO dto, BackendBulkDataProvider dataProvider) throws ValidationException {

ObjectResponse<GenePhenotypeAnnotation> apaResponse = new ObjectResponse<GenePhenotypeAnnotation>();
Expand All @@ -41,6 +45,8 @@ public GenePhenotypeAnnotation validatePrimaryAnnotation(Gene subject, Phenotype
annotation = annotationSearch.getSingleResult();
}

subject = xrefHelper.addGenePhenotypeCrossReference(dataProvider, subject);

annotation.setUniqueId(uniqueId);
annotation.setSingleReference(reference);
annotation.setPhenotypeAnnotationSubject(subject);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ private void loadRequiredEntities() throws Exception {
createMpTerm(mpTerm, "Test PhenotypeTerm");
ResourceDescriptor rd = createResourceDescriptor("PMID");
createResourceDescriptorPage("default", "https://www.ncbi.nlm.nih.gov/pubmed/[%s]", rd);
ResourceDescriptor rd2 = createResourceDescriptor("PATEST");
createResourceDescriptorPage("gene/phenotypes", "https://xref_url_test/[%s]", rd2);
}

@Test
Expand Down Expand Up @@ -198,6 +200,16 @@ public void genePhenotypeAnnotationBulkUploadCheckFields() throws Exception {
.body("results[0].crossReference.displayName", is("PMID:25920554"))
.body("results[0].phenotypeTerms", hasSize(1))
.body("results[0].phenotypeTerms[0].curie", is(mpTerm));

RestAssured.given().when().get("/api/gene/" + gene).
then().
statusCode(200).
body("entity.modEntityId", is(gene)).
body("entity.crossReferences", hasSize(1)).
body("entity.crossReferences[0].displayName", is("PATEST")).
body("entity.crossReferences[0].referencedCurie", is(gene)).
body("entity.crossReferences[0].resourceDescriptorPage.name", is("gene/phenotypes")).
body("entity.crossReferences[0].resourceDescriptorPage.urlTemplate", is("https://xref_url_test/[%s]"));
}

@Test
Expand Down

0 comments on commit de97af9

Please sign in to comment.