Search in sources :

Example 1 with CvTermGraph

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

the class ProteinExistenceInferenceServiceImpl method isChildOfExperimentalEvidenceTerm.

private boolean isChildOfExperimentalEvidenceTerm(String evidenceCodeAC, int evidenceCodeACAncestor) {
    CvTermGraph evidenceCodeTermGraph = cvTermGraphService.findCvTermGraph(TerminologyCv.EvidenceCodeOntologyCv);
    int termId = terminologyService.findCvTermByAccession(evidenceCodeAC).getId().intValue();
    return evidenceCodeACAncestor == termId || evidenceCodeTermGraph.isDescendantOf(termId, evidenceCodeACAncestor);
}
Also used : CvTermGraph(org.nextprot.api.core.domain.CvTermGraph)

Example 2 with CvTermGraph

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

the class TerminologyServiceImpl method getAllAncestorTerms.

@Override
public List<CvTerm> getAllAncestorTerms(String cvTermAccession) {
    CvTerm cvTerm = terminologyDao.findTerminologyByAccession(cvTermAccession);
    CvTermGraph graph = cvTermGraphService.findCvTermGraph(TerminologyCv.valueOf(cvTerm.getOntology()));
    return Arrays.stream(graph.getAncestors(cvTerm.getId().intValue())).boxed().map(graph::getCvTermAccessionById).map(terminologyDao::findTerminologyByAccession).collect(Collectors.toList());
}
Also used : CvTerm(org.nextprot.api.core.domain.CvTerm) CvTermGraph(org.nextprot.api.core.domain.CvTermGraph)

Example 3 with CvTermGraph

use of org.nextprot.api.core.domain.CvTermGraph 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;
}
Also used : CvTerm(org.nextprot.api.core.domain.CvTerm) Instant(java.time.Instant) CvTermGraph(org.nextprot.api.core.domain.CvTermGraph)

Example 4 with CvTermGraph

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

the class OntologyDAGAnalyserTask method calcStatisticsForAllOntologies.

private void calcStatisticsForAllOntologies() throws FileNotFoundException {
    Set<TerminologyCv> excludedOntology = EnumSet.of(TerminologyCv.NextprotCellosaurusCv, TerminologyCv.MeshAnatomyCv, TerminologyCv.MeshCv);
    PrintWriter pw = new PrintWriter(getCommandLineParser().getOutputDirectory() + "/dag-ontology.csv");
    pw.write(getStatisticsHeaders().stream().collect(Collectors.joining(",")));
    pw.write(",building time (ms),TerminologyUtils.getAllAncestors() time (ms),OntologyDAG.getAncestors() time (ms)\n");
    for (TerminologyCv terminologyCv : terminologyCvs) {
        Instant t1 = Instant.now();
        // no cache here: create a new instance to access graph advanced methods
        CvTermGraph graph = cvTermGraphService.findCvTermGraph(terminologyCv);
        long buildingTime = ChronoUnit.MILLIS.between(t1, Instant.now());
        List<String> statistics = calcStatistics(graph);
        statistics.add(new DecimalFormat("######.##").format(buildingTime));
        if (!excludedOntology.contains(terminologyCv)) {
            statistics.addAll(benchmarkingGetAncestorsMethods(terminologyCv, terminologyService).stream().map(l -> Long.toString(l)).collect(Collectors.toList()));
        } else {
            statistics.addAll(Arrays.asList("NA", "NA"));
        }
        pw.write(statistics.stream().collect(Collectors.joining(",")));
        pw.write("\n");
        pw.flush();
    }
    pw.close();
}
Also used : Instant(java.time.Instant) DecimalFormat(java.text.DecimalFormat) TerminologyCv(org.nextprot.api.commons.constants.TerminologyCv) CvTermGraph(org.nextprot.api.core.domain.CvTermGraph) PrintWriter(java.io.PrintWriter)

Example 5 with CvTermGraph

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

the class TermController method getAncestorGraph.

@ApiMethod(path = "/term/{term}/ancestor-graph", verb = ApiVerb.GET, description = "Get the ancestor graph of the given term", produces = MediaType.APPLICATION_JSON_VALUE)
@RequestMapping(value = "/term/{term}/ancestor-graph", method = { RequestMethod.GET }, produces = MediaType.APPLICATION_JSON_VALUE)
public Map<String, CvTermGraph.View> getAncestorGraph(@ApiPathParam(name = "term", description = "The accession of the cv term", allowedvalues = { "TS-0079" }) @PathVariable("term") String term) {
    CvTerm cvTerm = terminologyService.findCvTermByAccession(term);
    CvTermGraph graph = cvTermGraphService.findCvTermGraph(TerminologyCv.getTerminologyOf(cvTerm.getOntology()));
    return Collections.singletonMap("ancestor-graph", graph.calcAncestorSubgraph(cvTerm.getId().intValue()).toView());
}
Also used : CvTerm(org.nextprot.api.core.domain.CvTerm) CvTermGraph(org.nextprot.api.core.domain.CvTermGraph) ApiMethod(org.jsondoc.core.annotation.ApiMethod) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

CvTermGraph (org.nextprot.api.core.domain.CvTermGraph)6 CvTerm (org.nextprot.api.core.domain.CvTerm)4 Instant (java.time.Instant)2 ApiMethod (org.jsondoc.core.annotation.ApiMethod)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 PrintWriter (java.io.PrintWriter)1 DecimalFormat (java.text.DecimalFormat)1 TerminologyCv (org.nextprot.api.commons.constants.TerminologyCv)1