use of ubic.gemma.core.analysis.expression.coexpression.CoexpressionValueObjectExt in project Gemma by PavlidisLab.
the class CoexpressionSearchController method doSearch.
/**
* Important entry point - called by the CoexpressionSearchTask
*
* @param searchOptions search options
* @return coexp. meta VO
*/
public CoexpressionMetaValueObject doSearch(CoexpressionSearchCommand searchOptions) {
Collection<ExpressionExperiment> myEE = null;
CoexpressionMetaValueObject result = new CoexpressionMetaValueObject();
if (searchOptions.getGeneIds() == null || searchOptions.getGeneIds().isEmpty()) {
if (searchOptions.getGeneSetId() != null) {
searchOptions.setGeneIds(geneSetService.getGeneIdsInGroup(new GeneSetValueObject(searchOptions.getGeneSetId())));
}
if (searchOptions.getGeneIds().isEmpty()) {
result.setErrorState("No genes were selected");
return result;
}
}
if (searchOptions.getGeneIds().size() > CoexpressionSearchController.MAX_GENES_FOR_QUERY_GENES_ONLY_QUERY) {
result.setErrorState("Too many genes selected, please limit searches to " + CoexpressionSearchController.MAX_GENES_FOR_QUERY_GENES_ONLY_QUERY + " genes");
return result;
}
if (searchOptions.getGeneIds().size() == 0) {
result.setErrorState("Invalid gene id(s) - no genes found");
return result;
}
// Add the user's datasets to the selected datasets
if (searchOptions.isUseMyDatasets()) {
myEE = expressionExperimentService.loadAll();
}
Collection<Long> eeIds = this.chooseExperimentsToQuery(searchOptions, result);
if (StringUtils.isNotBlank(result.getErrorState()))
return result;
if (myEE != null && !myEE.isEmpty()) {
eeIds.addAll(EntityUtils.getIds(myEE));
} else {
CoexpressionSearchController.log.info("No user data to add");
}
if (eeIds.isEmpty()) {
// search all available experiments.
} else {
searchOptions.setEeIds(eeIds);
}
CoexpressionSearchController.log.info("Starting coexpression search: " + searchOptions);
result = geneCoexpressionService.coexpressionSearch(searchOptions.getEeIds(), searchOptions.getGeneIds(), searchOptions.getStringency(), CoexpressionSearchController.MAX_RESULTS_PER_GENE, searchOptions.getQueryGenesOnly());
// make sure to create an empty list instead of null for front-end
if (result.getResults() == null) {
List<CoexpressionValueObjectExt> res = new ArrayList<>();
result.setResults(res);
}
if (result.getResults().isEmpty()) {
result.setErrorState(CoexpressionSearchController.NOTHING_FOUND_MESSAGE);
CoexpressionSearchController.log.info("No search results for query: " + searchOptions);
}
return result;
}
use of ubic.gemma.core.analysis.expression.coexpression.CoexpressionValueObjectExt in project Gemma by PavlidisLab.
the class GeneCoexpressionEndpoint 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();
this.setLocalName(GeneCoexpressionEndpoint.LOCAL_NAME);
Collection<String> geneInput = this.getArrayValues(requestElement, "gene_ids");
Collection<Long> geneIDLong = new HashSet<>();
for (String id : geneInput) geneIDLong.add(Long.parseLong(id));
Collection<String> taxonInput = this.getSingleNodeValue(requestElement, "taxon_id");
String taxonId = "";
for (String id : taxonInput) {
taxonId = id;
}
// Collection<String> analysisInput = getSingleNodeValue( requestElement, "expression_experiment_set_id" );
// String analysisId = "";
// for ( String id : analysisInput ) {
// analysisId = id;
// }
Collection<String> stringencyInput = this.getSingleNodeValue(requestElement, "stringency");
String string = "";
for (String id : stringencyInput) {
string = id;
}
Collection<String> queryGenesOnlyInput = this.getSingleNodeValue(requestElement, "queryGenesOnly");
String query = "";
for (String id : queryGenesOnlyInput) {
query = id;
}
boolean queryGenesOnly = false;
if (query.endsWith("1"))
queryGenesOnly = true;
GeneCoexpressionEndpoint.log.debug("XML input read: " + geneInput.size() + " gene ids, & taxon id, " + taxonId + " & stringency, " + string + " & queryGenesOnly=" + query);
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);
}
Collection<Gene> rawGeneCol = geneService.loadThawed(geneIDLong);
if (rawGeneCol.isEmpty()) {
String msg = "None of the gene id's can be found.";
return this.buildBadResponse(document, msg);
}
Collection<Gene> geneCol = this.retainGenesInCorrectTaxon(rawGeneCol, taxon);
if (geneCol == null || geneCol.isEmpty()) {
String msg = "Input genes do not match input taxon.";
return this.buildBadResponse(document, msg);
}
int stringency = Integer.parseInt(string);
// get Gene2GeneCoexpression objects canned analysis
Collection<CoexpressionValueObjectExt> coexpressedGenes = geneCoexpressionSearchService.coexpressionSearchQuick(null, EntityUtils.getIds(geneCol), stringency, GeneCoexpressionEndpoint.MAX_RESULTS, queryGenesOnly).getResults();
if (coexpressedGenes.isEmpty()) {
String msg = "No coexpressed genes found.";
return this.buildBadResponse(document, msg);
}
final String QUERY_GENE_NAME = "query_gene";
final String QUERY_GENE_ID = "query_id";
final String FOUND_GENE_NAME = "found_gene";
final String FOUND_GENE_ID = "found_id";
final String SUPPORT_NAME = "support";
final String SIGN_NAME = "sign";
Element responseWrapper = document.createElementNS(AbstractGemmaEndpoint.NAMESPACE_URI, GeneCoexpressionEndpoint.LOCAL_NAME);
Element responseElement = document.createElementNS(AbstractGemmaEndpoint.NAMESPACE_URI, GeneCoexpressionEndpoint.LOCAL_NAME + AbstractGemmaEndpoint.RESPONSE);
responseWrapper.appendChild(responseElement);
for (CoexpressionValueObjectExt cvo : coexpressedGenes) {
// log.info( cvo );
Element e1 = document.createElement(QUERY_GENE_NAME);
e1.appendChild(document.createTextNode(cvo.getQueryGene().getOfficialSymbol()));
responseElement.appendChild(e1);
Element e2 = document.createElement(QUERY_GENE_ID);
e2.appendChild(document.createTextNode(cvo.getQueryGene().getId().toString()));
responseElement.appendChild(e2);
Element e3 = document.createElement(FOUND_GENE_NAME);
e3.appendChild(document.createTextNode(cvo.getFoundGene().getOfficialSymbol()));
responseElement.appendChild(e3);
Element e4 = document.createElement(FOUND_GENE_ID);
e4.appendChild(document.createTextNode(cvo.getFoundGene().getId().toString()));
responseElement.appendChild(e4);
Integer support = 0;
String sign = "";
if (cvo.getPosSupp() > 0) {
support = cvo.getPosSupp();
sign = "+";
} else if (cvo.getNegSupp() > 0) {
support = cvo.getNegSupp();
sign = "-";
}
// If it happens that a result has both neg and pos links, then the pos link and sign will be used
// OLDTODO: Handle cases where a result can have both neg and pos links
Element e5 = document.createElement(SUPPORT_NAME);
e5.appendChild(document.createTextNode(support.toString()));
responseElement.appendChild(e5);
Element e6 = document.createElement(SIGN_NAME);
e6.appendChild(document.createTextNode(sign));
responseElement.appendChild(e6);
// Element e7 = document.createElement( EEID_NAME );
// e7.appendChild( document.createTextNode( encode( cvo.getSupportingExperiments().toArray() ) ) );
// responseElement.appendChild( e7 );
}
watch.stop();
Long time = watch.getTime();
if (time > 1000) {
GeneCoexpressionEndpoint.log.info("XML response for " + coexpressedGenes.size() + " results built in " + time + "ms.");
}
return responseWrapper;
} catch (Exception e) {
return this.buildBadResponse(document, e.getMessage());
}
}
use of ubic.gemma.core.analysis.expression.coexpression.CoexpressionValueObjectExt 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());
}
}
Aggregations