use of org.baderlab.csplugins.enrichmentmap.model.GenesetSimilarity in project EnrichmentMapApp by BaderLab.
the class CreateDiseaseSignatureNetworkTask method createEdge.
/**
* Returns true iff the user should be warned about an existing edge that
* does not pass the new cutoff. If the edge already exists it will be
* returned, if the edge had to be created it will not be returned.
*/
private void createEdge(SimilarityKey similarityKey, CyNetwork network, CyNetworkView netView, String prefix, CyTable edgeTable, CyTable nodeTable, boolean passedCutoff, EMSignatureDataSet sigDataSet) {
// PA always generates distinct edges
final String edgeName = similarityKey.toString();
GenesetSimilarity genesetSimilarity = geneSetSimilarities.get(similarityKey);
CyEdge edge = existingEdgeCache.get(new EdgeCacheKey(edgeName, sigDataSet.getName()));
if (edge == null) {
if (passedCutoff) {
CyNode hubNode = nodeCache.get(genesetSimilarity.getGeneset1Name());
CyNode geneSet = NetworkUtil.getNodeWithValue(network, nodeTable, CyNetwork.NAME, genesetSimilarity.getGeneset2Name());
if (hubNode == null || geneSet == null)
return;
edge = network.addEdge(hubNode, geneSet, false);
// We actually add the edges to the EM data sets, not the signature data set
sigDataSet.addEdgeSuid(edge.getSUID());
// map.getDataSet(similarityKey.getName()).addEdgeSuid(edge.getSUID());
taskResult.addNewEdge(edge);
} else {
// edge does not exist and does not pass cutoff, do nothing
return;
}
} else {
if (!passedCutoff && existingEdgeCache.containsKey(edgeName))
taskResult.addExistingEdgeFailsCutoff(edge);
}
if (passedCutoff)
taskResult.incrementPassedCutoffCount();
CyRow row = edgeTable.getRow(edge.getSUID());
row.set(CyNetwork.NAME, edgeName);
row.set(CyEdge.INTERACTION, similarityKey.getInteraction());
List<String> geneList = new ArrayList<>();
Set<Integer> genesHash = genesetSimilarity.getOverlappingGenes();
for (Integer current : genesHash) {
String gene = map.getGeneFromHashKey(current);
if (gene != null)
geneList.add(gene);
}
Collections.sort(geneList);
Columns.EDGE_OVERLAP_GENES.set(row, prefix, null, geneList);
Columns.EDGE_OVERLAP_SIZE.set(row, prefix, null, genesetSimilarity.getSizeOfOverlap());
Columns.EDGE_SIMILARITY_COEFF.set(row, prefix, null, genesetSimilarity.getSimilarityCoeffecient());
Columns.EDGE_DATASET.set(row, prefix, null, similarityKey.getName());
Columns.EDGE_SIG_DATASET.set(row, prefix, null, sigDataSet.getName());
if (passedCutoff)
Columns.EDGE_CUTOFF_TYPE.set(row, prefix, null, params.getRankTestParameters().getType().display);
PostAnalysisFilterType filterType = params.getRankTestParameters().getType();
if (filterType.isMannWhitney()) {
Columns.EDGE_MANN_WHIT_TWOSIDED_PVALUE.set(row, prefix, null, genesetSimilarity.getMannWhitPValueTwoSided());
Columns.EDGE_MANN_WHIT_GREATER_PVALUE.set(row, prefix, null, genesetSimilarity.getMannWhitPValueGreater());
Columns.EDGE_MANN_WHIT_LESS_PVALUE.set(row, prefix, null, genesetSimilarity.getMannWhitPValueLess());
Columns.EDGE_MANN_WHIT_CUTOFF.set(row, prefix, null, params.getRankTestParameters().getValue());
}
// always calculate hypergeometric
Columns.EDGE_HYPERGEOM_PVALUE.set(row, prefix, null, genesetSimilarity.getHypergeomPValue());
Columns.EDGE_HYPERGEOM_U.set(row, prefix, null, genesetSimilarity.getHypergeomU());
Columns.EDGE_HYPERGEOM_N.set(row, prefix, null, genesetSimilarity.getHypergeomN());
Columns.EDGE_HYPERGEOM_M.set(row, prefix, null, genesetSimilarity.getHypergeomM());
Columns.EDGE_HYPERGEOM_K.set(row, prefix, null, genesetSimilarity.getHypergeomK());
Columns.EDGE_HYPERGEOM_CUTOFF.set(row, prefix, null, params.getRankTestParameters().getValue());
}
use of org.baderlab.csplugins.enrichmentmap.model.GenesetSimilarity in project EnrichmentMapApp by BaderLab.
the class ComputeSimilarityTaskParallel method computeGenesetSimilarity.
static GenesetSimilarity computeGenesetSimilarity(EMCreationParameters params, String geneset1Name, String geneset2Name, Set<Integer> geneset1, Set<Integer> geneset2, String dataset) {
Set<Integer> intersection = Sets.intersection(geneset1, geneset2);
Set<Integer> union = Sets.union(geneset1, geneset2);
double coeffecient = computeSimilarityCoeffecient(params, intersection, union, geneset1, geneset2);
if (coeffecient < params.getSimilarityCutoff())
return null;
String edgeType = params.getEnrichmentEdgeType();
GenesetSimilarity similarity = new GenesetSimilarity(geneset1Name, geneset2Name, coeffecient, edgeType, intersection, dataset);
return similarity;
}
use of org.baderlab.csplugins.enrichmentmap.model.GenesetSimilarity 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