Search in sources :

Example 41 with BioSequence

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

the class BioSequenceDaoImpl method findByAccession.

@Override
public BioSequence findByAccession(DatabaseEntry databaseEntry) {
    BusinessKey.checkValidKey(databaseEntry);
    String queryString;
    List<BioSequence> results;
    if (databaseEntry.getId() != null) {
        queryString = "select b from BioSequenceImpl b inner join fetch b.sequenceDatabaseEntry d inner join fetch d.externalDatabase e  where d=:dbe";
        // noinspection unchecked
        results = this.getSessionFactory().getCurrentSession().createQuery(queryString).setParameter("dbe", databaseEntry).list();
    } else {
        queryString = "select b from BioSequenceImpl b inner join fetch b.sequenceDatabaseEntry d " + "inner join fetch d.externalDatabase e where d.accession = :acc and e.name = :dbName";
        // noinspection unchecked
        results = this.getSessionFactory().getCurrentSession().createQuery(queryString).setParameter("acc", databaseEntry.getAccession()).setParameter("dbName", databaseEntry.getExternalDatabase().getName()).list();
    }
    if (results.size() > 1) {
        this.debug(null, results);
        AbstractDao.log.warn("More than one instance of '" + BioSequence.class.getName() + "' was found when executing query for accession=" + databaseEntry.getAccession());
        // favor the one with name matching the accession.
        for (Object object : results) {
            BioSequence bs = (BioSequence) object;
            if (bs.getName().equals(databaseEntry.getAccession())) {
                return bs;
            }
        }
        AbstractDao.log.error("No biosequence really matches " + databaseEntry.getAccession());
        return null;
    } else if (results.size() == 1) {
        return results.iterator().next();
    } else {
        return null;
    }
}
Also used : BioSequence(ubic.gemma.model.genome.biosequence.BioSequence) BioSequenceValueObject(ubic.gemma.model.genome.sequenceAnalysis.BioSequenceValueObject)

Example 42 with BioSequence

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

the class BioSequenceDaoImpl method findByGenesBatch.

private void findByGenesBatch(Collection<Gene> genes, Map<Gene, Collection<BioSequence>> results) {
    // noinspection unchecked
    List<Object[]> qr = this.getSessionFactory().getCurrentSession().createQuery("select distinct gene,bs from Gene gene inner join fetch gene.products ggp," + " BioSequenceImpl bs inner join bs.bioSequence2GeneProduct bs2gp inner join bs2gp.geneProduct bsgp" + " where ggp=bsgp and gene in (:genes)").setParameterList("genes", genes).list();
    for (Object[] oa : qr) {
        Gene g = (Gene) oa[0];
        BioSequence b = (BioSequence) oa[1];
        if (!results.containsKey(g)) {
            results.put(g, new HashSet<BioSequence>());
        }
        results.get(g).add(b);
    }
}
Also used : Gene(ubic.gemma.model.genome.Gene) BioSequence(ubic.gemma.model.genome.biosequence.BioSequence) BioSequenceValueObject(ubic.gemma.model.genome.sequenceAnalysis.BioSequenceValueObject)

Example 43 with BioSequence

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

the class BioSequenceDaoImpl method thaw.

@Override
public Collection<BioSequence> thaw(final Collection<BioSequence> bioSequences) {
    if (bioSequences.isEmpty())
        return new HashSet<>();
    Collection<BioSequence> result = new HashSet<>();
    Collection<BioSequence> batch = new HashSet<>();
    for (BioSequence g : bioSequences) {
        batch.add(g);
        if (batch.size() == 100) {
            result.addAll(this.doThawBatch(batch));
            batch.clear();
        }
    }
    if (!batch.isEmpty()) {
        result.addAll(this.doThawBatch(batch));
    }
    return result;
}
Also used : BioSequence(ubic.gemma.model.genome.biosequence.BioSequence)

Example 44 with BioSequence

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

the class ArrayDesignDaoImpl method getBioSequences.

@Override
public Map<CompositeSequence, BioSequence> getBioSequences(ArrayDesign arrayDesign) {
    if (arrayDesign.getId() == null) {
        throw new IllegalArgumentException("Cannot fetch sequences for a non-persistent array design");
    }
    StopWatch timer = new StopWatch();
    timer.start();
    String queryString = "select ad from ArrayDesign ad inner join fetch ad.compositeSequences cs " + "left outer join fetch cs.biologicalCharacteristic bs where ad = :ad";
    // have to include ad in the select to be able to use fetch join
    Query query = this.getSessionFactory().getCurrentSession().createQuery(queryString).setParameter("ad", arrayDesign);
    List result = query.list();
    Map<CompositeSequence, BioSequence> bioSequences = new HashMap<>();
    if (result.isEmpty()) {
        return bioSequences;
    }
    for (CompositeSequence cs : ((ArrayDesign) result.get(0)).getCompositeSequences()) {
        bioSequences.put(cs, cs.getBiologicalCharacteristic());
    }
    if (timer.getTime() > 1000) {
        AbstractDao.log.info("Fetch sequences: " + timer.getTime() + "ms");
    }
    return bioSequences;
}
Also used : BioSequence(ubic.gemma.model.genome.biosequence.BioSequence) ArrayDesign(ubic.gemma.model.expression.arrayDesign.ArrayDesign) CompositeSequence(ubic.gemma.model.expression.designElement.CompositeSequence) StopWatch(org.apache.commons.lang3.time.StopWatch)

Example 45 with BioSequence

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

the class ArrayDesignMergeServiceImpl method makeBioSeqMap.

/**
 * If we're merging into an existing platform, it is important that this method is called for that platform first.
 *
 * @param globalBsMap Map that tells us, in effect, how many probes to make for the sequence. Modified by this.
 */
private ArrayDesign makeBioSeqMap(Map<BioSequence, Collection<CompositeSequence>> globalBsMap, ArrayDesign arrayDesign) {
    Map<BioSequence, Collection<CompositeSequence>> bsMap = new HashMap<>();
    arrayDesign = this.arrayDesignService.thaw(arrayDesign);
    int count = 0;
    for (CompositeSequence cs : arrayDesign.getCompositeSequences()) {
        BioSequence bs = cs.getBiologicalCharacteristic();
        if (bs == null) {
            // this is common. We could try to match them up based on the probe name, because there is nothing else
            // to go on.
            bs = ExpressionExperimentPlatformSwitchService.NULL_BIOSEQUENCE;
        }
        if (!globalBsMap.containsKey(bs)) {
            globalBsMap.put(bs, new HashSet<CompositeSequence>());
        }
        if (!bsMap.containsKey(bs)) {
            bsMap.put(bs, new HashSet<CompositeSequence>());
        }
        bsMap.get(bs).add(cs);
        /*
             * We need at one probe for each time the sequence appears on one platform. Here we ensure that the global
             * map has enough 'slots'.
             */
        if (globalBsMap.get(bs).size() < bsMap.get(bs).size()) {
            globalBsMap.get(bs).add(cs);
        }
    }
    if (++count % 10000 == 0) {
        ArrayDesignMergeServiceImpl.log.info("Processed " + count + " probes");
    }
    return arrayDesign;
}
Also used : BioSequence(ubic.gemma.model.genome.biosequence.BioSequence) HashMap(java.util.HashMap) Collection(java.util.Collection) CompositeSequence(ubic.gemma.model.expression.designElement.CompositeSequence)

Aggregations

BioSequence (ubic.gemma.model.genome.biosequence.BioSequence)105 CompositeSequence (ubic.gemma.model.expression.designElement.CompositeSequence)40 ArrayDesign (ubic.gemma.model.expression.arrayDesign.ArrayDesign)24 Test (org.junit.Test)18 HashSet (java.util.HashSet)17 Taxon (ubic.gemma.model.genome.Taxon)15 BlatResult (ubic.gemma.model.genome.sequenceAnalysis.BlatResult)12 InputStream (java.io.InputStream)11 Collection (java.util.Collection)11 HashMap (java.util.HashMap)10 BaseSpringContextTest (ubic.gemma.core.testing.BaseSpringContextTest)10 GZIPInputStream (java.util.zip.GZIPInputStream)7 Gene (ubic.gemma.model.genome.Gene)7 GeoPlatform (ubic.gemma.core.loader.expression.geo.model.GeoPlatform)6 DatabaseEntry (ubic.gemma.model.common.description.DatabaseEntry)6 StopWatch (org.apache.commons.lang3.time.StopWatch)5 GeneProduct (ubic.gemma.model.genome.gene.GeneProduct)5 BioSequenceValueObject (ubic.gemma.model.genome.sequenceAnalysis.BioSequenceValueObject)5 BlatAssociation (ubic.gemma.model.genome.sequenceAnalysis.BlatAssociation)5 AbstractGeoServiceTest (ubic.gemma.core.loader.expression.geo.AbstractGeoServiceTest)4