Search in sources :

Example 6 with SimilarityKey

use of org.baderlab.csplugins.enrichmentmap.model.SimilarityKey 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;
}
Also used : DiscreteTaskMonitor(org.baderlab.csplugins.enrichmentmap.util.DiscreteTaskMonitor) GeneSet(org.baderlab.csplugins.enrichmentmap.model.GeneSet) Set(java.util.Set) EMDataSet(org.baderlab.csplugins.enrichmentmap.model.EMDataSet) SimilarityKey(org.baderlab.csplugins.enrichmentmap.model.SimilarityKey) EMDataSet(org.baderlab.csplugins.enrichmentmap.model.EMDataSet) GenesetSimilarity(org.baderlab.csplugins.enrichmentmap.model.GenesetSimilarity) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) GeneSet(org.baderlab.csplugins.enrichmentmap.model.GeneSet) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) EnrichmentMap(org.baderlab.csplugins.enrichmentmap.model.EnrichmentMap) Map(java.util.Map)

Aggregations

SimilarityKey (org.baderlab.csplugins.enrichmentmap.model.SimilarityKey)6 GenesetSimilarity (org.baderlab.csplugins.enrichmentmap.model.GenesetSimilarity)5 EMDataSet (org.baderlab.csplugins.enrichmentmap.model.EMDataSet)3 GeneSet (org.baderlab.csplugins.enrichmentmap.model.GeneSet)3 DiscreteTaskMonitor (org.baderlab.csplugins.enrichmentmap.util.DiscreteTaskMonitor)3 Set (java.util.Set)2 Timer (java.util.Timer)2 TimerTask (java.util.TimerTask)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 ExecutorService (java.util.concurrent.ExecutorService)2 Map (java.util.Map)1 EMSignatureDataSet (org.baderlab.csplugins.enrichmentmap.model.EMSignatureDataSet)1 EnrichmentMap (org.baderlab.csplugins.enrichmentmap.model.EnrichmentMap)1 PostAnalysisFilterType (org.baderlab.csplugins.enrichmentmap.model.PostAnalysisFilterType)1 CyEdge (org.cytoscape.model.CyEdge)1 CyNetwork (org.cytoscape.model.CyNetwork)1 CyNode (org.cytoscape.model.CyNode)1 CyRow (org.cytoscape.model.CyRow)1 CyTable (org.cytoscape.model.CyTable)1 CyNetworkView (org.cytoscape.view.model.CyNetworkView)1