use of org.nextprot.api.core.domain.CvTerm 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;
}
use of org.nextprot.api.core.domain.CvTerm in project nextprot-api by calipho-sib.
the class TerminologyServiceImpl method getOnePathToRootTerm.
@Override
public List<CvTerm> getOnePathToRootTerm(String cvTermAccession) {
List<CvTerm> path = new ArrayList<>();
String ac = cvTermAccession;
while (true) {
CvTerm t = findCvTermByAccession(ac);
path.add(t);
List<String> parents = t.getAncestorAccession();
if (parents == null || parents.size() == 0)
break;
ac = parents.get(0);
}
return path;
}
use of org.nextprot.api.core.domain.CvTerm in project nextprot-api by calipho-sib.
the class ExperimentalContextDictionaryServiceImpl method updateTerminologies.
private void updateTerminologies(List<ExperimentalContext> ecs) {
Set<String> terminologyAccessions = new HashSet<String>();
for (ExperimentalContext ec : ecs) {
terminologyAccessions.add(ec.getCellLineAC());
terminologyAccessions.add(ec.getTissueAC());
terminologyAccessions.add(ec.getOrganelleAC());
terminologyAccessions.add(ec.getDetectionMethodAC());
terminologyAccessions.add(ec.getDiseaseAC());
terminologyAccessions.add(ec.getDevelopmentalStageAC());
}
if (terminologyAccessions.size() > 0) {
List<CvTerm> terms = terminologyService.findCvTermsByAccessions(terminologyAccessions);
Map<String, CvTerm> map = new HashMap<>();
for (CvTerm term : terms) {
map.put(term.getAccession(), term);
}
for (ExperimentalContext ec : ecs) {
updateTerminologies(ec, map);
}
}
}
use of org.nextprot.api.core.domain.CvTerm in project nextprot-api by calipho-sib.
the class OntologyDAGAnalyserTask method benchmarkingGetAncestorsMethods.
private List<Long> benchmarkingGetAncestorsMethods(TerminologyCv terminologyCv, TerminologyService terminologyService) {
List<Long> timings = new ArrayList<>();
CvTermGraph graph = cvTermGraphService.findCvTermGraph(terminologyCv);
Map<Long, List<String>> ancestors = new HashMap<>();
Map<Long, List<String>> ancestorsQuick = new HashMap<>();
List<CvTerm> cvTerms = terminologyService.findCvTermsByOntology(terminologyCv.name());
// COMPARE COMPUTATION DURATIONS
Instant t = Instant.now();
for (CvTerm cvTerm : cvTerms) {
ancestors.put(cvTerm.getId(), terminologyService.getAllAncestorsAccession(cvTerm.getAccession()));
}
timings.add(ChronoUnit.MILLIS.between(t, Instant.now()));
t = Instant.now();
for (CvTerm cvTerm : cvTerms) {
ancestorsQuick.put(cvTerm.getId(), Arrays.stream(graph.getAncestors(Math.toIntExact(cvTerm.getId()))).boxed().map(graph::getCvTermAccessionById).collect(Collectors.toList()));
}
timings.add(ChronoUnit.MILLIS.between(t, Instant.now()));
// TEST CORRECTNESS
Set<Long> ids = ancestors.keySet();
for (long id : ids) {
Set<String> ancestorsOld = new HashSet<>(ancestors.get(id));
Set<String> ancestorsNew = new HashSet<>(ancestorsQuick.get(id));
boolean equals = ancestorsOld.equals(ancestorsNew);
if (!equals) {
System.err.println("WARNING: INCONSISTENCY: found different ancestors for cv term " + graph.getCvTermAccessionById((int) id) + "\n\t: old=" + ancestors.get(id) + "\n" + "\t: new=" + ancestorsNew);
}
}
return timings;
}
use of org.nextprot.api.core.domain.CvTerm in project nextprot-api by calipho-sib.
the class TerminologyDaoImpl method findAllTerminology.
@Override
public List<CvTerm> findAllTerminology() {
SqlParameterSource params = new MapSqlParameterSource();
List<CvTerm> terms = new NamedParameterJdbcTemplate(dsLocator.getDataSource()).query(sqlDictionary.getSQLQuery("terminology-all"), params, new DbTermRowMapper());
return terms;
}
Aggregations