Search in sources :

Example 11 with Statement

use of org.nextprot.commons.statements.Statement in project nextprot-api by calipho-sib.

the class StatementTransformUnitTest method rawStatementsShouldBeWellConvertedToMappedStatements.

@Test
public void rawStatementsShouldBeWellConvertedToMappedStatements() {
    StatementsExtractorLocalMockImpl sle = new StatementsExtractorLocalMockImpl();
    Set<Statement> rawStatements = sle.getStatementsForSourceForGeneNameAndEnvironment(null, null, "msh2-multiple-mutant");
    Set<Statement> mappedStatements = statementETLServiceMocked.transformStatements(rawStatements, new ReportBuilder());
    int statementsCount = rawStatements.stream().map(s -> s.getValue(StatementField.STATEMENT_ID)).distinct().collect(Collectors.toList()).size();
    int annotationsCount = mappedStatements.stream().map(s -> s.getValue(StatementField.ANNOTATION_ID)).distinct().collect(Collectors.toList()).size();
    assertEquals(5, statementsCount);
    assertEquals(4, annotationsCount);
    Statement phenotypicVariationStatement = filterStatementsBy(mappedStatements, StatementField.ANNOTATION_CATEGORY, "phenotypic-variation").get(0);
    String[] subjectAnnotations = phenotypicVariationStatement.getValue(StatementField.SUBJECT_ANNOTATION_IDS).split(",");
    String referenceVarAnnotation1 = subjectAnnotations[0];
    String referenceVarAnnotation2 = subjectAnnotations[1];
    String variantAnnotA = filterStatementsBy(mappedStatements, StatementField.ANNOTATION_CATEGORY, "variant").get(0).getValue(StatementField.ANNOTATION_ID);
    String variantAnnotB = filterStatementsBy(mappedStatements, StatementField.ANNOTATION_CATEGORY, "variant").get(1).getValue(StatementField.ANNOTATION_ID);
    Set<String> refAnnots = new TreeSet<>(Arrays.asList(referenceVarAnnotation1, referenceVarAnnotation2));
    Set<String> varAnnots = new TreeSet<>(Arrays.asList(variantAnnotA, variantAnnotB));
    assertEquals(refAnnots.size(), 2);
    assertEquals(refAnnots, varAnnots);
}
Also used : ReportBuilder(org.nextprot.api.etl.service.impl.StatementETLServiceImpl.ReportBuilder) Arrays(java.util.Arrays) List(java.util.List) StatementETLBaseUnitTest(org.nextprot.api.etl.statement.StatementETLBaseUnitTest) Set(java.util.Set) Test(org.junit.Test) StatementField(org.nextprot.commons.statements.StatementField) Collectors(java.util.stream.Collectors) Statement(org.nextprot.commons.statements.Statement) TreeSet(java.util.TreeSet) Assert.assertEquals(org.junit.Assert.assertEquals) ReportBuilder(org.nextprot.api.etl.service.impl.StatementETLServiceImpl.ReportBuilder) Statement(org.nextprot.commons.statements.Statement) TreeSet(java.util.TreeSet) StatementETLBaseUnitTest(org.nextprot.api.etl.statement.StatementETLBaseUnitTest) Test(org.junit.Test)

Example 12 with Statement

use of org.nextprot.commons.statements.Statement in project nextprot-api by calipho-sib.

the class EntryAnnotationBuilderTest method shouldReturnCorrectEcoName.

@Test
public void shouldReturnCorrectEcoName() {
    Statement sb1 = StatementBuilder.createNew().addCompulsaryFields("NX_P01308", "NX_P01308-1", "go-cellular-component", QualityQualifier.GOLD).addField(StatementField.EVIDENCE_CODE, "ECO:00001").addField(StatementField.REFERENCE_DATABASE, "PubMed").addField(StatementField.REFERENCE_ACCESSION, "123").addTargetIsoformsField(new TargetIsoformSet()).buildWithAnnotationHash(AnnotationType.ENTRY);
    List<Statement> statements = Arrays.asList(sb1);
    Annotation annotation = newAnnotationBuilder().buildAnnotation("NX_P01308-1", statements);
    Assert.assertEquals(annotation.getAPICategory(), AnnotationCategory.GO_CELLULAR_COMPONENT);
    Assert.assertEquals(annotation.getEvidences().size(), 1);
    Assert.assertEquals("eco-name-1", annotation.getEvidences().get(0).getEvidenceCodeName());
}
Also used : Statement(org.nextprot.commons.statements.Statement) TargetIsoformSet(org.nextprot.commons.statements.TargetIsoformSet) Annotation(org.nextprot.api.core.domain.annotation.Annotation) Test(org.junit.Test)

Example 13 with Statement

use of org.nextprot.commons.statements.Statement in project nextprot-api by calipho-sib.

the class EntryAnnotationBuilderTest method shouldReturnAnExceptionIf2AnnotationsAreExpectedInsteadOfOne.

@Test(expected = NextProtException.class)
public void shouldReturnAnExceptionIf2AnnotationsAreExpectedInsteadOfOne() {
    Statement sb1 = StatementBuilder.createNew().addCompulsaryFields("NX_P01308", "NX_P01308", "go-cellular-component", QualityQualifier.GOLD).addField(StatementField.REFERENCE_DATABASE, "PubMed").addField(StatementField.REFERENCE_ACCESSION, "123").addTargetIsoformsField(new TargetIsoformSet()).buildWithAnnotationHash(AnnotationType.ENTRY);
    Statement sb2 = StatementBuilder.createNew().addCompulsaryFields("NX_P99999", "NX_P99999", "go-cellular-component", QualityQualifier.GOLD).addField(StatementField.REFERENCE_DATABASE, "PubMed").addField(StatementField.REFERENCE_ACCESSION, "123").addTargetIsoformsField(new TargetIsoformSet()).buildWithAnnotationHash(AnnotationType.ENTRY);
    List<Statement> statements = Arrays.asList(sb1, sb2);
    newAnnotationBuilder().buildAnnotation("NX_P01308", statements);
}
Also used : Statement(org.nextprot.commons.statements.Statement) TargetIsoformSet(org.nextprot.commons.statements.TargetIsoformSet) Test(org.junit.Test)

Example 14 with Statement

use of org.nextprot.commons.statements.Statement in project nextprot-api by calipho-sib.

the class EntryAnnotationBuilderTest method shouldFindCorrectPublicationId.

@Test
public void shouldFindCorrectPublicationId() {
    Statement sb1 = StatementBuilder.createNew().addField(StatementField.REFERENCE_DATABASE, "PubMed").addField(StatementField.REFERENCE_ACCESSION, "123").build();
    StatementAnnotationBuilder ab = StatementEntryAnnotationBuilder.newBuilder(terminologyService, publicationService, mainNamesService);
    ab.findPublicationId(sb1);
}
Also used : Statement(org.nextprot.commons.statements.Statement) Test(org.junit.Test)

Example 15 with Statement

use of org.nextprot.commons.statements.Statement in project nextprot-api by calipho-sib.

the class StatementAnnotationBuilder method buildAnnotationEvidences.

protected List<AnnotationEvidence> buildAnnotationEvidences(List<Statement> Statements) {
    // Ensures there is no repeated evidence!
    Set<AnnotationEvidence> evidencesSet = Statements.stream().map(s -> {
        AnnotationEvidence evidence = new AnnotationEvidence();
        // TODO to be checked with Amos and Lydie
        evidence.setResourceType("database");
        evidence.setResourceAssociationType("evidence");
        evidence.setQualityQualifier(s.getValue(StatementField.EVIDENCE_QUALITY));
        evidence.setResourceId(findPublicationId(s));
        AnnotationEvidenceProperty evidenceProperty = addPropertyIfPresent(s.getValue(StatementField.EVIDENCE_INTENSITY), "intensity");
        AnnotationEvidenceProperty expContextSubjectProteinOrigin = addPropertyIfPresent(s.getValue(StatementField.ANNOTATION_SUBJECT_SPECIES), "subject-protein-origin");
        AnnotationEvidenceProperty expContextObjectProteinOrigin = addPropertyIfPresent(s.getValue(StatementField.ANNOTATION_OBJECT_SPECIES), "object-protein-origin");
        // Set properties which are not null
        evidence.setProperties(Arrays.asList(evidenceProperty, expContextSubjectProteinOrigin, expContextObjectProteinOrigin).stream().filter(p -> p != null).collect(Collectors.toList()));
        String statementEvidenceCode = s.getValue(StatementField.EVIDENCE_CODE);
        evidence.setEvidenceCodeAC(statementEvidenceCode);
        evidence.setAssignedBy(s.getValue(StatementField.ASSIGNED_BY));
        evidence.setAssignmentMethod(s.getValue(StatementField.ASSIGMENT_METHOD));
        evidence.setResourceType(s.getValue(StatementField.RESOURCE_TYPE));
        evidence.setEvidenceCodeOntology("evidence-code-ontology-cv");
        evidence.setNegativeEvidence("true".equalsIgnoreCase(s.getValue(StatementField.IS_NEGATIVE)));
        if (statementEvidenceCode != null) {
            CvTerm term = terminologyService.findCvTermByAccession(statementEvidenceCode);
            if (term != null) {
                evidence.setEvidenceCodeName(term.getName());
            } else {
                throw new NextProtException("Not found " + statementEvidenceCode + " in the database");
            }
        }
        evidence.setNote(s.getValue(StatementField.EVIDENCE_NOTE));
        return evidence;
    }).collect(Collectors.toSet());
    // Ensures there is no repeated evidence!
    evidencesSet.forEach(e -> {
        long generatedEvidenceId = IdentifierOffset.EVIDENCE_ID_COUNTER_FOR_STATEMENTS.incrementAndGet();
        e.setEvidenceId(generatedEvidenceId);
    });
    List<AnnotationEvidence> evidencesFiltered = evidencesSet.stream().filter(e -> e.getResourceId() != -2).collect(Collectors.toList());
    if (evidencesFiltered.size() < evidencesSet.size()) {
        int total = evidencesSet.size();
        int removed = total - evidencesFiltered.size();
        LOGGER.debug("Removed " + removed + " evidence because no resource id from a total of " + total);
    }
    return new ArrayList<>(evidencesFiltered);
}
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) AnnotationEvidence(org.nextprot.api.core.domain.annotation.AnnotationEvidence) NextProtException(org.nextprot.api.commons.exception.NextProtException) CvTerm(org.nextprot.api.core.domain.CvTerm) AnnotationEvidenceProperty(org.nextprot.api.core.domain.annotation.AnnotationEvidenceProperty)

Aggregations

Statement (org.nextprot.commons.statements.Statement)16 Test (org.junit.Test)11 StatementETLBaseUnitTest (org.nextprot.api.etl.statement.StatementETLBaseUnitTest)6 Annotation (org.nextprot.api.core.domain.annotation.Annotation)4 ReportBuilder (org.nextprot.api.etl.service.impl.StatementETLServiceImpl.ReportBuilder)4 StatementField (org.nextprot.commons.statements.StatementField)4 TargetIsoformSet (org.nextprot.commons.statements.TargetIsoformSet)4 Collectors (java.util.stream.Collectors)3 NextProtException (org.nextprot.api.commons.exception.NextProtException)3 Supplier (com.google.common.base.Supplier)2 java.util (java.util)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 Set (java.util.Set)2 Logger (org.apache.log4j.Logger)2 AnnotationCategory (org.nextprot.api.commons.constants.AnnotationCategory)2 IdentifierOffset (org.nextprot.api.commons.constants.IdentifierOffset)2 StringUtils (org.nextprot.api.commons.utils.StringUtils)2 BioObject (org.nextprot.api.core.domain.BioObject)2 BioType (org.nextprot.api.core.domain.BioObject.BioType)2