use of ubic.gemma.model.expression.designElement.CompositeSequence in project Gemma by PavlidisLab.
the class PlatformArg method getElements.
/**
* Retrieves the Elements of the Platform that this argument represents.
*
* @param service service that will be used to retrieve the persistent AD object.
* @return a collection of Composite Sequence VOs that the platform represented by this argument contains.
*/
public Collection<CompositeSequenceValueObject> getElements(ArrayDesignService service, CompositeSequenceService csService, int limit, int offset) {
ArrayDesign ad = this.getPersistentObject(service);
Collection<CompositeSequence> css = ad == null ? null : service.getCompositeSequences(ad, limit, offset);
Collection<CompositeSequenceValueObject> csVos = new ArrayList<>(css != null ? css.size() : 0);
if (css == null)
return csVos;
for (CompositeSequence cs : css) {
CompositeSequenceValueObject csVo = csService.loadValueObject(cs);
csVo.setGeneMappingSummaries(csService.getGeneMappingSummary(cs));
csVos.add(csVo);
}
return csVos;
}
use of ubic.gemma.model.expression.designElement.CompositeSequence in project Gemma by PavlidisLab.
the class ExperimentDEDVEndpoint 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) throws Exception {
StopWatch watch = new StopWatch();
watch.start();
setLocalName(EXPERIMENT_LOCAL_NAME);
String eeid = "";
Collection<String> eeResults = getSingleNodeValue(requestElement, "ee_id");
for (String id : eeResults) {
eeid = id;
}
// Check to make sure we haven't already generated this EE report.
Document doc = readReport(DEFAULT_FILENAME + eeid + DEFAULT_EXTENSION);
if (doc != null) {
// Successfully got report from disk
watch.stop();
Long time = watch.getTime();
log.info("XML response for ee" + eeid + " retrieved from disk in " + time + "ms.");
return doc.getDocumentElement();
}
// Build the matrix
ExpressionExperiment ee = expressionExperimentService.load(Long.parseLong(eeid));
ee = expressionExperimentService.thawLite(ee);
ExpressionDataDoubleMatrix dmatrix = expressionDataMatrixService.getProcessedExpressionDataMatrix(ee);
// start building the wrapper
// build xml manually rather than use buildWrapper inherited from AbstractGemmeEndpoint
String elementName1 = "dedv";
String elementName2 = "geneIdist";
// log.info( "Building " + EXPERIMENT_LOCAL_NAME + " XML response" );
Element responseWrapper = document.createElementNS(NAMESPACE_URI, EXPERIMENT_LOCAL_NAME);
Element responseElement = document.createElementNS(NAMESPACE_URI, EXPERIMENT_LOCAL_NAME + RESPONSE);
responseWrapper.appendChild(responseElement);
if (dmatrix == null || (dmatrix.rows() == 0))
responseElement.appendChild(document.createTextNode("No " + elementName1 + " result"));
else {
for (int rowNum = 0; rowNum < dmatrix.rows(); rowNum++) {
// data vector string for output
String elementString1 = encode(dmatrix.getRow(rowNum));
String elementString2 = "";
CompositeSequence de = dmatrix.getDesignElementForRow(rowNum);
Collection<Gene> geneCol = compositeSequenceService.getGenes(de);
for (Gene gene : geneCol) {
if (elementString2.equals(""))
elementString2 = elementString2.concat(gene.getId().toString());
else
elementString2 = elementString2.concat(DELIMITER + gene.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("XML response for ee:" + eeid + " created from scratch in " + time + "ms.");
writeReport(responseWrapper, document, DEFAULT_FILENAME + eeid);
return responseWrapper;
}
use of ubic.gemma.model.expression.designElement.CompositeSequence 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;
}
use of ubic.gemma.model.expression.designElement.CompositeSequence in project Gemma by PavlidisLab.
the class PersistentDummyObjectHelper method getDesignElementDataVectors.
/**
* @param bioAssays BAs
* @param ad AD
* @param ee EE
* @param quantitationTypes QTs
* @return These are non-persistent
*/
private Collection<RawExpressionDataVector> getDesignElementDataVectors(ExpressionExperiment ee, Collection<QuantitationType> quantitationTypes, List<BioAssay> bioAssays, ArrayDesign ad) {
BioAssayDimension baDim = BioAssayDimension.Factory.newInstance(ee.getShortName() + "_" + RandomStringUtils.randomAlphanumeric(20), null, bioAssays);
Collection<RawExpressionDataVector> vectors = new HashSet<>();
for (QuantitationType quantType : quantitationTypes) {
for (CompositeSequence cs : ad.getCompositeSequences()) {
RawExpressionDataVector vector = RawExpressionDataVector.Factory.newInstance();
byte[] bdata = this.getDoubleData();
vector.setData(bdata);
vector.setDesignElement(cs);
assert cs.getArrayDesign() != null;
vector.setExpressionExperiment(ee);
vector.setQuantitationType(quantType);
vector.setBioAssayDimension(baDim);
vectors.add(vector);
}
}
return vectors;
}
use of ubic.gemma.model.expression.designElement.CompositeSequence in project Gemma by PavlidisLab.
the class AncovaTest method testAncovaWithInteraction.
/*
* Two factors with interactions.
*/
@Test
public void testAncovaWithInteraction() {
this.configureMocks();
DifferentialExpressionAnalysisConfig config = new DifferentialExpressionAnalysisConfig();
config.getFactorsToInclude().add(this.experimentalFactorA_Area);
config.getFactorsToInclude().add(this.experimentalFactorB);
config.getInteractionsToInclude().add(config.getFactorsToInclude());
Collection<DifferentialExpressionAnalysis> expressionAnalyses = analyzer.run(expressionExperiment, config);
DifferentialExpressionAnalysis expressionAnalysis = expressionAnalyses.iterator().next();
assertNotNull(expressionAnalysis);
Collection<ExpressionAnalysisResultSet> resultSets = expressionAnalysis.getResultSets();
assertEquals(3, resultSets.size());
boolean foundInteractions = false;
boolean foundContrast = false;
for (ExpressionAnalysisResultSet resultSet : resultSets) {
Collection<ExperimentalFactor> factors = resultSet.getExperimentalFactors();
for (DifferentialExpressionAnalysisResult r : resultSet.getResults()) {
CompositeSequence probe = r.getProbe();
Double pvalue = r.getPvalue();
assertNotNull(probe);
Collection<ContrastResult> contrasts = r.getContrasts();
Double stat;
if (contrasts.isEmpty()) {
continue;
}
stat = contrasts.iterator().next().getTstat();
if (factors.size() == 2) {
// interaction
foundInteractions = true;
switch(probe.getName()) {
case "probe_98":
assertEquals(0.7893, pvalue, 0.001);
break;
case "probe_10":
assertEquals(0.04514, pvalue, 0.0001);
break;
case "probe_4":
assertEquals(null, pvalue);
break;
}
} else {
ExperimentalFactor f = factors.iterator().next();
assertNotNull(f);
if (f.equals(super.experimentalFactorA_Area)) {
switch(probe.getName()) {
case "probe_98":
assertEquals(0.8769, pvalue, 0.001);
break;
case "probe_10":
assertEquals(5.158e-10, pvalue, 1e-12);
break;
case "probe_4":
assertEquals(0.0048, pvalue, 0.0001);
assertNotNull(stat);
assertEquals(-125.746, stat, 0.001);
break;
case "probe_0":
assertEquals(1, r.getContrasts().size());
ContrastResult contrast = r.getContrasts().iterator().next();
assertEquals(super.factorValueA1, contrast.getFactorValue());
assertEquals(-202.5587, contrast.getLogFoldChange(), 0.001);
foundContrast = true;
break;
}
} else {
if (probe.getName().equals("probe_98")) {
assertEquals(0.6888, pvalue, 0.001);
} else if (probe.getName().equals("probe_10")) {
assertEquals(0.07970, pvalue, 0.001);
}
}
}
}
}
assertTrue(foundInteractions);
assertTrue(foundContrast);
}
Aggregations