Search in sources :

Example 21 with GeneValueObject

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;
}
Also used : StopWatch(org.apache.commons.lang3.time.StopWatch) GeneValueObject(ubic.gemma.model.genome.gene.GeneValueObject) GeneValueObject(ubic.gemma.model.genome.gene.GeneValueObject)

Example 22 with GeneValueObject

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;
}
Also used : GeneValueObject(ubic.gemma.model.genome.gene.GeneValueObject) ArrayList(java.util.ArrayList)

Example 23 with GeneValueObject

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;
}
Also used : GeneValueObject(ubic.gemma.model.genome.gene.GeneValueObject)

Example 24 with GeneValueObject

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();
}
Also used : GeneValueObject(ubic.gemma.model.genome.gene.GeneValueObject)

Example 25 with GeneValueObject

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;
    }
}
Also used : ExpressionExperimentSetValueObject(ubic.gemma.model.expression.experiment.ExpressionExperimentSetValueObject) GeneValueObject(ubic.gemma.model.genome.gene.GeneValueObject) Gene(ubic.gemma.model.genome.Gene) ExpressionExperimentValueObject(ubic.gemma.model.expression.experiment.ExpressionExperimentValueObject) SessionBoundGeneSetValueObject(ubic.gemma.core.genome.gene.SessionBoundGeneSetValueObject) GeneSetValueObject(ubic.gemma.model.genome.gene.GeneSetValueObject)

Aggregations

GeneValueObject (ubic.gemma.model.genome.gene.GeneValueObject)31 StopWatch (org.apache.commons.lang3.time.StopWatch)6 Gene (ubic.gemma.model.genome.Gene)6 Taxon (ubic.gemma.model.genome.Taxon)5 DoubleVectorValueObject (ubic.gemma.model.expression.bioAssayData.DoubleVectorValueObject)4 GeneSetValueObject (ubic.gemma.model.genome.gene.GeneSetValueObject)4 CharacteristicValueObject (ubic.gemma.model.genome.gene.phenotype.valueObject.CharacteristicValueObject)4 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 ModelAndView (org.springframework.web.servlet.ModelAndView)3 GeneProductValueObject (ubic.gemma.model.genome.gene.GeneProductValueObject)3 HashSet (java.util.HashSet)2 OntologyTerm (ubic.basecode.ontology.model.OntologyTerm)2 DifferentialExpressionValueObject (ubic.gemma.model.analysis.expression.diff.DifferentialExpressionValueObject)2 BioAssayValueObject (ubic.gemma.model.expression.bioAssay.BioAssayValueObject)2 ExpressionExperimentValueObject (ubic.gemma.model.expression.experiment.ExpressionExperimentValueObject)2 EvidenceValueObject (ubic.gemma.model.genome.gene.phenotype.valueObject.EvidenceValueObject)2 CoexpressionValueObject (ubic.gemma.persistence.service.association.coexpression.CoexpressionValueObject)2 VisualizationValueObject (ubic.gemma.web.controller.visualization.VisualizationValueObject)2 ImageValueObject (ubic.gemma.web.image.aba.ImageValueObject)2 DoubleArrayList (cern.colt.list.DoubleArrayList)1