use of ubic.gemma.model.common.quantitationtype.QuantitationType in project Gemma by PavlidisLab.
the class ProcessedExpressionDataVectorCreateHelperServiceImpl method loadIntensities.
/**
* Computes expression intensities depending on which ArrayDesign TechnologyType is used.
*
* @return ExpressionDataDoubleMatrix
*/
private ExpressionDataDoubleMatrix loadIntensities(ExpressionExperiment ee, Collection<ProcessedExpressionDataVector> processedVectors) {
Collection<ArrayDesign> arrayDesignsUsed = this.eeService.getArrayDesignsUsed(ee);
assert !arrayDesignsUsed.isEmpty();
ArrayDesign arrayDesign = arrayDesignsUsed.iterator().next();
assert arrayDesign != null && arrayDesign.getTechnologyType() != null;
ExpressionDataDoubleMatrix intensities;
if (!arrayDesign.getTechnologyType().equals(TechnologyType.ONECOLOR) && !arrayDesign.getTechnologyType().equals(TechnologyType.NONE)) {
ProcessedExpressionDataVectorCreateHelperServiceImpl.log.info("Computing intensities for two-color data from underlying data");
/*
* Get vectors needed to compute intensities.
*/
Collection<QuantitationType> quantitationTypes = eeService.getQuantitationTypes(ee);
Collection<QuantitationType> usefulQuantitationTypes = ExpressionDataMatrixBuilder.getUsefulQuantitationTypes(quantitationTypes);
if (usefulQuantitationTypes.isEmpty()) {
throw new IllegalStateException("No useful quantitation types for " + ee.getShortName());
}
Collection<? extends DesignElementDataVector> vectors = rawExpressionDataVectorService.find(usefulQuantitationTypes);
if (vectors.isEmpty()) {
vectors = processedExpressionDataVectorService.find(usefulQuantitationTypes);
}
if (vectors.isEmpty()) {
throw new IllegalStateException("No vectors for useful quantitation types for " + ee.getShortName());
}
ProcessedExpressionDataVectorCreateHelperServiceImpl.log.info("Vectors loaded ...");
Collection<DesignElementDataVector> vs = new HashSet<>(vectors);
rawExpressionDataVectorService.thawRawAndProcessed(vs);
ExpressionDataMatrixBuilder builder = new ExpressionDataMatrixBuilder(processedVectors, vectors);
intensities = builder.getIntensity();
ExpressionDataBooleanMatrix missingValues = builder.getMissingValueData();
if (missingValues == null) {
ProcessedExpressionDataVectorCreateHelperServiceImpl.log.warn("Could not locate missing value matrix for " + ee + ", rank computation skipped (needed for two-color data)");
return intensities;
}
if (intensities == null) {
ProcessedExpressionDataVectorCreateHelperServiceImpl.log.warn("Could not locate intensity matrix for " + ee + ", rank computation skipped (needed for two-color data)");
return null;
}
ProcessedExpressionDataVectorCreateHelperServiceImpl.log.info("Masking ...");
this.maskMissingValues(intensities, missingValues);
} else {
ProcessedExpressionDataVectorCreateHelperServiceImpl.log.info("Computing intensities directly from processed data");
intensities = new ExpressionDataDoubleMatrix(processedVectors);
}
return intensities;
}
use of ubic.gemma.model.common.quantitationtype.QuantitationType in project Gemma by PavlidisLab.
the class ExpressionExperimentServiceTest method testGetDesignElementDataVectorsByQt.
@Test
public final void testGetDesignElementDataVectorsByQt() {
QuantitationType quantitationType = ee.getRawExpressionDataVectors().iterator().next().getQuantitationType();
Collection<QuantitationType> quantitationTypes = new HashSet<>();
quantitationTypes.add(quantitationType);
Collection<RawExpressionDataVector> vectors = rawExpressionDataVectorService.find(quantitationTypes);
assertEquals(12, vectors.size());
}
use of ubic.gemma.model.common.quantitationtype.QuantitationType in project Gemma by PavlidisLab.
the class AnalysisSelectionAndExecutionServiceImpl method determineAnalysis.
/**
* FIXME this should probably deal with the case of outliers and also the {@link LinearModelAnalyzer}'s
* EXCLUDE_CHARACTERISTICS_VALUES
*
* @return AnalysisType
*/
@Override
public AnalysisType determineAnalysis(BioAssaySet bioAssaySet, Collection<ExperimentalFactor> experimentalFactors, ExperimentalFactor subsetFactor, boolean includeInteractionsIfPossible) {
Collection<ExperimentalFactor> efsToUse = this.getFactorsToUse(bioAssaySet, experimentalFactors);
if (subsetFactor != null) {
/*
* Note that the interaction term might still get used (if selected), we just don't decide here.
*/
return AnalysisType.GENERICLM;
}
assert !efsToUse.isEmpty();
/*
* If any of the factors are continuous, just use a generic glm.
*/
for (ExperimentalFactor ef : efsToUse) {
if (ef.getType().equals(FactorType.CONTINUOUS)) {
return AnalysisType.GENERICLM;
}
}
Collection<FactorValue> factorValues;
switch(efsToUse.size()) {
case 1:
ExperimentalFactor experimentalFactor = efsToUse.iterator().next();
factorValues = experimentalFactor.getFactorValues();
/*
* Check that there is more than one value in at least one group
*/
boolean ok = DifferentialExpressionAnalysisUtil.checkValidForLm(bioAssaySet, experimentalFactor);
if (!ok) {
return null;
}
if (factorValues.isEmpty())
throw new IllegalArgumentException("Collection of factor values is either null or 0. Cannot execute differential expression analysis.");
switch(factorValues.size()) {
case 1:
// one sample t-test.
return AnalysisType.OSTTEST;
case 2:
/*
* Return t-test analyzer. This can be taken care of by the one way anova, but keeping it separate for
* clarity.
*/
return AnalysisType.TTEST;
default:
/*
* Return one way anova analyzer. NOTE: This can take care of the t-test as well, since a one-way anova
* with two groups is just a t-test
*/
return AnalysisType.OWA;
}
case 2:
/*
* Candidate for ANOVA
*/
boolean okForInteraction = true;
Collection<QuantitationType> qts = this.getQts(bioAssaySet);
for (ExperimentalFactor f : efsToUse) {
factorValues = f.getFactorValues();
if (factorValues.size() == 1) {
boolean useIntercept = false;
// check for a ratiometric quantitation type.
for (QuantitationType qt : qts) {
if (qt.getIsPreferred() && qt.getIsRatio()) {
// use ANOVA but treat the intercept as a factor.
useIntercept = true;
break;
}
}
if (useIntercept) {
return AnalysisType.GENERICLM;
}
return null;
}
if (BatchInfoPopulationServiceImpl.isBatchFactor(f)) {
AnalysisSelectionAndExecutionServiceImpl.log.info("One of the two factors is 'batch', not using it for an interaction");
okForInteraction = false;
}
}
/* Check for block design and execute two way ANOVA (with or without interactions). */
if (!includeInteractionsIfPossible || !DifferentialExpressionAnalysisUtil.blockComplete(bioAssaySet, experimentalFactors) || !okForInteraction) {
// NO interactions
return AnalysisType.TWO_WAY_ANOVA_NO_INTERACTION;
}
return AnalysisType.TWO_WAY_ANOVA_WITH_INTERACTION;
default:
/*
* Upstream we bail if there are too many factors.
*/
return AnalysisType.GENERICLM;
}
}
use of ubic.gemma.model.common.quantitationtype.QuantitationType in project Gemma by PavlidisLab.
the class GeeqServiceImpl method scoreRawData.
private boolean scoreRawData(ExpressionExperiment ee, Geeq gq) {
double score;
Collection<QuantitationType> quantitationTypes = expressionExperimentService.getQuantitationTypes(ee);
boolean dataReprocessedFromRaw = false;
for (QuantitationType qt : quantitationTypes) {
if (qt.getIsMaskedPreferred() != null && qt.getIsMaskedPreferred() && qt.getIsRecomputedFromRawData()) {
dataReprocessedFromRaw = true;
}
}
score = dataReprocessedFromRaw ? GeeqServiceImpl.P_10 : GeeqServiceImpl.N_10;
gq.setsScoreRawData(score);
return dataReprocessedFromRaw;
}
use of ubic.gemma.model.common.quantitationtype.QuantitationType in project Gemma by PavlidisLab.
the class ExpressionExperimentDaoImpl method remove.
@Override
public void remove(final ExpressionExperiment ee) {
if (ee == null)
throw new IllegalArgumentException();
Session session = this.getSessionFactory().getCurrentSession();
try {
// Note that links and analyses are deleted separately - see the ExpressionExperimentService.
// At this point, the ee is probably still in the session, as the service already has gotten it
// in this transaction.
session.flush();
session.clear();
session.buildLockRequest(LockOptions.NONE).lock(ee);
Hibernate.initialize(ee.getAuditTrail());
Set<BioAssayDimension> dims = new HashSet<>();
Set<QuantitationType> qts = new HashSet<>();
Collection<RawExpressionDataVector> designElementDataVectors = ee.getRawExpressionDataVectors();
Hibernate.initialize(designElementDataVectors);
ee.setRawExpressionDataVectors(null);
/*
* We don't remove the investigators, just breaking the association.
*/
ee.getInvestigators().clear();
int count = 0;
if (designElementDataVectors != null) {
count = this.removeDataVectors(session, dims, qts, designElementDataVectors, count);
}
Collection<ProcessedExpressionDataVector> processedVectors = ee.getProcessedExpressionDataVectors();
Hibernate.initialize(processedVectors);
if (processedVectors != null && processedVectors.size() > 0) {
ee.setProcessedExpressionDataVectors(null);
this.removeProcessedVectors(session, dims, qts, count, processedVectors);
}
session.flush();
session.clear();
session.update(ee);
AbstractDao.log.info("Removing BioAssay Dimensions ...");
for (BioAssayDimension dim : dims) {
dim.getBioAssays().clear();
session.update(dim);
session.delete(dim);
}
dims.clear();
session.flush();
AbstractDao.log.info("Removing Bioassays and biomaterials ...");
// keep to put back in the object.
Map<BioAssay, BioMaterial> copyOfRelations = new HashMap<>();
Collection<BioMaterial> bioMaterialsToDelete = new HashSet<>();
Collection<BioAssay> bioAssays = ee.getBioAssays();
this.removeBioAssays(session, copyOfRelations, bioMaterialsToDelete, bioAssays);
AbstractDao.log.info("Last bits ...");
// We remove them here in case they are associated to more than one bioassay-- no cascade is possible.
for (BioMaterial bm : bioMaterialsToDelete) {
session.delete(bm);
}
for (QuantitationType qt : qts) {
session.delete(qt);
}
session.flush();
session.delete(ee);
/*
* Put transient instances back. This is possibly useful for clearing ACLS.
*/
ee.setProcessedExpressionDataVectors(processedVectors);
ee.setRawExpressionDataVectors(designElementDataVectors);
for (BioAssay ba : ee.getBioAssays()) {
ba.setSampleUsed(copyOfRelations.get(ba));
}
AbstractDao.log.info("Deleted " + ee);
} catch (Exception e) {
AbstractDao.log.error(e);
} finally {
AbstractDao.log.info("Finalising remove method.");
}
}
Aggregations