use of ubic.basecode.ontology.model.OntologyResource 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.OntologyResource in project Gemma by PavlidisLab.
the class GeneSetSearchImpl method goTermToGeneSet.
/**
* Convert a GO term to a 'GeneSet', including genes from all child terms. Divide up by taxon.
*/
private GeneSet goTermToGeneSet(OntologyResource term, Taxon taxon, Integer maxGeneSetSize) {
assert taxon != null;
if (term == null)
return null;
if (term.getUri() == null)
return null;
Collection<OntologyResource> allMatches = new HashSet<>();
allMatches.add(term);
assert term instanceof OntologyTerm;
allMatches.addAll(this.geneOntologyService.getAllChildren((OntologyTerm) term));
GeneSetSearchImpl.log.info(term);
/*
* Gather up uris
*/
Collection<String> termsToFetch = new HashSet<>();
for (OntologyResource t : allMatches) {
String goId = this.uri2goid(t);
termsToFetch.add(goId);
}
Collection<Gene> genes = this.gene2GoService.findByGOTerms(termsToFetch, taxon);
if (genes.isEmpty() || (maxGeneSetSize != null && genes.size() > maxGeneSetSize)) {
return null;
}
GeneSet transientGeneSet = GeneSet.Factory.newInstance();
transientGeneSet.setName(this.uri2goid(term));
if (term.getLabel() == null) {
GeneSetSearchImpl.log.warn(" Label for term " + term.getUri() + " was null");
}
// noinspection StatementWithEmptyBody // FIXME this is an individual or a 'resource', not a 'class', but it's a real GO term. How to get the text.
if (term.getLabel() != null && term.getLabel().toUpperCase().startsWith("GO_")) {
}
transientGeneSet.setDescription(term.getLabel());
for (Gene gene : genes) {
GeneSetMember gmember = GeneSetMember.Factory.newInstance();
gmember.setGene(gene);
transientGeneSet.getMembers().add(gmember);
}
return transientGeneSet;
}
Aggregations