Search in sources :

Example 6 with Taxon

use of ubic.gemma.model.genome.Taxon in project Gemma by PavlidisLab.

the class GeneIDbyTaxonEndpoint method invokeInternal.

/**
 * Reads the given <code>requestElement</code>, and sends 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) {
    StopWatch watch = new StopWatch();
    watch.start();
    setLocalName(EXPERIMENT_LOCAL_NAME);
    Collection<String> taxonResults = getSingleNodeValue(requestElement, "taxon_id");
    String taxonId = "";
    for (String id : taxonResults) {
        taxonId = id;
    }
    log.info("XML input read: taxon id, " + taxonId);
    // Get Gene matched with Taxon
    Taxon tax = taxonService.load(Long.parseLong(taxonId));
    if (tax == null) {
        String msg = "No taxon with id, " + taxonId + " can be found.";
        return buildBadResponse(document, msg);
    }
    Collection<Gene> geneCollection = geneService.loadAll(tax);
    // build results in the form of a collection
    Collection<String> geneIds = new HashSet<String>();
    for (Gene gene : geneCollection) {
        geneIds.add(gene.getId().toString());
    }
    Element wrapper = buildWrapper(document, geneIds, "gene_ids");
    watch.stop();
    Long time = watch.getTime();
    log.info("XML response for gene id results built in " + time + "ms.");
    return wrapper;
}
Also used : Gene(ubic.gemma.model.genome.Gene) Taxon(ubic.gemma.model.genome.Taxon) Element(org.w3c.dom.Element) StopWatch(org.apache.commons.lang3.time.StopWatch) HashSet(java.util.HashSet)

Example 7 with Taxon

use of ubic.gemma.model.genome.Taxon in project Gemma by PavlidisLab.

the class DifferentialExpressionProbeResultEndpoint 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) {
    StopWatch watch = new StopWatch();
    watch.start();
    setLocalName(LOCAL_NAME);
    // taxon input
    Collection<String> taxonInput = getSingleNodeValue(requestElement, "taxon_id");
    String taxonId = "";
    for (String id : taxonInput) {
        taxonId = id;
    }
    Taxon taxon = taxonService.load(Long.parseLong(taxonId));
    if (taxon == null) {
        String msg = "No taxon with id, " + taxonId + ", can be found.";
        return buildBadResponse(document, msg);
    }
    // gene ids input
    Collection<String> geneInput = getArrayValues(requestElement, "gene_ids");
    Collection<Long> geneIDLong = new HashSet<Long>();
    for (String id : geneInput) geneIDLong.add(Long.parseLong(id));
    Collection<Gene> rawGeneCol = geneService.loadThawed(geneIDLong);
    if (rawGeneCol.isEmpty()) {
        String msg = "None of the gene id's can be found.";
        return buildBadResponse(document, msg);
    }
    Collection<Gene> geneCol = retainGenesInCorrectTaxon(rawGeneCol, taxon);
    if (geneCol == null || geneCol.isEmpty()) {
        String msg = "Input genes do not match input taxon.";
        return buildBadResponse(document, msg);
    }
    // expression experiment set id input
    Collection<String> analysisInput = getSingleNodeValue(requestElement, "expression_experiment_set_id");
    String analysisId = "";
    for (String id : analysisInput) {
        analysisId = id;
    }
    ExpressionExperimentSet ees = expressionExperimentSetService.load(Long.parseLong(analysisId));
    if (ees == null) {
        String msg = "No matching expression experiment set can be found for id, " + analysisId;
        return buildBadResponse(document, msg);
    }
    if (!(ees.getTaxon().getId()).equals(taxon.getId())) {
        String msg = "Expression experiment set " + analysisId + " does not match input taxon " + taxon.getCommonName();
        return buildBadResponse(document, msg);
    }
    Collection<ExpressionExperiment> eeCol = getExperiments(ees);
    Collection<BioAssaySet> bioAssaySets = new HashSet<BioAssaySet>();
    bioAssaySets.addAll(eeCol);
    // threshold input
    Collection<String> thresholdInput = getSingleNodeValue(requestElement, "threshold");
    String threshold = "";
    for (String id : thresholdInput) {
        threshold = id;
    }
    log.info("XML input read: " + geneInput.size() + " gene ids,  & taxon id " + taxonId + ", & expression experiment set id " + analysisId + ", and threshold " + threshold);
    Element responseWrapper = document.createElementNS(NAMESPACE_URI, LOCAL_NAME);
    Element responseElement = document.createElementNS(NAMESPACE_URI, LOCAL_NAME + RESPONSE);
    responseWrapper.appendChild(responseElement);
    for (Gene gene : geneCol) {
        Map<ExpressionExperimentValueObject, List<DifferentialExpressionValueObject>> results = differentialExpressionResultService.find(gene, EntityUtils.getIds(bioAssaySets), Double.parseDouble(threshold), null);
        for (ExpressionExperimentValueObject ee : results.keySet()) {
            // main call to the DifferentialExpressionAnalysisService to retrieve
            // DifferentialExpressionAnalysisResultSet collection
            Collection<DifferentialExpressionValueObject> parCol = results.get(ee);
            // check that a DifferentialExpressionAnalysisResult is not null
            if (parCol == null || parCol.isEmpty()) {
                log.error("No probe analysis results can be found for gene: " + gene.getOfficialSymbol() + " & experiment: " + ee);
                buildXMLResponse(document, responseElement, gene.getId().toString(), ee.getId().toString(), null);
            } else
                buildXMLResponse(document, responseElement, gene.getId().toString(), ee.getId().toString(), parCol);
        }
    }
    watch.stop();
    Long time = watch.getTime();
    log.info("XML response for differential expression probe results built in " + time + "ms.");
    return responseWrapper;
}
Also used : Taxon(ubic.gemma.model.genome.Taxon) Element(org.w3c.dom.Element) DifferentialExpressionValueObject(ubic.gemma.model.analysis.expression.diff.DifferentialExpressionValueObject) ExpressionExperiment(ubic.gemma.model.expression.experiment.ExpressionExperiment) StopWatch(org.apache.commons.lang3.time.StopWatch) Gene(ubic.gemma.model.genome.Gene) BioAssaySet(ubic.gemma.model.expression.experiment.BioAssaySet) ExpressionExperimentValueObject(ubic.gemma.model.expression.experiment.ExpressionExperimentValueObject) ExpressionExperimentSet(ubic.gemma.model.analysis.expression.ExpressionExperimentSet)

Example 8 with Taxon

use of ubic.gemma.model.genome.Taxon in project Gemma by PavlidisLab.

the class Gene2ProbeEndpoint 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) {
    StopWatch watch = new StopWatch();
    watch.start();
    this.setLocalName(Gene2ProbeEndpoint.PROBE_LOCAL_NAME);
    // OLDFIXME this should take gene_id
    String geneSymbol = "";
    Collection<String> geneResults = this.getSingleNodeValue(requestElement, "gene_official_symbol");
    for (String id : geneResults) {
        geneSymbol = id;
    }
    String taxonid = "";
    Collection<String> taxonResults = this.getSingleNodeValue(requestElement, "taxon_id");
    for (String id : taxonResults) {
        taxonid = id;
    }
    Gene2ProbeEndpoint.log.info("XML iput read: Gene symbol, " + geneSymbol + " & taxon id, " + taxonid);
    // get the probe and array design info
    // get taxon
    Taxon taxon = taxonService.load(Long.parseLong(taxonid));
    if (taxon == null) {
        String msg = "No taxon with id, " + taxonid + ", can be found.";
        return this.buildBadResponse(document, msg);
    }
    // get gene, gven taxon and symbol
    Gene gene = geneService.findByOfficialSymbol(geneSymbol, taxon);
    if (gene == null) {
        String msg = "No gene with symbol, " + geneSymbol + ", can be found.";
        return this.buildBadResponse(document, msg);
    }
    // get probe
    Collection<CompositeSequence> csCol = compositeSequenceService.findByGene(gene);
    if (csCol == null || csCol.isEmpty()) {
        String msg = "No composite sequence can be found.";
        return this.buildBadResponse(document, msg);
    }
    // start building the wrapper
    // build xml manually rather than use buildWrapper inherited from
    // AbstractGemmeEndpoint
    String elementName1 = "probe_id";
    String elementName2 = "array_design_identifier";
    Element responseWrapper = document.createElementNS(AbstractGemmaEndpoint.NAMESPACE_URI, Gene2ProbeEndpoint.PROBE_LOCAL_NAME);
    Element responseElement = document.createElementNS(AbstractGemmaEndpoint.NAMESPACE_URI, Gene2ProbeEndpoint.PROBE_LOCAL_NAME + AbstractGemmaEndpoint.RESPONSE);
    responseWrapper.appendChild(responseElement);
    for (CompositeSequence cs : csCol) {
        // CompositeSequence id
        String elementString1 = cs.getId().toString();
        // corresponding ArrayDesign identifier
        String elementString2 = cs.getArrayDesign().getId().toString();
        Element e1 = document.createElement(elementName1);
        e1.appendChild(document.createTextNode(elementString1));
        responseElement.appendChild(e1);
        Element e2 = document.createElement(elementName2);
        e2.appendChild(document.createTextNode(elementString2));
        responseElement.appendChild(e2);
    }
    watch.stop();
    Long time = watch.getTime();
    // log.info( "Finished generating result. Sending response to client." );
    Gene2ProbeEndpoint.log.info("XML response for Probe result built in " + time + "ms.");
    return responseWrapper;
}
Also used : Gene(ubic.gemma.model.genome.Gene) Taxon(ubic.gemma.model.genome.Taxon) Element(org.w3c.dom.Element) CompositeSequence(ubic.gemma.model.expression.designElement.CompositeSequence) StopWatch(org.apache.commons.lang3.time.StopWatch)

Example 9 with Taxon

use of ubic.gemma.model.genome.Taxon in project Gemma by PavlidisLab.

the class GeneSetSearchImpl method goTermToGeneSets.

private Collection<GeneSet> goTermToGeneSets(OntologyTerm term, Integer maxGeneSetSize) {
    if (term == null)
        return null;
    if (term.getUri() == null)
        return null;
    Collection<OntologyResource> allMatches = new HashSet<>();
    allMatches.add(term);
    allMatches.addAll(this.geneOntologyService.getAllChildren(term));
    GeneSetSearchImpl.log.info(term);
    /*
         * Gather up uris
         */
    Collection<String> termsToFetch = new HashSet<>();
    for (OntologyResource t : allMatches) {
        String goId = this.uri2goid(t);
        termsToFetch.add(goId);
    }
    Map<Taxon, Collection<Gene>> genesByTaxon = this.gene2GoService.findByGOTermsPerTaxon(termsToFetch);
    Collection<GeneSet> results = new HashSet<>();
    for (Taxon t : genesByTaxon.keySet()) {
        Collection<Gene> genes = genesByTaxon.get(t);
        if (genes.isEmpty() || (maxGeneSetSize != null && genes.size() > maxGeneSetSize)) {
            continue;
        }
        GeneSet transientGeneSet = GeneSet.Factory.newInstance();
        transientGeneSet.setName(this.uri2goid(term));
        transientGeneSet.setDescription(term.getLabel());
        for (Gene gene : genes) {
            GeneSetMember gmember = GeneSetMember.Factory.newInstance();
            gmember.setGene(gene);
            transientGeneSet.getMembers().add(gmember);
        }
        results.add(transientGeneSet);
    }
    return results;
}
Also used : Taxon(ubic.gemma.model.genome.Taxon) GeneSetMember(ubic.gemma.model.genome.gene.GeneSetMember) Gene(ubic.gemma.model.genome.Gene) Collection(java.util.Collection) GeneSet(ubic.gemma.model.genome.gene.GeneSet) OntologyResource(ubic.basecode.ontology.model.OntologyResource) HashSet(java.util.HashSet)

Example 10 with Taxon

use of ubic.gemma.model.genome.Taxon in project Gemma by PavlidisLab.

the class GeneSetSearchImpl method findGeneSetValueObjectByGoId.

@Override
public GOGroupValueObject findGeneSetValueObjectByGoId(String goId, Long taxonId) {
    // shouldn't need to set the taxon here, should be taken care of when creating the value object
    Taxon taxon;
    if (taxonId != null) {
        taxon = taxonService.load(taxonId);
        if (taxon == null) {
            GeneSetSearchImpl.log.warn("No such taxon with id=" + taxonId);
        } else {
            GeneSet result = this.findByGoId(goId, taxonService.load(taxonId));
            if (result == null) {
                GeneSetSearchImpl.log.warn("No matching gene set found for: " + goId);
                return null;
            }
            GOGroupValueObject ggvo = geneSetValueObjectHelper.convertToGOValueObject(result, goId, goId);
            ggvo.setTaxonId(taxon.getId());
            ggvo.setTaxonName(taxon.getCommonName());
            return ggvo;
        }
    }
    return null;
}
Also used : GOGroupValueObject(ubic.gemma.core.genome.gene.GOGroupValueObject) Taxon(ubic.gemma.model.genome.Taxon) GeneSet(ubic.gemma.model.genome.gene.GeneSet)

Aggregations

Taxon (ubic.gemma.model.genome.Taxon)161 Gene (ubic.gemma.model.genome.Gene)34 Test (org.junit.Test)31 BaseSpringContextTest (ubic.gemma.core.testing.BaseSpringContextTest)29 HashSet (java.util.HashSet)23 ArrayDesign (ubic.gemma.model.expression.arrayDesign.ArrayDesign)23 InputStream (java.io.InputStream)17 Before (org.junit.Before)16 BioSequence (ubic.gemma.model.genome.biosequence.BioSequence)15 ExpressionExperiment (ubic.gemma.model.expression.experiment.ExpressionExperiment)14 CompositeSequence (ubic.gemma.model.expression.designElement.CompositeSequence)12 StopWatch (org.apache.commons.lang3.time.StopWatch)11 Transactional (org.springframework.transaction.annotation.Transactional)11 ArrayList (java.util.ArrayList)10 File (java.io.File)9 SimpleExpressionExperimentMetaData (ubic.gemma.core.loader.expression.simple.model.SimpleExpressionExperimentMetaData)9 Chromosome (ubic.gemma.model.genome.Chromosome)8 Collection (java.util.Collection)7 Element (org.w3c.dom.Element)7 PhysicalLocation (ubic.gemma.model.genome.PhysicalLocation)7