use of ubic.gemma.model.expression.experiment.BioAssaySet in project Gemma by PavlidisLab.
the class ExpressionExperimentSetServiceImpl method updateDatabaseEntityMembers.
/**
* update the members of the experiment set with the given ids
*
* @param groupId set to update
* @param eeIds new set member ids
*/
@Override
@Transactional
public void updateDatabaseEntityMembers(Long groupId, Collection<Long> eeIds) {
if (eeIds.isEmpty()) {
throw new IllegalArgumentException("No expression experiment ids provided. Cannot save an empty set.");
}
ExpressionExperimentSet eeSet = this.load(groupId);
if (eeSet == null) {
throw new IllegalArgumentException("No experiment set with id=" + groupId + " could be loaded. " + "Either it does not exist or you do not have permission to view it.");
}
// check that new member ids are valid
Collection<ExpressionExperiment> newExperiments = expressionExperimentService.load(eeIds);
if (newExperiments.isEmpty()) {
throw new IllegalArgumentException("None of the experiment ids were valid (out of " + eeIds.size() + " provided)");
}
if (newExperiments.size() < eeIds.size()) {
throw new IllegalArgumentException("Some of the experiment ids were invalid: only found " + newExperiments.size() + " out of " + eeIds.size() + " provided)");
}
assert newExperiments.size() == eeIds.size();
Collection<BioAssaySet> basColl = new HashSet<>();
for (ExpressionExperiment experiment : newExperiments) {
Taxon eeTaxon = this.getTaxonForSet(experiment);
// make sure experiments being added are from the right taxon
if (eeTaxon == null || !eeTaxon.equals(eeSet.getTaxon())) {
throw new IllegalArgumentException(experiment + " is of the wrong taxon to add to eeset. EESet taxon is " + eeSet.getTaxon());
}
basColl.add(experiment);
}
eeSet.getExperiments().clear();
eeSet.getExperiments().addAll(basColl);
this.update(eeSet);
}
use of ubic.gemma.model.expression.experiment.BioAssaySet in project Gemma by PavlidisLab.
the class ExpressionExperimentSetServiceImpl method update.
/**
* @see ExpressionExperimentSetService#update(ExpressionExperimentSet)
*/
@Override
@Transactional
public void update(final ExpressionExperimentSet expressionExperimentSet) {
if (expressionExperimentSet == null) {
throw new IllegalArgumentException("Cannot update null set");
}
if (expressionExperimentSet.getId() == null || expressionExperimentSet.getId() < 0) {
throw new IllegalArgumentException("Can only update an existing eeset (passed id=" + expressionExperimentSet.getId() + ")");
}
if (StringUtils.isBlank(expressionExperimentSet.getName())) {
throw new IllegalArgumentException("You must provide a name");
}
// make sure potentially new experiment members are of the right taxon
Taxon groupTaxon = expressionExperimentSet.getTaxon();
Taxon eeTaxon;
for (BioAssaySet ee : expressionExperimentSet.getExperiments()) {
eeTaxon = this.getTaxonForSet(ee);
assert eeTaxon != null;
if (!eeTaxon.equals(groupTaxon)) {
throw new IllegalArgumentException("Failed to add experiments of wrong taxa (" + ee + ") to eeset. " + "EESet taxon is " + groupTaxon + ", experiment was " + eeTaxon);
}
}
if (StringUtils.isBlank(expressionExperimentSet.getName())) {
throw new IllegalArgumentException("Attempt to update an ExpressionExperimentSet so it has no name");
}
this.expressionExperimentSetDao.update(expressionExperimentSet);
}
use of ubic.gemma.model.expression.experiment.BioAssaySet in project Gemma by PavlidisLab.
the class ProcessedExpressionDataVectorServiceImpl method getDiffExVectors.
@Override
public List<DoubleVectorValueObject> getDiffExVectors(Long resultSetId, Double threshold, int maxNumberOfResults) {
ExpressionAnalysisResultSet ar = differentialExpressionResultService.loadAnalysisResultSet(resultSetId);
if (ar == null) {
Log.warn(this.getClass(), "No diff ex result set with ID=" + resultSetId);
return null;
}
differentialExpressionResultService.thawLite(ar);
BioAssaySet analyzedSet = ar.getAnalysis().getExperimentAnalyzed();
List<DifferentialExpressionValueObject> ee2probeResults = differentialExpressionResultService.findInResultSet(ar, threshold, maxNumberOfResults, ProcessedExpressionDataVectorServiceImpl.DIFFEX_MIN_NUMBER_OF_RESULTS);
Collection<Long> probes = new HashSet<>();
// Map<CompositeSequenceId, pValue>
// using id instead of entity for map key because want to use a value object for retrieval later
Map<Long, Double> pvalues = new HashMap<>();
for (DifferentialExpressionValueObject par : ee2probeResults) {
probes.add(par.getProbeId());
pvalues.put(par.getProbeId(), par.getP());
}
Collection<DoubleVectorValueObject> processedDataArraysByProbe = this.getProcessedDataArraysByProbeIds(analyzedSet, probes);
List<DoubleVectorValueObject> dedvs = new ArrayList<>(processedDataArraysByProbe);
/*
* Resort
*/
for (DoubleVectorValueObject v : dedvs) {
v.setPvalue(pvalues.get(v.getDesignElement().getId()));
}
Collections.sort(dedvs, new Comparator<DoubleVectorValueObject>() {
@Override
public int compare(DoubleVectorValueObject o1, DoubleVectorValueObject o2) {
if (o1.getPvalue() == null)
return -1;
if (o2.getPvalue() == null)
return 1;
return o1.getPvalue().compareTo(o2.getPvalue());
}
});
return dedvs;
}
use of ubic.gemma.model.expression.experiment.BioAssaySet in project Gemma by PavlidisLab.
the class ProcessedExpressionDataVectorDaoImpl method getExperiments.
/**
* Determine the experiments that bioAssaySets refer to.
*
* @param bioAssaySets - either ExpressionExperiment or ExpressionExperimentSubSet (which has an associated
* ExpressionExperiment, which is what we're after)
* @return Note that this collection can be smaller than the input, if two bioAssaySets come from (or are) the same
* Experiment
*/
private Collection<ExpressionExperiment> getExperiments(Collection<? extends BioAssaySet> bioAssaySets) {
Collection<ExpressionExperiment> result = new HashSet<>();
for (BioAssaySet bas : bioAssaySets) {
ExpressionExperiment e = this.getExperiment(bas);
result.add(e);
}
return result;
}
use of ubic.gemma.model.expression.experiment.BioAssaySet in project Gemma by PavlidisLab.
the class LinkAnalysisServiceTest method testLoadAnalyzeSaveAndCoexpSearch.
@Test
public void testLoadAnalyzeSaveAndCoexpSearch() {
ee = this.getTestPersistentCompleteExpressionExperimentWithSequences();
processedExpressionDataVectorService.computeProcessedExpressionData(ee);
tableMaintenanceUtil.disableEmail();
tableMaintenanceUtil.updateGene2CsEntries();
linkAnalysisConfig.setCdfCut(0.1);
linkAnalysisConfig.setSingularThreshold(SingularThreshold.cdfcut);
linkAnalysisConfig.setProbeDegreeThreshold(25);
linkAnalysisConfig.setCheckCorrelationDistribution(false);
linkAnalysisConfig.setCheckForBatchEffect(false);
filterConfig.setIgnoreMinimumSampleThreshold(true);
// first time.
// noinspection UnusedAssignment // we still want to do this for the testing sake
LinkAnalysis la = linkAnalysisService.process(ee, filterConfig, linkAnalysisConfig);
// test remove is clean; to check this properly requires checking the db.
linkAnalysisPersisterService.deleteAnalyses(ee);
this.checkUnsupportedLinksHaveNoSupport();
assertEquals(0, geneCoexpressionService.getCoexpression(ee, true).size());
la = linkAnalysisService.process(ee, filterConfig, linkAnalysisConfig);
CoexpressionAnalysis analysisObj = la.getAnalysisObj();
assertEquals(151, analysisObj.getNumberOfElementsAnalyzed().intValue());
assertTrue(analysisObj.getNumberOfLinks() > 0);
assertNotNull(analysisObj.getCoexpCorrelationDistribution());
Collection<BioAssaySet> ees = new HashSet<>();
ees.add(ee);
this.updateNodeDegree();
int totalLinksFirstPass = this.checkResults(ees, 1);
// should be ~1140.
assertTrue(totalLinksFirstPass > 1000);
// test redo
linkAnalysisService.process(ee, filterConfig, linkAnalysisConfig);
this.updateNodeDegree();
int totalLinksRedo = this.checkResults(ees, 1);
assertEquals(totalLinksFirstPass, totalLinksRedo);
// now add another experiment that has overlapping links (same data...
Map<CompositeSequence, byte[]> dataMap = new HashMap<>();
ee = eeService.thaw(ee);
for (RawExpressionDataVector v : ee.getRawExpressionDataVectors()) {
dataMap.put(v.getDesignElement(), v.getData());
}
ExpressionExperiment ee2 = this.getTestPersistentCompleteExpressionExperimentWithSequences(ee);
// eeService.thawRawAndProcessed( ee2 );
for (RawExpressionDataVector v : ee2.getRawExpressionDataVectors()) {
assert dataMap.get(v.getDesignElement()) != null;
v.setData(dataMap.get(v.getDesignElement()));
}
eeService.update(ee2);
processedExpressionDataVectorService.computeProcessedExpressionData(ee2);
linkAnalysisService.process(ee2, filterConfig, linkAnalysisConfig);
this.updateNodeDegree();
// expect to get at least one links with support >1
ees.add(ee2);
this.checkResults(ees, 2);
}
Aggregations