Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SCRUM-4447 Add gene/phenotypes xrefs #1748

Merged
merged 1 commit into from
Dec 5, 2024
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 @@ -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
Loading