Author: laylaoesper
Date: 2010-08-04 13:48:56 -0700 (Wed, 04 Aug 2010)
New Revision: 21199
Added:
csplugins/trunk/soc/layla/SemanticSummary/src/cytoscape/csplugins/semanticsummary/CreateCloudNetworkAction.java
csplugins/trunk/soc/layla/SemanticSummary/src/cytoscape/csplugins/semanticsummary/WordCloudVisualStyle.java
Modified:
csplugins/trunk/soc/layla/SemanticSummary/jars/SemanticSummary.jar
csplugins/trunk/soc/layla/SemanticSummary/src/cytoscape/csplugins/semanticsummary/CloudParameters.java
csplugins/trunk/soc/layla/SemanticSummary/src/cytoscape/csplugins/semanticsummary/CreateCloudAction.java
csplugins/trunk/soc/layla/SemanticSummary/src/cytoscape/csplugins/semanticsummary/SemanticSummaryInputPanel.java
Log:
Add ability to create a network view of a cloud.
Modified: csplugins/trunk/soc/layla/SemanticSummary/jars/SemanticSummary.jar
===================================================================
(Binary files differ)
Modified:
csplugins/trunk/soc/layla/SemanticSummary/src/cytoscape/csplugins/semanticsummary/CloudParameters.java
===================================================================
---
csplugins/trunk/soc/layla/SemanticSummary/src/cytoscape/csplugins/semanticsummary/CloudParameters.java
2010-08-04 20:32:36 UTC (rev 21198)
+++
csplugins/trunk/soc/layla/SemanticSummary/src/cytoscape/csplugins/semanticsummary/CloudParameters.java
2010-08-04 20:48:56 UTC (rev 21199)
@@ -101,6 +101,10 @@
private static final String WORDDELIMITER = "CloudParamWordDelimiter";
private static final char controlChar = '\u001F';
+ //Network Name creation variables
+ private Integer networkCount = 1;
+ private static final String NETWORKNAME = "Net";
+ private static final String SEPARATER = "_";
//Default Values for User Input
private Double defaultNetWeight = 0.0;
@@ -201,6 +205,10 @@
if (val != null)
{this.maxWeight = new Double(props.get("MaxWeight"));}
+ val = props.get("NetworkCount");
+ if (val != null)
+ {this.networkCount = new Integer(props.get("NetworkCount"));}
+
//Rebuild attribute List
String value = props.get("AttributeName");
String[] attributes = value.split(WORDDELIMITER);
@@ -881,6 +889,7 @@
paramVariables.append("MinWeight\t" + minWeight + "\n");
paramVariables.append("CloudNum\t" + cloudNum + "\n");
paramVariables.append("UseNetNormal\t" + useNetNormal + "\n");
+ paramVariables.append("NetworkCount\t" + networkCount + "\n");
//List of Nodes as a comma delimited list
StringBuffer output2 = new StringBuffer();
@@ -1188,7 +1197,19 @@
return 0;
}
+ /**
+ * Returns the name for the next network for this cloud.
+ * @return String - name of the next cloud
+ */
+ public String getNextNetworkName()
+ {
+ String name = networkParams.getNetworkName() + "-" + cloudName
+ "-" + NETWORKNAME + SEPARATER + networkCount;
+ networkCount++;
+
+ return name;
+ }
+
//Getters and Setters
public String getCloudName()
{
Modified:
csplugins/trunk/soc/layla/SemanticSummary/src/cytoscape/csplugins/semanticsummary/CreateCloudAction.java
===================================================================
---
csplugins/trunk/soc/layla/SemanticSummary/src/cytoscape/csplugins/semanticsummary/CreateCloudAction.java
2010-08-04 20:32:36 UTC (rev 21198)
+++
csplugins/trunk/soc/layla/SemanticSummary/src/cytoscape/csplugins/semanticsummary/CreateCloudAction.java
2010-08-04 20:48:56 UTC (rev 21199)
@@ -151,6 +151,7 @@
//inputPanel.setNetworkList(params);
inputPanel.addNewCloud(cloudParams);
+ inputPanel.getCreateNetworkButton().setEnabled(true);
//Update the list of filter words and checkbox
inputPanel.refreshNetworkSettings();
Added:
csplugins/trunk/soc/layla/SemanticSummary/src/cytoscape/csplugins/semanticsummary/CreateCloudNetworkAction.java
===================================================================
---
csplugins/trunk/soc/layla/SemanticSummary/src/cytoscape/csplugins/semanticsummary/CreateCloudNetworkAction.java
(rev 0)
+++
csplugins/trunk/soc/layla/SemanticSummary/src/cytoscape/csplugins/semanticsummary/CreateCloudNetworkAction.java
2010-08-04 20:48:56 UTC (rev 21199)
@@ -0,0 +1,163 @@
+/*
+ File: CreateCloudNetworkAction.java
+
+ Copyright 2010 - The Cytoscape Consortium (www.cytoscape.org)
+
+ Code written by: Layla Oesper
+ Authors: Layla Oesper, Ruth Isserlin, Daniele Merico
+
+ This library is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this project. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package cytoscape.csplugins.semanticsummary;
+
+import giny.model.Edge;
+import giny.model.Node;
+
+import java.awt.event.ActionEvent;
+import java.util.HashMap;
+import java.util.Iterator;
+
+import cytoscape.CyNetwork;
+import cytoscape.Cytoscape;
+import cytoscape.data.CyAttributes;
+import cytoscape.data.Semantics;
+import cytoscape.layout.CyLayouts;
+import cytoscape.util.CytoscapeAction;
+import cytoscape.view.CyNetworkView;
+import cytoscape.visual.CalculatorCatalog;
+import cytoscape.visual.VisualMappingManager;
+import cytoscape.visual.VisualStyle;
+
+/**
+ * This is the action is associated with creating a new Network from an
existing
+ * word tag cloud.
+ * @author Layla Oesper
+ * @version 1.0
+ */
+
+public class CreateCloudNetworkAction extends CytoscapeAction
+{
+
+ //VARIABLES
+ public static String WORD_VAL = "Word_Prob";
+ public static String CO_VAL = "CO_Prob";
+ public static String INTERACTION_TYPE = "CO";
+
+ //CONSTRUCTORS
+
+ /**
+ * CreateCloudAction constructor.
+ */
+ public CreateCloudNetworkAction()
+ {
+ super("Create Cloud Network");
+ }
+
+ //METHODS
+
+ /**
+ * Method called when a Create Network Cloud action occurs.
+ *
+ * @param ActionEvent - event created when choosing to create a network
+ * from an existing cloud.
+ */
+ public void actionPerformed(ActionEvent ae)
+ {
+ //Retrieve the current cloud and relevent information
+ CloudParameters curCloud =
SemanticSummaryManager.getInstance().getCurCloud();
+ HashMap<String, Double> ratios = curCloud.getRatios();
+ HashMap<String, Double> pairRatios = curCloud.getPairRatios();
+
+ //Create the network
+ String newNetworkName = curCloud.getNextNetworkName();
+ CyNetwork network = Cytoscape.createNetwork(newNetworkName);
+
+ //Create nodes
+ for (Iterator<String> iter = ratios.keySet().iterator();
iter.hasNext();)
+ {
+ String curWord = iter.next();
+ Node node = Cytoscape.getCyNode(curWord, true);
+
+ network.addNode(node);
+
+ //Add attribute to the node
+ Double nodeRatio = ratios.get(curWord);
+ String attName = newNetworkName + ":" +
CreateCloudNetworkAction.WORD_VAL;
+ CyAttributes nodeAttrs = Cytoscape.getNodeAttributes();
+ nodeAttrs.setAttribute(node.getIdentifier(), attName,
nodeRatio);
+ }
+
+ //Create edges
+ for (Iterator<String> iter = pairRatios.keySet().iterator();
iter.hasNext();)
+ {
+ String curEdge = iter.next();
+ Double edgeRatio = pairRatios.get(curEdge);
+ String[] nodeNames = curEdge.split(" ");
+ String nodeName1 = nodeNames[0];
+ String nodeName2 = nodeNames[1];
+ Node node1 = Cytoscape.getCyNode(nodeName1, false);
+ Node node2 = Cytoscape.getCyNode(nodeName2, false);
+ Double node1Ratio = ratios.get(nodeName1);
+ Double node2Ratio = ratios.get(nodeName2);
+ Double conditionalRatio = edgeRatio / (node1Ratio *
node2Ratio);
+
+ //Only create if prob > 1
+ if (conditionalRatio > 1)
+ {
+ Edge edge = (Edge) Cytoscape.getCyEdge(node1,
node2, Semantics.INTERACTION, CreateCloudNetworkAction.INTERACTION_TYPE, true);
+
+ //Add attribute to the edge
+ String attName = newNetworkName + ":" +
CreateCloudNetworkAction.CO_VAL;
+ CyAttributes edgeAttrs =
Cytoscape.getEdgeAttributes();
+ edgeAttrs.setAttribute(edge.getIdentifier(),
attName, conditionalRatio);
+
+ network.addEdge(edge);
+ }
+ }
+
+ //Visual Style stuff
+ CyNetworkView view = Cytoscape.createNetworkView(network);
+
+ //make sure that network is registered so that Quickfind works
+
Cytoscape.firePropertyChange(cytoscape.view.CytoscapeDesktop.NETWORK_VIEW_CREATED,
network, view);
+
+ VisualMappingManager manager =
Cytoscape.getVisualMappingManager();
+ CalculatorCatalog catalog = manager.getCalculatorCatalog();
+
+ String vs_name = newNetworkName + "WordCloud_style";
+ //check to see if the style exists
+ VisualStyle vs = catalog.getVisualStyle(vs_name);
+
+ if (vs == null)
+ {
+ WordCloudVisualStyle wc_vs = new
WordCloudVisualStyle(vs_name, newNetworkName,curCloud);
+ vs = wc_vs.createVisualStyle(network, newNetworkName);
+
+ catalog.addVisualStyle(vs);
+ }
+
+ view.setVisualStyle(vs.getName());
+ manager.setVisualStyle(vs);
+ view.redrawGraph(true, true);
+
+ //Create view
+ view.applyLayout(CyLayouts.getLayout("force-directed"));
+
+ //make sure that network is registered so that Quickfind works
+
Cytoscape.firePropertyChange(cytoscape.view.CytoscapeDesktop.NETWORK_VIEW_CREATED,
network, view);
+
+ }
+
+}
Modified:
csplugins/trunk/soc/layla/SemanticSummary/src/cytoscape/csplugins/semanticsummary/SemanticSummaryInputPanel.java
===================================================================
---
csplugins/trunk/soc/layla/SemanticSummary/src/cytoscape/csplugins/semanticsummary/SemanticSummaryInputPanel.java
2010-08-04 20:32:36 UTC (rev 21198)
+++
csplugins/trunk/soc/layla/SemanticSummary/src/cytoscape/csplugins/semanticsummary/SemanticSummaryInputPanel.java
2010-08-04 20:48:56 UTC (rev 21199)
@@ -119,6 +119,7 @@
private JButton addWordButton;
private JButton addDelimiterButton;
private JButton removeDelimiterButton;
+ private JButton createNetworkButton;
//Checkbox
private JCheckBox numExclusion;
@@ -129,7 +130,11 @@
//Checkbox list
private CheckBoxJList attributeList;
+
+ //Popup menu
private JPopupMenu attributeSelectionPopupMenu;
+
+ //Text Area
private JTextArea attNames;
//String Constants for Separators in remove word combo box
@@ -154,7 +159,6 @@
intFormat = NumberFormat.getIntegerInstance();
intFormat.setParseIntegerOnly(true);
- //TODO
setLayout(new BorderLayout());
//INITIALIZE PARAMETERS
@@ -735,7 +739,7 @@
*/
private CollapsiblePanel createCloudLayoutPanel()
{
- CollapsiblePanel collapsiblePanel = new CollapsiblePanel("Cloud
Layout");
+ CollapsiblePanel collapsiblePanel = new
CollapsiblePanel("Layout");
JPanel panel = new JPanel();
panel.setLayout(new GridLayout(0,1));
@@ -744,7 +748,7 @@
JPanel cloudLayoutPanel = new JPanel();
cloudLayoutPanel.setLayout(new GridBagLayout());
- JLabel cloudStyleLabel = new JLabel("Style: ");
+ JLabel cloudStyleLabel = new JLabel("Cloud Style: ");
WidestStringComboBoxModel wscbm = new
WidestStringComboBoxModel();
cmbStyle = new JComboBox(wscbm);
@@ -780,6 +784,31 @@
panel.add(cloudLayoutPanel);
+ //Create network button stuff
+ JLabel createNetworkLabel = new JLabel("Network View:");
+
+ createNetworkButton = new JButton("Export Cloud to Network");
+ createNetworkButton.setEnabled(false);
+ createNetworkButton.setToolTipText("Creates a new network based
on the current cloud");
+ createNetworkButton.addActionListener(new
CreateCloudNetworkAction());
+
+ gridBagConstraints = new GridBagConstraints();
+ gridBagConstraints.gridx = 0;
+ gridBagConstraints.gridy = 1;
+ gridBagConstraints.anchor = GridBagConstraints.WEST;
+ gridBagConstraints.insets = new Insets(5, 0, 0, 0);
+ cloudLayoutPanel.add(createNetworkLabel, gridBagConstraints);
+
+ gridBagConstraints = new GridBagConstraints();
+ gridBagConstraints.gridx = 1;
+ gridBagConstraints.gridy = 1;
+ gridBagConstraints.gridwidth = 2;
+ gridBagConstraints.anchor = GridBagConstraints.EAST;
+ gridBagConstraints.weightx = 1.0;
+ gridBagConstraints.insets = new Insets(5, 10, 0, 0);
+ cloudLayoutPanel.add(createNetworkButton, gridBagConstraints);
+
+
collapsiblePanel.getContentPane().add(panel,BorderLayout.NORTH);
return collapsiblePanel;
}
@@ -882,6 +911,16 @@
useNetworkCounts.setEnabled(true);
}
+ //Enable button based on cloud
+ if
(params.equals(SemanticSummaryManager.getInstance().getNullCloudParameters()))
+ {
+ createNetworkButton.setEnabled(false);
+ }
+ else
+ {
+ createNetworkButton.setEnabled(true);
+ }
+
SemanticSummaryManager.getInstance().setCurCloud(params);
this.refreshNetworkSettings();
}
@@ -1669,7 +1708,12 @@
return attNames;
}
+ public JButton getCreateNetworkButton()
+ {
+ return createNetworkButton;
+ }
+
/**
* Private Class to ensure that text fields are being set properly
*/
Added:
csplugins/trunk/soc/layla/SemanticSummary/src/cytoscape/csplugins/semanticsummary/WordCloudVisualStyle.java
===================================================================
---
csplugins/trunk/soc/layla/SemanticSummary/src/cytoscape/csplugins/semanticsummary/WordCloudVisualStyle.java
(rev 0)
+++
csplugins/trunk/soc/layla/SemanticSummary/src/cytoscape/csplugins/semanticsummary/WordCloudVisualStyle.java
2010-08-04 20:48:56 UTC (rev 21199)
@@ -0,0 +1,199 @@
+/*
+ File: WordCloudVisualStyle.java
+
+ Copyright 2010 - The Cytoscape Consortium (www.cytoscape.org)
+
+ Code written by: Layla Oesper
+ Authors: Layla Oesper, Ruth Isserlin, Daniele Merico
+
+ This library is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this project. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package cytoscape.csplugins.semanticsummary;
+
+import java.awt.Color;
+
+import cytoscape.CyNetwork;
+import cytoscape.visual.EdgeAppearance;
+import cytoscape.visual.EdgeAppearanceCalculator;
+import cytoscape.visual.GlobalAppearanceCalculator;
+import cytoscape.visual.NodeAppearance;
+import cytoscape.visual.NodeAppearanceCalculator;
+import cytoscape.visual.NodeShape;
+import cytoscape.visual.VisualPropertyType;
+import cytoscape.visual.VisualStyle;
+import cytoscape.visual.calculators.BasicCalculator;
+import cytoscape.visual.calculators.Calculator;
+import cytoscape.visual.mappings.BoundaryRangeValues;
+import cytoscape.visual.mappings.ContinuousMapping;
+import cytoscape.visual.mappings.Interpolator;
+import cytoscape.visual.mappings.LinearNumberToNumberInterpolator;
+import cytoscape.visual.mappings.ObjectMapping;
+import cytoscape.visual.mappings.PassThroughMapping;
+
+/**
+ * This contains all of the visual style information for the associated
network.
+ * @author Layla Oesper
+ * @version 1.0
+ */
+
+public class WordCloudVisualStyle
+{
+ //VARIABLES
+ private String networkName;
+ private VisualStyle vs;
+ private CloudParameters cloudParams;
+
+ //CONSTRUCTORS
+
+ /**
+ * Basic Constructor
+ * @param string - name of the visual style to create.
+ * @param name - name of the network this visual style pertains to
+ */
+ public WordCloudVisualStyle(String string, String name, CloudParameters
params)
+ {
+ this.networkName = name;
+ vs = new VisualStyle(string);
+ cloudParams = params;
+ }
+
+ /**
+ * Creates visual style for this WordCloud network.
+ * @param network - network to apply this visual style
+ * @param name - name of the network, to be appended to attribute names
+ */
+ public VisualStyle createVisualStyle(CyNetwork network, String name)
+ {
+ GlobalAppearanceCalculator globalAppCalc = new
GlobalAppearanceCalculator();
+ globalAppCalc.setDefaultBackgroundColor(new Color(205, 205,
235));
+
+ vs.setGlobalAppearanceCalculator(globalAppCalc);
+
+ createEdgeAppearance(network, name);
+ createNodeAppearance(network, name);
+
+ return vs;
+ }
+
+ /**
+ * Create edge appearances for this WordCloud network. Specify edge
thickness mapped
+ * to the inputted word co occurence probability.
+ *
+ * @param network - network to apply this visual style
+ * @param name - name to be appended to each of the attribute names
+ */
+ private void createEdgeAppearance(CyNetwork network, String name)
+ {
+ EdgeAppearanceCalculator edgeAppCalc = new
EdgeAppearanceCalculator(vs.getDependency());
+
+ //Set the default edge appearance
+ EdgeAppearance edgeAppear = new EdgeAppearance();
+ edgeAppear.set(VisualPropertyType.EDGE_COLOR, new Color(100,
200, 000));
+ edgeAppCalc.setDefaultAppearance(edgeAppear);
+
+ //Continuous Mapping - set edge line thickness based on the
probability ratio
+ ContinuousMapping continuousMapping_edgeWidth = new
ContinuousMapping(1, ObjectMapping.EDGE_MAPPING);
+ continuousMapping_edgeWidth.setControllingAttributeName(name +
":" + CreateCloudNetworkAction.CO_VAL, network, false);
+ Interpolator numTonum2 = new LinearNumberToNumberInterpolator();
+ continuousMapping_edgeWidth.setInterpolator(numTonum2);
+
+ Double under_width = 0.5;
+ Double min_width = 1.0;
+ Double max_width = 8.0;
+ Double over_width = 9.0;
+
+ //Create boundary conditions
+ BoundaryRangeValues bv4 = new BoundaryRangeValues(under_width,
min_width, min_width);
+ BoundaryRangeValues bv5 = new BoundaryRangeValues(max_width,
max_width, over_width);
+ continuousMapping_edgeWidth.addPoint(1.0, bv4);
+ continuousMapping_edgeWidth.addPoint(40.0, bv5);
+
+ Calculator edgeWidthCalculator = new BasicCalculator(name +
"edgesize", continuousMapping_edgeWidth, VisualPropertyType.EDGE_LINE_WIDTH);
+ edgeAppCalc.setCalculator(edgeWidthCalculator);
+
+ vs.setEdgeAppearanceCalculator(edgeAppCalc);
+ }
+
+ /**
+ * Create node appearances for this WordCloud network. Specify node
size and label size
+ * based on the word probability values.
+ *
+ * @param network - network to apply this visual style
+ * @param name - name to be appended to each of the attribute names
+ */
+ private void createNodeAppearance(CyNetwork network, String name)
+ {
+ NodeAppearanceCalculator nodeAppCalc = new
NodeAppearanceCalculator(vs.getDependency());
+
+ //set the default appearance
+ NodeAppearance nodeAppear = new NodeAppearance();
+ nodeAppear.set(VisualPropertyType.NODE_FILL_COLOR, Color.GRAY);
+ nodeAppear.set(VisualPropertyType.NODE_BORDER_COLOR, Color.GRAY);
+ nodeAppear.set(VisualPropertyType.NODE_SHAPE, NodeShape.ELLIPSE);
+ nodeAppear.set(VisualPropertyType.NODE_SIZE, new Double(35.0));
+ nodeAppear.set(VisualPropertyType.NODE_LINE_WIDTH, new Double(4.0));
+ nodeAppCalc.setDefaultAppearance(nodeAppear);
+
+ //Continuous Mapping - set node size based on the probability value
+ ContinuousMapping continuousMapping_size = new ContinuousMapping(35,
ObjectMapping.NODE_MAPPING);
+ continuousMapping_size.setControllingAttributeName(name + ":" +
CreateCloudNetworkAction.WORD_VAL, network, false);
+ Interpolator numTonum = new LinearNumberToNumberInterpolator();
+ continuousMapping_size.setInterpolator(numTonum);
+
+ Integer min = 20;
+ Integer max = 65;
+
+ //Boundary Conditions
+ BoundaryRangeValues bv0 = new BoundaryRangeValues(min, min, min);
+ BoundaryRangeValues bv1 = new BoundaryRangeValues(max, max, max);
+
+ continuousMapping_size.addPoint(cloudParams.getMinRatio(), bv0);
+ continuousMapping_size.addPoint(cloudParams.getMaxRatio(), bv1);
+
+
+ Calculator nodeSizeCalculator = new BasicCalculator(name +
"size2size", continuousMapping_size, VisualPropertyType.NODE_SIZE);
+ nodeAppCalc.setCalculator(nodeSizeCalculator);
+
+ //Passthrough for node label
+ PassThroughMapping pm = new PassThroughMapping(new String(),
"canonicalName");
+ Calculator nlc = new BasicCalculator(name + "nodeLabel", pm,
VisualPropertyType.NODE_LABEL);
+ nodeAppCalc.setCalculator(nlc);
+
+ //Label size
+ //Continuous Mapping - set node size based on the probability value
+ ContinuousMapping continuousMapping_labelSize = new
ContinuousMapping(35, ObjectMapping.NODE_MAPPING);
+ continuousMapping_labelSize.setControllingAttributeName(name + ":" +
CreateCloudNetworkAction.WORD_VAL, network, false);
+ Interpolator numTonum2 = new LinearNumberToNumberInterpolator();
+ continuousMapping_labelSize.setInterpolator(numTonum2);
+
+ min = 12;
+ max = 56;
+
+ //Boundary Conditions
+ bv0 = new BoundaryRangeValues(min, min, min);
+ bv1 = new BoundaryRangeValues(max, max, max);
+
+ continuousMapping_labelSize.addPoint(cloudParams.getMinRatio(), bv0);
+ continuousMapping_labelSize.addPoint(cloudParams.getMaxRatio(), bv1);
+
+
+ Calculator labelSizeCalculator = new BasicCalculator(name +
"size2label", continuousMapping_labelSize, VisualPropertyType.NODE_FONT_SIZE);
+ nodeAppCalc.setCalculator(labelSizeCalculator);
+
+ vs.setNodeAppearanceCalculator(nodeAppCalc);
+ }
+
+
+}
--
You received this message because you are subscribed to the Google Groups
"cytoscape-cvs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/cytoscape-cvs?hl=en.