use of ubic.gemma.model.expression.experiment.ExperimentalFactor in project Gemma by PavlidisLab.
the class ExpressionDataMatrixColumnSort method orderFactorsByExperimentalDesign.
/**
* @return list of factors, sorted from simplest (fewest number of values from the biomaterials passed in) to least
* simple. Continuous factors will always be first, and batch factors last.
*/
private static List<ExperimentalFactor> orderFactorsByExperimentalDesign(List<BioMaterial> start, Collection<ExperimentalFactor> factors) {
if (factors == null || factors.isEmpty()) {
ExpressionDataMatrixColumnSort.log.warn("No factors supplied for sorting");
return new LinkedList<>();
}
LinkedList<ExperimentalFactor> sortedFactors = new LinkedList<>();
Collection<ExperimentalFactor> factorsToTake = new HashSet<>(factors);
while (!factorsToTake.isEmpty()) {
ExperimentalFactor simplest = ExpressionDataMatrixColumnSort.chooseSimplestFactor(start, factorsToTake);
if (simplest == null) {
// none of the factors have more than one factor value. One-sided t-tests ...
/*
* This assertion isn't right -- we now allow this, though we can only have ONE such constant factor.
* See bug 2390. Unless we are dealing with a subset, in which case there can be any number of constant
* factors within the subset.
*/
// assert factors.size() == 1 :
// "It's possible to have just one factor value, but only if there is only one factor.";
sortedFactors.addAll(factors);
return sortedFactors;
}
sortedFactors.addLast(simplest);
factorsToTake.remove(simplest);
}
return sortedFactors;
}
use of ubic.gemma.model.expression.experiment.ExperimentalFactor in project Gemma by PavlidisLab.
the class FactorValueDeletionImpl method deleteFactorValues.
@Override
@Transactional
public void deleteFactorValues(Collection<Long> fvIds) {
Collection<FactorValue> fvsToDelete = new ArrayList<>();
for (Long fvId : fvIds) {
FactorValue fv = factorValueService.load(fvId);
if (fv == null) {
throw new IllegalArgumentException("No factor value with id=" + fvId + " could be loaded");
}
if (fv.getExperimentalFactor() == null) {
throw new IllegalStateException("No experimental factor for factor value " + fv.getId());
}
/*
* Delete any diff ex analyses that use this factor.
*/
ExperimentalFactor ef = experimentalFactorService.load(fv.getExperimentalFactor().getId());
Collection<DifferentialExpressionAnalysis> analyses = differentialExpressionAnalysisService.findByFactor(ef);
// Warning: slow.
for (DifferentialExpressionAnalysis a : analyses) {
differentialExpressionAnalysisService.remove(a);
}
// this gets done by the factorValueService as well, but can't hurt.
ef.getFactorValues().remove(fv);
fvsToDelete.add(fv);
}
for (FactorValue fv : fvsToDelete) {
factorValueService.remove(fv);
}
}
use of ubic.gemma.model.expression.experiment.ExperimentalFactor in project Gemma by PavlidisLab.
the class DifferentialExpressionAnalysisController method runCustom.
public String runCustom(Long id, Collection<Long> factorids, boolean includeInteractions, Long subsetFactorId) {
if (factorids.isEmpty()) {
throw new IllegalArgumentException("You must provide at least one factor to analyze");
}
ExpressionExperiment ee = expressionExperimentService.load(id);
if (ee == null) {
throw new IllegalArgumentException("Cannot access experiment with id=" + id);
}
ee = expressionExperimentService.thawLite(ee);
/*
* Get the factors matching the factorids
*/
Collection<ExperimentalFactor> factors = new HashSet<>();
for (ExperimentalFactor ef : ee.getExperimentalDesign().getExperimentalFactors()) {
if (factorids.contains(ef.getId())) {
factors.add(ef);
}
}
if (factors.size() != factorids.size()) {
throw new IllegalArgumentException("Unknown factors?");
}
ExperimentalFactor subsetFactor = null;
if (subsetFactorId != null) {
for (ExperimentalFactor ef : ee.getExperimentalDesign().getExperimentalFactors()) {
if (subsetFactorId.equals(ef.getId())) {
subsetFactor = ef;
break;
}
}
if (subsetFactor == null) {
throw new IllegalArgumentException("Unknown subset factor?");
}
if (factors.contains(subsetFactor)) {
throw new IllegalArgumentException("Subset factor must not be one of the factors used in the analysis");
}
}
DifferentialExpressionAnalysisTaskCommand cmd = new DifferentialExpressionAnalysisTaskCommand(ee);
boolean rnaSeq = expressionExperimentService.isRNASeq(ee);
cmd.setUseWeights(rnaSeq);
cmd.setFactors(factors);
cmd.setSubsetFactor(subsetFactor);
for (ExperimentalFactor ef : factors) {
if (BatchInfoPopulationServiceImpl.isBatchFactor(ef)) {
/*
* This is a policy and I am pretty sure it makes sense!
*/
DifferentialExpressionAnalysisController.log.warn("Removing interaction term because it includes 'batch'");
includeInteractions = false;
}
}
cmd.setIncludeInteractions(includeInteractions);
DifferentialExpressionAnalysisController.log.info("Initializing analysis");
this.experimentReportService.evictFromCache(ee.getId());
return taskRunningService.submitRemoteTask(cmd);
}
use of ubic.gemma.model.expression.experiment.ExperimentalFactor in project Gemma by PavlidisLab.
the class DifferentialExpressionAnalysisController method determineAnalysisType.
/**
* Ajax method. Pick the analysis type when we want it to be completely automated.
*
* @param id id
* @return analysis info
*/
public DifferentialExpressionAnalyzerInfo determineAnalysisType(Long id) {
ExpressionExperiment ee = expressionExperimentService.load(id);
if (ee == null) {
throw new IllegalArgumentException("Cannot access experiment with id=" + id);
}
ee = expressionExperimentService.thawLite(ee);
Collection<ExperimentalFactor> factorsWithoutBatch = ExperimentalDesignUtils.factorsWithoutBatch(ee.getExperimentalDesign().getExperimentalFactors());
AnalysisType analyzer = this.analysisSelectionAndExecutionService.determineAnalysis(ee, factorsWithoutBatch, null, true);
DifferentialExpressionAnalyzerInfo result = new DifferentialExpressionAnalyzerInfo();
// we include all factors here, so that batch can be used for subsetting (up to client)
for (ExperimentalFactor factor : ee.getExperimentalDesign().getExperimentalFactors()) {
result.getFactors().add(new ExperimentalFactorValueObject(factor));
}
if (analyzer == null) {
/*
* Either there are no viable automatic choices, or there are no usable factors...
*/
if (factorsWithoutBatch.size() < 2) {
throw new IllegalStateException("This data set does not seem suitable for analysis.");
}
result.setType(AnalysisType.GENERICLM.toString());
} else {
result.setType(analyzer.toString());
}
return result;
}
use of ubic.gemma.model.expression.experiment.ExperimentalFactor in project Gemma by PavlidisLab.
the class CharacteristicBrowserController method findCharacteristicsCustom.
/**
* @param searchFVs Search factor values that lack characteristics -- that is, search the factorValue.value.
* @param searchCategories Should the Category be searched, not just the Value?
*/
public Collection<AnnotationValueObject> findCharacteristicsCustom(String valuePrefix, boolean searchNos, boolean searchEEs, boolean searchBMs, boolean searchFVs, boolean searchPAs, boolean searchFVVs, boolean searchCategories) {
List<AnnotationValueObject> results = new ArrayList<>();
if (StringUtils.isBlank(valuePrefix)) {
return results;
}
Collection<Characteristic> chars = characteristicService.findByValue(valuePrefix);
if (searchCategories) {
chars.addAll(characteristicService.findByCategory(valuePrefix));
}
Map<Characteristic, Object> charToParent = characteristicService.getParents(chars);
for (Object o : chars) {
Characteristic c = (Characteristic) o;
Object parent = charToParent.get(c);
if ((searchEEs && parent instanceof ExpressionExperiment) || (searchBMs && parent instanceof BioMaterial) || (searchFVs && (parent instanceof FactorValue || parent instanceof ExperimentalFactor)) || (searchNos && parent == null) || (searchPAs && parent instanceof PhenotypeAssociation)) {
AnnotationValueObject avo = new AnnotationValueObject();
avo.setId(c.getId());
avo.setClassName(c.getCategory());
avo.setTermName(c.getValue());
if (c.getEvidenceCode() != null)
avo.setEvidenceCode(c.getEvidenceCode().toString());
populateClassValues(c, avo);
if (parent != null) {
populateParentInformation(avo, parent);
}
results.add(avo);
}
}
if (searchFVVs) {
// non-characteristics.
Collection<FactorValue> factorValues = factorValueService.findByValue(valuePrefix);
for (FactorValue factorValue : factorValues) {
if (factorValue.getCharacteristics().size() > 0)
continue;
if (StringUtils.isBlank(factorValue.getValue()))
continue;
AnnotationValueObject avo = new AnnotationValueObject();
avo.setId(factorValue.getId());
avo.setTermName(factorValue.getValue());
avo.setObjectClass(FactorValue.class.getSimpleName());
populateParentInformation(avo, factorValue);
results.add(avo);
}
}
log.info("Characteristic search for: '" + valuePrefix + "*': " + results.size() + " results, returning up to " + MAX_RESULTS);
return results.subList(0, Math.min(results.size(), MAX_RESULTS));
}
Aggregations