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