use of org.baderlab.csplugins.enrichmentmap.util.DiscreteTaskMonitor in project EnrichmentMapApp by BaderLab.
the class ComputeSimilarityTaskParallel method startComputeSimilarities.
private Map<SimilarityKey, GenesetSimilarity> startComputeSimilarities(TaskMonitor tm, ExecutorService executor, boolean distinct, boolean compound) {
Set<String> names = map.getAllGeneSetOfInterestNames();
Map<String, Set<Integer>> unionedGenesets = compound ? map.unionAllGeneSetsOfInterest() : null;
DiscreteTaskMonitor taskMonitor = discreteTaskMonitor(tm, names.size());
String edgeType = map.getParams().getEnrichmentEdgeType();
Map<SimilarityKey, GenesetSimilarity> similarities = new ConcurrentHashMap<>();
Collection<EMDataSet> dataSets = map.getDataSetList();
for (final String geneset1Name : names) {
// Compute similarities in batches, creating a Runnable for every similarity pair would create too many objects
executor.execute(() -> {
loop: for (final String geneset2Name : names) {
if (Thread.interrupted())
break loop;
if (geneset1Name.equalsIgnoreCase(geneset2Name))
//don't compare two identical gene sets
continue;
if (distinct) {
for (EMDataSet dataset : dataSets) {
SimilarityKey key = new SimilarityKey(geneset1Name, geneset2Name, edgeType, dataset.getName());
if (!similarities.containsKey(key)) {
Map<String, GeneSet> genesets = dataset.getGeneSetsOfInterest().getGeneSets();
GeneSet geneset1 = genesets.get(geneset1Name);
GeneSet geneset2 = genesets.get(geneset2Name);
if (geneset1 != null && geneset2 != null) {
// returns null if the similarity coefficient doesn't pass the cutoff
GenesetSimilarity similarity = computeGenesetSimilarity(map.getParams(), geneset1Name, geneset2Name, geneset1.getGenes(), geneset2.getGenes(), dataset.getName());
if (similarity != null) {
similarities.put(key, similarity);
}
}
}
}
}
if (compound) {
SimilarityKey key = new SimilarityKey(geneset1Name, geneset2Name, edgeType, null);
if (!similarities.containsKey(key)) {
Set<Integer> geneset1 = unionedGenesets.get(geneset1Name);
Set<Integer> geneset2 = unionedGenesets.get(geneset2Name);
// returns null if the similarity coefficient doesn't pass the cutoff
GenesetSimilarity similarity = computeGenesetSimilarity(map.getParams(), geneset1Name, geneset2Name, geneset1, geneset2, "compound");
if (similarity != null) {
similarities.put(key, similarity);
}
}
}
}
taskMonitor.inc();
});
}
return similarities;
}
Aggregations