Search in sources :

Example 6 with CvTerm

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

the class TerminologyServiceTest method shouldReturnAUniprotSubcell.

@Test
public void shouldReturnAUniprotSubcell() {
    CvTerm term = this.terminologyService.findCvTermByAccession("SL-0276");
    assertEquals("UniprotSubcellularLocationCv", term.getOntology());
}
Also used : CvTerm(org.nextprot.api.core.domain.CvTerm) CoreUnitBaseTest(org.nextprot.api.core.test.base.CoreUnitBaseTest) Test(org.junit.Test)

Example 7 with CvTerm

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

the class TerminologyUtils method populateTree.

static void populateTree(Tree.Node<CvTerm> currentNode, Map<String, CvTerm> termMap, int depth, final int maxDepth) {
    if (depth > maxDepth)
        return;
    if (depth > 100)
        throw new NextProtException("Getting stuck in building graph");
    if (currentNode.getValue() == null || currentNode.getValue().getChildAccession() == null || currentNode.getValue().getChildAccession().isEmpty()) {
        return;
    }
    for (String childAccession : currentNode.getValue().getChildAccession()) {
        CvTerm childTerm = termMap.get(childAccession);
        if (childTerm != null) {
            if (currentNode.getChildren() == null) {
                currentNode.setChildren(new ArrayList<Tree.Node<CvTerm>>());
            }
            Tree.Node<CvTerm> childNode = new Tree.Node<CvTerm>(childTerm);
            childNode.setParents(Arrays.asList(currentNode));
            currentNode.getChildren().add(childNode);
            populateTree(childNode, termMap, depth + 1, maxDepth);
        }
    }
}
Also used : NextProtException(org.nextprot.api.commons.exception.NextProtException) CvTerm(org.nextprot.api.core.domain.CvTerm) Node(org.nextprot.api.commons.utils.Tree.Node) Tree(org.nextprot.api.commons.utils.Tree)

Example 8 with CvTerm

use of org.nextprot.api.core.domain.CvTerm 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 9 with CvTerm

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

the class SolrIndexingServiceImpl method indexTerminologies.

@Override
public String indexTerminologies() {
    long seconds = System.currentTimeMillis() / 1000;
    StringBuilder info = new StringBuilder();
    logAndCollect(info, "terms indexing...STARTING at " + new Date());
    String serverUrl = getServerUrl(CvIndex.NAME);
    logAndCollect(info, "Solr server: " + serverUrl);
    logAndCollect(info, "clearing term index");
    SolrIndexer<CvTerm> indexer = new CvTermSolrIndexer(serverUrl);
    List<CvTerm> allterms;
    indexer.clearDatabase("");
    logAndCollect(info, "getting terms for all terminologies");
    allterms = terminologyService.findAllCVTerms();
    logAndCollect(info, "start indexing of " + allterms.size() + " terms");
    int termcnt = 0;
    for (CvTerm term : allterms) {
        indexer.add(term);
        termcnt++;
        if ((termcnt % 3000) == 0)
            logAndCollect(info, termcnt + "/" + allterms.size() + " cv terms done");
    }
    indexer.addRemaing();
    logAndCollect(info, "comitting");
    indexer.commit();
    seconds = (System.currentTimeMillis() / 1000 - seconds);
    logAndCollect(info, termcnt + " terms indexed in " + seconds + " seconds ...END at " + new Date());
    return info.toString();
}
Also used : CvTerm(org.nextprot.api.core.domain.CvTerm) Date(java.util.Date)

Example 10 with CvTerm

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

the class GenerateSolrTerminologyIndex method start.

@Override
public void start(String[] args) {
    TerminologyService terminologyService = getBean(TerminologyService.class);
    int termcnt = 0;
    String solrServer = System.getProperty("solr.server");
    NPreconditions.checkNotNull(solrServer, "Please set solr.server variable. For example: java -Dsolr.server=\"http://localhost:8983/solr/npcvs1\"");
    logger.info("Solr server: " + solrServer);
    // eg: java -Dsolr.ontology="UniprotFamilyCv" (don't forget CamelCasing)
    String ontologyToReindex = System.getProperty("solr.ontology");
    SolrIndexer<CvTerm> indexer = new CvTermSolrIndexer(solrServer);
    List<CvTerm> allterms;
    if (ontologyToReindex == null) {
        // No arg: index all ontologies
        System.err.println("indexing: all ontologies");
        logger.info("indexing all terminologies");
        indexer.clearDatabase("");
        allterms = terminologyService.findAllCVTerms();
    } else {
        // Index ontology given as VM argument
        System.err.println("indexing: " + ontologyToReindex);
        logger.info("indexing terminology: " + ontologyToReindex);
        indexer.clearDatabase("filters:" + ontologyToReindex);
        allterms = terminologyService.findCvTermsByOntology(ontologyToReindex);
    }
    for (CvTerm term : allterms) {
        indexer.add(term);
        termcnt++;
        if ((termcnt % 3000) == 0)
            logger.info(termcnt + "/" + allterms.size() + " cv terms done");
    }
    indexer.addRemaing();
    logger.info("comitting");
    indexer.commit();
    logger.info(termcnt + " terms indexed...END");
}
Also used : CvTermSolrIndexer(org.nextprot.api.tasks.solr.indexer.CvTermSolrIndexer) CvTerm(org.nextprot.api.core.domain.CvTerm) TerminologyService(org.nextprot.api.core.service.TerminologyService)

Aggregations

CvTerm (org.nextprot.api.core.domain.CvTerm)34 Test (org.junit.Test)9 CoreUnitBaseTest (org.nextprot.api.core.test.base.CoreUnitBaseTest)8 AnnotationEvidence (org.nextprot.api.core.domain.annotation.AnnotationEvidence)5 NextProtException (org.nextprot.api.commons.exception.NextProtException)4 CvTermGraph (org.nextprot.api.core.domain.CvTermGraph)4 Annotation (org.nextprot.api.core.domain.annotation.Annotation)4 MapSqlParameterSource (org.springframework.jdbc.core.namedparam.MapSqlParameterSource)4 NamedParameterJdbcTemplate (org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate)4 SqlParameterSource (org.springframework.jdbc.core.namedparam.SqlParameterSource)4 Publication (org.nextprot.api.core.domain.Publication)3 Supplier (com.google.common.base.Supplier)2 Instant (java.time.Instant)2 java.util (java.util)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 Collectors (java.util.stream.Collectors)2 Logger (org.apache.log4j.Logger)2 ApiMethod (org.jsondoc.core.annotation.ApiMethod)2 ConsoleProgressBar (org.nextprot.api.commons.app.ConsoleProgressBar)2