Search in sources :

Example 36 with BioAssaySet

use of ubic.gemma.model.expression.experiment.BioAssaySet in project Gemma by PavlidisLab.

the class LinkAnalysisCli method doWork.

@Override
protected Exception doWork(String[] args) {
    Exception err = this.processCommandLine(args);
    if (err != null) {
        return err;
    }
    if (initializeFromOldData) {
        AbstractCLI.log.info("Initializing links from old data for " + this.taxon);
        LinkAnalysisPersister s = this.getBean(LinkAnalysisPersister.class);
        s.initializeLinksFromOldData(this.taxon);
        return null;
    } else if (updateNodeDegree) {
        // we waste some time here getting the experiments.
        this.loadTaxon();
        this.getBean(CoexpressionService.class).updateNodeDegrees(this.taxon);
        return null;
    }
    this.linkAnalysisService = this.getBean(LinkAnalysisService.class);
    if (this.dataFileName != null) {
        /*
             * Read vectors from file. Could provide as a matrix, but it's easier to provide vectors (less mess in later
             * code)
             */
        ArrayDesignService arrayDesignService = this.getBean(ArrayDesignService.class);
        ArrayDesign arrayDesign = arrayDesignService.findByShortName(this.linkAnalysisConfig.getArrayName());
        if (arrayDesign == null) {
            return new IllegalArgumentException("No such array design " + this.linkAnalysisConfig.getArrayName());
        }
        this.loadTaxon();
        arrayDesign = arrayDesignService.thawLite(arrayDesign);
        Collection<ProcessedExpressionDataVector> dataVectors = new HashSet<>();
        Map<String, CompositeSequence> csMap = new HashMap<>();
        for (CompositeSequence cs : arrayDesign.getCompositeSequences()) {
            csMap.put(cs.getName(), cs);
        }
        QuantitationType qtype = this.makeQuantitationType();
        SimpleExpressionDataLoaderService simpleExpressionDataLoaderService = this.getBean(SimpleExpressionDataLoaderService.class);
        ByteArrayConverter bArrayConverter = new ByteArrayConverter();
        try (InputStream data = new FileInputStream(new File(this.dataFileName))) {
            DoubleMatrix<String, String> matrix = simpleExpressionDataLoaderService.parse(data);
            BioAssayDimension bad = this.makeBioAssayDimension(arrayDesign, matrix);
            for (int i = 0; i < matrix.rows(); i++) {
                byte[] bData = bArrayConverter.doubleArrayToBytes(matrix.getRow(i));
                ProcessedExpressionDataVector vector = ProcessedExpressionDataVector.Factory.newInstance();
                vector.setData(bData);
                CompositeSequence cs = csMap.get(matrix.getRowName(i));
                if (cs == null) {
                    continue;
                }
                vector.setDesignElement(cs);
                vector.setBioAssayDimension(bad);
                vector.setQuantitationType(qtype);
                dataVectors.add(vector);
            }
            AbstractCLI.log.info("Read " + dataVectors.size() + " data vectors");
        } catch (Exception e) {
            return e;
        }
        this.linkAnalysisService.processVectors(this.taxon, dataVectors, filterConfig, linkAnalysisConfig);
    } else {
        /*
             * Do in decreasing order of size, to help capture more links earlier - reduces fragmentation.
             */
        List<BioAssaySet> sees = new ArrayList<>(expressionExperiments);
        if (expressionExperiments.size() > 1) {
            AbstractCLI.log.info("Sorting data sets by number of samples, doing large data sets first.");
            Collection<ExpressionExperimentValueObject> vos = eeService.loadValueObjects(EntityUtils.getIds(expressionExperiments), true);
            final Map<Long, ExpressionExperimentValueObject> idMap = EntityUtils.getIdMap(vos);
            Collections.sort(sees, new Comparator<BioAssaySet>() {

                @Override
                public int compare(BioAssaySet o1, BioAssaySet o2) {
                    ExpressionExperimentValueObject e1 = idMap.get(o1.getId());
                    ExpressionExperimentValueObject e2 = idMap.get(o2.getId());
                    assert e1 != null : "No valueobject: " + e2;
                    assert e2 != null : "No valueobject: " + e1;
                    return -e1.getBioMaterialCount().compareTo(e2.getBioMaterialCount());
                }
            });
        }
        for (BioAssaySet ee : sees) {
            if (ee instanceof ExpressionExperiment) {
                this.processExperiment((ExpressionExperiment) ee);
            } else {
                throw new UnsupportedOperationException("Can't handle non-EE BioAssaySets yet");
            }
        }
        this.summarizeProcessing();
    }
    return null;
}
Also used : ByteArrayConverter(ubic.basecode.io.ByteArrayConverter) BioAssaySet(ubic.gemma.model.expression.experiment.BioAssaySet) ExpressionExperimentValueObject(ubic.gemma.model.expression.experiment.ExpressionExperimentValueObject) ArrayDesign(ubic.gemma.model.expression.arrayDesign.ArrayDesign) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ProcessedExpressionDataVector(ubic.gemma.model.expression.bioAssayData.ProcessedExpressionDataVector) SimpleExpressionDataLoaderService(ubic.gemma.core.loader.expression.simple.SimpleExpressionDataLoaderService) CompositeSequence(ubic.gemma.model.expression.designElement.CompositeSequence) ExpressionExperiment(ubic.gemma.model.expression.experiment.ExpressionExperiment) FileInputStream(java.io.FileInputStream) BioAssayDimension(ubic.gemma.model.expression.bioAssayData.BioAssayDimension) LinkAnalysisPersister(ubic.gemma.core.analysis.expression.coexpression.links.LinkAnalysisPersister) LinkAnalysisService(ubic.gemma.core.analysis.expression.coexpression.links.LinkAnalysisService) File(java.io.File) ArrayDesignService(ubic.gemma.persistence.service.expression.arrayDesign.ArrayDesignService)

Example 37 with BioAssaySet

use of ubic.gemma.model.expression.experiment.BioAssaySet in project Gemma by PavlidisLab.

the class OrderVectorsByDesignCli method doWork.

@Override
protected Exception doWork(String[] args) {
    Exception e = super.processCommandLine(args);
    if (e != null)
        return e;
    ProcessedExpressionDataVectorService processedExpressionDataVectorService = this.getBean(ProcessedExpressionDataVectorService.class);
    for (BioAssaySet ee : this.expressionExperiments) {
        if (!(ee instanceof ExpressionExperiment)) {
            continue;
        }
        ee = this.eeService.thawLite((ExpressionExperiment) ee);
        processedExpressionDataVectorService.reorderByDesign(ee.getId());
    }
    return null;
}
Also used : ProcessedExpressionDataVectorService(ubic.gemma.persistence.service.expression.bioAssayData.ProcessedExpressionDataVectorService) BioAssaySet(ubic.gemma.model.expression.experiment.BioAssaySet) ExpressionExperiment(ubic.gemma.model.expression.experiment.ExpressionExperiment)

Example 38 with BioAssaySet

use of ubic.gemma.model.expression.experiment.BioAssaySet in project Gemma by PavlidisLab.

the class GeneCoexpressionSearchEndpoint method invokeInternal.

/**
 * Reads the given <code>requestElement</code>, and sends a the response back.
 *
 * @param requestElement the contents of the SOAP message as DOM elements
 * @param document       a DOM document to be used for constructing <code>Node</code>s
 * @return the response element
 */
@Override
protected Element invokeInternal(Element requestElement, Document document) {
    try {
        StopWatch watch = new StopWatch();
        watch.start();
        setLocalName(LOCAL_NAME);
        String queryGeneId = getNodeValue(requestElement, "query_gene_id");
        String pairQueryGeneId = getOptionalNodeValue(requestElement, "pair_query_gene_id");
        String stringency = getNodeValue(requestElement, "stringency");
        Collection<Gene> queryGenes = new LinkedList<>();
        Gene queryGene = geneService.findByNCBIId(Integer.parseInt(queryGeneId));
        if (queryGene == null) {
            String msg = "Query gene with id [" + queryGeneId + "] cannot be found.";
            return buildBadResponse(document, msg);
        }
        queryGenes.add(queryGene);
        if (pairQueryGeneId != null) {
            Gene queryGene2 = geneService.findByNCBIId(Integer.parseInt(pairQueryGeneId));
            if (queryGene2 == null) {
                String msg = "Query gene with id [" + pairQueryGeneId + "] cannot be found.";
                return buildBadResponse(document, msg);
            }
            queryGenes.add(queryGene2);
        }
        Collection<ExpressionExperimentSet> eeSets = expressionExperimentSetService.findByName("All mouse");
        // .load(5662l); // uses 'All mouse' by default.
        ExpressionExperimentSet eeSet = eeSets.iterator().next();
        Collection<BioAssaySet> experiments = eeSet.getExperiments();
        Collection<Long> inputEeIds = new ArrayList<>();
        for (BioAssaySet e : experiments) {
            inputEeIds.add(e.getId());
        }
        CoexpressionMetaValueObject metaVO;
        if (pairQueryGeneId == null) {
            metaVO = geneCoexpressionSearchService.coexpressionSearch(inputEeIds, EntityUtils.getIds(queryGenes), Integer.valueOf(stringency), MAX_RESULTS, false);
        } else {
            metaVO = geneCoexpressionSearchService.coexpressionSearch(inputEeIds, EntityUtils.getIds(queryGenes), Integer.valueOf(stringency), MAX_RESULTS, true);
        }
        Collection<CoexpressionValueObjectExt> coexpressedGenes = metaVO.getResults();
        if (coexpressedGenes.isEmpty()) {
            String msg = "No coexpressed genes found.";
            return buildBadResponse(document, msg);
        }
        Element responseWrapper = document.createElementNS(NAMESPACE_URI, LOCAL_NAME);
        Element responseElement = document.createElementNS(NAMESPACE_URI, LOCAL_NAME + RESPONSE);
        responseWrapper.appendChild(responseElement);
        for (CoexpressionValueObjectExt cvo : coexpressedGenes) {
            Element item = document.createElement("CoexpressionSearchResult");
            Element foundGeneElement = document.createElement("found_gene_id");
            foundGeneElement.appendChild(document.createTextNode(cvo.getFoundGene().getNcbiId() == null ? "" : cvo.getFoundGene().getNcbiId().toString()));
            item.appendChild(foundGeneElement);
            Element numExperimentsElement = document.createElement("num_experiments_tested");
            numExperimentsElement.appendChild(document.createTextNode(cvo.getNumTestedIn().toString()));
            item.appendChild(numExperimentsElement);
            Element numCoexpressedElement = document.createElement("num_experiments_coexpressed");
            numCoexpressedElement.appendChild(document.createTextNode(String.valueOf(cvo.getSupportingExperiments().size())));
            item.appendChild(numCoexpressedElement);
            Element gemmaURL = document.createElement("gemma_details_url");
            gemmaURL.appendChild(document.createTextNode(Settings.getBaseUrl() + "searchCoexpression.html?g=" + queryGene.getId() + "," + cvo.getFoundGene().getId() + "&s=" + stringency + "&t=2&q&a=5662&an=All%20mouse"));
            item.appendChild(gemmaURL);
            responseElement.appendChild(item);
        }
        watch.stop();
        Long time = watch.getTime();
        if (time > 1000) {
            log.info("XML response for " + coexpressedGenes.size() + " results built in " + time + "ms.");
        }
        return responseWrapper;
    } catch (Exception e) {
        return buildBadResponse(document, e.getMessage());
    }
}
Also used : Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) StopWatch(org.apache.commons.lang3.time.StopWatch) CoexpressionMetaValueObject(ubic.gemma.core.analysis.expression.coexpression.CoexpressionMetaValueObject) Gene(ubic.gemma.model.genome.Gene) BioAssaySet(ubic.gemma.model.expression.experiment.BioAssaySet) ExpressionExperimentSet(ubic.gemma.model.analysis.expression.ExpressionExperimentSet) CoexpressionValueObjectExt(ubic.gemma.core.analysis.expression.coexpression.CoexpressionValueObjectExt)

Example 39 with BioAssaySet

use of ubic.gemma.model.expression.experiment.BioAssaySet in project Gemma by PavlidisLab.

the class SessionListManagerImpl method getExperimentIdsInSet.

@Override
public Collection<Long> getExperimentIdsInSet(Long id) {
    // secure
    ExpressionExperimentSet eeSet = expressionExperimentSetService.load(id);
    // Not secure.
    Collection<BioAssaySet> datasets = eeSet.getExperiments();
    Collection<Long> eeids = new HashSet<>();
    for (BioAssaySet ee : datasets) {
        eeids.add(ee.getId());
    }
    return eeids;
}
Also used : BioAssaySet(ubic.gemma.model.expression.experiment.BioAssaySet) ExpressionExperimentSet(ubic.gemma.model.analysis.expression.ExpressionExperimentSet) HashSet(java.util.HashSet)

Aggregations

BioAssaySet (ubic.gemma.model.expression.experiment.BioAssaySet)39 ExpressionExperiment (ubic.gemma.model.expression.experiment.ExpressionExperiment)25 HashSet (java.util.HashSet)6 ExpressionExperimentSet (ubic.gemma.model.analysis.expression.ExpressionExperimentSet)6 Taxon (ubic.gemma.model.genome.Taxon)6 IOException (java.io.IOException)4 ArrayDesign (ubic.gemma.model.expression.arrayDesign.ArrayDesign)4 ArrayList (java.util.ArrayList)3 StopWatch (org.apache.commons.lang3.time.StopWatch)3 Transactional (org.springframework.transaction.annotation.Transactional)3 SecurityService (gemma.gsec.SecurityService)2 Element (org.w3c.dom.Element)2 PreprocessingException (ubic.gemma.core.analysis.preprocess.PreprocessingException)2 DataUpdater (ubic.gemma.core.loader.expression.geo.DataUpdater)2 DifferentialExpressionValueObject (ubic.gemma.model.analysis.expression.diff.DifferentialExpressionValueObject)2 CompositeSequence (ubic.gemma.model.expression.designElement.CompositeSequence)2 ExpressionExperimentSubSet (ubic.gemma.model.expression.experiment.ExpressionExperimentSubSet)2 ExpressionExperimentValueObject (ubic.gemma.model.expression.experiment.ExpressionExperimentValueObject)2 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1