use of ubic.basecode.ontology.model.OntologyTerm in project Gemma by PavlidisLab.
the class GoMetric method getChildrenOccurrence.
/**
* @param termCountMap each GO term uri mapped to the number of its occurrence in the corpus
* @param term the uri of the query GO term
* @return the number of times the query GO term occurs in addition to the number of times its children occur in
* the corpus
*/
public Integer getChildrenOccurrence(Map<String, Integer> termCountMap, String term) {
int termCount = termCountMap.get(term);
OntologyTerm ont = GeneOntologyServiceImpl.getTermForURI(term);
Collection<OntologyTerm> children = geneOntologyService.getAllChildren(ont, partOf);
if (children.isEmpty()) {
return termCount;
}
for (OntologyTerm child : children) {
if (termCountMap.containsKey(child.getUri())) {
int count = termCountMap.get(child.getUri());
termCount += count;
}
}
return termCount;
}
use of ubic.basecode.ontology.model.OntologyTerm in project Gemma by PavlidisLab.
the class OntologyServiceImpl method termsToCharacteristics.
/**
* Convert raw ontology resources into VocabCharacteristics.
*/
@Override
public Collection<VocabCharacteristic> termsToCharacteristics(final Collection<? extends OntologyResource> terms) {
Collection<VocabCharacteristic> results = new HashSet<>();
if ((terms == null) || (terms.isEmpty()))
return results;
for (OntologyResource res : terms) {
if (res == null)
continue;
VocabCharacteristic vc = VocabCharacteristic.Factory.newInstance();
if (res instanceof OntologyTerm) {
OntologyTerm term = (OntologyTerm) res;
vc.setValue(term.getTerm());
vc.setValueUri(term.getUri());
vc.setDescription(term.getComment());
} else if (res instanceof OntologyIndividual) {
OntologyIndividual indi = (OntologyIndividual) res;
vc.setValue(indi.getLabel());
vc.setValueUri(indi.getUri());
vc.setDescription("Individual");
} else {
OntologyServiceImpl.log.warn("What is it? " + res);
continue;
}
if (vc.getValue() == null)
continue;
results.add(vc);
}
OntologyServiceImpl.log.debug("returning " + results.size() + " terms after filter");
return results;
}
use of ubic.basecode.ontology.model.OntologyTerm in project Gemma by PavlidisLab.
the class OntologyServiceImpl method convert.
/**
* Given a collection of ontology terms converts them to a collection of VocabCharacteristics
*/
private Collection<VocabCharacteristic> convert(final Collection<OntologyResource> resources) {
Collection<VocabCharacteristic> converted = new HashSet<>();
if ((resources == null) || (resources.isEmpty()))
return converted;
for (OntologyResource res : resources) {
VocabCharacteristic vc = VocabCharacteristic.Factory.newInstance();
// If there is no URI we don't want to send it back (ie useless)
if ((res.getUri() == null) || StringUtils.isEmpty(res.getUri()))
continue;
if (res instanceof OntologyTerm) {
OntologyTerm term = (OntologyTerm) res;
vc.setValue(term.getTerm());
vc.setValueUri(term.getUri());
vc.setDescription(term.getComment());
}
if (res instanceof OntologyIndividual) {
OntologyIndividual indi = (OntologyIndividual) res;
vc.setValue(indi.getLabel());
vc.setValueUri(indi.getUri());
vc.setDescription("Individual");
}
converted.add(vc);
}
return converted;
}
use of ubic.basecode.ontology.model.OntologyTerm in project Gemma by PavlidisLab.
the class OntologyServiceImpl method initializeCategoryTerms.
private synchronized void initializeCategoryTerms() {
URL termUrl = OntologyServiceImpl.class.getResource("/ubic/gemma/core/ontology/EFO.factor.categories.txt");
OntologyServiceImpl.categoryTerms = new ConcurrentHashSet<>();
try (BufferedReader reader = new BufferedReader(new InputStreamReader(termUrl.openStream()))) {
String line;
boolean warned = false;
while ((line = reader.readLine()) != null) {
if (line.startsWith("#") || StringUtils.isEmpty(line))
continue;
String[] f = StringUtils.split(line, '\t');
if (f.length < 2) {
continue;
}
OntologyTerm t = this.getTerm(f[0]);
if (t == null) {
// available. Inference will not be available.
if (!warned) {
OntologyServiceImpl.log.info("Ontology needed is not loaded? Using light-weight placeholder for " + f[0] + " (further warnings hidden)");
warned = true;
}
t = new OntologyTermSimple(f[0], f[1]);
}
OntologyServiceImpl.categoryTerms.add(t);
}
} catch (IOException ioe) {
OntologyServiceImpl.log.error("Error reading from term list '" + termUrl + "'; returning general term list", ioe);
OntologyServiceImpl.categoryTerms = null;
}
OntologyServiceImpl.categoryTerms = Collections.unmodifiableCollection(OntologyServiceImpl.categoryTerms);
}
use of ubic.basecode.ontology.model.OntologyTerm in project Gemma by PavlidisLab.
the class GeneOntologyServiceImpl method getParents.
@Override
public Collection<OntologyTerm> getParents(OntologyTerm entry, boolean includePartOf) {
Collection<OntologyTerm> parents = entry.getParents(true);
Collection<OntologyTerm> results = new HashSet<>();
for (OntologyTerm term : parents) {
// The isRoot() returns true for the MolecularFunction, BiologicalProcess, CellularComponent
if (term.isRoot())
continue;
if (term.getUri().equalsIgnoreCase(GeneOntologyServiceImpl.ALL_ROOT))
continue;
// noinspection StatementWithEmptyBody // Better readability
if (term instanceof OntologyClassRestriction) {
// don't keep it. - for example, "ends_during" RO_0002093
} else {
results.add(term);
}
}
if (includePartOf)
results.addAll(this.getIsPartOf(entry));
return results;
}
Aggregations