Search in sources :

Example 36 with OntologyTerm

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();
}
Also used : Gene(ubic.gemma.model.genome.Gene) OntologyTerm(ubic.basecode.ontology.model.OntologyTerm)

Example 37 with OntologyTerm

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;
}
Also used : VocabCharacteristic(ubic.gemma.model.common.description.VocabCharacteristic) OntologyTerm(ubic.basecode.ontology.model.OntologyTerm)

Example 38 with OntologyTerm

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;
}
Also used : HashMap(java.util.HashMap) VocabCharacteristic(ubic.gemma.model.common.description.VocabCharacteristic) OntologyTerm(ubic.basecode.ontology.model.OntologyTerm) Gene(ubic.gemma.model.genome.Gene) Collection(java.util.Collection) HashSet(java.util.HashSet)

Example 39 with OntologyTerm

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
}
Also used : OntologyTerm(ubic.basecode.ontology.model.OntologyTerm) Test(org.junit.Test)

Example 40 with OntologyTerm

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);
}
Also used : GeneValueObject(ubic.gemma.model.genome.gene.GeneValueObject) OntologyTerm(ubic.basecode.ontology.model.OntologyTerm) Test(org.junit.Test) BaseSpringContextTest(ubic.gemma.core.testing.BaseSpringContextTest)

Aggregations

OntologyTerm (ubic.basecode.ontology.model.OntologyTerm)73 Test (org.junit.Test)13 VocabCharacteristic (ubic.gemma.model.common.description.VocabCharacteristic)13 Gene (ubic.gemma.model.genome.Gene)11 OntologyResource (ubic.basecode.ontology.model.OntologyResource)8 HashSet (java.util.HashSet)6 StopWatch (org.apache.commons.lang3.time.StopWatch)6 CharacteristicValueObject (ubic.gemma.model.genome.gene.phenotype.valueObject.CharacteristicValueObject)6 BufferedReader (java.io.BufferedReader)3 ConcurrentHashSet (org.compass.core.util.concurrent.ConcurrentHashSet)3 Element (org.w3c.dom.Element)3 OntologyIndividual (ubic.basecode.ontology.model.OntologyIndividual)3 EntityNotFoundException (ubic.gemma.core.association.phenotype.PhenotypeExceptions.EntityNotFoundException)3 Characteristic (ubic.gemma.model.common.description.Characteristic)3 GeneEvidenceValueObject (ubic.gemma.model.genome.gene.phenotype.valueObject.GeneEvidenceValueObject)3 Resource (com.hp.hpl.jena.rdf.model.Resource)2 FileReader (java.io.FileReader)2 SocketException (java.net.SocketException)2 Collection (java.util.Collection)2 BaseSpringContextTest (ubic.gemma.core.testing.BaseSpringContextTest)2