use of ubic.basecode.ontology.model.OntologyTerm in project Gemma by PavlidisLab.
the class GeneOntologyServiceImpl method getGOTerms.
@Override
public Collection<OntologyTerm> getGOTerms(Gene gene, boolean includePartOf, GOAspect goAspect) {
Collection<OntologyTerm> cachedTerms = goTerms.get(gene);
if (GeneOntologyServiceImpl.log.isTraceEnabled() && cachedTerms != null) {
this.logIds("found cached GO terms for " + gene.getOfficialSymbol(), goTerms.get(gene));
}
if (cachedTerms == null) {
Collection<OntologyTerm> allGOTermSet = new HashSet<>();
Collection<VocabCharacteristic> annotations = gene2GOAssociationService.findByGene(gene);
for (VocabCharacteristic c : annotations) {
if (!GeneOntologyServiceImpl.uri2Term.containsKey(c.getValueUri())) {
GeneOntologyServiceImpl.log.warn("Term " + c.getValueUri() + " not found in term list cant add to results");
continue;
}
allGOTermSet.add(GeneOntologyServiceImpl.uri2Term.get(c.getValueUri()));
}
allGOTermSet.addAll(this.getAllParents(allGOTermSet, includePartOf));
cachedTerms = Collections.unmodifiableCollection(allGOTermSet);
if (GeneOntologyServiceImpl.log.isTraceEnabled())
this.logIds("caching GO terms for " + gene.getOfficialSymbol(), allGOTermSet);
goTerms.put(gene, cachedTerms);
}
if (goAspect != null) {
Collection<OntologyTerm> finalTerms = new HashSet<>();
for (OntologyTerm ontologyTerm : cachedTerms) {
GOAspect term = this.getTermAspect(ontologyTerm);
if (term != null && term.equals(goAspect)) {
finalTerms.add(ontologyTerm);
}
}
return finalTerms;
}
return cachedTerms;
}
use of ubic.basecode.ontology.model.OntologyTerm in project Gemma by PavlidisLab.
the class GeneOntologyServiceImpl method getDescendants.
/**
* @return Given an ontology term recursively determines all the children and adds them to a cache (same as
* getAllParents but the recursive code is a little cleaner and doesn't use and accumulator)
*/
private synchronized Collection<OntologyTerm> getDescendants(OntologyTerm entry, boolean includePartOf) {
Collection<OntologyTerm> descendants = childrenCache.get(entry.getUri());
if (descendants == null) {
descendants = new HashSet<>();
Collection<OntologyTerm> children = this.getChildren(entry, includePartOf);
if (children != null) {
for (OntologyTerm child : children) {
descendants.add(child);
descendants.addAll(this.getDescendants(child, includePartOf));
}
}
descendants = Collections.unmodifiableCollection(descendants);
childrenCache.put(entry.getUri(), descendants);
}
return new HashSet<>(descendants);
}
use of ubic.basecode.ontology.model.OntologyTerm in project Gemma by PavlidisLab.
the class GeneOntologyServiceImpl method getTermDefinition.
@Override
public String getTermDefinition(String goId) {
OntologyTerm t = GeneOntologyServiceImpl.getTermForId(goId);
assert t != null;
Collection<AnnotationProperty> annotations = t.getAnnotations();
for (AnnotationProperty annot : annotations) {
GeneOntologyServiceImpl.log.info(annot.getProperty());
if (annot.getProperty().equals("hasDefinition")) {
return annot.getContents();
}
}
return null;
}
use of ubic.basecode.ontology.model.OntologyTerm in project Gemma by PavlidisLab.
the class GeneOntologyServiceImpl method getGenes.
@Override
public Collection<Gene> getGenes(String goId, Taxon taxon) {
OntologyTerm t = GeneOntologyServiceImpl.getTermForId(goId);
if (t == null)
return null;
Collection<OntologyTerm> terms = this.getAllChildren(t);
Collection<Gene> results = new HashSet<>(this.gene2GOAssociationService.findByGOTerm(goId, taxon));
for (OntologyTerm term : terms) {
results.addAll(this.gene2GOAssociationService.findByGOTerm(GeneOntologyServiceImpl.asRegularGoId(term), taxon));
}
return results;
}
use of ubic.basecode.ontology.model.OntologyTerm in project Gemma by PavlidisLab.
the class GeneOntologyServiceImpl method getIsPartOf.
/**
* Return terms to which the given term has a part_of relation (it is "part_of" them).
*/
private Collection<OntologyTerm> getIsPartOf(OntologyTerm entry) {
Collection<OntologyTerm> r = new HashSet<>();
String u = entry.getUri();
String queryString = "SELECT ?x WHERE { <" + u + "> <http://www.w3.org/2000/01/rdf-schema#subClassOf> ?v . " + "?v <http://www.w3.org/2002/07/owl#onProperty> <" + GeneOntologyServiceImpl.PART_OF_URI + "> . " + "?v <http://www.w3.org/2002/07/owl#someValuesFrom> ?x . }";
Query q = QueryFactory.create(queryString);
QueryExecution qexec = QueryExecutionFactory.create(q, (Model) entry.getModel());
try {
ResultSet results = qexec.execSelect();
while (results.hasNext()) {
QuerySolution soln = results.nextSolution();
Resource x = soln.getResource("x");
if (x.isAnon())
// some reasoners will return these.
continue;
String uri = x.getURI();
if (GeneOntologyServiceImpl.log.isDebugEnabled())
GeneOntologyServiceImpl.log.debug(entry + " is part of " + GeneOntologyServiceImpl.uri2Term.get(uri));
r.add(GeneOntologyServiceImpl.uri2Term.get(uri));
}
} finally {
qexec.close();
}
return r;
}
Aggregations