Search in sources :

Example 36 with AnnotationEvidence

use of org.nextprot.api.core.domain.annotation.AnnotationEvidence in project nextprot-api by calipho-sib.

the class StatementAnnotationBuilder method buildAnnotationList.

public List<T> buildAnnotationList(String isoformName, List<Statement> flatStatements) {
    List<T> annotations = new ArrayList<>();
    Map<String, List<Statement>> flatStatementsByAnnotationHash = flatStatements.stream().collect(Collectors.groupingBy(rs -> rs.getValue(StatementField.ANNOTATION_ID)));
    flatStatementsByAnnotationHash.forEach((key, statements) -> {
        T annotation = get();
        Statement firstStatement = statements.get(0);
        annotation.setAnnotationHash(firstStatement.getValue(StatementField.ANNOTATION_ID));
        // annotation.setAnnotationName(firstStatement.getValue(StatementField.ANNOTATION_NAME));
        AnnotationCategory category = AnnotationCategory.getDecamelizedAnnotationTypeName(StringUtils.camelToKebabCase(firstStatement.getValue(StatementField.ANNOTATION_CATEGORY)));
        annotation.setAnnotationCategory(category);
        if (category.equals(AnnotationCategory.VARIANT) || category.equals(AnnotationCategory.MUTAGENESIS)) {
            setVariantAttributes(annotation, firstStatement);
        }
        setIsoformTargeting(annotation, firstStatement);
        setIsoformName(annotation, isoformName);
        annotation.setDescription(firstStatement.getValue(StatementField.ANNOT_DESCRIPTION));
        String cvTermAccession = firstStatement.getValue(StatementField.ANNOT_CV_TERM_ACCESSION);
        // Set the evidences if not Mammalian phenotype or Protein Property https://issues.isb-sib.ch/browse/BIOEDITOR-466
        if (!ANNOT_CATEGORIES_WITHOUT_EVIDENCES.contains(category)) {
            annotation.setEvidences(buildAnnotationEvidences(statements));
            // TODO Remove this when you are able to do XREFs
            if (((annotation.getEvidences() == null) || ((annotation.getEvidences().isEmpty()))) && (category.equals(AnnotationCategory.VARIANT) || category.equals(AnnotationCategory.MUTAGENESIS))) {
                // All variants from BED are GOLD, and this is a special case when we don't have evidences for VDs.
                annotation.setQualityQualifier("GOLD");
            } else {
                annotation.setQualityQualifier(AnnotationUtils.computeAnnotationQualityBasedOnEvidences(annotation.getEvidences()).name());
            }
        } else {
            // Case of Protein propert and mammalian phenotypes
            annotation.setEvidences(new ArrayList<AnnotationEvidence>());
            boolean foundGold = statements.stream().anyMatch(s -> s.getValue(StatementField.EVIDENCE_QUALITY).equalsIgnoreCase("GOLD"));
            if (foundGold) {
                annotation.setQualityQualifier("GOLD");
            } else {
                annotation.setQualityQualifier("SILVER");
            }
        }
        if (cvTermAccession != null && !cvTermAccession.isEmpty()) {
            annotation.setCvTermAccessionCode(cvTermAccession);
            CvTerm cvTerm = terminologyService.findCvTermByAccession(cvTermAccession);
            if (cvTerm != null) {
                annotation.setCvTermName(cvTerm.getName());
                annotation.setCvApiName(cvTerm.getOntology());
                annotation.setCvTermDescription(cvTerm.getDescription());
                if (category.equals(AnnotationCategory.PROTEIN_PROPERTY)) {
                    // according to https://issues.isb-sib.ch/browse/BIOEDITOR-466
                    annotation.setDescription(cvTerm.getDescription());
                } else if (category.equals(AnnotationCategory.MAMMALIAN_PHENOTYPE)) {
                    annotation.setDescription("Relative to modification-effect annotations");
                }
            } else {
                LOGGER.error("cv term was expected to be found " + cvTermAccession);
                annotation.setCvTermName(firstStatement.getValue(StatementField.ANNOT_CV_TERM_NAME));
                annotation.setCvApiName(firstStatement.getValue(StatementField.ANNOT_CV_TERM_TERMINOLOGY));
            }
        }
        annotation.setAnnotationHash(firstStatement.getValue(StatementField.ANNOTATION_ID));
        annotation.setAnnotationName(firstStatement.getValue(StatementField.ANNOTATION_NAME));
        // Check this with PAM (does it need to be a human readable stuff)
        // Does it need a name?
        annotation.setUniqueName(firstStatement.getValue(StatementField.ANNOTATION_ID));
        String bioObjectAnnotationHash = firstStatement.getValue(StatementField.OBJECT_ANNOTATION_IDS);
        String bioObjectAccession = firstStatement.getValue(StatementField.BIOLOGICAL_OBJECT_ACCESSION);
        String bot = firstStatement.getValue(StatementField.BIOLOGICAL_OBJECT_TYPE);
        if ((bioObjectAnnotationHash != null) && (bioObjectAnnotationHash.length() > 0) || (bioObjectAccession != null && (bioObjectAccession.length() > 0))) {
            BioObject bioObject;
            if (AnnotationCategory.BINARY_INTERACTION.equals(annotation.getAPICategory())) {
                if (bioObjectAccession.startsWith("NX_") && BioType.PROTEIN.name().equalsIgnoreCase(bot)) {
                    // note that if we handle BioType.PROTEIN_ISOFORM in the future, we should
                    // add the property isoformName as well, see how it's done in BinaryInteraction2Annotation.newBioObject()
                    bioObject = BioObject.internal(BioType.PROTEIN);
                    // // TODO: REMOVE THIS HACK WHEN ISSUE https://issues.isb-sib.ch/browse/NEXTPROT-1513 will be fixed
                    // // NX_P62158 was split in 3 accessions: NX_P0DP23/CALM1, NX_P0DP24/CALM2 and NX_P0DP25/CALM3
                    // // BEGIN DIRTY HACK
                    /*
                        if (bioObjectAccession.equals("NX_P62158")) {
                            switch (isoformName) {
                                case "NX_P35499":
                                    bioObjectAccession = "NX_P0DP23";
                                    break;
                                case "NX_Q99250":
                                    bioObjectAccession = "NX_P0DP23";
                                    break;
                                case "NX_Q9UQD0":
                                    bioObjectAccession = "NX_P0DP23";
                                    break;
                                case "NX_Q9Y5Y9":
                                    bioObjectAccession = "NX_P0DP23";
                                    break;
                            }
                        }
                        */
                    // /// END OF HACK
                    bioObject.setAccession(bioObjectAccession);
                    bioObject.putPropertyNameValue("geneName", firstStatement.getValue(StatementField.BIOLOGICAL_OBJECT_NAME));
                    String proteinName = mainNamesService.findIsoformOrEntryMainName(bioObjectAccession).orElseThrow(() -> new NextProtException("Cannot create a binary interaction with " + isoformName + ": unknown protein accession " + bioObject.getAccession())).getName();
                    bioObject.putPropertyNameValue("proteinName", proteinName);
                    bioObject.putPropertyNameValue("url", "https://www.nextprot.org/entry/" + bioObjectAccession + "/interactions");
                } else {
                    throw new NextProtException("Binary Interaction only expects to be a nextprot entry NX_ and found " + bioObjectAccession + " with type " + bot);
                }
            } else if (AnnotationCategory.PHENOTYPIC_VARIATION.equals(annotation.getAPICategory())) {
                bioObject = BioObject.internal(BioType.ENTRY_ANNOTATION);
                bioObject.setAnnotationHash(bioObjectAnnotationHash);
            } else {
                throw new NextProtException("Category not expected for bioobject " + annotation.getAPICategory());
            }
            annotation.setBioObject(bioObject);
        }
        annotations.add(annotation);
    });
    return annotations;
}
Also used : java.util(java.util) Supplier(com.google.common.base.Supplier) Annotation(org.nextprot.api.core.domain.annotation.Annotation) NextProtException(org.nextprot.api.commons.exception.NextProtException) StringUtils(org.nextprot.api.commons.utils.StringUtils) CvTerm(org.nextprot.api.core.domain.CvTerm) StatementField(org.nextprot.commons.statements.StatementField) Collectors(java.util.stream.Collectors) Statement(org.nextprot.commons.statements.Statement) BioType(org.nextprot.api.core.domain.BioObject.BioType) AnnotationEvidence(org.nextprot.api.core.domain.annotation.AnnotationEvidence) Logger(org.apache.log4j.Logger) Publication(org.nextprot.api.core.domain.Publication) AnnotationCategory(org.nextprot.api.commons.constants.AnnotationCategory) AnnotationUtils(org.nextprot.api.core.service.annotation.AnnotationUtils) AnnotationEvidenceProperty(org.nextprot.api.core.domain.annotation.AnnotationEvidenceProperty) IdentifierOffset(org.nextprot.api.commons.constants.IdentifierOffset) BioObject(org.nextprot.api.core.domain.BioObject) AnnotationVariant(org.nextprot.api.core.domain.annotation.AnnotationVariant) CvTerm(org.nextprot.api.core.domain.CvTerm) Statement(org.nextprot.commons.statements.Statement) AnnotationCategory(org.nextprot.api.commons.constants.AnnotationCategory) AnnotationEvidence(org.nextprot.api.core.domain.annotation.AnnotationEvidence) NextProtException(org.nextprot.api.commons.exception.NextProtException) BioObject(org.nextprot.api.core.domain.BioObject)

Example 37 with AnnotationEvidence

use of org.nextprot.api.core.domain.annotation.AnnotationEvidence in project nextprot-api by calipho-sib.

the class AnnotationUtils method convertRelativeEvidenceToExternalChemicalBioObject.

private static List<AnnotationEvidence> convertRelativeEvidenceToExternalChemicalBioObject(Annotation annot) {
    List<AnnotationEvidence> toRemove = new ArrayList<>();
    for (AnnotationEvidence evi : annot.getEvidences()) {
        if ("relative".equals(evi.getResourceAssociationType())) {
            annot.setBioObject(newExternalChemicalBioObject(evi));
            toRemove.add(evi);
        }
    }
    return toRemove;
}
Also used : AnnotationEvidence(org.nextprot.api.core.domain.annotation.AnnotationEvidence)

Example 38 with AnnotationEvidence

use of org.nextprot.api.core.domain.annotation.AnnotationEvidence in project nextprot-api by calipho-sib.

the class AnnotationUtils method filterAnnotationsByCategory.

/**
 * Filter annotation by its category
 * @param withChildren if true, annotations having a category which is a child of annotationCategory are included in the list
 * @return a list of annotations
 */
public static List<Annotation> filterAnnotationsByCategory(List<Annotation> annotations, AnnotationCategory annotationCategory, boolean withChildren, boolean goldOnly) {
    if (annotations == null)
        return null;
    List<Annotation> filteredAnnotations = annotations.stream().filter((a) -> {
        boolean categoryMatch = (annotationCategory == null) || ((a.getAPICategory() == annotationCategory) || (withChildren && a.getAPICategory().isChildOf(annotationCategory)));
        boolean qualityMatch = true;
        if (goldOnly) {
            qualityMatch = "GOLD".equalsIgnoreCase(a.getQualityQualifier());
        }
        return categoryMatch && qualityMatch;
    }).collect(Collectors.toList());
    if (goldOnly) {
        for (Annotation a : filteredAnnotations) {
            List<AnnotationEvidence> evidences = a.getEvidences();
            List<AnnotationEvidence> goldEvidences = evidences.stream().filter(e -> "GOLD".equalsIgnoreCase(e.getQualityQualifier()) || (e.getQualityQualifier() == null) || e.getQualityQualifier().isEmpty()).collect(Collectors.toList());
            // TODO check if this mutable annotation is not breaken in eh cache!!
            a.setEvidences(goldEvidences);
        }
    }
    if (annotationCategory == AnnotationCategory.PHENOTYPIC_VARIATION) {
        Collections.sort(filteredAnnotations, AnnotationComparators.newPhenotypicVariationComparator(EntryUtils.getHashAnnotationMap(annotations)));
    } else {
        Collections.sort(filteredAnnotations, AnnotationComparators.newComparator(annotationCategory));
    }
    return filteredAnnotations;
}
Also used : ExperimentalContext(org.nextprot.api.core.domain.ExperimentalContext) java.util(java.util) Entry(org.nextprot.api.core.domain.Entry) Annotation(org.nextprot.api.core.domain.annotation.Annotation) AnnotationListMapReduceMerger(org.nextprot.api.core.service.annotation.merge.impl.AnnotationListMapReduceMerger) NextProtException(org.nextprot.api.commons.exception.NextProtException) QualityQualifier(org.nextprot.commons.constants.QualityQualifier) AnnotationListMergerImpl(org.nextprot.api.core.service.annotation.merge.impl.AnnotationListMergerImpl) PropertyApiModel(org.nextprot.api.commons.constants.PropertyApiModel) CvTerm(org.nextprot.api.core.domain.CvTerm) Collectors(java.util.stream.Collectors) AnnotationEvidence(org.nextprot.api.core.domain.annotation.AnnotationEvidence) AnnotationComparators(org.nextprot.api.core.service.annotation.comp.AnnotationComparators) AnnotationIsoformSpecificity(org.nextprot.api.core.domain.annotation.AnnotationIsoformSpecificity) AnnotationCategory(org.nextprot.api.commons.constants.AnnotationCategory) BioObject(org.nextprot.api.core.domain.BioObject) AnnotationProperty(org.nextprot.api.core.domain.annotation.AnnotationProperty) EntryUtils(org.nextprot.api.core.utils.EntryUtils) AnnotationEvidence(org.nextprot.api.core.domain.annotation.AnnotationEvidence) Annotation(org.nextprot.api.core.domain.annotation.Annotation)

Example 39 with AnnotationEvidence

use of org.nextprot.api.core.domain.annotation.AnnotationEvidence in project nextprot-api by calipho-sib.

the class EntryPartExporterImpl method collectRows.

/*
    protected List<Row> sortRows(List<Row> rows, Comparator<Row> comparator) {
    	return rows.stream().sorted(comparator).collect(Collectors.toList());
    }
    */
private void collectRows(List<Row> rows, Entry entry, Annotation annotation) {
    for (AnnotationEvidence evidence : annotation.getEvidences()) {
        Row row = new Row(headerList.size());
        setRowValue(row, ENTRY_ACCESSION, entry.getUniqueName());
        setRowValue(row, CATEGORY, StringUtils.camelToKebabCase(annotation.getApiTypeName()));
        setRowValue(row, TERM_ACCESSION, annotation.getCvTermAccessionCode());
        setRowValue(row, TERM_NAME, annotation.getCvTermName());
        setRowValue(row, ECO_ACCESSION, evidence.getEvidenceCodeAC());
        setRowValue(row, ECO_NAME, evidence.getEvidenceCodeName());
        setRowValue(row, QUALITY, evidence.getQualityQualifier());
        setRowValue(row, NEGATIVE, String.valueOf(evidence.isNegativeEvidence()));
        setRowValue(row, EXPRESSION_LEVEL, evidence.getExpressionLevel());
        setRowValue(row, SOURCE, evidence.getAssignedBy());
        setRowValue(row, URL, entry.getXref(evidence.getResourceId()).map(DbXref::getResolvedUrl).orElse("null"));
        setExperimentalContextRowValues(row, entry, evidence);
        rows.add(row);
    }
}
Also used : AnnotationEvidence(org.nextprot.api.core.domain.annotation.AnnotationEvidence) DbXref(org.nextprot.api.core.domain.DbXref)

Aggregations

AnnotationEvidence (org.nextprot.api.core.domain.annotation.AnnotationEvidence)39 Annotation (org.nextprot.api.core.domain.annotation.Annotation)28 Test (org.junit.Test)23 ArrayList (java.util.ArrayList)16 CoreUnitBaseTest (org.nextprot.api.core.test.base.CoreUnitBaseTest)11 AnnotationIsoformSpecificity (org.nextprot.api.core.domain.annotation.AnnotationIsoformSpecificity)7 CvTerm (org.nextprot.api.core.domain.CvTerm)6 AnnotationCategory (org.nextprot.api.commons.constants.AnnotationCategory)5 Collectors (java.util.stream.Collectors)4 BioObject (org.nextprot.api.core.domain.BioObject)4 java.util (java.util)3 List (java.util.List)3 NextProtException (org.nextprot.api.commons.exception.NextProtException)3 DbXref (org.nextprot.api.core.domain.DbXref)3 AnnotationEvidenceProperty (org.nextprot.api.core.domain.annotation.AnnotationEvidenceProperty)3 AnnotationProperty (org.nextprot.api.core.domain.annotation.AnnotationProperty)3 Supplier (com.google.common.base.Supplier)2 Logger (org.apache.log4j.Logger)2 IdentifierOffset (org.nextprot.api.commons.constants.IdentifierOffset)2 StringUtils (org.nextprot.api.commons.utils.StringUtils)2