Search in sources :

Example 1 with GenesetSimilarity

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;
    }
}
Also used : PostAnalysisFilterParameters(org.baderlab.csplugins.enrichmentmap.model.PostAnalysisFilterParameters) EMDataSet(org.baderlab.csplugins.enrichmentmap.model.EMDataSet) GenesetSimilarity(org.baderlab.csplugins.enrichmentmap.model.GenesetSimilarity) GeneSet(org.baderlab.csplugins.enrichmentmap.model.GeneSet)

Example 2 with GenesetSimilarity

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;
}
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) PostAnalysisFilterType(org.baderlab.csplugins.enrichmentmap.model.PostAnalysisFilterType) 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)

Example 3 with GenesetSimilarity

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);
    }
}
Also used : Task(org.cytoscape.work.Task) AbstractTask(org.cytoscape.work.AbstractTask) TimerTask(java.util.TimerTask) Timer(java.util.Timer) TimerTask(java.util.TimerTask) ExecutorService(java.util.concurrent.ExecutorService) SimilarityKey(org.baderlab.csplugins.enrichmentmap.model.SimilarityKey) GenesetSimilarity(org.baderlab.csplugins.enrichmentmap.model.GenesetSimilarity) GeneSet(org.baderlab.csplugins.enrichmentmap.model.GeneSet)

Example 4 with GenesetSimilarity

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);
}
Also used : Timer(java.util.Timer) TimerTask(java.util.TimerTask) ExecutorService(java.util.concurrent.ExecutorService) SimilarityKey(org.baderlab.csplugins.enrichmentmap.model.SimilarityKey) GenesetSimilarity(org.baderlab.csplugins.enrichmentmap.model.GenesetSimilarity)

Example 5 with GenesetSimilarity

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());
        }
    }
}
Also used : SimilarityKey(org.baderlab.csplugins.enrichmentmap.model.SimilarityKey) CyNode(org.cytoscape.model.CyNode) EMDataSet(org.baderlab.csplugins.enrichmentmap.model.EMDataSet) GenesetSimilarity(org.baderlab.csplugins.enrichmentmap.model.GenesetSimilarity) CyRow(org.cytoscape.model.CyRow) CyEdge(org.cytoscape.model.CyEdge)

Aggregations

GenesetSimilarity (org.baderlab.csplugins.enrichmentmap.model.GenesetSimilarity)8 SimilarityKey (org.baderlab.csplugins.enrichmentmap.model.SimilarityKey)5 EMDataSet (org.baderlab.csplugins.enrichmentmap.model.EMDataSet)4 GeneSet (org.baderlab.csplugins.enrichmentmap.model.GeneSet)4 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 PostAnalysisFilterType (org.baderlab.csplugins.enrichmentmap.model.PostAnalysisFilterType)2 DiscreteTaskMonitor (org.baderlab.csplugins.enrichmentmap.util.DiscreteTaskMonitor)2 CyEdge (org.cytoscape.model.CyEdge)2 CyNode (org.cytoscape.model.CyNode)2 CyRow (org.cytoscape.model.CyRow)2 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 EnrichmentMap (org.baderlab.csplugins.enrichmentmap.model.EnrichmentMap)1 PostAnalysisFilterParameters (org.baderlab.csplugins.enrichmentmap.model.PostAnalysisFilterParameters)1 AbstractTask (org.cytoscape.work.AbstractTask)1 Task (org.cytoscape.work.Task)1