use of ubic.basecode.ontology.model.OntologyTerm in project Gemma by PavlidisLab.
the class GoMetric method getOntologyTerms.
/**
* @param gene gene
* @return direct GO annotation terms
*/
private Collection<OntologyTerm> getOntologyTerms(Gene gene) {
Collection<VocabCharacteristic> termsVoc = gene2GOAssociationService.findByGene(gene);
HashSet<OntologyTerm> termsGO = new HashSet<>();
for (VocabCharacteristic characteristic : termsVoc) {
OntologyTerm term = GeneOntologyServiceImpl.getTermForId(characteristic.getValue());
if ((term != null))
termsGO.add(term);
}
return termsGO;
}
use of ubic.basecode.ontology.model.OntologyTerm in project Gemma by PavlidisLab.
the class OntologyServiceImpl method findCharacteristicsFromOntology.
/**
* given a collection of characteristics add them to the correct List
*/
private Collection<CharacteristicValueObject> findCharacteristicsFromOntology(String searchQuery, boolean useNeuroCartaOntology, Map<String, CharacteristicValueObject> characteristicFromDatabaseWithValueUri) {
Collection<CharacteristicValueObject> characteristicsFromOntology = new HashSet<>();
// in neurocarta we don't need to search all Ontologies
Collection<AbstractOntologyService> ontologyServicesToUse = new HashSet<>();
if (useNeuroCartaOntology) {
ontologyServicesToUse.add(this.nifstdOntologyService);
ontologyServicesToUse.add(this.fmaOntologyService);
ontologyServicesToUse.add(this.obiService);
} else {
ontologyServicesToUse = this.ontologyServices;
}
// search all Ontology
for (AbstractOntologyService ontologyService : ontologyServicesToUse) {
Collection<OntologyTerm> ontologyTerms = ontologyService.findTerm(searchQuery);
for (OntologyTerm ontologyTerm : ontologyTerms) {
// if the ontology term wasnt already found in the database
if (characteristicFromDatabaseWithValueUri.get(ontologyTerm.getUri()) == null) {
CharacteristicValueObject phenotype = new CharacteristicValueObject(-1L, ontologyTerm.getLabel().toLowerCase(), ontologyTerm.getUri());
characteristicsFromOntology.add(phenotype);
}
}
}
return characteristicsFromOntology;
}
use of ubic.basecode.ontology.model.OntologyTerm in project Gemma by PavlidisLab.
the class GeneOntologyServiceImpl method getPartsOf.
/**
* Return terms which have "part_of" relation with the given term (they are "part_of" the given term).
*/
private Collection<OntologyTerm> getPartsOf(OntologyTerm entry) {
Collection<OntologyTerm> r = new HashSet<>();
String u = entry.getUri();
String queryString = "SELECT ?x WHERE {" + "?x <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> <" + u + "> . }";
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");
String uri = x.getURI();
if (x.isAnon())
// some reasoners will return these.
continue;
if (GeneOntologyServiceImpl.log.isDebugEnabled())
GeneOntologyServiceImpl.log.debug(GeneOntologyServiceImpl.uri2Term.get(uri) + " is part of " + entry);
r.add(GeneOntologyServiceImpl.uri2Term.get(uri));
}
} finally {
qexec.close();
}
return r;
}
use of ubic.basecode.ontology.model.OntologyTerm in project Gemma by PavlidisLab.
the class GeneOntologyServiceImpl method addTerms.
private void addTerms(Collection<OntologyResource> newTerms) {
for (OntologyResource term : newTerms) {
if (term.getUri() == null)
continue;
if (term instanceof OntologyTerm) {
OntologyTerm ontTerm = (OntologyTerm) term;
GeneOntologyServiceImpl.uri2Term.put(term.getUri(), ontTerm);
for (String alternativeID : ontTerm.getAlternativeIds()) {
GeneOntologyServiceImpl.log.debug(GeneOntologyServiceImpl.toUri(alternativeID));
GeneOntologyServiceImpl.uri2Term.put(GeneOntologyServiceImpl.toUri(alternativeID), ontTerm);
}
}
}
}
use of ubic.basecode.ontology.model.OntologyTerm in project Gemma by PavlidisLab.
the class GeneOntologyServiceImpl method getAncestors.
private synchronized Collection<OntologyTerm> getAncestors(OntologyTerm entry, boolean includePartOf) {
if (entry == null) {
return new HashSet<>();
}
Collection<OntologyTerm> ancestors = parentsCache.get(entry.getUri());
if (ancestors == null) {
ancestors = new HashSet<>();
Collection<OntologyTerm> parents = this.getParents(entry, includePartOf);
if (parents != null) {
for (OntologyTerm parent : parents) {
ancestors.add(parent);
ancestors.addAll(this.getAncestors(parent, includePartOf));
}
}
ancestors = Collections.unmodifiableCollection(ancestors);
parentsCache.put(entry.getUri(), ancestors);
}
return new HashSet<>(ancestors);
}
Aggregations