use of org.baderlab.csplugins.enrichmentmap.util.DiscreteTaskMonitor in project EnrichmentMapApp by BaderLab.
the class CreateDiseaseSignatureTaskParallel method startBuildDiseaseSignatureParallel.
/**
* Returns immediately, need to wait on the executor to join all threads.
*/
private Map<SimilarityKey, GenesetSimilarity> startBuildDiseaseSignatureParallel(TaskMonitor tm, ExecutorService executor, Set<String> enrichmentGeneSetNames, Map<String, GeneSet> signatureGeneSets) {
DiscreteTaskMonitor taskMonitor = discreteTaskMonitor(tm, signatureGeneSets.size());
// Gene universe is all enrichment genes in the map
Set<Integer> geneUniverse = map.getAllEnrichmentGenes();
Map<SimilarityKey, GenesetSimilarity> geneSetSimilarities = new ConcurrentHashMap<>();
for (String hubName : signatureGeneSets.keySet()) {
GeneSet sigGeneSet = signatureGeneSets.get(hubName);
Set<Integer> sigGenesInUniverse = Sets.intersection(sigGeneSet.getGenes(), geneUniverse);
// Compute similarities in batches
executor.execute(() -> {
loop: for (String geneSetName : enrichmentGeneSetNames) {
for (EMDataSet dataSet : dataSets) {
if (Thread.interrupted())
break loop;
GeneSet enrGeneSet = dataSet.getSetOfGeneSets().getGeneSetByName(geneSetName);
if (enrGeneSet != null) {
// restrict to a common gene universe
Set<Integer> enrGenes = Sets.intersection(enrGeneSet.getGenes(), geneUniverse);
Set<Integer> union = Sets.union(sigGeneSet.getGenes(), enrGenes);
Set<Integer> intersection = Sets.intersection(sigGenesInUniverse, enrGenes);
if (!intersection.isEmpty()) {
double coeffecient = ComputeSimilarityTaskParallel.computeSimilarityCoeffecient(map.getParams(), intersection, union, sigGeneSet.getGenes(), enrGenes);
GenesetSimilarity comparison = new GenesetSimilarity(hubName, geneSetName, coeffecient, INTERACTION, intersection);
PostAnalysisFilterType filterType = params.getRankTestParameters().getType();
switch(filterType) {
case HYPERGEOM:
int hyperUniverseSize1 = getHypergeometricUniverseSize(dataSet);
hypergeometric(hyperUniverseSize1, sigGenesInUniverse, enrGenes, intersection, comparison);
break;
case MANN_WHIT_TWO_SIDED:
case MANN_WHIT_GREATER:
case MANN_WHIT_LESS:
mannWhitney(intersection, comparison, dataSet);
default:
// want mann-whit to fall through
// #70 calculate hypergeometric also
int hyperUniverseSize2 = map.getNumberOfGenes();
hypergeometric(hyperUniverseSize2, sigGenesInUniverse, enrGenes, intersection, comparison);
break;
}
SimilarityKey key = new SimilarityKey(hubName, geneSetName, INTERACTION, dataSet.getName());
geneSetSimilarities.put(key, comparison);
}
}
}
}
taskMonitor.inc();
});
}
return geneSetSimilarities;
}
use of org.baderlab.csplugins.enrichmentmap.util.DiscreteTaskMonitor in project EnrichmentMapApp by BaderLab.
the class CreateDiseaseSignatureTaskParallel method discreteTaskMonitor.
private static DiscreteTaskMonitor discreteTaskMonitor(TaskMonitor tm, int size) {
DiscreteTaskMonitor taskMonitor = new DiscreteTaskMonitor(tm, size);
taskMonitor.setTitle("Post Analysis Geneset Similarities...");
taskMonitor.setStatusMessageTemplate("Computing Geneset Similarity: {0} of {1} tasks");
return taskMonitor;
}
use of org.baderlab.csplugins.enrichmentmap.util.DiscreteTaskMonitor in project EnrichmentMapApp by BaderLab.
the class InitializeGenesetsOfInterestTask method initializeSets.
/**
* filter the genesets, restricting them to only those passing the user
* specified thresholds.
*
* @return true if successful and false otherwise.
*/
public boolean initializeSets(TaskMonitor tm) {
if (tm == null)
tm = new NullTaskMonitor();
DiscreteTaskMonitor taskMonitor = new DiscreteTaskMonitor(tm, map.getDataSetCount());
//create subset of genesets that contains only the genesets of interest with pvalue and qbalue less than values specified by the user.
//Go through each Dataset populating the Gene set of interest in each dataset object
Map<String, EMDataSet> datasets = map.getDataSets();
// count how many experiments (DataSets) contain the geneset
Optional<Integer> minExperiments = map.getParams().getMinExperiments();
Map<String, Integer> occurrences = minExperiments.isPresent() ? new HashMap<>() : null;
for (String datasetName : datasets.keySet()) {
taskMonitor.inc();
EMDataSet dataset = datasets.get(datasetName);
// all these maps use the geneset name as key
Map<String, EnrichmentResult> enrichmentResults = dataset.getEnrichments().getEnrichments();
Map<String, GeneSet> genesets = dataset.getSetOfGeneSets().getGeneSets();
Map<String, GeneSet> genesetsOfInterest = dataset.getGeneSetsOfInterest().getGeneSets();
// If there are no genesets associated with this dataset then get the complete set assumption being that the gmt file applies to all datasets.
if (genesets == null || genesets.isEmpty()) {
genesets = map.getAllGeneSets();
}
//if there are no enrichment Results then do nothing
if (enrichmentResults == null || enrichmentResults.isEmpty()) {
return false;
}
//iterate through the GSEA Results to figure out which genesets we want to use
for (String genesetName : enrichmentResults.keySet()) {
EnrichmentResult result = enrichmentResults.get(genesetName);
// update rank at max for leading edge calculation
if (dataset.getMethod() == Method.GSEA) {
Ranking ranks = dataset.getExpressionSets().getRanksByName(datasetName);
updateRankAtMax((GSEAResult) result, ranks);
}
if (result.geneSetOfInterest(map.getParams())) {
GeneSet geneset = genesets.get(genesetName);
if (geneset != null) {
// while we are checking, update the size of the genesets based on post filtered data
result.setGsSize(geneset.getGenes().size());
if (occurrences != null) {
occurrences.merge(genesetName, 1, (v, d) -> v + 1);
}
genesetsOfInterest.put(genesetName, geneset);
} else if (throwIfMissing) {
throw new IllegalThreadStateException("The Geneset: " + genesetName + " is not found in the GMT file.");
}
}
}
}
// Remove gene-sets that don't pass the minimum occurrence cutoff
if (occurrences != null) {
for (EMDataSet dataset : datasets.values()) {
Map<String, GeneSet> genesetsOfInterest = dataset.getGeneSetsOfInterest().getGeneSets();
genesetsOfInterest.keySet().removeIf(geneset -> occurrences.getOrDefault(geneset, 0) < minExperiments.get());
}
}
return true;
}
use of org.baderlab.csplugins.enrichmentmap.util.DiscreteTaskMonitor in project EnrichmentMapApp by BaderLab.
the class ComputeSimilarityTaskParallel method discreteTaskMonitor.
private static DiscreteTaskMonitor discreteTaskMonitor(TaskMonitor tm, int size) {
DiscreteTaskMonitor taskMonitor = new DiscreteTaskMonitor(tm, size);
taskMonitor.setTitle("Computing Geneset Similarities...");
taskMonitor.setStatusMessageTemplate("Computing Geneset Similarity: {0} of {1} tasks");
return taskMonitor;
}
use of org.baderlab.csplugins.enrichmentmap.util.DiscreteTaskMonitor in project EnrichmentMapApp by BaderLab.
the class CreateDiseaseSignatureNetworkTask method run.
/**
* This task is NOT cancellable.
*/
@Override
public void run(TaskMonitor tm) {
tm.setTitle("Post Analysis Geneset Similarities...");
CyNetwork network = networkManager.getNetwork(map.getNetworkID());
CyNetworkView networkView = getNetworKView(network);
taskResult.setNetwork(network);
taskResult.setNetworkView(networkView);
// Gene universe is all enrichment genes in the map
Set<Integer> geneUniverse = map.getAllEnrichmentGenes();
String prefix = params.getAttributePrefix();
//get the node attribute and edge attribute tables
tm.setStatusMessage("Creating Columns");
CyTable edgeTable = createEdgeColumns(network, "", prefix);
CyTable nodeTable = createNodeColumns(network, "", prefix);
tm.setProgress(0.1);
tm.setStatusMessage("Caching Nodes");
existingEdgeCache = createExistingEdgeCache(prefix, network, edgeTable);
tm.setProgress(0.2);
EMSignatureDataSet sigDataSet = createSignatureDataSet();
// Create Signature Hub Nodes
tm.setStatusMessage("Creating Nodes");
signatureGeneSets.forEach(sigDataSet.getGeneSetsOfInterest()::addGeneSet);
signatureGeneSets.forEach((hubName, sigGeneSet) -> createHubNode(hubName, network, networkView, prefix, edgeTable, nodeTable, geneUniverse, sigGeneSet, sigDataSet));
tm.setProgress(0.3);
// Layout nodes
tm.setStatusMessage("Laying out Nodes");
layoutHubNodes(networkView);
tm.setProgress(0.4);
// Create Signature Hub Edges
tm.setStatusMessage("Creating Edges");
DiscreteTaskMonitor dtm = new DiscreteTaskMonitor(tm, geneSetSimilarities.size(), 0.4, 0.9);
dtm.setStatusMessageTemplate("Similarity {0} of {1}");
for (SimilarityKey similarityKey : geneSetSimilarities.keySet()) {
boolean passedCutoff = passesCutoff(similarityKey, sigDataSet);
createEdge(similarityKey, network, networkView, prefix, edgeTable, nodeTable, passedCutoff, sigDataSet);
dtm.inc();
}
// Set edge widths
tm.setStatusMessage("Setting Edge Widths");
widthFunctionProvider.get().setEdgeWidths(network, prefix, tm);
tm.setProgress(1.0);
// Add the new data set to the map
map.addSignatureDataSet(sigDataSet);
}
Aggregations