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);
}
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());
}
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);
}
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);
}
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);
}
Aggregations