use of org.cytoscape.view.vizmap.mappings.PassthroughMapping in project clusterMaker2 by RBVI.
the class NetworkColorDialog method actionPerformed.
/**
* DOCUMENT ME!
*
* @param e DOCUMENT ME!
*/
public void actionPerformed(ActionEvent e) {
// Are we the source of the event?
String command = e.getActionCommand();
if (command.equals("done")) {
animating = false;
this.setVisible(false);
} else if (command.equals("up")) {
shiftList(-1);
} else if (command.equals("down")) {
shiftList(1);
} else if (command.equals("vizmap")) {
String attribute = (String) attributeSelector.getSelectedValue();
MapTask task = new MapTask(attribute, "-heatMap", false);
taskManager.execute(new TaskIterator(task));
} else if (command.equals("animate")) {
if (animating) {
animating = false;
animateButton.setText("Animate Vizmap");
return;
}
// Get the selected attributes
Object[] attributeArray = attributeSelector.getSelectedValues();
if (attributeArray.length < 2) {
// Really nothing to animate if we only have one map
MapTask task = new MapTask((String) attributeArray[0], "-heatMap", false);
taskManager.execute(new TaskIterator(task));
return;
}
if (currentAttribute == null) {
// Build the necessary vizmap entries
styles = new VisualStyle[attributeArray.length];
for (int i = 0; i < attributeArray.length; i++) {
styles[i] = createNewStyle((String) attributeArray[i], "-" + (String) attributeArray[i], false, false);
}
}
// Change the animate button
animateButton.setText("Stop animation");
animating = true;
// Set up the animation task
Animate a = new Animate(styles, attributeArray);
a.start();
} else if (command.equals("heatstrip")) {
// Get the selected attributes
Object[] attributeArray = attributeSelector.getSelectedValues();
// We need to use enhancedgraphics for this.
// 1) create a heatstrip command
// 2) Write it into a column for every node
// 3) Add a passthrough mapper for custom graphics
String heatstrip = "heatstripchart: separation=\"1\" attributelist=\"";
for (Object attr : attributeArray) heatstrip += attr.toString() + ",";
// strip off the extra comma
heatstrip = heatstrip.substring(0, heatstrip.length() - 1);
String colorSpec = getColorSpec();
heatstrip += "\" colorlist=\"" + colorSpec + "\" position=south showlabels=false size=30x60\"";
CyNetwork net = clusterManager.getNetwork();
String columnName = "clusterMaker-heatStrip";
CyTable nodeTable = net.getDefaultNodeTable();
if (nodeTable.getColumn(columnName) == null)
nodeTable.createColumn(columnName, String.class, false);
for (CyNode node : net.getNodeList()) {
nodeTable.getRow(node.getSUID()).set(columnName, heatstrip);
}
VisualStyle style = ViewUtils.getCurrentVisualStyle(clusterManager);
if (!style.getTitle().endsWith("-heatStrip"))
style = ViewUtils.copyStyle(clusterManager, style, "-heatStrip");
// Get the default lexicon (CUSTOMGRAPHICS aren't in the basic lexicon)
VisualLexicon currentLexicon = ((RenderingEngineManager) clusterManager.getService(RenderingEngineManager.class)).getDefaultVisualLexicon();
VisualProperty customGraphicsVP = currentLexicon.lookup(CyNode.class, "NODE_CUSTOMGRAPHICS_1");
if (customGraphicsVP == null)
System.err.println("couldn't get NODE CUSTOM GRAPHICS");
// Get a function factory
VisualMappingFunctionFactory vmff = clusterManager.getService(VisualMappingFunctionFactory.class, "(mapping.type=passthrough)");
PassthroughMapping map = (PassthroughMapping) vmff.createVisualMappingFunction(columnName, String.class, customGraphicsVP);
style.addVisualMappingFunction(map);
// TODO: Do we want to mess with the CUSTOMGRAPHICS_POSITION?
ViewUtils.setVisualStyle(clusterManager, clusterManager.getNetworkView(), style);
}
}
use of org.cytoscape.view.vizmap.mappings.PassthroughMapping 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);
}
}
use of org.cytoscape.view.vizmap.mappings.PassthroughMapping in project cytoscape-impl by cytoscape.
the class VisualStyleSerializerTest method testCy270Vizmap.
@Test
@SuppressWarnings("unchecked")
public void testCy270Vizmap() throws Exception {
Properties props = loadVizmapProps("v270_vizmap.props");
Set<VisualStyle> styles = serializer.createVisualStyles(props);
assertEquals(2, styles.size());
assertVisualStylesNotNull(styles, new String[] { "default", "Binary_SIF_Version_1" });
// Test visual styles (defaults, mappings and dependencies)
// -----
VisualStyle s = getVisualStyleByTitle(styles, "Binary_SIF_Version_1");
assertEquals(new Color(255, 153, 153), s.getDefaultValue(NODE_FILL_COLOR));
assertEquals(new Color(255, 255, 0), s.getDefaultValue(NODE_SELECTED_PAINT));
assertEquals(NodeShapeVisualProperty.ELLIPSE, s.getDefaultValue(NODE_SHAPE));
assertEquals(70, s.getDefaultValue(NODE_WIDTH).intValue());
assertEquals(30, s.getDefaultValue(NODE_HEIGHT).intValue());
assertEquals(35, s.getDefaultValue(NODE_SIZE).intValue());
assertEquals(125, s.getDefaultValue(NODE_TRANSPARENCY).intValue());
assertEquals(new Color(0, 0, 0), s.getDefaultValue(NODE_BORDER_PAINT));
assertEquals(1, s.getDefaultValue(NODE_BORDER_WIDTH).intValue());
assertEquals(255, s.getDefaultValue(NODE_BORDER_TRANSPARENCY).intValue());
assertEquals("", s.getDefaultValue(NODE_LABEL));
assertEquals(Font.decode("Default-PLAIN-12"), s.getDefaultValue(NODE_LABEL_FONT_FACE));
assertEquals(12, s.getDefaultValue(NODE_LABEL_FONT_SIZE).intValue());
assertEquals(new Color(0, 0, 0), s.getDefaultValue(NODE_LABEL_COLOR));
assertEquals(100, s.getDefaultValue(NODE_LABEL_WIDTH).intValue());
assertEquals(255, s.getDefaultValue(NODE_LABEL_TRANSPARENCY).intValue());
assertEquals(LineTypeVisualProperty.SOLID, s.getDefaultValue(NODE_BORDER_LINE_TYPE));
assertEquals("", s.getDefaultValue(NODE_TOOLTIP));
assertEquals(Boolean.TRUE, s.getDefaultValue(NODE_NESTED_NETWORK_IMAGE_VISIBLE));
assertEquals(4, s.getDefaultValue(EDGE_WIDTH).intValue());
assertEquals(new Color(0, 0, 0), s.getDefaultValue(EDGE_UNSELECTED_PAINT));
assertEquals(new Color(0, 0, 0), s.getDefaultValue(EDGE_STROKE_UNSELECTED_PAINT));
assertEquals(new Color(255, 0, 0), s.getDefaultValue(EDGE_STROKE_SELECTED_PAINT));
assertEquals(255, s.getDefaultValue(EDGE_TRANSPARENCY).intValue());
assertEquals(LineTypeVisualProperty.SOLID, s.getDefaultValue(EDGE_LINE_TYPE));
assertEquals("", s.getDefaultValue(EDGE_LABEL));
assertEquals(Font.decode("SanSerif-PLAIN-10"), s.getDefaultValue(EDGE_LABEL_FONT_FACE));
assertEquals(10, s.getDefaultValue(EDGE_LABEL_FONT_SIZE).intValue());
assertEquals(new Color(0, 0, 0), s.getDefaultValue(EDGE_LABEL_COLOR));
assertEquals(255, s.getDefaultValue(EDGE_LABEL_TRANSPARENCY).intValue());
assertEquals(ArrowShapeVisualProperty.NONE, s.getDefaultValue(EDGE_SOURCE_ARROW_SHAPE));
assertEquals(ArrowShapeVisualProperty.NONE, s.getDefaultValue(EDGE_TARGET_ARROW_SHAPE));
assertEquals("", s.getDefaultValue(EDGE_TOOLTIP));
PassthroughMapping<String, String> nLabelMp = (PassthroughMapping<String, String>) s.getVisualMappingFunction(NODE_LABEL);
assertEquals("biopax.node_label", nLabelMp.getMappingColumnName());
assertEquals(String.class, nLabelMp.getMappingColumnType());
assertNull(s.getVisualMappingFunction(EDGE_LABEL));
DiscreteMapping<String, Paint> nColorMp = (DiscreteMapping<String, Paint>) s.getVisualMappingFunction(NODE_FILL_COLOR);
assertEquals("biopax.entity_type", nColorMp.getMappingColumnName());
assertEquals(String.class, nColorMp.getMappingColumnType());
assertEquals(new Color(153, 153, 255), nColorMp.getMapValue("Complex"));
assertNull(nColorMp.getMapValue("Protein"));
DiscreteMapping<String, Paint> eColorMp = (DiscreteMapping<String, Paint>) s.getVisualMappingFunction(EDGE_STROKE_UNSELECTED_PAINT);
assertEquals(INTERACTION, eColorMp.getMappingColumnName());
assertEquals(String.class, eColorMp.getMappingColumnType());
// Test a few entries
assertEquals(new Color(255, 192, 0), eColorMp.getMapValue("COMPONENT_OF"));
assertEquals(new Color(255, 0, 0), eColorMp.getMapValue("CO_CONTROL_DEPENDENT_ANTI"));
assertEquals(new Color(0, 176, 80), eColorMp.getMapValue("CO_CONTROL_DEPENDENT_SIMILAR"));
assertEquals(new Color(253, 149, 166), eColorMp.getMapValue("CO_CONTROL_INDEPENDENT_ANTI"));
assertEquals(new Color(0, 176, 80), eColorMp.getMapValue("CO_CONTROL_DEPENDENT_SIMILAR"));
DiscreteMapping<String, ArrowShape> eTgtArrowMp = (DiscreteMapping<String, ArrowShape>) s.getVisualMappingFunction(EDGE_TARGET_ARROW_SHAPE);
assertEquals(INTERACTION, eTgtArrowMp.getMappingColumnName());
assertEquals(String.class, eTgtArrowMp.getMappingColumnType());
assertEquals(ArrowShapeVisualProperty.ARROW, eTgtArrowMp.getMapValue("COMPONENT_OF"));
assertEquals(ArrowShapeVisualProperty.ARROW, eTgtArrowMp.getMapValue("METABOLIC_CATALYSIS"));
assertEquals(ArrowShapeVisualProperty.ARROW, eTgtArrowMp.getMapValue("SEQUENTIAL_CATALYSIS"));
assertEquals(ArrowShapeVisualProperty.ARROW, eTgtArrowMp.getMapValue("SEQUENTIAL_CATALYSIS"));
assertEquals(ArrowShapeVisualProperty.ARROW, eTgtArrowMp.getMapValue("STATE_CHANGE"));
assertNull(eTgtArrowMp.getMapValue("INTERACTS_WITH"));
VisualPropertyDependency<?> dep1 = getDependency(s, NODE_SIZE_LOCKED_DEPENDENCY);
assertFalse(dep1.isDependencyEnabled());
}
use of org.cytoscape.view.vizmap.mappings.PassthroughMapping in project cytoscape-impl by cytoscape.
the class VisualStyleSerializerTest method testCy252Vizmap.
@Test
@SuppressWarnings("unchecked")
public void testCy252Vizmap() throws Exception {
Properties props = loadVizmapProps("v252_vizmap.props");
Set<VisualStyle> styles = serializer.createVisualStyles(props);
assertEquals(5, styles.size());
assertVisualStylesNotNull(styles, new String[] { "default", "Sample1", "Sample2", "Sample3", "SimpleBioMoleculeEditor" });
// Test one style
// -----
VisualStyle s3 = getVisualStyleByTitle(styles, "Sample3");
assertEquals(new Color(0, 0, 0), s3.getDefaultValue(NETWORK_BACKGROUND_PAINT));
assertEquals(new Color(255, 255, 255), s3.getDefaultValue(NODE_FILL_COLOR));
assertEquals(new Color(255, 255, 0), s3.getDefaultValue(NODE_SELECTED_PAINT));
assertEquals(NodeShapeVisualProperty.ROUND_RECTANGLE, s3.getDefaultValue(NODE_SHAPE));
assertEquals(80, s3.getDefaultValue(NODE_WIDTH).intValue());
assertEquals(30, s3.getDefaultValue(NODE_HEIGHT).intValue());
assertEquals(180, s3.getDefaultValue(NODE_TRANSPARENCY).intValue());
assertEquals(new Color(153, 153, 255), s3.getDefaultValue(NODE_BORDER_PAINT));
assertEquals(2, s3.getDefaultValue(NODE_BORDER_WIDTH).intValue());
assertEquals(255, s3.getDefaultValue(NODE_BORDER_TRANSPARENCY).intValue());
assertEquals(new Font("Arial-BoldMT", Font.PLAIN, 12), s3.getDefaultValue(NODE_LABEL_FONT_FACE));
assertEquals(16, s3.getDefaultValue(NODE_LABEL_FONT_SIZE).intValue());
assertEquals(new Color(255, 255, 255), s3.getDefaultValue(NODE_LABEL_COLOR));
assertEquals(255, s3.getDefaultValue(NODE_LABEL_TRANSPARENCY).intValue());
assertEquals(LineTypeVisualProperty.SOLID, s3.getDefaultValue(NODE_BORDER_LINE_TYPE));
assertEquals("", s3.getDefaultValue(NODE_TOOLTIP));
assertEquals(1, s3.getDefaultValue(EDGE_WIDTH).intValue());
assertEquals(new Color(153, 153, 255), s3.getDefaultValue(EDGE_UNSELECTED_PAINT));
assertEquals(new Color(153, 153, 255), s3.getDefaultValue(EDGE_STROKE_UNSELECTED_PAINT));
assertEquals(new Color(255, 0, 0), s3.getDefaultValue(EDGE_STROKE_SELECTED_PAINT));
assertEquals(255, s3.getDefaultValue(EDGE_TRANSPARENCY).intValue());
assertEquals(LineTypeVisualProperty.SOLID, s3.getDefaultValue(EDGE_LINE_TYPE));
assertEquals(Font.decode("SanSerif-PLAIN-10"), s3.getDefaultValue(EDGE_LABEL_FONT_FACE));
assertEquals(14, s3.getDefaultValue(EDGE_LABEL_FONT_SIZE).intValue());
assertEquals(new Color(255, 255, 204), s3.getDefaultValue(EDGE_LABEL_COLOR));
assertEquals(255, s3.getDefaultValue(EDGE_LABEL_TRANSPARENCY).intValue());
assertEquals(ArrowShapeVisualProperty.NONE, s3.getDefaultValue(EDGE_SOURCE_ARROW_SHAPE));
assertEquals(ArrowShapeVisualProperty.NONE, s3.getDefaultValue(EDGE_TARGET_ARROW_SHAPE));
assertEquals("", s3.getDefaultValue(EDGE_TOOLTIP));
PassthroughMapping<String, String> nLabelMp = (PassthroughMapping<String, String>) s3.getVisualMappingFunction(NODE_LABEL);
assertEquals(NAME, nLabelMp.getMappingColumnName());
assertEquals(String.class, nLabelMp.getMappingColumnType());
PassthroughMapping<String, String> eLabelMp = (PassthroughMapping<String, String>) s3.getVisualMappingFunction(EDGE_LABEL);
assertEquals(INTERACTION, eLabelMp.getMappingColumnName());
assertEquals(String.class, eLabelMp.getMappingColumnType());
PassthroughMapping<String, String> nTooltipMp = (PassthroughMapping<String, String>) s3.getVisualMappingFunction(NODE_TOOLTIP);
assertEquals("gal4RGexp", nTooltipMp.getMappingColumnName());
assertEquals(String.class, nTooltipMp.getMappingColumnType());
ContinuousMapping<Double, Paint> nColorMp = (ContinuousMapping<Double, Paint>) s3.getVisualMappingFunction(NODE_FILL_COLOR);
assertEquals("gal4RGexp", nColorMp.getMappingColumnName());
assertEquals(Number.class, nColorMp.getMappingColumnType());
assertEquals(3, nColorMp.getPointCount());
assertEquals(-2.4059998989105242, nColorMp.getPoint(0).getValue(), 0.0001);
assertEquals(new Color(0, 153, 0), nColorMp.getPoint(0).getRange().equalValue);
assertEquals(new Color(0, 153, 0), nColorMp.getPoint(0).getRange().greaterValue);
assertEquals(Color.BLACK, nColorMp.getPoint(0).getRange().lesserValue);
assertEquals(-3.254413627473696E-8, nColorMp.getPoint(1).getValue(), 0.0001);
assertEquals(Color.WHITE, nColorMp.getPoint(1).getRange().equalValue);
assertEquals(Color.WHITE, nColorMp.getPoint(1).getRange().greaterValue);
assertEquals(Color.WHITE, nColorMp.getPoint(1).getRange().lesserValue);
assertEquals(1.2239999999999998, nColorMp.getPoint(2).getValue(), 0.0001);
assertEquals(new Color(255, 0, 0), nColorMp.getPoint(2).getRange().equalValue);
assertEquals(new Color(255, 255, 255), nColorMp.getPoint(2).getRange().greaterValue);
assertEquals(new Color(255, 0, 0), nColorMp.getPoint(2).getRange().lesserValue);
DiscreteMapping<String, Paint> eColorMp = (DiscreteMapping<String, Paint>) s3.getVisualMappingFunction(EDGE_STROKE_UNSELECTED_PAINT);
assertEquals(INTERACTION, eColorMp.getMappingColumnName());
assertEquals(String.class, eColorMp.getMappingColumnType());
assertEquals(new Color(102, 255, 255), eColorMp.getMapValue("pd"));
assertEquals(new Color(255, 255, 255), eColorMp.getMapValue("pp"));
DiscreteMapping<String, LineType> eTypeMp = (DiscreteMapping<String, LineType>) s3.getVisualMappingFunction(EDGE_LINE_TYPE);
assertEquals(INTERACTION, eTypeMp.getMappingColumnName());
assertEquals(LineTypeVisualProperty.LONG_DASH, eTypeMp.getMapValue("pd"));
assertEquals(LineTypeVisualProperty.SOLID, eTypeMp.getMapValue("pp"));
VisualPropertyDependency<?> dep1 = getDependency(s3, NODE_SIZE_LOCKED_DEPENDENCY);
assertFalse(dep1.isDependencyEnabled());
}
use of org.cytoscape.view.vizmap.mappings.PassthroughMapping in project cytoscape-impl by cytoscape.
the class VisualPropertySheetItem method updateMappingIcon.
private void updateMappingIcon() {
if (!model.isVisualMappingAllowed())
return;
final JToggleButton btn = getMappingBtn();
final VisualMappingFunction<?, T> mapping = model.getVisualMappingFunction();
final String colName = mapping != null ? mapping.getMappingColumnName() : null;
final IconManager iconManager = servicesUtil.get(IconManager.class);
btn.setFont(iconManager.getIconFont(16.0f));
if (btn.isSelected())
btn.setForeground(UIManager.getColor("Table.focusCellForeground"));
else
btn.setForeground(getForegroundColor());
if (mapping == null) {
btn.setText("");
btn.setToolTipText("No Mapping");
} else if (mapping instanceof DiscreteMapping) {
btn.setText(DISCRETE_ICON);
btn.setToolTipText("Discrete Mapping for column \"" + colName + "\"");
} else if (mapping instanceof ContinuousMapping) {
btn.setText(CONTINUOUS_ICON);
btn.setToolTipText("Continuous Mapping for column \"" + colName + "\"");
} else if (mapping instanceof PassthroughMapping) {
btn.setText(PASSTHROUGH_ICON);
btn.setToolTipText("Passthrough Mapping for column \"" + colName + "\"");
}
}
Aggregations