Search in sources :

Example 1 with Gene

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

the class GoTerm2GeneEndpoint 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(GO2Gene_LOCAL_NAME);
    String goId = "";
    String taxonId = "";
    // get GO id from request
    Collection<String> goIdResult = getSingleNodeValue(requestElement, "go_id");
    for (String id : goIdResult) {
        goId = id;
    }
    // get taxon id from request
    Collection<String> taxonIdResult = getSingleNodeValue(requestElement, "taxon_id");
    for (String id : taxonIdResult) {
        taxonId = id;
    }
    log.debug("XML input read: GO id, " + goId + " & taxon id, " + taxonId);
    // get gene from GO term
    Taxon taxon = taxonService.load(Long.parseLong(taxonId));
    if (taxon == null) {
        String msg = "No taxon with id, " + taxonId + " can be found.";
        return buildBadResponse(document, msg);
    }
    Collection<Gene> genes = geneOntologyService.getGenes(goId, taxon);
    if (genes == null || genes.isEmpty()) {
        return buildBadResponse(document, "No genes associated with goId = " + goId + " and taxon = " + taxon.getCommonName());
    }
    // build results in the form of a collection
    Collection<String> geneIds = new HashSet<String>();
    for (Gene gene : genes) {
        geneIds.add(gene.getId().toString());
    }
    Element wrapper = buildWrapper(document, geneIds, "gene_id");
    watch.stop();
    Long time = watch.getTime();
    log.debug("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 2 with Gene

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

the class GeneSymbolArg method getPersistentObject.

@Override
public Gene getPersistentObject(GeneService service) {
    Gene gene;
    Collection<Gene> genes = this.value == null || this.value.isEmpty() ? null : service.findByOfficialSymbol(this.value);
    if (genes == null || genes.isEmpty()) {
        gene = null;
    } else {
        gene = genes.iterator().next();
    }
    return check(gene);
}
Also used : Gene(ubic.gemma.model.genome.Gene)

Example 3 with Gene

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

the class GeneSymbolArg method getGeneLocation.

@Override
public Collection<PhysicalLocationValueObject> getGeneLocation(GeneService geneService) {
    Collection<Gene> genes = geneService.findByOfficialSymbol(this.value);
    Collection<PhysicalLocationValueObject> gVos = new ArrayList<>(genes.size());
    for (Gene gene : genes) {
        gVos.addAll(geneService.getPhysicalLocationsValueObjects(gene));
    }
    return gVos;
}
Also used : Gene(ubic.gemma.model.genome.Gene) PhysicalLocationValueObject(ubic.gemma.model.genome.PhysicalLocationValueObject) ArrayList(java.util.ArrayList)

Example 4 with Gene

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

the class Gene2GoTermEndpoint 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(GENE2GO_LOCAL_NAME);
    Collection<String> geneResult = getArrayValues(requestElement, "gene_ids");
    log.info("XML input read: " + geneResult.size() + " gene ids");
    // start building the wrapper
    // build xml manually for mapped result rather than use buildWrapper inherited from AbstractGemmeEndpoint
    // log.info( "Building " + GENE2GO_LOCAL_NAME + " XML response" );
    String elementName1 = "gene_id";
    String elementName2 = "goIdList";
    Element responseWrapper = document.createElementNS(NAMESPACE_URI, GENE2GO_LOCAL_NAME);
    Element responseElement = document.createElementNS(NAMESPACE_URI, GENE2GO_LOCAL_NAME + RESPONSE);
    responseWrapper.appendChild(responseElement);
    for (String geneString : geneResult) {
        Long geneId = Long.parseLong(geneString);
        Gene gene = geneService.load(geneId);
        if (gene == null) {
            String msg = "No gene with ids, " + geneId + " can be found.";
            return buildBadResponse(document, msg);
        }
        Collection<OntologyTerm> terms = geneOntologyService.getGOTerms(gene);
        // get the labels and store them
        Collection<String> goTerms = new HashSet<String>();
        if (terms != null) {
            for (OntologyTerm ot : terms) {
                goTerms.add(GeneOntologyServiceImpl.asRegularGoId(ot));
            }
        } else
            goTerms.add("NaN");
        String elementString1 = geneId.toString();
        String elementString2 = encode(retainNumericIds(goTerms).toArray());
        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." );
    log.info("XML response for GO Term results built in " + time + "ms.");
    return responseWrapper;
}
Also used : Gene(ubic.gemma.model.genome.Gene) Element(org.w3c.dom.Element) OntologyTerm(ubic.basecode.ontology.model.OntologyTerm) StopWatch(org.apache.commons.lang3.time.StopWatch) HashSet(java.util.HashSet)

Example 5 with Gene

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

the class GeneByNCBIIdEndpoint 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(GENE_LOCAL_NAME);
    Collection<String> ncbiInput = getArrayValues(requestElement, "ncbi_ids");
    Collection<Long> ncbiLongInput = new ArrayList<Long>(ncbiInput.size());
    for (String gene : ncbiInput) ncbiLongInput.add(Long.parseLong(gene));
    log.info("XML input read: " + ncbiInput.size() + " ncbi ids read");
    Element responseWrapper = document.createElementNS(NAMESPACE_URI, GENE_LOCAL_NAME);
    Element responseElement = document.createElementNS(NAMESPACE_URI, GENE_LOCAL_NAME + RESPONSE);
    responseWrapper.appendChild(responseElement);
    for (String ncbi : ncbiInput) {
        String geneId;
        Gene gene = null;
        try {
            gene = geneService.findByNCBIId(Integer.parseInt(ncbi));
        } catch (NumberFormatException e) {
        // 
        }
        if (gene == null)
            geneId = "NaN";
        else
            geneId = gene.getId().toString();
        Element e1 = document.createElement("gene_id");
        e1.appendChild(document.createTextNode(geneId));
        responseElement.appendChild(e1);
        Element e2 = document.createElement("ncbi_id");
        e2.appendChild(document.createTextNode(ncbi));
        responseElement.appendChild(e2);
    }
    watch.stop();
    Long time = watch.getTime();
    log.info("XML response for NCBI id result built in " + time + "ms.");
    return responseWrapper;
}
Also used : Gene(ubic.gemma.model.genome.Gene) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) StopWatch(org.apache.commons.lang3.time.StopWatch)

Aggregations

Gene (ubic.gemma.model.genome.Gene)186 Taxon (ubic.gemma.model.genome.Taxon)34 CompositeSequence (ubic.gemma.model.expression.designElement.CompositeSequence)32 StopWatch (org.apache.commons.lang3.time.StopWatch)31 Test (org.junit.Test)24 HashSet (java.util.HashSet)23 GeneProduct (ubic.gemma.model.genome.gene.GeneProduct)20 BaseSpringContextTest (ubic.gemma.core.testing.BaseSpringContextTest)18 Element (org.w3c.dom.Element)16 ArrayList (java.util.ArrayList)13 Transactional (org.springframework.transaction.annotation.Transactional)12 ExpressionExperiment (ubic.gemma.model.expression.experiment.ExpressionExperiment)12 Collection (java.util.Collection)11 OntologyTerm (ubic.basecode.ontology.model.OntologyTerm)11 CharacteristicValueObject (ubic.gemma.model.genome.gene.phenotype.valueObject.CharacteristicValueObject)10 HashMap (java.util.HashMap)8 ArrayDesign (ubic.gemma.model.expression.arrayDesign.ArrayDesign)8 BioSequence2GeneProduct (ubic.gemma.model.association.BioSequence2GeneProduct)7 PhysicalLocation (ubic.gemma.model.genome.PhysicalLocation)7 BioSequence (ubic.gemma.model.genome.biosequence.BioSequence)7