use of ubic.gemma.model.genome.gene.GeneValueObject in project Gemma by PavlidisLab.
the class DifferentialExpressionResultDaoImpl method find.
@Override
public Map<ExpressionExperimentValueObject, List<DifferentialExpressionValueObject>> find(Gene gene, double threshold, Integer limit) {
StopWatch timer = new StopWatch();
timer.start();
Session session = this.getSessionFactory().getCurrentSession();
String sql = DifferentialExpressionResultDaoImpl.fetchResultsByGeneSQL;
if (threshold > 0.0) {
sql = sql + " and d.CORRECTED_PVALUE < :threshold ";
}
if (limit != null) {
sql = sql + " order by d.PVALUE ASC ";
}
SQLQuery query = session.createSQLQuery(sql);
query.setParameter("gene_id", gene.getId());
if (limit != null) {
query.setMaxResults(limit);
}
if (threshold > 0.0) {
query.setParameter("threshold", threshold);
}
Map<ExpressionExperimentValueObject, List<DifferentialExpressionValueObject>> results = new HashMap<>();
// noinspection unchecked
List<Object[]> qResult = query.list();
Set<Long> resultSets = new HashSet<>();
Map<Long, DifferentialExpressionValueObject> resultsInter = new HashMap<>();
Set<Long> probeIds = new HashSet<>();
GeneValueObject genevo = new GeneValueObject(gene);
for (Object[] rec : qResult) {
Long id = SQLUtils.asId(rec[0]);
if (!resultsInter.containsKey(id)) {
DifferentialExpressionValueObject vo = new DifferentialExpressionValueObject(id);
vo.setP((Double) rec[1]);
vo.setCorrP((Double) rec[2]);
// fill in probe name later.
vo.setProbeId(SQLUtils.asId(rec[3]));
probeIds.add(vo.getProbeId());
vo.setResultSetId(SQLUtils.asId(rec[4]));
if (threshold > 0)
vo.setMetThreshold(true);
vo.setGene(genevo);
// gather up result sets so we can fetch the experiments, experimental factors
resultSets.add(vo.getResultSetId());
resultsInter.put(id, vo);
}
resultsInter.get(id).addContrast(SQLUtils.asId(rec[9]), SQLUtils.asId(rec[5]), (Double) rec[6], (Double) rec[7], SQLUtils.asId(rec[8]));
}
// gather up probe information
Map<Long, String> probeNames = new HashMap<>();
// noinspection unchecked
for (Object[] rec : (List<Object[]>) session.createQuery("select id,name from CompositeSequence where id in (:ids)").setParameterList("ids", probeIds).list()) {
probeNames.put((Long) rec[0], (String) rec[1]);
}
/*
* load the result set information.
*/
if (resultSets.isEmpty())
return results;
// noinspection unchecked
List<Object[]> ees = session.createQuery("select ee, rs from ExpressionAnalysisResultSet rs join fetch rs.experimentalFactors join rs.analysis a join a.experimentAnalyzed ee" + " where rs.id in (:rsids)").setParameterList("rsids", resultSets).list();
/*
* Finish populating the objects
*/
for (Object[] oa : ees) {
ExpressionAnalysisResultSet rs = (ExpressionAnalysisResultSet) oa[1];
ExpressionExperimentValueObject evo = ((BioAssaySet) oa[0]).createValueObject();
if (!results.containsKey(evo)) {
results.put(evo, new ArrayList<DifferentialExpressionValueObject>());
}
for (Iterator<DifferentialExpressionValueObject> it = resultsInter.values().iterator(); it.hasNext(); ) {
DifferentialExpressionValueObject dvo = it.next();
dvo.setExpressionExperiment(evo);
dvo.setProbe(probeNames.get(dvo.getProbeId()));
dvo.getExperimentalFactors().clear();
for (ExperimentalFactor ef : rs.getExperimentalFactors()) {
dvo.getExperimentalFactors().add(new ExperimentalFactorValueObject(ef));
}
if (dvo.getResultSetId().equals(rs.getId())) {
results.get(evo).add(dvo);
it.remove();
}
}
}
AbstractDao.log.debug("Num experiments with probe analysis results (with limit = " + limit + ") : " + results.size() + ". Number of results (probes x contrasts) returned in total: " + qResult.size());
timer.stop();
if (timer.getTime() > 1000) {
AbstractDao.log.info("Diff ex results: " + timer.getTime() + " ms");
}
return results;
}
use of ubic.gemma.model.genome.gene.GeneValueObject in project Gemma by PavlidisLab.
the class GeneArg method getValueObjects.
/**
* Lists Gene Value Objects of all genes that this GeneArg represents, discarding any genes that are not on the
* given taxon.
*
* @param service the service to use to retrieve the Gene Value Objects.
* @param taxon the taxon to limit the genes search to.
* @return collection of Gene Value Objects.
*/
private Collection<GeneValueObject> getValueObjects(GeneService service, Taxon taxon) {
Collection<GeneValueObject> genes = this.getValueObjects(service);
Collection<GeneValueObject> result = new ArrayList<>(genes.size());
for (GeneValueObject vo : genes) {
if (Objects.equals(vo.getTaxonId(), taxon.getId())) {
result.add(vo);
}
}
if (result.isEmpty()) {
this.nullCause = this.getTaxonError();
return null;
}
return result;
}
use of ubic.gemma.model.genome.gene.GeneValueObject in project Gemma by PavlidisLab.
the class GeneDiffExMetaAnalysisHelperServiceImpl method convertToValueObject.
@Override
public GeneDifferentialExpressionMetaAnalysisDetailValueObject convertToValueObject(GeneDifferentialExpressionMetaAnalysis metaAnalysis) {
if (metaAnalysis == null) {
return null;
}
GeneDifferentialExpressionMetaAnalysisDetailValueObject analysisVO = new GeneDifferentialExpressionMetaAnalysisDetailValueObject();
analysisVO.setNumGenesAnalyzed(metaAnalysis.getNumGenesAnalyzed());
Collection<ExpressionAnalysisResultSet> resultSetsIncluded = metaAnalysis.getResultSetsIncluded();
analysisVO.setIncludedResultSetsInfo(new HashSet<IncludedResultSetInfoValueObject>(resultSetsIncluded.size()));
for (ExpressionAnalysisResultSet resultSetIncluded : resultSetsIncluded) {
IncludedResultSetInfoValueObject includedResultSetInfo = new IncludedResultSetInfoValueObject();
includedResultSetInfo.setExperimentId(resultSetIncluded.getAnalysis().getExperimentAnalyzed().getId());
includedResultSetInfo.setAnalysisId(resultSetIncluded.getAnalysis().getId());
includedResultSetInfo.setResultSetId(resultSetIncluded.getId());
analysisVO.getIncludedResultSetsInfo().add(includedResultSetInfo);
}
analysisVO.setResults(new HashSet<GeneDifferentialExpressionMetaAnalysisResultValueObject>(metaAnalysis.getResults().size()));
for (GeneDifferentialExpressionMetaAnalysisResult result : metaAnalysis.getResults()) {
GeneDifferentialExpressionMetaAnalysisResultValueObject resultVO = new GeneDifferentialExpressionMetaAnalysisResultValueObject();
GeneValueObject gene = new GeneValueObject(result.getGene());
resultVO.setGeneSymbol(gene.getOfficialSymbol());
resultVO.setGeneName(gene.getOfficialName());
resultVO.setMetaPvalue(result.getMetaPvalue());
resultVO.setMetaQvalue(result.getMetaQvalue());
resultVO.setUpperTail(result.getUpperTail());
analysisVO.getResults().add(resultVO);
}
return analysisVO;
}
use of ubic.gemma.model.genome.gene.GeneValueObject in project Gemma by PavlidisLab.
the class SearchResultDisplayObject method setValues.
private void setValues(Gene gene) {
this.setResultValueObject(new GeneValueObject(gene));
this.isGroup = false;
this.size = 1;
if (gene.getTaxon() != null) {
this.taxonId = gene.getTaxon().getId();
this.taxonName = gene.getTaxon().getCommonName();
}
this.name = gene.getOfficialSymbol();
this.description = gene.getOfficialName();
this.memberIds.add(gene.getId());
this.id = gene.getId();
}
use of ubic.gemma.model.genome.gene.GeneValueObject in project Gemma by PavlidisLab.
the class SearchResultDisplayObject method setValues.
/**
* this method does not set the publik variable for the returned object (cannot autowire security service from here)
*
* @param searchResult search result
*/
private void setValues(SearchResult searchResult) {
// if it's a search result, grab the underlying object
Class<?> searchResultClass = searchResult.getResultClass();
// class-specific construction
if (searchResult.getResultObject() instanceof GeneValueObject) {
GeneValueObject gene = (GeneValueObject) searchResult.getResultObject();
this.setValues(gene);
} else if (searchResult.getResultObject() instanceof Gene) {
Gene gene = (Gene) searchResult.getResultObject();
this.setValues(gene);
} else if (searchResult.getResultObject() instanceof GeneSetValueObject) {
GeneSetValueObject geneSet = (GeneSetValueObject) searchResult.getResultObject();
this.setValues(geneSet);
} else if (searchResult.getResultObject() instanceof ExpressionExperimentValueObject) {
ExpressionExperimentValueObject ee = (ExpressionExperimentValueObject) searchResult.getResultObject();
this.setValues(ee);
} else if (searchResult.getResultObject() instanceof ExpressionExperimentSetValueObject) {
ExpressionExperimentSetValueObject eeSet = (ExpressionExperimentSetValueObject) searchResult.getResultObject();
this.setValues(eeSet);
} else {
this.isGroup = false;
this.size = -1;
this.taxonId = (long) -1;
this.taxonName = "unknown";
this.name = "Unhandled type";
this.description = "Unhandled result type: " + searchResultClass;
this.memberIds = null;
}
}
Aggregations