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;
}
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);
}
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;
}
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;
}
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;
}
Aggregations