Search in sources :

Example 71 with CompositeSequence

use of ubic.gemma.model.expression.designElement.CompositeSequence 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 72 with CompositeSequence

use of ubic.gemma.model.expression.designElement.CompositeSequence in project Gemma by PavlidisLab.

the class CompositeSequenceDaoImpl method find.

@Override
public CompositeSequence find(CompositeSequence compositeSequence) {
    if (compositeSequence.getName() == null)
        return null;
    Criteria queryObject = this.getSessionFactory().getCurrentSession().createCriteria(CompositeSequence.class);
    queryObject.add(Restrictions.eq("name", compositeSequence.getName()));
    queryObject.createCriteria("arrayDesign").add(Restrictions.eq("name", compositeSequence.getArrayDesign().getName()));
    java.util.List<?> results = queryObject.list();
    Object result = null;
    if (results != null) {
        if (results.size() > 1) {
            throw new org.springframework.dao.InvalidDataAccessResourceUsageException("More than one instance of '" + CompositeSequence.class.getName() + "' was found when executing query");
        } else if (results.size() == 1) {
            result = results.iterator().next();
        }
    }
    return (CompositeSequence) result;
}
Also used : java.util(java.util) CompositeSequenceValueObject(ubic.gemma.model.expression.designElement.CompositeSequenceValueObject) CompositeSequence(ubic.gemma.model.expression.designElement.CompositeSequence)

Example 73 with CompositeSequence

use of ubic.gemma.model.expression.designElement.CompositeSequence in project Gemma by PavlidisLab.

the class CompositeSequenceDaoImpl method batchGetGenesWithSpecificity.

/**
 * @param batch   of composite sequences to process
 * @param results - adding to this
 */
private void batchGetGenesWithSpecificity(Collection<CompositeSequence> batch, Map<CompositeSequence, Collection<BioSequence2GeneProduct>> results) {
    if (batch.size() == 0) {
        return;
    }
    // language=HQL
    final String queryString = "select cs,bas from CompositeSequence cs, BioSequence2GeneProduct bas inner join cs.biologicalCharacteristic bs " + "inner join fetch bas.geneProduct gp inner join fetch gp.gene gene " + "where bas.bioSequence=bs and cs in (:cs)";
    List<?> qr = this.getHibernateTemplate().findByNamedParam(queryString, "cs", batch);
    for (Object o : qr) {
        Object[] oa = (Object[]) o;
        CompositeSequence csa = (CompositeSequence) oa[0];
        BioSequence2GeneProduct ba = (BioSequence2GeneProduct) oa[1];
        if (ba instanceof BlatAssociation) {
            BlatResult blatResult = ((BlatAssociation) ba).getBlatResult();
            PhysicalLocation pl = blatResult.getTargetAlignedRegion();
            /*
                 * We didn't always used to fill in the targetAlignedRegion ... this is just in case.
                 */
            if (pl == null) {
                pl = PhysicalLocation.Factory.newInstance();
                pl.setChromosome(blatResult.getTargetChromosome());
                pl.setNucleotide(blatResult.getTargetStart());
                pl.setNucleotideLength(blatResult.getTargetEnd().intValue() - blatResult.getTargetStart().intValue());
                pl.setStrand(blatResult.getStrand());
            // Note: not bothering to fill in the bin.
            }
        }
        if (!results.containsKey(csa)) {
            results.put(csa, new HashSet<BioSequence2GeneProduct>());
        }
        results.get(csa).add(ba);
    }
    /*
         * This is kind of important. We ensure we return an empty map for probes that do not have a mapping.
         */
    for (CompositeSequence cs : batch) {
        if (!results.containsKey(cs)) {
            results.put(cs, new HashSet<BioSequence2GeneProduct>());
        }
    }
}
Also used : BioSequence2GeneProduct(ubic.gemma.model.association.BioSequence2GeneProduct) CompositeSequenceValueObject(ubic.gemma.model.expression.designElement.CompositeSequenceValueObject) CompositeSequence(ubic.gemma.model.expression.designElement.CompositeSequence) BlatAssociation(ubic.gemma.model.genome.sequenceAnalysis.BlatAssociation) BlatResult(ubic.gemma.model.genome.sequenceAnalysis.BlatResult) PhysicalLocation(ubic.gemma.model.genome.PhysicalLocation)

Example 74 with CompositeSequence

use of ubic.gemma.model.expression.designElement.CompositeSequence in project Gemma by PavlidisLab.

the class CompositeSequenceDaoImpl method loadValueObjectsPreFilter.

@Override
public Collection<CompositeSequenceValueObject> loadValueObjectsPreFilter(int offset, int limit, String orderBy, boolean asc, ArrayList<ObjectFilter[]> filter) {
    // Compose query
    Query query = this.getLoadValueObjectsQueryString(filter, orderBy, !asc);
    query.setCacheable(true);
    if (limit > 0)
        query.setMaxResults(limit);
    query.setFirstResult(offset);
    // noinspection unchecked
    List<Object[]> list = query.list();
    List<CompositeSequenceValueObject> vos = new ArrayList<>(list.size());
    for (Object[] row : list) {
        CompositeSequence cs = (CompositeSequence) row[1];
        cs.setArrayDesign((ArrayDesign) row[2]);
        CompositeSequenceValueObject vo = new CompositeSequenceValueObject(cs);
        vos.add(vo);
    }
    return vos;
}
Also used : CompositeSequenceValueObject(ubic.gemma.model.expression.designElement.CompositeSequenceValueObject) CompositeSequenceValueObject(ubic.gemma.model.expression.designElement.CompositeSequenceValueObject) CompositeSequence(ubic.gemma.model.expression.designElement.CompositeSequence)

Example 75 with CompositeSequence

use of ubic.gemma.model.expression.designElement.CompositeSequence in project Gemma by PavlidisLab.

the class CompositeSequenceServiceImpl method findByNamesInArrayDesigns.

/**
 * Checks to see if the CompositeSequence exists in any of the array designs. If so, it is internally stored in the
 * collection of composite sequences as a HashSet, preserving order based on insertion.
 */
@Override
public Collection<CompositeSequence> findByNamesInArrayDesigns(Collection<String> compositeSequenceNames, Collection<ArrayDesign> arrayDesigns) {
    LinkedHashMap<String, CompositeSequence> compositeSequencesMap = new LinkedHashMap<>();
    for (ArrayDesign arrayDesign : arrayDesigns) {
        for (Object obj : compositeSequenceNames) {
            String name = (String) obj;
            name = StringUtils.trim(name);
            AbstractService.log.debug("entered: " + name);
            CompositeSequence cs = this.findByName(arrayDesign, name);
            if (cs != null && !compositeSequencesMap.containsKey(cs.getName())) {
                compositeSequencesMap.put(cs.getName(), cs);
            } else {
                AbstractService.log.warn("Composite sequence " + name + " does not exist.  Discarding ... ");
            }
        }
    }
    if (compositeSequencesMap.isEmpty())
        return null;
    return compositeSequencesMap.values();
}
Also used : ArrayDesign(ubic.gemma.model.expression.arrayDesign.ArrayDesign) GeneValueObject(ubic.gemma.model.genome.gene.GeneValueObject) BioSequenceValueObject(ubic.gemma.model.genome.sequenceAnalysis.BioSequenceValueObject) BlatResultValueObject(ubic.gemma.model.genome.sequenceAnalysis.BlatResultValueObject) CompositeSequenceValueObject(ubic.gemma.model.expression.designElement.CompositeSequenceValueObject) GeneProductValueObject(ubic.gemma.model.genome.gene.GeneProductValueObject) CompositeSequence(ubic.gemma.model.expression.designElement.CompositeSequence)

Aggregations

CompositeSequence (ubic.gemma.model.expression.designElement.CompositeSequence)206 ArrayDesign (ubic.gemma.model.expression.arrayDesign.ArrayDesign)43 BioSequence (ubic.gemma.model.genome.biosequence.BioSequence)40 Gene (ubic.gemma.model.genome.Gene)32 Test (org.junit.Test)30 BioMaterial (ubic.gemma.model.expression.biomaterial.BioMaterial)19 ExpressionDataDoubleMatrix (ubic.gemma.core.datastructure.matrix.ExpressionDataDoubleMatrix)18 BioAssay (ubic.gemma.model.expression.bioAssay.BioAssay)18 DesignElementDataVector (ubic.gemma.model.expression.bioAssayData.DesignElementDataVector)18 RawExpressionDataVector (ubic.gemma.model.expression.bioAssayData.RawExpressionDataVector)18 StopWatch (org.apache.commons.lang3.time.StopWatch)17 HashSet (java.util.HashSet)15 BioAssayDimension (ubic.gemma.model.expression.bioAssayData.BioAssayDimension)15 CompositeSequenceValueObject (ubic.gemma.model.expression.designElement.CompositeSequenceValueObject)15 ArrayList (java.util.ArrayList)14 QuantitationType (ubic.gemma.model.common.quantitationtype.QuantitationType)14 BaseSpringContextTest (ubic.gemma.core.testing.BaseSpringContextTest)13 Taxon (ubic.gemma.model.genome.Taxon)12 Collection (java.util.Collection)11 ByteArrayConverter (ubic.basecode.io.ByteArrayConverter)11