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());
}
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());
}
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());
}
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);
}
}
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);
}
Aggregations