use of ubic.basecode.ontology.model.OntologyTerm in project Gemma by PavlidisLab.
the class ArrayDesignAnnotationServiceImpl method generateAnnotationFile.
@Override
public int generateAnnotationFile(Writer writer, Collection<Gene> genes, OutputType type) {
Map<Gene, Collection<VocabCharacteristic>> goMappings = gene2GOAssociationService.findByGenes(genes);
for (Gene gene : genes) {
Collection<OntologyTerm> ontologyTerms = this.getGoTerms(goMappings.get(gene), type);
Integer ncbiId = gene.getNcbiGeneId();
String ncbiIds = ncbiId == null ? "" : ncbiId.toString();
String geneString = gene.getOfficialSymbol();
String geneDescriptionString = gene.getOfficialName();
try {
Long id = gene.getId();
this.writeAnnotationLine(writer, geneString, ncbiIds, geneDescriptionString, ontologyTerms, id.toString(), ncbiIds);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return genes.size();
}
use of ubic.basecode.ontology.model.OntologyTerm in project Gemma by PavlidisLab.
the class ArrayDesignAnnotationServiceImpl method getGoTerms.
/**
* @param ty Configures which GO terms to return: With all parents, biological process only, or direct annotations
* only.
* @return the goTerms for a given gene, as configured
*/
private Collection<OntologyTerm> getGoTerms(Collection<VocabCharacteristic> ontologyTerms, OutputType ty) {
Collection<OntologyTerm> results = new HashSet<>();
if (ontologyTerms == null || ontologyTerms.size() == 0)
return results;
for (VocabCharacteristic vc : ontologyTerms) {
results.add(GeneOntologyServiceImpl.getTermForId(vc.getValue()));
}
if (ty.equals(OutputType.SHORT))
return results;
if (ty.equals(OutputType.LONG)) {
Collection<OntologyTerm> oes = goService.getAllParents(results);
results.addAll(oes);
} else if (ty.equals(OutputType.BIOPROCESS)) {
Collection<OntologyTerm> toRemove = new HashSet<>();
for (OntologyTerm ont : results) {
if ((ont == null)) {
// / shouldn't happen!
continue;
}
if (!goService.isBiologicalProcess(ont)) {
toRemove.add(ont);
}
}
for (OntologyTerm toRemoveOnto : toRemove) {
results.remove(toRemoveOnto);
}
}
return results;
}
use of ubic.basecode.ontology.model.OntologyTerm in project Gemma by PavlidisLab.
the class GeneMultifunctionalityPopulationServiceImpl method fetchGoAnnotations.
private Map<Gene, Collection<String>> fetchGoAnnotations(Collection<Gene> genes) {
if (!goService.isRunning()) {
goService.init(true);
}
while (!goService.isReady()) {
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
//
}
GeneMultifunctionalityPopulationServiceImpl.log.info("Waiting for GO to load");
}
/*
* Build the GO 'matrix'.
*/
int count = 0;
Map<Gene, Collection<String>> gomap = new HashMap<>();
for (Gene gene : genes) {
Collection<VocabCharacteristic> annots = gene2GOService.findByGene(gene);
Collection<String> termsForGene = new HashSet<>();
// noinspection StatementWithEmptyBody // TODO we just count it as a gene with lowest multifunctionality
if (annots.isEmpty()) {
// continue;
}
for (VocabCharacteristic t : annots) {
if (ontologyService.isObsolete(t.getValueUri())) {
GeneMultifunctionalityPopulationServiceImpl.log.warn("Obsolete term annotated to " + gene + " : " + t);
continue;
}
termsForGene.add(t.getValue());
Collection<OntologyTerm> parents = goService.getAllParents(GeneOntologyServiceImpl.getTermForURI(t.getValueUri()));
for (OntologyTerm p : parents) {
termsForGene.add(p.getTerm());
}
}
// noinspection StatementWithEmptyBody // TODO we just count it as a gene with lowest multifunctionality
if (termsForGene.isEmpty()) {
// continue;
}
gomap.put(gene, termsForGene);
if (++count % 1000 == 0) {
GeneMultifunctionalityPopulationServiceImpl.log.info("Fetched GO annotations for: " + count + "/" + genes.size() + " genes");
}
}
return gomap;
}
use of ubic.basecode.ontology.model.OntologyTerm in project Gemma by PavlidisLab.
the class GeneOntologyServiceTest2 method testParents.
@Test
public final void testParents() {
// regulation of erythrocyte aggregation
String id = "GO:0034118";
OntologyTerm termForId = GeneOntologyServiceImpl.getTermForId(id);
assertNotNull(termForId);
Collection<OntologyTerm> terms = GeneOntologyServiceTest2.gos.getParents(termForId);
assertEquals(1, terms.size());
OntologyTerm par = terms.iterator().next();
// regulation of homotypic cell-cell
assertEquals("http://purl.obolibrary.org/obo/GO_0034110", par.getUri());
// adhesion
}
use of ubic.basecode.ontology.model.OntologyTerm in project Gemma by PavlidisLab.
the class PhenotypeAssociationTest method testFindGenesWithPhenotype.
@Test
public void testFindGenesWithPhenotype() {
OntologyTerm term = os.getDiseaseOntologyService().getTerm("http://purl.obolibrary.org/obo/DOID_2531");
assertNotNull(term);
this.createLiteratureEvidence(this.geneNCBI, "http://purl.obolibrary.org/obo/DOID_2531");
Map<GeneValueObject, OntologyTerm> r = this.phenotypeAssociationManagerService.findGenesForPhenotype(term.getUri(), this.humanTaxon.getId(), true);
assertTrue(r.size() > 0);
}
Aggregations