Search in sources :

Example 26 with EMDataSet

use of org.baderlab.csplugins.enrichmentmap.model.EMDataSet 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 27 with EMDataSet

use of org.baderlab.csplugins.enrichmentmap.model.EMDataSet 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 28 with EMDataSet

use of org.baderlab.csplugins.enrichmentmap.model.EMDataSet in project EnrichmentMapApp by BaderLab.

the class ChartUtil method sortDataSets.

public static List<EMDataSet> sortDataSets(Collection<EMDataSet> dataSets) {
    List<EMDataSet> list = new ArrayList<>(dataSets);
    // Sort them by name
    Collator collator = Collator.getInstance();
    Collections.sort(list, (EMDataSet o1, EMDataSet o2) -> {
        return collator.compare(o1.getName(), o2.getName());
    });
    return list;
}
Also used : ArrayList(java.util.ArrayList) EMDataSet(org.baderlab.csplugins.enrichmentmap.model.EMDataSet) Collator(java.text.Collator)

Example 29 with EMDataSet

use of org.baderlab.csplugins.enrichmentmap.model.EMDataSet in project EnrichmentMapApp by BaderLab.

the class EMStyleBuilder method setNodeColors.

private void setNodeColors(VisualStyle vs, EMStyleOptions options) {
    String prefix = options.getAttributePrefix();
    List<AbstractDataSet> dataSets = options.getDataSets().stream().filter(// Ignore Signature Data Sets in charts
    ds -> ds instanceof EMDataSet).collect(Collectors.toList());
    if (dataSets.size() == 1) {
        // Only 1 Data Set? Use node colour instead of charts...
        EMDataSet ds = (EMDataSet) dataSets.iterator().next();
        // Create boundary conditions
        BoundaryRangeValues<Paint> bv3a = new BoundaryRangeValues<>(Colors.MAX_PHENOTYPE_2, Colors.MAX_PHENOTYPE_2, Colors.MAX_PHENOTYPE_2);
        BoundaryRangeValues<Paint> bv3b = new BoundaryRangeValues<>(Colors.LIGHTER_PHENOTYPE_2, Colors.LIGHTER_PHENOTYPE_2, Colors.MAX_PHENOTYPE_2);
        BoundaryRangeValues<Paint> bv3c = new BoundaryRangeValues<>(Colors.LIGHTEST_PHENOTYPE_2, Colors.LIGHTEST_PHENOTYPE_2, Colors.LIGHTER_PHENOTYPE_2);
        BoundaryRangeValues<Paint> bv3d = new BoundaryRangeValues<>(Colors.LIGHTEST_PHENOTYPE_2, Colors.OVER_COLOR, Colors.OVER_COLOR);
        BoundaryRangeValues<Paint> bv3e = new BoundaryRangeValues<>(Colors.OVER_COLOR, Colors.OVER_COLOR, Colors.OVER_COLOR);
        BoundaryRangeValues<Paint> bv3f = new BoundaryRangeValues<>(Colors.OVER_COLOR, Colors.OVER_COLOR, Colors.LIGHTEST_PHENOTYPE_1);
        BoundaryRangeValues<Paint> bv3g = new BoundaryRangeValues<>(Colors.LIGHTEST_PHENOTYPE_1, Colors.LIGHTEST_PHENOTYPE_1, Colors.LIGHTER_PHENOTYPE_1);
        BoundaryRangeValues<Paint> bv3h = new BoundaryRangeValues<>(Colors.LIGHTER_PHENOTYPE_1, Colors.LIGHTER_PHENOTYPE_1, Colors.MAX_PHENOTYPE_1);
        BoundaryRangeValues<Paint> bv3i = new BoundaryRangeValues<>(Colors.MAX_PHENOTYPE_1, Colors.MAX_PHENOTYPE_1, Colors.MAX_PHENOTYPE_1);
        // Continuous Mapping - set node colour based on the sign of the ES score of the dataset
        ContinuousMapping<Double, Paint> cm = (ContinuousMapping<Double, Paint>) cmFactory.createVisualMappingFunction(Columns.NODE_COLOURING.with(prefix, ds.getName()), Double.class, BasicVisualLexicon.NODE_FILL_COLOR);
        // Silence events fired by this mapping to prevent unnecessary style and view updates
        eventHelper.silenceEventSource(cm);
        try {
            // Set the attribute point values associated with the boundary values
            cm.addPoint(-1.0, bv3a);
            cm.addPoint(-0.995, bv3b);
            cm.addPoint(-0.95, bv3c);
            cm.addPoint(-0.9, bv3d);
            cm.addPoint(0.0, bv3e);
            cm.addPoint(0.9, bv3f);
            cm.addPoint(0.95, bv3g);
            cm.addPoint(0.995, bv3h);
            cm.addPoint(1.0, bv3i);
        } finally {
            eventHelper.unsilenceEventSource(cm);
        }
        vs.addVisualMappingFunction(cm);
        // Then we need to use bypass to colour the hub nodes (signature genesets)
        List<EMSignatureDataSet> signatureDataSets = options.getEnrichmentMap().getSignatureSetList();
        CyNetworkView netView = options.getNetworkView();
        CyNetwork net = netView.getModel();
        for (EMSignatureDataSet sds : signatureDataSets) {
            for (Long suid : sds.getNodeSuids()) {
                CyNode node = net.getNode(suid);
                if (node != null) {
                    View<CyNode> nv = netView.getNodeView(node);
                    if (nv != null)
                        nv.setLockedValue(NODE_FILL_COLOR, Colors.SIG_NODE_COLOR);
                }
            }
        }
    } else {
        // 2 or more Data Sets? Use simple node colours and charts...
        // Add mapping function for node fill color
        DiscreteMapping<String, Paint> dm = (DiscreteMapping<String, Paint>) dmFactory.createVisualMappingFunction(Columns.NODE_GS_TYPE.with(prefix, null), String.class, NODE_FILL_COLOR);
        // Silence events fired by this mapping to prevent unnecessary style and view updates
        eventHelper.silenceEventSource(dm);
        try {
            dm.putMapValue(Columns.NODE_GS_TYPE_ENRICHMENT, Colors.DEF_NODE_COLOR);
            dm.putMapValue(Columns.NODE_GS_TYPE_SIGNATURE, Colors.SIG_NODE_COLOR);
        } finally {
            eventHelper.unsilenceEventSource(dm);
        }
        vs.addVisualMappingFunction(dm);
    }
}
Also used : Color(java.awt.Color) NODE_SHAPE(org.cytoscape.view.presentation.property.BasicVisualLexicon.NODE_SHAPE) RECTANGLE(org.cytoscape.view.presentation.property.NodeShapeVisualProperty.RECTANGLE) NODE_BORDER_TRANSPARENCY(org.cytoscape.view.presentation.property.BasicVisualLexicon.NODE_BORDER_TRANSPARENCY) NodeShape(org.cytoscape.view.presentation.property.values.NodeShape) Inject(com.google.inject.Inject) EDGE_UNSELECTED_PAINT(org.cytoscape.view.presentation.property.BasicVisualLexicon.EDGE_UNSELECTED_PAINT) LineType(org.cytoscape.view.presentation.property.values.LineType) ColorBrewer(org.jcolorbrewer.ColorBrewer) View(org.cytoscape.view.model.View) CyCustomGraphics2(org.cytoscape.view.presentation.customgraphics.CyCustomGraphics2) NODE_TOOLTIP(org.cytoscape.view.presentation.property.BasicVisualLexicon.NODE_TOOLTIP) Discrete(org.baderlab.csplugins.enrichmentmap.CytoscapeServiceModule.Discrete) CyNetwork(org.cytoscape.model.CyNetwork) NODE_SIZE(org.cytoscape.view.presentation.property.BasicVisualLexicon.NODE_SIZE) NODE_FILL_COLOR(org.cytoscape.view.presentation.property.BasicVisualLexicon.NODE_FILL_COLOR) VisualStyleChangedEvent(org.cytoscape.view.vizmap.events.VisualStyleChangedEvent) BasicVisualLexicon(org.cytoscape.view.presentation.property.BasicVisualLexicon) RenderingEngineManager(org.cytoscape.view.presentation.RenderingEngineManager) VisualLexicon(org.cytoscape.view.model.VisualLexicon) Collectors(java.util.stream.Collectors) AbstractDataSet(org.baderlab.csplugins.enrichmentmap.model.AbstractDataSet) List(java.util.List) NETWORK_BACKGROUND_PAINT(org.cytoscape.view.presentation.property.BasicVisualLexicon.NETWORK_BACKGROUND_PAINT) EMDataSet(org.baderlab.csplugins.enrichmentmap.model.EMDataSet) Paint(java.awt.Paint) DIAMOND(org.cytoscape.view.presentation.property.NodeShapeVisualProperty.DIAMOND) Optional(java.util.Optional) NODE_LABEL(org.cytoscape.view.presentation.property.BasicVisualLexicon.NODE_LABEL) LineTypeVisualProperty(org.cytoscape.view.presentation.property.LineTypeVisualProperty) VisualStyle(org.cytoscape.view.vizmap.VisualStyle) ContinuousMapping(org.cytoscape.view.vizmap.mappings.ContinuousMapping) Passthrough(org.baderlab.csplugins.enrichmentmap.CytoscapeServiceModule.Passthrough) EDGE_LINE_TYPE(org.cytoscape.view.presentation.property.BasicVisualLexicon.EDGE_LINE_TYPE) EDGE_STROKE_UNSELECTED_PAINT(org.cytoscape.view.presentation.property.BasicVisualLexicon.EDGE_STROKE_UNSELECTED_PAINT) CyNode(org.cytoscape.model.CyNode) PassthroughMapping(org.cytoscape.view.vizmap.mappings.PassthroughMapping) EnrichmentMap(org.baderlab.csplugins.enrichmentmap.model.EnrichmentMap) EDGE_LABEL_TRANSPARENCY(org.cytoscape.view.presentation.property.BasicVisualLexicon.EDGE_LABEL_TRANSPARENCY) EDGE_WIDTH(org.cytoscape.view.presentation.property.BasicVisualLexicon.EDGE_WIDTH) ELLIPSE(org.cytoscape.view.presentation.property.NodeShapeVisualProperty.ELLIPSE) DiscreteMapping(org.cytoscape.view.vizmap.mappings.DiscreteMapping) NODE_BORDER_PAINT(org.cytoscape.view.presentation.property.BasicVisualLexicon.NODE_BORDER_PAINT) NODE_BORDER_WIDTH(org.cytoscape.view.presentation.property.BasicVisualLexicon.NODE_BORDER_WIDTH) Continuous(org.baderlab.csplugins.enrichmentmap.CytoscapeServiceModule.Continuous) NODE_TRANSPARENCY(org.cytoscape.view.presentation.property.BasicVisualLexicon.NODE_TRANSPARENCY) VisualMappingFunctionFactory(org.cytoscape.view.vizmap.VisualMappingFunctionFactory) CyEventHelper(org.cytoscape.event.CyEventHelper) DiscreteRange(org.cytoscape.view.model.DiscreteRange) NODE_LABEL_TRANSPARENCY(org.cytoscape.view.presentation.property.BasicVisualLexicon.NODE_LABEL_TRANSPARENCY) EDGE_TRANSPARENCY(org.cytoscape.view.presentation.property.BasicVisualLexicon.EDGE_TRANSPARENCY) VisualProperty(org.cytoscape.view.model.VisualProperty) ContinuousMappingPoint(org.cytoscape.view.vizmap.mappings.ContinuousMappingPoint) BoundaryRangeValues(org.cytoscape.view.vizmap.mappings.BoundaryRangeValues) CyNetworkView(org.cytoscape.view.model.CyNetworkView) VisualMappingFunction(org.cytoscape.view.vizmap.VisualMappingFunction) EMSignatureDataSet(org.baderlab.csplugins.enrichmentmap.model.EMSignatureDataSet) CyEdge(org.cytoscape.model.CyEdge) VisualStyleChangeRecord(org.cytoscape.view.vizmap.events.VisualStyleChangeRecord) ContinuousMapping(org.cytoscape.view.vizmap.mappings.ContinuousMapping) EMSignatureDataSet(org.baderlab.csplugins.enrichmentmap.model.EMSignatureDataSet) DiscreteMapping(org.cytoscape.view.vizmap.mappings.DiscreteMapping) CyNetwork(org.cytoscape.model.CyNetwork) Paint(java.awt.Paint) AbstractDataSet(org.baderlab.csplugins.enrichmentmap.model.AbstractDataSet) BoundaryRangeValues(org.cytoscape.view.vizmap.mappings.BoundaryRangeValues) EMDataSet(org.baderlab.csplugins.enrichmentmap.model.EMDataSet) CyNode(org.cytoscape.model.CyNode) CyNetworkView(org.cytoscape.view.model.CyNetworkView)

Example 30 with EMDataSet

use of org.baderlab.csplugins.enrichmentmap.model.EMDataSet in project EnrichmentMapApp by BaderLab.

the class EMStyleBuilder method createEdgeColorMapping.

private DiscreteMapping<String, Paint> createEdgeColorMapping(EMStyleOptions options, VisualProperty<Paint> vp) {
    String prefix = options.getAttributePrefix();
    String col = Columns.EDGE_DATASET.with(prefix, null);
    DiscreteMapping<String, Paint> dm = (DiscreteMapping<String, Paint>) dmFactory.createVisualMappingFunction(col, String.class, vp);
    // Silence events fired by this mapping, or it will fire too many VisualMappingFunctionChangedEvents,
    // which can be captured by VisualStyle later and cause unnecessary view updates,
    // even though this mapping has not been set to a style yet
    // (unfortunately that's just how Cytoscape's event payloads work).
    eventHelper.silenceEventSource(dm);
    try {
        dm.putMapValue(Columns.EDGE_DATASET_VALUE_COMPOUND, Colors.COMPOUND_EDGE_COLOR);
        //			dm.putMapValue(Columns.EDGE_DATASET_VALUE_SIG, Colors.SIG_EDGE_COLOR);
        List<EMDataSet> dataSets = options.getEnrichmentMap().getDataSetList();
        final ColorBrewer colorBrewer;
        // Try colorblind and/or print friendly colours first
        if (// Try a colorblind safe color scheme first
        dataSets.size() <= 4)
            // http://colorbrewer2.org/#type=qualitative&scheme=Paired&n=4
            colorBrewer = ColorBrewer.Paired;
        else if (// Same--more than 5, it adds a RED that can be confused with the edge selection color
        dataSets.size() <= 5)
            // http://colorbrewer2.org/#type=qualitative&scheme=Paired&n=5
            colorBrewer = ColorBrewer.Paired;
        else
            // http://colorbrewer2.org/#type=qualitative&scheme=Set3&n=12
            colorBrewer = ColorBrewer.Set3;
        Color[] colors = colorBrewer.getColorPalette(dataSets.size());
        // Do not use the filtered data sets here, because we don't want edge colours changing when filtering
        for (int i = 0; i < dataSets.size(); i++) {
            EMDataSet ds = dataSets.get(i);
            Color color = colors[i];
            dm.putMapValue(ds.getName(), color);
            ds.setColor(color);
        }
    } finally {
        eventHelper.unsilenceEventSource(dm);
    }
    return dm;
}
Also used : ColorBrewer(org.jcolorbrewer.ColorBrewer) Color(java.awt.Color) DiscreteMapping(org.cytoscape.view.vizmap.mappings.DiscreteMapping) EMDataSet(org.baderlab.csplugins.enrichmentmap.model.EMDataSet) Paint(java.awt.Paint) Paint(java.awt.Paint) ContinuousMappingPoint(org.cytoscape.view.vizmap.mappings.ContinuousMappingPoint)

Aggregations

EMDataSet (org.baderlab.csplugins.enrichmentmap.model.EMDataSet)58 EnrichmentMap (org.baderlab.csplugins.enrichmentmap.model.EnrichmentMap)30 DataSetFiles (org.baderlab.csplugins.enrichmentmap.model.DataSetFiles)20 Test (org.junit.Test)19 Method (org.baderlab.csplugins.enrichmentmap.model.EMDataSet.Method)13 EnrichmentMapParameters (org.baderlab.csplugins.enrichmentmap.model.EnrichmentMapParameters)11 Map (java.util.Map)10 EMCreationParameters (org.baderlab.csplugins.enrichmentmap.model.EMCreationParameters)10 Set (java.util.Set)8 EnrichmentResult (org.baderlab.csplugins.enrichmentmap.model.EnrichmentResult)8 GeneSet (org.baderlab.csplugins.enrichmentmap.model.GeneSet)7 CyNode (org.cytoscape.model.CyNode)7 JPanel (javax.swing.JPanel)6 Inject (com.google.inject.Inject)5 Color (java.awt.Color)5 ArrayList (java.util.ArrayList)5 List (java.util.List)5 JLabel (javax.swing.JLabel)5 CyEdge (org.cytoscape.model.CyEdge)5 CyNetwork (org.cytoscape.model.CyNetwork)5