use of org.baderlab.csplugins.enrichmentmap.model.SimilarityKey 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.model.SimilarityKey in project EnrichmentMapApp by BaderLab.
the class CreateDiseaseSignatureTaskParallel method run.
@Override
public void run(TaskMonitor tm) throws InterruptedException {
int cpus = Runtime.getRuntime().availableProcessors();
ExecutorService executor = Executors.newFixedThreadPool(cpus);
// Compare enrichment gene sets to signature gene sets
Set<String> enrichmentGeneSetNames = getEnrichmentGeneSetNames();
Map<String, GeneSet> signatureGeneSets = getSignatureGeneSets();
handleDuplicateNames(enrichmentGeneSetNames, signatureGeneSets);
Map<SimilarityKey, GenesetSimilarity> geneSetSimilarities = startBuildDiseaseSignatureParallel(tm, executor, enrichmentGeneSetNames, signatureGeneSets);
// Support cancellation
Timer timer = new Timer();
timer.scheduleAtFixedRate(new TimerTask() {
public void run() {
if (cancelled) {
executor.shutdownNow();
}
}
}, 0, 1000);
executor.shutdown();
executor.awaitTermination(3, TimeUnit.HOURS);
timer.cancel();
// create the network here
if (!cancelled) {
Task networkTask = networkTaskFactory.create(map, params, signatureGeneSets, geneSetSimilarities);
insertTasksAfterCurrentTask(networkTask);
}
}
use of org.baderlab.csplugins.enrichmentmap.model.SimilarityKey in project EnrichmentMapApp by BaderLab.
the class ComputeSimilarityTaskParallel method run.
@Override
public void run(TaskMonitor tm) throws InterruptedException {
int cpus = Runtime.getRuntime().availableProcessors();
ExecutorService executor = Executors.newFixedThreadPool(cpus);
boolean distinct = map.getParams().getCreateDistinctEdges();
Map<SimilarityKey, GenesetSimilarity> similarities = startComputeSimilarities(tm, executor, distinct, !distinct);
// Support cancellation
Timer timer = new Timer();
timer.scheduleAtFixedRate(new TimerTask() {
public void run() {
if (cancelled) {
executor.shutdownNow();
}
}
}, 0, 1000);
executor.shutdown();
executor.awaitTermination(3, TimeUnit.HOURS);
timer.cancel();
if (!cancelled)
consumer.accept(similarities);
}
use of org.baderlab.csplugins.enrichmentmap.model.SimilarityKey in project EnrichmentMapApp by BaderLab.
the class CreateEMNetworkTask method createEdges.
/**
* Note, we expect that GenesetSimilarity object that don't pass the cutoff have already been filtered out.
* @param network
* @param nodes
*/
private void createEdges(CyNetwork network, Map<String, CyNode> nodes) {
Map<SimilarityKey, GenesetSimilarity> similarities = supplier.get();
for (SimilarityKey key : similarities.keySet()) {
GenesetSimilarity similarity = similarities.get(key);
CyNode node1 = nodes.get(similarity.getGeneset1Name());
CyNode node2 = nodes.get(similarity.getGeneset2Name());
CyEdge edge = network.addEdge(node1, node2, false);
String datasetName = key.getName();
if (datasetName != null) {
EMDataSet dataset = map.getDataSet(datasetName);
if (dataset != null) {
dataset.addEdgeSuid(edge.getSUID());
}
}
List<String> overlapGenes = similarity.getOverlappingGenes().stream().map(map::getGeneFromHashKey).collect(Collectors.toList());
String edgeName = key.toString();
CyRow row = network.getRow(edge);
row.set(CyNetwork.NAME, edgeName);
row.set(CyEdge.INTERACTION, similarity.getInteractionType());
Columns.EDGE_SIMILARITY_COEFF.set(row, prefix, null, similarity.getSimilarityCoeffecient());
Columns.EDGE_OVERLAP_SIZE.set(row, prefix, null, similarity.getSizeOfOverlap());
Columns.EDGE_OVERLAP_GENES.set(row, prefix, null, overlapGenes);
if (key.isCompound()) {
Columns.EDGE_DATASET.set(row, prefix, null, Columns.EDGE_DATASET_VALUE_COMPOUND);
} else {
Columns.EDGE_DATASET.set(row, prefix, null, similarity.getDataSetName());
}
}
}
use of org.baderlab.csplugins.enrichmentmap.model.SimilarityKey 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