Search in sources :

Example 21 with CyNetwork

use of org.cytoscape.model.CyNetwork in project cytoscape-api by cytoscape.

the class AbstractNetworkEventTest method testGetNetwork.

@Test
public final void testGetNetwork() {
    final CyNetworkManager networkManager = mock(CyNetworkManager.class);
    final CyNetwork network = mock(CyNetwork.class);
    final AbstractNetworkEvent event = new AbstractNetworkEvent(networkManager, Object.class, network);
    assertEquals("Network returned by getNetwork() is *not* the one passed into the constructor!", network, event.getNetwork());
}
Also used : CyNetworkManager(org.cytoscape.model.CyNetworkManager) CyNetwork(org.cytoscape.model.CyNetwork) Test(org.junit.Test)

Example 22 with CyNetwork

use of org.cytoscape.model.CyNetwork in project cytoscape-api by cytoscape.

the class NetworkAddedEventTest method testGetNetwork.

@Test
public final void testGetNetwork() {
    final CyNetworkManager networkManager = mock(CyNetworkManager.class);
    final CyNetwork network = mock(CyNetwork.class);
    final NetworkAddedEvent event = new NetworkAddedEvent(networkManager, network);
    assertEquals("Network returned by getNetwork() is *not* the one passed into the constructor!", network, event.getNetwork());
}
Also used : CyNetworkManager(org.cytoscape.model.CyNetworkManager) CyNetwork(org.cytoscape.model.CyNetwork) Test(org.junit.Test)

Example 23 with CyNetwork

use of org.cytoscape.model.CyNetwork in project cytoscape-api by cytoscape.

the class AbstractRenderingEngineManagerTest method testGetRendringEngines.

@Test
public void testGetRendringEngines() throws Exception {
    // First, create mock view models.
    final CyNetworkView networkView1 = mock(CyNetworkView.class);
    final CyNetworkView networkView2 = mock(CyNetworkView.class);
    final RenderingEngine<CyNetwork> engine1 = mock(RenderingEngine.class);
    when(engine1.getViewModel()).thenReturn(networkView1);
    final RenderingEngine<CyNetwork> engine2 = mock(RenderingEngine.class);
    when(engine2.getViewModel()).thenReturn(networkView1);
    final RenderingEngine<CyNetwork> engine3 = mock(RenderingEngine.class);
    when(engine3.getViewModel()).thenReturn(networkView2);
    manager.addRenderingEngine(engine1);
    manager.addRenderingEngine(engine2);
    manager.addRenderingEngine(engine3);
    final Collection<RenderingEngine<?>> allEngines = manager.getAllRenderingEngines();
    assertNotNull(allEngines);
    final Collection<RenderingEngine<?>> engines = manager.getRenderingEngines(networkView1);
    assertNotNull(engines);
    assertEquals(2, engines.size());
    when(engine1.getViewModel()).thenReturn(networkView1);
    manager.addRenderingEngine(engine1);
    assertTrue(manager.getRenderingEngines(networkView1).contains(engine1));
    // Remove from manager
    manager.removeRenderingEngine(engine1);
    manager.removeRenderingEngine(engine3);
    assertEquals(1, manager.getRenderingEngines(networkView1).size());
    assertEquals(0, manager.getRenderingEngines(networkView2).size());
    manager.removeRenderingEngine(engine2);
    assertEquals(0, manager.getRenderingEngines(networkView1).size());
}
Also used : CyNetwork(org.cytoscape.model.CyNetwork) CyNetworkView(org.cytoscape.view.model.CyNetworkView) Test(org.junit.Test)

Example 24 with CyNetwork

use of org.cytoscape.model.CyNetwork 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 25 with CyNetwork

use of org.cytoscape.model.CyNetwork in project EnrichmentMapApp by BaderLab.

the class RadialHeatMapChart method getLayers.

@Override
public List<RadialHeatMapLayer> getLayers(final CyNetworkView networkView, final View<? extends CyIdentifiable> view) {
    final CyNetwork network = networkView.getModel();
    final CyIdentifiable model = view.getModel();
    final double startAngle = get(START_ANGLE, Double.class, 0.0);
    final Rotation rotation = get(ROTATION, Rotation.class, Rotation.ANTICLOCKWISE);
    final List<String> labels = getItemLabels(network, model);
    final Map<String, List<Double>> data = getData(network, model);
    final List<Color> colors = getColors(data);
    final double size = 32;
    final Rectangle2D bounds = new Rectangle2D.Double(-size / 2, -size / 2, size, size);
    final boolean showLabels = get(SHOW_ITEM_LABELS, Boolean.class, false);
    final float itemFontSize = convertFontSize(get(ITEM_LABEL_FONT_SIZE, Integer.class, 1));
    final float borderWidth = get(BORDER_WIDTH, Float.class, 0.25f);
    final Color borderColor = get(BORDER_COLOR, Color.class, Color.DARK_GRAY);
    final boolean global = get(GLOBAL_RANGE, Boolean.class, true);
    final List<Double> range = global ? getList(RANGE, Double.class) : null;
    final RadialHeatMapLayer layer = new RadialHeatMapLayer(data, labels, showLabels, itemFontSize, colors, borderWidth, borderColor, startAngle, rotation, range, bounds);
    return Collections.singletonList(layer);
}
Also used : Color(java.awt.Color) Rectangle2D(java.awt.geom.Rectangle2D) CyNetwork(org.cytoscape.model.CyNetwork) Rotation(org.baderlab.csplugins.enrichmentmap.style.charts.Rotation) ArrayList(java.util.ArrayList) List(java.util.List) CyIdentifiable(org.cytoscape.model.CyIdentifiable)

Aggregations

CyNetwork (org.cytoscape.model.CyNetwork)48 Test (org.junit.Test)20 CyNode (org.cytoscape.model.CyNode)16 CyNetworkView (org.cytoscape.view.model.CyNetworkView)13 EnrichmentMap (org.baderlab.csplugins.enrichmentmap.model.EnrichmentMap)11 CyEdge (org.cytoscape.model.CyEdge)9 ArrayList (java.util.ArrayList)8 List (java.util.List)6 CyNetworkManager (org.cytoscape.model.CyNetworkManager)6 CyRow (org.cytoscape.model.CyRow)6 BaseIntegrationTest (org.baderlab.csplugins.enrichmentmap.integration.BaseIntegrationTest)5 DataSetFiles (org.baderlab.csplugins.enrichmentmap.model.DataSetFiles)5 EMDataSet (org.baderlab.csplugins.enrichmentmap.model.EMDataSet)5 CyTable (org.cytoscape.model.CyTable)5 Map (java.util.Map)4 Set (java.util.Set)4 EMCreationParameters (org.baderlab.csplugins.enrichmentmap.model.EMCreationParameters)4 View (org.cytoscape.view.model.View)4 Inject (com.google.inject.Inject)3 Color (java.awt.Color)3