use of ubic.gemma.model.genome.Taxon in project Gemma by PavlidisLab.
the class TaxonDaoImpl method find.
@Override
public Taxon find(Taxon taxon) {
BusinessKey.checkValidKey(taxon);
Criteria queryObject = this.getSessionFactory().getCurrentSession().createCriteria(Taxon.class).setReadOnly(true);
queryObject.setReadOnly(true);
queryObject.setFlushMode(FlushMode.MANUAL);
BusinessKey.addRestrictions(queryObject, taxon);
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 '" + taxon.getClass().getName() + "' was found when executing query");
} else if (results.size() == 1) {
result = results.iterator().next();
}
}
return (Taxon) result;
}
use of ubic.gemma.model.genome.Taxon in project Gemma by PavlidisLab.
the class TaxonServiceImpl method getTaxaWithArrays.
/**
* @return List of taxa with array designs in gemma
*/
@Override
@Transactional(readOnly = true)
public Collection<TaxonValueObject> getTaxaWithArrays() {
Set<TaxonValueObject> taxaWithArrays = new TreeSet<>(TaxonServiceImpl.TAXON_VO_COMPARATOR);
for (Taxon taxon : arrayDesignService.getPerTaxonCount().keySet()) {
taxaWithArrays.add(TaxonValueObject.fromEntity(taxon));
}
AbstractService.log.debug("GenePicker::getTaxaWithArrays returned " + taxaWithArrays.size() + " results");
return taxaWithArrays;
}
use of ubic.gemma.model.genome.Taxon in project Gemma by PavlidisLab.
the class ArrayDesignDaoImpl method getPerTaxonCount.
@Override
public Map<Taxon, Long> getPerTaxonCount() {
Map<Taxon, Long> result = new HashMap<>();
final String csString = "select t, count(ad) from ArrayDesign ad inner join ad.primaryTaxon t group by t ";
org.hibernate.Query csQueryObject = this.getSessionFactory().getCurrentSession().createQuery(csString);
csQueryObject.setReadOnly(true);
csQueryObject.setCacheable(true);
List csList = csQueryObject.list();
Taxon t;
for (Object object : csList) {
Object[] oa = (Object[]) object;
t = (Taxon) oa[0];
Long count = (Long) oa[1];
result.put(t, count);
}
return result;
}
use of ubic.gemma.model.genome.Taxon in project Gemma by PavlidisLab.
the class ExpressionExperimentDaoImpl method getPerTaxonCount.
@Override
public Map<Taxon, Long> getPerTaxonCount() {
Map<Taxon, Taxon> taxonParents = new HashMap<>();
// noinspection unchecked
List<Object[]> tp = this.getSessionFactory().getCurrentSession().createQuery("select t, p from Taxon t left outer join t.parentTaxon p").list();
for (Object[] o : tp) {
taxonParents.put((Taxon) o[0], (Taxon) o[1]);
}
Map<Taxon, Long> taxonCount = new LinkedHashMap<>();
String queryString = "select t, count(distinct ee) from ExpressionExperiment " + "ee inner join ee.bioAssays as ba inner join ba.sampleUsed su " + "inner join su.sourceTaxon t group by t order by t.scientificName ";
// it is important to cache this, as it gets called on the home page. Though it's actually fast.
org.hibernate.Query queryObject = this.getSessionFactory().getCurrentSession().createQuery(queryString);
queryObject.setCacheable(true);
ScrollableResults list = queryObject.scroll();
while (list.next()) {
Taxon taxon = (Taxon) list.get(0);
Taxon parent = taxonParents.get(taxon);
Long count = list.getLong(1);
if (parent != null) {
if (!taxonCount.containsKey(parent)) {
taxonCount.put(parent, 0L);
}
taxonCount.put(parent, taxonCount.get(parent) + count);
} else {
taxonCount.put(taxon, count);
}
}
return taxonCount;
}
use of ubic.gemma.model.genome.Taxon in project Gemma by PavlidisLab.
the class GeneCoexpressionSearchServiceImpl method doCoexpressionSearch.
/**
* @param genes 1 or more.
* @param stringency; this may be modified to control the number of results, unless "queryGenesOnly" is true.
* @param maxResults per gene, not including the query genes themselves. Ignored if this is 'queryGenesOnly'
* @param queryGenesOnly will be ignored if number of genes is 1.
* @return CoexpressionMetaValueObject, in which the results are already populated and sorted.
*/
private CoexpressionMetaValueObject doCoexpressionSearch(Collection<Long> inputEeIds, Collection<Long> genes, int stringency, final int maxResults, final boolean queryGenesOnly, final boolean quick) {
if (genes.isEmpty()) {
CoexpressionMetaValueObject r = new CoexpressionMetaValueObject();
r.setErrorState("No genes selected");
return r;
}
boolean actuallyUseQueryGeneOnly = queryGenesOnly && genes.size() > 1;
Taxon taxon = this.geneService.load(genes.iterator().next()).getTaxon();
List<ExpressionExperimentValueObject> eevos = this.getFilteredEEVos(inputEeIds, taxon);
CoexpressionMetaValueObject result = this.initValueObject(genes, eevos);
if (eevos.isEmpty()) {
result = new CoexpressionMetaValueObject();
result.setErrorState("No experiments selected");
return result;
}
Collection<Long> eeIds = EntityUtils.getIds(eevos);
Map<Long, List<CoexpressionValueObject>> allCoexpressions;
if (genes.size() > GeneCoexpressionSearchServiceImpl.THRESHOLD_TRIGGER_QUERY_GENES_ONLY) {
if (!actuallyUseQueryGeneOnly) {
GeneCoexpressionSearchServiceImpl.log.info("Switching to 'query genes only'");
}
actuallyUseQueryGeneOnly = true;
}
if (stringency < 1)
stringency = 1;
if (!queryGenesOnly) {
stringency = Math.max(stringency, this.chooseStringency(actuallyUseQueryGeneOnly, eeIds.size(), genes.size()));
GeneCoexpressionSearchServiceImpl.log.info("Stringency set to " + stringency + " based on number of experiments (" + eeIds.size() + ") and genes (" + genes.size() + ") queried");
} else {
GeneCoexpressionSearchServiceImpl.log.info("Query gene only: stringency maintained at requested value=" + stringency);
}
assert stringency >= 1 || eeIds.size() == 1;
// HACK drop the stringency until we get some results.
int stepSize = 3;
while (true) {
if (actuallyUseQueryGeneOnly) {
// note that maxResults is ignored.
if (genes.size() < 2) {
// should be impossible - could assert.
throw new IllegalArgumentException("cannot do inter-gene coexpression search with only one gene");
}
allCoexpressions = coexpressionService.findInterCoexpressionRelationships(taxon, genes, eeIds, stringency, quick);
} else {
allCoexpressions = coexpressionService.findCoexpressionRelationships(taxon, genes, eeIds, stringency, maxResults, quick);
}
int minimum_stringency_for_requery = 2;
if (allCoexpressions.isEmpty() && stringency > minimum_stringency_for_requery) {
// step size completely made up.
stringency -= stepSize;
// keep stringency at least 2.
stringency = Math.max(minimum_stringency_for_requery, stringency);
GeneCoexpressionSearchServiceImpl.log.info("No results, re-querying with stringency=" + stringency);
} else {
// no results.
break;
}
}
GeneCoexpressionSearchServiceImpl.log.info("Final actual stringency used was " + stringency);
result.setQueryStringency(stringency);
result.setQueryGenesOnly(actuallyUseQueryGeneOnly);
Set<Long> queryGeneIds = allCoexpressions.keySet();
assert genes.containsAll(queryGeneIds);
Map<Long, GeneValueObject> idMap = EntityUtils.getIdMap(geneService.loadValueObjectsByIds(queryGeneIds));
int k = 0;
for (Long queryGene : queryGeneIds) {
Collection<CoexpressionValueObject> coexpressions = allCoexpressions.get(queryGene);
List<CoexpressionValueObjectExt> results = this.addExtCoexpressionValueObjects(idMap.get(queryGene), coexpressions, actuallyUseQueryGeneOnly, genes);
result.getResults().addAll(results);
CoexpressionSummaryValueObject summary = new CoexpressionSummaryValueObject(queryGene);
summary.setDatasetsAvailable(eevos.size());
summary.setLinksFound(coexpressions.size());
result.getSummaries().put(queryGene, summary);
if (++k % 100 == 0) {
GeneCoexpressionSearchServiceImpl.log.info("Processed results for " + k + " query genes ...");
}
}
Collections.sort(result.getResults());
// FIXME we might want to suppress this in some situations
if (!queryGenesOnly) {
result.trim();
}
this.populateNodeDegrees(result);
return result;
}
Aggregations