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;
}
}
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);
}
}
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;
}
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;
}
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;
}
Aggregations