Search in sources :

Example 11 with GeneProduct

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

the class ExternalFileGeneLoaderServiceImpl method createGeneProduct.

/**
 * When loading genes with a file each gene will have just 1 gene product. The gene product is a filler taking its
 * details from the gene.
 *
 * @param gene The gene associated to this gene product
 * @return Collection of gene products in this case just 1.
 */
private GeneProduct createGeneProduct(Gene gene) {
    GeneProduct geneProduct = GeneProduct.Factory.newInstance();
    geneProduct.setType(GeneProductType.RNA);
    geneProduct.setGene(gene);
    geneProduct.setName(gene.getName());
    geneProduct.setDescription("Gene product placeholder");
    return geneProduct;
}
Also used : GeneProduct(ubic.gemma.model.genome.gene.GeneProduct)

Example 12 with GeneProduct

use of ubic.gemma.model.genome.gene.GeneProduct 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 13 with GeneProduct

use of ubic.gemma.model.genome.gene.GeneProduct 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 14 with GeneProduct

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

the class GeneProductServiceImpl method remove.

@Override
@Transactional
public void remove(Collection<GeneProduct> toRemove) {
    Collection<BlatAssociation> associations = this.blatAssociationDao.find(toRemove);
    if (!associations.isEmpty()) {
        AbstractService.log.info("Removing " + associations.size() + " blat associations involving up to " + toRemove.size() + " products.");
        this.blatAssociationDao.remove(associations);
    }
    Collection<AnnotationAssociation> annotationAssociations = this.annotationAssociationDao.find(toRemove);
    if (!annotationAssociations.isEmpty()) {
        AbstractService.log.info("Removing " + annotationAssociations.size() + " annotationAssociations involving up to " + toRemove.size() + " products.");
        this.annotationAssociationDao.remove(annotationAssociations);
    }
    // remove associations to database entries that are still associated with sequences.
    for (GeneProduct gp : toRemove) {
        gp = this.thaw(gp);
        Collection<DatabaseEntry> accessions = gp.getAccessions();
        Collection<DatabaseEntry> toRelease = new HashSet<>();
        for (DatabaseEntry de : accessions) {
            if (this.bioSequenceDao.findByAccession(de) != null) {
                toRelease.add(de);
            }
        }
        gp.getAccessions().removeAll(toRelease);
        this.geneProductDao.remove(gp);
    }
}
Also used : GeneProduct(ubic.gemma.model.genome.gene.GeneProduct) AnnotationAssociation(ubic.gemma.model.genome.sequenceAnalysis.AnnotationAssociation) DatabaseEntry(ubic.gemma.model.common.description.DatabaseEntry) BlatAssociation(ubic.gemma.model.genome.sequenceAnalysis.BlatAssociation) HashSet(java.util.HashSet) Transactional(org.springframework.transaction.annotation.Transactional)

Example 15 with GeneProduct

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

the class GenomePersister method persistGeneProduct.

private GeneProduct persistGeneProduct(GeneProduct geneProduct) {
    if (geneProduct == null)
        return null;
    if (!this.isTransient(geneProduct))
        return geneProduct;
    GeneProduct existing = geneProductDao.find(geneProduct);
    if (existing != null) {
        if (AbstractPersister.log.isDebugEnabled())
            AbstractPersister.log.debug(geneProduct + " exists, will not update");
        return existing;
    }
    if (AbstractPersister.log.isDebugEnabled())
        AbstractPersister.log.debug("*** New: " + geneProduct + " *** ");
    this.fillInGeneProductAssociations(geneProduct);
    if (this.isTransient(geneProduct.getGene())) {
        // this results in the persistence of the gene products, but only if the gene is transient.
        geneProduct.setGene(this.persistGene(geneProduct.getGene()));
    } else {
        geneProduct = geneProductDao.create(geneProduct);
    }
    if (geneProduct.getId() == null) {
        return geneProductDao.create(geneProduct);
    }
    return geneProduct;
}
Also used : BioSequence2GeneProduct(ubic.gemma.model.association.BioSequence2GeneProduct) GeneProduct(ubic.gemma.model.genome.gene.GeneProduct)

Aggregations

GeneProduct (ubic.gemma.model.genome.gene.GeneProduct)41 Gene (ubic.gemma.model.genome.Gene)20 HashSet (java.util.HashSet)16 BioSequence2GeneProduct (ubic.gemma.model.association.BioSequence2GeneProduct)12 DatabaseEntry (ubic.gemma.model.common.description.DatabaseEntry)8 BlatAssociation (ubic.gemma.model.genome.sequenceAnalysis.BlatAssociation)8 Test (org.junit.Test)6 BaseSpringContextTest (ubic.gemma.core.testing.BaseSpringContextTest)5 BioSequence (ubic.gemma.model.genome.biosequence.BioSequence)5 AnnotationAssociation (ubic.gemma.model.genome.sequenceAnalysis.AnnotationAssociation)5 HashMap (java.util.HashMap)4 PhysicalLocation (ubic.gemma.model.genome.PhysicalLocation)4 Criteria (org.hibernate.Criteria)3 CompositeSequence (ubic.gemma.model.expression.designElement.CompositeSequence)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 GeneProductValueObject (ubic.gemma.model.genome.gene.GeneProductValueObject)2 BufferedReader (java.io.BufferedReader)1 FileReader (java.io.FileReader)1