use of org.baderlab.csplugins.enrichmentmap.model.GenesetSimilarity in project EnrichmentMapApp by BaderLab.
the class CreateDiseaseSignatureNetworkTask method passesCutoff.
/**
* Why not put this in CreateDiseaseSignatureTaskParallel... don't even create the GenesetSimilarity object if it fails!!!
* @param similarityKey
* @return
*/
private boolean passesCutoff(SimilarityKey similarityKey, EMSignatureDataSet sigDataSet) {
GenesetSimilarity similarity = geneSetSimilarities.get(similarityKey);
PostAnalysisFilterParameters filterParams = params.getRankTestParameters();
switch(filterParams.getType()) {
case HYPERGEOM:
return similarity.getHypergeomPValue() <= filterParams.getValue();
case MANN_WHIT_TWO_SIDED:
return !similarity.isMannWhitMissingRanks() && similarity.getMannWhitPValueTwoSided() <= filterParams.getValue();
case MANN_WHIT_GREATER:
return !similarity.isMannWhitMissingRanks() && similarity.getMannWhitPValueGreater() <= filterParams.getValue();
case MANN_WHIT_LESS:
return !similarity.isMannWhitMissingRanks() && similarity.getMannWhitPValueLess() <= filterParams.getValue();
case NUMBER:
return similarity.getSizeOfOverlap() >= filterParams.getValue();
case PERCENT:
EMDataSet dataSet = map.getDataSet(similarityKey.getName());
String enrGeneSetName = similarity.getGeneset2Name();
GeneSet enrGeneset = dataSet.getGeneSetsOfInterest().getGeneSetByName(enrGeneSetName);
int enrGenesetSize = enrGeneset.getGenes().size();
double relative_per = (double) similarity.getSizeOfOverlap() / (double) enrGenesetSize;
return relative_per >= filterParams.getValue() / 100.0;
case SPECIFIC:
String hubName = similarity.getGeneset1Name();
GeneSet sigGeneSet = sigDataSet.getGeneSetsOfInterest().getGeneSetByName(hubName);
int sigGeneSetSize = sigGeneSet.getGenes().size();
double relativePer2 = (double) similarity.getSizeOfOverlap() / (double) sigGeneSetSize;
return relativePer2 >= filterParams.getValue() / 100.0;
default:
return false;
}
}
use of org.baderlab.csplugins.enrichmentmap.model.GenesetSimilarity 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.GenesetSimilarity 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.GenesetSimilarity 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.GenesetSimilarity 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());
}
}
}
Aggregations