Search in sources :

Example 1 with ContinuousMapping

use of org.cytoscape.view.vizmap.mappings.ContinuousMapping in project EnrichmentMapApp by BaderLab.

the class EMStyleBuilder method setEdgeWidth.

private void setEdgeWidth(VisualStyle vs, EMStyleOptions options) {
    String prefix = options.getAttributePrefix();
    EnrichmentMap map = options.getEnrichmentMap();
    if (options.isPostAnalysis()) {
        // Replace the edge width mapping that was created by EnrichmentMapVisualStyle
        String widthAttribute = Columns.EDGE_WIDTH_FORMULA_COLUMN.with(prefix, null);
        PassthroughMapping<Double, Double> edgewidth = (PassthroughMapping<Double, Double>) pmFactory.createVisualMappingFunction(widthAttribute, Double.class, BasicVisualLexicon.EDGE_WIDTH);
        vs.addVisualMappingFunction(edgewidth);
    } else {
        // Continous Mapping - set edge line thickness based on the number of genes in the overlap
        ContinuousMapping<Double, Double> cm = (ContinuousMapping<Double, Double>) cmFactory.createVisualMappingFunction(Columns.EDGE_SIMILARITY_COEFF.with(prefix, null), Double.class, EDGE_WIDTH);
        Double underWidth = 0.5;
        Double minWidth = 1.0;
        Double maxWidth = 5.0;
        Double overWidth = 6.0;
        // Create boundary conditions
        BoundaryRangeValues<Double> bv4 = new BoundaryRangeValues<>(underWidth, minWidth, minWidth);
        BoundaryRangeValues<Double> bv5 = new BoundaryRangeValues<>(maxWidth, maxWidth, overWidth);
        // Silence events fired by this mapping to prevent unnecessary style and view updates
        eventHelper.silenceEventSource(cm);
        try {
            cm.addPoint(map.getParams().getSimilarityCutoff(), bv4);
            cm.addPoint(1.0, bv5);
        } finally {
            eventHelper.unsilenceEventSource(cm);
        }
        vs.addVisualMappingFunction(cm);
    }
}
Also used : ContinuousMapping(org.cytoscape.view.vizmap.mappings.ContinuousMapping) BoundaryRangeValues(org.cytoscape.view.vizmap.mappings.BoundaryRangeValues) PassthroughMapping(org.cytoscape.view.vizmap.mappings.PassthroughMapping) EnrichmentMap(org.baderlab.csplugins.enrichmentmap.model.EnrichmentMap)

Example 2 with ContinuousMapping

use of org.cytoscape.view.vizmap.mappings.ContinuousMapping 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 3 with ContinuousMapping

use of org.cytoscape.view.vizmap.mappings.ContinuousMapping in project EnrichmentMapApp by BaderLab.

the class EMStyleBuilder method setNodeSize.

@SuppressWarnings("rawtypes")
private void setNodeSize(VisualStyle vs, EMStyleOptions options, ChartType chartType) {
    if (chartType == null || chartType == ChartType.RADIAL_HEAT_MAP) {
        String prefix = options.getAttributePrefix();
        String columnName = Columns.NODE_GS_SIZE.with(prefix, null);
        int val0 = 10;
        int val1 = 474;
        VisualMappingFunction<?, Double> oldMapping = vs.getVisualMappingFunction(NODE_SIZE);
        // This is done for performance optimization only!
        boolean update = oldMapping instanceof ContinuousMapping == false;
        if (!update) {
            try {
                // Also test the mapped column name and number of points
                update = !columnName.equals(oldMapping.getMappingColumnName()) || ((ContinuousMapping) oldMapping).getPointCount() != 2;
                if (!update) {
                    // And the mapping values
                    ContinuousMappingPoint pt0 = ((ContinuousMapping) oldMapping).getPoint(0);
                    ContinuousMappingPoint pt1 = ((ContinuousMapping) oldMapping).getPoint(1);
                    update = val0 != (Integer) pt0.getValue();
                    update = update || val1 != (Integer) pt1.getValue();
                    if (// Finally test the boundary ranges
                    !update)
                        update = MIN_NODE_SIZE != (Double) pt0.getRange().equalValue || MAX_NODE_SIZE != (Double) pt1.getRange().equalValue;
                }
            } catch (NullPointerException | ClassCastException e) {
                update = true;
            }
        }
        if (update) {
            ContinuousMapping<Integer, Double> cm = (ContinuousMapping<Integer, Double>) cmFactory.createVisualMappingFunction(columnName, Integer.class, NODE_SIZE);
            BoundaryRangeValues<Double> bv0 = new BoundaryRangeValues<>(MIN_NODE_SIZE, MIN_NODE_SIZE, MIN_NODE_SIZE);
            BoundaryRangeValues<Double> bv1 = new BoundaryRangeValues<>(MAX_NODE_SIZE, MAX_NODE_SIZE, MAX_NODE_SIZE);
            // Silence events fired by this mapping to prevent unnecessary style and view updates
            eventHelper.silenceEventSource(cm);
            try {
                cm.addPoint(val0, bv0);
                cm.addPoint(val1, bv1);
            } finally {
                eventHelper.unsilenceEventSource(cm);
            }
            vs.addVisualMappingFunction(cm);
        }
    } else {
        vs.removeVisualMappingFunction(NODE_SIZE);
    }
}
Also used : ContinuousMapping(org.cytoscape.view.vizmap.mappings.ContinuousMapping) ContinuousMappingPoint(org.cytoscape.view.vizmap.mappings.ContinuousMappingPoint) Paint(java.awt.Paint) ContinuousMappingPoint(org.cytoscape.view.vizmap.mappings.ContinuousMappingPoint) BoundaryRangeValues(org.cytoscape.view.vizmap.mappings.BoundaryRangeValues)

Example 4 with ContinuousMapping

use of org.cytoscape.view.vizmap.mappings.ContinuousMapping in project EnrichmentMapApp by BaderLab.

the class WidthFunction method calculateAndSetEdgeWidths.

private void calculateAndSetEdgeWidths(CyNetwork network, String prefix, TaskMonitor taskMonitor) {
    EdgeWidthParams edgeWidthParams = EdgeWidthParams.restore(network);
    EnrichmentMap map = emManager.getEnrichmentMap(network.getSUID());
    //		String widthAttribute = prefix + EDGE_WIDTH_FORMULA_COLUMN;
    int n = network.getDefaultEdgeTable().getRowCount();
    int i = 0;
    for (CyRow row : network.getDefaultEdgeTable().getAllRows()) {
        if (taskMonitor != null)
            taskMonitor.setProgress((double) i / (double) n);
        i++;
        String interaction = row.get(CyEdge.INTERACTION, String.class);
        if (isSignature(interaction)) {
            String cutoffType = EDGE_CUTOFF_TYPE.get(row, prefix, null);
            PostAnalysisFilterType filterType = PostAnalysisFilterType.fromDisplayString(cutoffType);
            if (filterType == null) {
                EDGE_WIDTH_FORMULA_COLUMN.set(row, prefix, null, null);
                continue;
            }
            Double pvalue, cutoff;
            switch(filterType) {
                case MANN_WHIT_TWO_SIDED:
                    pvalue = EDGE_MANN_WHIT_TWOSIDED_PVALUE.get(row, prefix);
                    cutoff = EDGE_MANN_WHIT_CUTOFF.get(row, prefix);
                    break;
                case MANN_WHIT_GREATER:
                    pvalue = EDGE_MANN_WHIT_GREATER_PVALUE.get(row, prefix);
                    cutoff = EDGE_MANN_WHIT_CUTOFF.get(row, prefix);
                    break;
                case MANN_WHIT_LESS:
                    pvalue = EDGE_MANN_WHIT_LESS_PVALUE.get(row, prefix);
                    cutoff = EDGE_MANN_WHIT_CUTOFF.get(row, prefix);
                    break;
                default:
                    pvalue = EDGE_HYPERGEOM_PVALUE.get(row, prefix);
                    cutoff = EDGE_HYPERGEOM_CUTOFF.get(row, prefix);
                    break;
            }
            if (pvalue == null || cutoff == null) {
                EDGE_WIDTH_FORMULA_COLUMN.set(row, prefix, null);
            } else if (pvalue <= cutoff / 100) {
                EDGE_WIDTH_FORMULA_COLUMN.set(row, prefix, edgeWidthParams.pa_lessThan100);
            } else if (pvalue <= cutoff / 10) {
                EDGE_WIDTH_FORMULA_COLUMN.set(row, prefix, edgeWidthParams.pa_lessThan10);
            } else {
                EDGE_WIDTH_FORMULA_COLUMN.set(row, prefix, edgeWidthParams.pa_greater);
            }
        } else {
            // Can use a continuous mapping object to perform calculation
            // even though it won't be added to the visual style.
            ContinuousMapping<Double, Double> conmapping_edgewidth = (ContinuousMapping<Double, Double>) vmfFactoryContinuous.createVisualMappingFunction(prefix + EDGE_SIMILARITY_COEFF, Double.class, BasicVisualLexicon.EDGE_WIDTH);
            Double under_width = 0.5;
            Double min_width = edgeWidthParams.em_lower;
            Double max_width = edgeWidthParams.em_upper;
            Double over_width = 6.0;
            // Create boundary conditions                  less than,   equals,  greater than
            BoundaryRangeValues<Double> bv4 = new BoundaryRangeValues<>(under_width, min_width, min_width);
            BoundaryRangeValues<Double> bv5 = new BoundaryRangeValues<>(max_width, max_width, over_width);
            conmapping_edgewidth.addPoint(map.getParams().getSimilarityCutoff(), bv4);
            conmapping_edgewidth.addPoint(1.0, bv5);
            Double value = conmapping_edgewidth.getMappedValue(row);
            EDGE_WIDTH_FORMULA_COLUMN.set(row, prefix, value);
        }
    }
}
Also used : ContinuousMapping(org.cytoscape.view.vizmap.mappings.ContinuousMapping) PostAnalysisFilterType(org.baderlab.csplugins.enrichmentmap.model.PostAnalysisFilterType) BoundaryRangeValues(org.cytoscape.view.vizmap.mappings.BoundaryRangeValues) EnrichmentMap(org.baderlab.csplugins.enrichmentmap.model.EnrichmentMap) CyRow(org.cytoscape.model.CyRow)

Aggregations

BoundaryRangeValues (org.cytoscape.view.vizmap.mappings.BoundaryRangeValues)4 ContinuousMapping (org.cytoscape.view.vizmap.mappings.ContinuousMapping)4 EnrichmentMap (org.baderlab.csplugins.enrichmentmap.model.EnrichmentMap)3 Paint (java.awt.Paint)2 ContinuousMappingPoint (org.cytoscape.view.vizmap.mappings.ContinuousMappingPoint)2 PassthroughMapping (org.cytoscape.view.vizmap.mappings.PassthroughMapping)2 Inject (com.google.inject.Inject)1 Color (java.awt.Color)1 List (java.util.List)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 Continuous (org.baderlab.csplugins.enrichmentmap.CytoscapeServiceModule.Continuous)1 Discrete (org.baderlab.csplugins.enrichmentmap.CytoscapeServiceModule.Discrete)1 Passthrough (org.baderlab.csplugins.enrichmentmap.CytoscapeServiceModule.Passthrough)1 AbstractDataSet (org.baderlab.csplugins.enrichmentmap.model.AbstractDataSet)1 EMDataSet (org.baderlab.csplugins.enrichmentmap.model.EMDataSet)1 EMSignatureDataSet (org.baderlab.csplugins.enrichmentmap.model.EMSignatureDataSet)1 PostAnalysisFilterType (org.baderlab.csplugins.enrichmentmap.model.PostAnalysisFilterType)1 CyEventHelper (org.cytoscape.event.CyEventHelper)1 CyEdge (org.cytoscape.model.CyEdge)1