Search in sources :

Example 56 with Gene

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

the class StringProteinProteinInteractionConverter method getNcbiGene.

/**
 * One ensemblProteinID can map to multiple ncbi genes. This method takes the ensembl gene and creates a collection
 * of entrez ncbi genes. It first has to remove the taxon id from the beginning of the peptide id as given by
 * string.
 *
 * @param ensemblProteinId The ensembl protein id in this interaction
 * @return Collection of genes as represented in ncbi entrez gene
 */
public Collection<Gene> getNcbiGene(String ensemblProteinId) {
    // log.debug("getting ncbi gene for ensembl id " + ensemblProteinId);
    Collection<Gene> genes = new ArrayList<>();
    // in case species id is still on there from STRING like 12334.ENSD....
    String eid = ensemblProteinId.replaceFirst("[0-9]+\\.", "");
    Ensembl2NcbiValueObject e2n = ensembl2ncbi.get(eid);
    if (e2n == null || e2n.getEntrezgenes().isEmpty()) {
        return genes;
    }
    String ensemblGeneId = e2n.getEnsemblGeneId();
    Collection<String> entrezGeneIds = (e2n.getEntrezgenes());
    for (String entrezGeneId : entrezGeneIds) {
        if (!entrezGeneId.isEmpty()) {
            Gene gene = Gene.Factory.newInstance();
            gene.setNcbiGeneId(Integer.parseInt(entrezGeneId));
            gene.setEnsemblId(ensemblGeneId);
            genes.add(gene);
            if (StringProteinProteinInteractionConverter.log.isDebugEnabled())
                StringProteinProteinInteractionConverter.log.debug("Entry found for entrezGeneId " + entrezGeneId);
        }
    }
    return genes;
}
Also used : Ensembl2NcbiValueObject(ubic.gemma.core.loader.protein.biomart.model.Ensembl2NcbiValueObject) Gene(ubic.gemma.model.genome.Gene) ArrayList(java.util.ArrayList)

Example 57 with Gene

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

the class ExternalFileGeneLoaderServiceImpl method createGene.

/**
 * Creates a gene, where gene name and official gene symbol is set to gene symbol(from file) and official name is
 * set to geneName(from file). The gene description is set to a message indicating that the gene was imported from
 * an external file and the associated uniprot id.
 * If the gene already exists, then it is not modified, unless it lacks a gene product. In that case we add one and
 * return it.
 *
 * @param fields A string array containing gene symbol, gene name and uniprot id.
 * @param taxon  Taxon relating to gene
 * @return Gene with associated gene product for loading into Gemma. Null if no gene was loaded (exists, or invalid
 * fields) or modified.
 */
private Gene createGene(String[] fields, Taxon taxon) {
    assert fields.length > 1;
    String geneSymbol = fields[0];
    String geneName = fields[1];
    String uniProt = "";
    if (fields.length > 2)
        uniProt = fields[2];
    Gene gene;
    // need at least the gene symbol and gene name
    if (StringUtils.isBlank(geneSymbol) || StringUtils.isBlank(geneName)) {
        log.warn("Line did not contain valid gene information; GeneSymbol=" + geneSymbol + "GeneName=" + geneName + " UniProt=" + uniProt);
        return null;
    }
    if (log.isDebugEnabled())
        log.debug("Creating gene " + geneSymbol);
    gene = geneService.findByOfficialSymbol(geneSymbol, taxon);
    if (gene != null) {
        Collection<GeneProductValueObject> existingProducts = geneService.getProducts(gene.getId());
        if (existingProducts.isEmpty()) {
            log.warn("Gene " + gene + " exists, but has no products; adding one");
            gene = geneService.thaw(gene);
            GeneProduct newgp = createGeneProduct(gene);
            newgp = geneProductService.create(newgp);
            gene.getProducts().add(newgp);
            geneService.update(gene);
            return gene;
        }
        log.info(gene + " already exists and is valid, will not update");
        // no need to create it, though we ignore the name.
        return null;
    }
    gene = Gene.Factory.newInstance();
    gene.setName(geneSymbol);
    gene.setOfficialSymbol(geneSymbol);
    gene.setOfficialName(StringUtils.lowerCase(geneName));
    gene.setDescription("Imported from external annotation file");
    gene.setTaxon(taxon);
    gene.getProducts().add(createGeneProduct(gene));
    gene = (Gene) persisterHelper.persistOrUpdate(gene);
    return gene;
}
Also used : GeneProduct(ubic.gemma.model.genome.gene.GeneProduct) GeneProductValueObject(ubic.gemma.model.genome.gene.GeneProductValueObject) Gene(ubic.gemma.model.genome.Gene)

Example 58 with Gene

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

the class CompositeSequenceDaoImpl method thaw.

@Override
public void thaw(final Collection<CompositeSequence> compositeSequences) {
    HibernateTemplate templ = this.getHibernateTemplate();
    templ.executeWithNativeSession(new org.springframework.orm.hibernate3.HibernateCallback<Object>() {

        @Override
        public Object doInHibernate(org.hibernate.Session session) throws org.hibernate.HibernateException {
            int i = 0;
            int numToDo = compositeSequences.size();
            for (CompositeSequence cs : compositeSequences) {
                session.buildLockRequest(LockOptions.NONE).lock(cs);
                Hibernate.initialize(cs.getArrayDesign());
                BioSequence bs = cs.getBiologicalCharacteristic();
                if (bs == null) {
                    continue;
                }
                session.buildLockRequest(LockOptions.NONE).lock(bs);
                Hibernate.initialize(bs);
                Hibernate.initialize(bs.getTaxon());
                DatabaseEntry dbEntry = bs.getSequenceDatabaseEntry();
                if (dbEntry != null) {
                    Hibernate.initialize(dbEntry);
                    Hibernate.initialize(dbEntry.getExternalDatabase());
                    session.evict(dbEntry);
                    session.evict(dbEntry.getExternalDatabase());
                }
                if (bs.getBioSequence2GeneProduct() == null) {
                    continue;
                }
                for (BioSequence2GeneProduct bs2gp : bs.getBioSequence2GeneProduct()) {
                    if (bs2gp == null) {
                        continue;
                    }
                    GeneProduct geneProduct = bs2gp.getGeneProduct();
                    if (geneProduct != null && geneProduct.getGene() != null) {
                        Gene g = geneProduct.getGene();
                        g.getAliases().size();
                        session.evict(g);
                        session.evict(geneProduct);
                    }
                }
                if (++i % 2000 == 0) {
                    AbstractDao.log.info("Progress: " + i + "/" + numToDo + "...");
                    try {
                        Thread.sleep(10);
                    } catch (InterruptedException e) {
                    // 
                    }
                }
                session.evict(bs);
            }
            session.clear();
            return null;
        }
    });
}
Also used : BioSequence(ubic.gemma.model.genome.biosequence.BioSequence) HibernateTemplate(org.springframework.orm.hibernate3.HibernateTemplate) BioSequence2GeneProduct(ubic.gemma.model.association.BioSequence2GeneProduct) DatabaseEntry(ubic.gemma.model.common.description.DatabaseEntry) org.hibernate(org.hibernate) CompositeSequence(ubic.gemma.model.expression.designElement.CompositeSequence) BioSequence2GeneProduct(ubic.gemma.model.association.BioSequence2GeneProduct) GeneProduct(ubic.gemma.model.genome.gene.GeneProduct) Gene(ubic.gemma.model.genome.Gene) CompositeSequenceValueObject(ubic.gemma.model.expression.designElement.CompositeSequenceValueObject)

Example 59 with Gene

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

the class GeneDaoImpl method thawLite.

@Override
public Collection<Gene> thawLite(final Collection<Gene> genes) {
    if (genes.isEmpty())
        return new HashSet<>();
    Collection<Gene> result = new HashSet<>();
    Collection<Gene> batch = new HashSet<>();
    for (Gene g : genes) {
        batch.add(g);
        if (batch.size() == GeneDaoImpl.BATCH_SIZE) {
            result.addAll(this.loadThawed(EntityUtils.getIds(batch)));
            batch.clear();
        }
    }
    if (!batch.isEmpty()) {
        result.addAll(this.loadThawed(EntityUtils.getIds(batch)));
    }
    return result;
}
Also used : Gene(ubic.gemma.model.genome.Gene)

Example 60 with Gene

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

the class GeneDaoImpl method loadThawed.

@Override
public Collection<Gene> loadThawed(Collection<Long> ids) {
    Collection<Gene> result = new HashSet<>();
    if (ids.isEmpty())
        return result;
    StopWatch timer = new StopWatch();
    timer.start();
    for (Collection<Long> batch : new BatchIterator<>(ids, GeneDaoImpl.BATCH_SIZE)) {
        result.addAll(this.doLoadThawedLite(batch));
    }
    if (timer.getTime() > 1000) {
        AbstractDao.log.debug("Load+thawRawAndProcessed " + result.size() + " genes: " + timer.getTime() + "ms");
    }
    return result;
}
Also used : Gene(ubic.gemma.model.genome.Gene) BatchIterator(ubic.basecode.util.BatchIterator) StopWatch(org.apache.commons.lang3.time.StopWatch)

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