Search in sources :

Example 96 with Gene

use of ubic.gemma.model.genome.Gene 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 97 with Gene

use of ubic.gemma.model.genome.Gene in project Gemma by PavlidisLab.

the class ArrayDesignAnnotationServiceImpl method getGOMappings.

private Map<Gene, Collection<VocabCharacteristic>> getGOMappings(Map<CompositeSequence, Collection<BioSequence2GeneProduct>> genesWithSpecificity) {
    ArrayDesignAnnotationServiceImpl.log.info("Fetching GO mappings");
    Collection<Gene> allGenes = new HashSet<>();
    for (CompositeSequence cs : genesWithSpecificity.keySet()) {
        Collection<BioSequence2GeneProduct> geneclusters = genesWithSpecificity.get(cs);
        for (BioSequence2GeneProduct bioSequence2GeneProduct : geneclusters) {
            Gene g = bioSequence2GeneProduct.getGeneProduct().getGene();
            allGenes.add(g);
        }
    }
    Map<Gene, Collection<VocabCharacteristic>> goMappings = gene2GOAssociationService.findByGenes(allGenes);
    ArrayDesignAnnotationServiceImpl.log.info("Got GO mappings for " + goMappings.size() + " genes");
    return goMappings;
}
Also used : Gene(ubic.gemma.model.genome.Gene) BioSequence2GeneProduct(ubic.gemma.model.association.BioSequence2GeneProduct) CompositeSequence(ubic.gemma.model.expression.designElement.CompositeSequence)

Example 98 with Gene

use of ubic.gemma.model.genome.Gene in project Gemma by PavlidisLab.

the class GeneMultifunctionalityPopulationServiceImpl method saveBatch.

private void saveBatch(Collection<Gene> genes, Map<Gene, Multifunctionality> mfs) {
    genes = geneService.thawLite(genes);
    for (Gene g : genes) {
        if (!mfs.containsKey(g)) {
            g.setMultifunctionality(null);
        } else {
            Multifunctionality updatedMf = mfs.get(g);
            Multifunctionality oldMf = g.getMultifunctionality();
            if (oldMf == null) {
                g.setMultifunctionality(updatedMf);
            } else {
                oldMf = g.getMultifunctionality();
                oldMf.setNumGoTerms(updatedMf.getNumGoTerms());
                oldMf.setRank(updatedMf.getRank());
                oldMf.setScore(updatedMf.getScore());
            }
        }
    }
    geneService.update(genes);
}
Also used : Multifunctionality(ubic.gemma.model.genome.gene.Multifunctionality) Gene(ubic.gemma.model.genome.Gene)

Example 99 with Gene

use of ubic.gemma.model.genome.Gene 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 100 with Gene

use of ubic.gemma.model.genome.Gene in project Gemma by PavlidisLab.

the class PhenotypeAssociationTest method tearDown.

@After
public void tearDown() {
    this.runAsAdmin();
    Collection<PhenotypeAssociation> toRemove = new HashSet<>();
    for (Gene g : this.geneService.loadAll()) {
        g = geneService.thaw(g);
        toRemove.addAll(g.getPhenotypeAssociations());
        g.getPhenotypeAssociations().clear();
        this.geneService.update(g);
    }
    for (PhenotypeAssociation pa : toRemove) {
        this.phenotypeAssociationService.remove(pa);
    }
// this.externalDatabaseService.remove( this.externalDatabase );
}
Also used : Gene(ubic.gemma.model.genome.Gene) After(org.junit.After)

Aggregations

Gene (ubic.gemma.model.genome.Gene)186 Taxon (ubic.gemma.model.genome.Taxon)34 CompositeSequence (ubic.gemma.model.expression.designElement.CompositeSequence)32 StopWatch (org.apache.commons.lang3.time.StopWatch)31 Test (org.junit.Test)24 HashSet (java.util.HashSet)23 GeneProduct (ubic.gemma.model.genome.gene.GeneProduct)20 BaseSpringContextTest (ubic.gemma.core.testing.BaseSpringContextTest)18 Element (org.w3c.dom.Element)16 ArrayList (java.util.ArrayList)13 Transactional (org.springframework.transaction.annotation.Transactional)12 ExpressionExperiment (ubic.gemma.model.expression.experiment.ExpressionExperiment)12 Collection (java.util.Collection)11 OntologyTerm (ubic.basecode.ontology.model.OntologyTerm)11 CharacteristicValueObject (ubic.gemma.model.genome.gene.phenotype.valueObject.CharacteristicValueObject)10 HashMap (java.util.HashMap)8 ArrayDesign (ubic.gemma.model.expression.arrayDesign.ArrayDesign)8 BioSequence2GeneProduct (ubic.gemma.model.association.BioSequence2GeneProduct)7 PhysicalLocation (ubic.gemma.model.genome.PhysicalLocation)7 BioSequence (ubic.gemma.model.genome.biosequence.BioSequence)7