Author: scooter
Date: 2012-10-10 18:14:53 -0700 (Wed, 10 Oct 2012)
New Revision: 30650
Modified:
csplugins/trunk/ucsf/scooter/chemViz/src/chemViz/ChemViz.java
csplugins/trunk/ucsf/scooter/chemViz/src/chemViz/commands/ChemVizCommandHandler.java
csplugins/trunk/ucsf/scooter/chemViz/src/chemViz/commands/ValueUtils.java
csplugins/trunk/ucsf/scooter/chemViz/src/chemViz/menus/NodeGraphicsMenus.java
csplugins/trunk/ucsf/scooter/chemViz/src/chemViz/tasks/CreateNodeGraphicsTask.java
Log:
Added node graphics support
Modified: csplugins/trunk/ucsf/scooter/chemViz/src/chemViz/ChemViz.java
===================================================================
--- csplugins/trunk/ucsf/scooter/chemViz/src/chemViz/ChemViz.java
2012-10-10 22:33:48 UTC (rev 30649)
+++ csplugins/trunk/ucsf/scooter/chemViz/src/chemViz/ChemViz.java
2012-10-11 01:14:53 UTC (rev 30650)
@@ -51,6 +51,7 @@
import cytoscape.view.CyNetworkView;
import cytoscape.view.CytoscapeDesktop;
import ding.view.DGraphView;
+import giny.model.GraphObject;
import chemViz.commands.ChemVizCommandHandler;
import chemViz.menus.ChemVizMenu;
@@ -144,7 +145,7 @@
view.addEdgeContextMenuListener(new
ChemVizContextMenu(systemProps, settingsDialog));
// Check to see if this view has custom graphics
if
(CreateNodeGraphicsTask.hasCustomGraphics(view.getNetwork())) {
- List<Node> selection =
+ List<GraphObject> selection =
CreateNodeGraphicsTask.getCustomGraphicsNodes(view);
CreateNodeGraphicsTask loader = null;
Modified:
csplugins/trunk/ucsf/scooter/chemViz/src/chemViz/commands/ChemVizCommandHandler.java
===================================================================
---
csplugins/trunk/ucsf/scooter/chemViz/src/chemViz/commands/ChemVizCommandHandler.java
2012-10-10 22:33:48 UTC (rev 30649)
+++
csplugins/trunk/ucsf/scooter/chemViz/src/chemViz/commands/ChemVizCommandHandler.java
2012-10-11 01:14:53 UTC (rev 30650)
@@ -58,6 +58,7 @@
import cytoscape.data.CyAttributes;
import cytoscape.layout.Tunable;
import cytoscape.task.util.TaskManager;
+import cytoscape.view.CyNetworkView;
import giny.model.GraphObject;
@@ -68,12 +69,13 @@
import chemViz.model.Compound.DescriptorType;
import chemViz.tasks.CreatePopupTask;
import chemViz.tasks.CreateCompoundTableTask;
+import chemViz.tasks.CreateNodeGraphicsTask;
import chemViz.ui.ChemInfoSettingsDialog;
enum Command {
ATTACH("attach",
"Attach 2D structures to nodes",
- "nodelist|node|attribute|smiles"),
+
"network|nodelist|node|inchiattribute|smilesattribute|inchi|smiles"),
CALCULATE("calculate similarity",
"Create a similarity network for the current nodes",
"nodelist"),
@@ -85,13 +87,13 @@
"dialog"),
GETDESC("get descriptors",
"Return chemical descriptors for nodes or edges",
-
"attribute|descriptors|edge|edgelist|network=current|node|nodelist|smiles"),
+
"inchiattribute|smilesattribute|descriptors|edge|edgelist|network=current|node|nodelist|inchi|smiles"),
LISTDESC("list descriptors",
"Return the list of available chemical descriptors",
""),
REMOVE("remove",
"Remove 2D structures from nodes",
- "nodelist|node"),
+ "network|nodelist|node"),
SHOWSTRUCTURES("show structures",
"Popup the 2D structures for a node/edge or group of
nodes/edges",
"node|nodelist|edge|edgelist|labelattribute"),
@@ -124,7 +126,6 @@
*/
public class ChemVizCommandHandler extends AbstractCommandHandler {
static final String ALL = "all";
- static final String ATTRIBUTE = "attribute";
static final String COLUMNLIST = "columnlist";
static final String CURRENT = "current";
static final String DIALOG = "dialog";
@@ -132,12 +133,14 @@
static final String EDGE = "edge";
static final String EDGELIST = "edgelist";
static final String INCHI = "inchi";
+ static final String INCHIATTRIBUTE = "inchiattribute";
static final String LABELATTRIBUTE = "labelattribute";
static final String NETWORK = "network";
static final String NODE = "node";
static final String NODELIST = "nodelist";
static final String SELECTED = "selected";
static final String SMILES = "smiles";
+ static final String SMILESATTRIBUTE = "smilesattribute";
private ChemInfoProperties props;
private ChemInfoSettingsDialog dialog;
@@ -192,21 +195,38 @@
List<String> smilesAttrList = null;
List<String> inchiAttrList = null;
- if (args.containsKey(ATTRIBUTE)) {
- smilesAttrList.add(args.get(ATTRIBUTE).toString());
- inchiAttrList.add(args.get(ATTRIBUTE).toString());
+ if (args.containsKey(INCHIATTRIBUTE)) {
+ inchiAttrList.add(args.get(INCHIATTRIBUTE).toString());
} else {
- smilesAttrList =
dialog.getCompoundAttributes(objectType,AttriType.smiles);
inchiAttrList =
dialog.getCompoundAttributes(objectType,AttriType.inchi);
}
+ if (args.containsKey(SMILESATTRIBUTE)) {
+
smilesAttrList.add(args.get(SMILESATTRIBUTE).toString());
+ } else {
+ smilesAttrList =
dialog.getCompoundAttributes(objectType,AttriType.smiles);
+ }
+
// Main command cascade
// ATTACH("attach",
// "Attach 2D structures to nodes",
- //
"nodelist|node|attribute|inchi|smiles"),
+ //
"network|nodelist|node|inchiattribute|smilesattribute|inchi|smiles"),
if (Command.ATTACH.equals(command)) {
+ if (gObjList == null)
+ throw new RuntimeException("chemviz
"+command+": must provide node or nodelist");
+ if (gObjList == null && mstring == null)
+ throw new RuntimeException("chemviz
"+command+": must have one of smiles/inchi string or nodes");
+ List<Compound> compoundList =
ValueUtils.getCompounds(gObjList, mstring, mtype, smilesAttrList,
inchiAttrList);
+
+ // Get the network view
+ CyNetworkView view =
Cytoscape.getNetworkView(ValueUtils.getNetwork(args).getIdentifier());
+
+ // Do it!
+ CreateNodeGraphicsTask cngTask = new
CreateNodeGraphicsTask(compoundList, view, dialog, false);
+ TaskManager.executeTask(cngTask,
cngTask.getDefaultTaskConfig());
+
// CALCULATE("calculate similarity",
// "Create a similarity network for the current
nodes",
// "nodelist"),
@@ -285,7 +305,7 @@
// REMOVE("remove",
// "Remove 2D structures from nodes",
- // "nodelist|node"),
+ // "network|nodelist|node"),
} else if (Command.REMOVE.equals(command)) {
// SHOWSTRUCTURES("show structures",
Modified:
csplugins/trunk/ucsf/scooter/chemViz/src/chemViz/commands/ValueUtils.java
===================================================================
--- csplugins/trunk/ucsf/scooter/chemViz/src/chemViz/commands/ValueUtils.java
2012-10-10 22:33:48 UTC (rev 30649)
+++ csplugins/trunk/ucsf/scooter/chemViz/src/chemViz/commands/ValueUtils.java
2012-10-11 01:14:53 UTC (rev 30650)
@@ -92,6 +92,16 @@
if (args.containsKey(EDGE) && args.containsKey(EDGELIST))
throw new RuntimeException("chemviz "+command+": can't
have both 'edge' and 'edgeList'");
+ CyNetwork network = getNetwork(args);
+
+ // OK, nodes or edges?
+ if (args.containsKey(NODE) || args.containsKey(NODELIST))
+ return getNodeList(command, args, network);
+ else
+ return getEdgeList(command, args, network);
+ }
+
+ static public CyNetwork getNetwork(Map<String,Object> args) {
// Get the network
CyNetwork network = Cytoscape.getCurrentNetwork();
if (args.containsKey(NETWORK)) {
@@ -99,12 +109,7 @@
if (!netName.equals(CURRENT) &&
Cytoscape.getNetwork(netName) != null)
network = Cytoscape.getNetwork(netName);
}
-
- // OK, nodes or edges?
- if (args.containsKey(NODE) || args.containsKey(NODELIST))
- return getNodeList(command, args, network);
- else
- return getEdgeList(command, args, network);
+ return network;
}
static public List<GraphObject> getNodeList(String command,
Map<String,Object> args, CyNetwork network) {
Modified:
csplugins/trunk/ucsf/scooter/chemViz/src/chemViz/menus/NodeGraphicsMenus.java
===================================================================
---
csplugins/trunk/ucsf/scooter/chemViz/src/chemViz/menus/NodeGraphicsMenus.java
2012-10-10 22:33:48 UTC (rev 30649)
+++
csplugins/trunk/ucsf/scooter/chemViz/src/chemViz/menus/NodeGraphicsMenus.java
2012-10-11 01:14:53 UTC (rev 30650)
@@ -35,6 +35,7 @@
package chemViz.menus;
+import giny.model.GraphObject;
import giny.model.Node;
import giny.view.NodeView;
@@ -187,7 +188,7 @@
if (cmd.equals("chemViz.menu.nodegraphics.thisNode")) {
// Bring up the popup-style of depiction
- List<Node>nl = new ArrayList();
+ List<GraphObject>nl = new ArrayList();
nl.add(nodeContext.getNode());
addNodeGraphics(nl, settingsDialog);
} else if
(cmd.equals("chemViz.menu.nodegraphics.selectedNodes")) {
@@ -197,14 +198,14 @@
addNodeGraphics(Cytoscape.getCurrentNetwork().nodesList(), settingsDialog);
} else if
(cmd.equals("chemViz.menu.clearnodegraphics.thisNode")) {
// Bring up the popup-style of depiction
- List<Node>nl = new ArrayList();
+ List<GraphObject>nl = new ArrayList();
nl.add(nodeContext.getNode());
removeNodeGraphics(nl, settingsDialog);
} else if
(cmd.equals("chemViz.menu.clearnodegraphics.selectedNodes")) {
// Bring up the compound table
removeNodeGraphics(Cytoscape.getCurrentNetwork().getSelectedNodes(),
settingsDialog);
} else if
(cmd.equals("chemViz.menu.clearnodegraphics.allNodes")) {
- removeNodeGraphics((List<Node>)null, settingsDialog);
+ removeNodeGraphics((List<GraphObject>)null,
settingsDialog);
}
}
@@ -214,7 +215,7 @@
* @param selection the nodes we're going to pull the compounds from
* @param dialog the settings dialog
*/
- private void addNodeGraphics(Collection<Node>selection,
ChemInfoSettingsDialog dialog) {
+ private void addNodeGraphics(Collection<GraphObject>selection,
ChemInfoSettingsDialog dialog) {
CyNetworkView view = Cytoscape.getCurrentNetworkView();
CreateNodeGraphicsTask loader = null;
loader = CreateNodeGraphicsTask.getCustomGraphicsTask(view);
@@ -234,7 +235,7 @@
* all custom graphics are cleared
* @param dialog the settings dialog
*/
- private void removeNodeGraphics(Collection<Node>selection,
ChemInfoSettingsDialog dialog) {
+ private void removeNodeGraphics(Collection<GraphObject>selection,
ChemInfoSettingsDialog dialog) {
CyNetworkView view = Cytoscape.getCurrentNetworkView();
CreateNodeGraphicsTask loader = null;
loader = CreateNodeGraphicsTask.getCustomGraphicsTask(view);
Modified:
csplugins/trunk/ucsf/scooter/chemViz/src/chemViz/tasks/CreateNodeGraphicsTask.java
===================================================================
---
csplugins/trunk/ucsf/scooter/chemViz/src/chemViz/tasks/CreateNodeGraphicsTask.java
2012-10-10 22:33:48 UTC (rev 30649)
+++
csplugins/trunk/ucsf/scooter/chemViz/src/chemViz/tasks/CreateNodeGraphicsTask.java
2012-10-11 01:14:53 UTC (rev 30650)
@@ -81,6 +81,8 @@
private static HashMap<CyNetworkView, CreateNodeGraphicsTask>
customGraphicsMap = new HashMap();
private static final String CustomGraphicsAttribute = "__has2DGraphics";
Collection<GraphObject> nodeSelection;
+ List<Compound> compoundList;
+ CyNetworkView view;
ChemInfoSettingsDialog settingsDialog;
HashMap<NodeView, Compound> viewMap = null;
HashMap<NodeView, CustomGraphic> graphMap = null;
@@ -108,9 +110,9 @@
return v.booleanValue();
}
- public static List<Node> getCustomGraphicsNodes(CyNetworkView view) {
+ public static List<GraphObject> getCustomGraphicsNodes(CyNetworkView
view) {
CyAttributes nodeAttributes = Cytoscape.getNodeAttributes();
- List<Node> nList = new ArrayList();
+ List<GraphObject> nList = new ArrayList();
for (Object obj: view.getNetwork().nodesList()) {
Node node = (Node)obj;
if (nodeAttributes.hasAttribute(node.getIdentifier(),
CustomGraphicsAttribute) &&
@@ -133,16 +135,31 @@
* @param selection the group of graph objects that should be included
in the table
* @param dialog the settings dialog, which we use to pull the
attribute names that contain the compound descriptors
*/
- public CreateNodeGraphicsTask(Collection nodeSelection,
+ public CreateNodeGraphicsTask(Collection<GraphObject> nodeSelection,
ChemInfoSettingsDialog settingsDialog,
boolean remove) {
this.nodeSelection = nodeSelection;
this.canceled = false;
this.compoundCount = 0;
this.settingsDialog = settingsDialog;
this.removeCustomGraphics = remove;
- customGraphicsMap.put(Cytoscape.getCurrentNetworkView(), this);
+ this.view = Cytoscape.getCurrentNetworkView();
+ customGraphicsMap.put(view, this);
}
+ public CreateNodeGraphicsTask(List<Compound> compoundList,
CyNetworkView view,
+ ChemInfoSettingsDialog settingsDialog,
boolean remove) {
+ this.compoundList = compoundList;
+ this.nodeSelection = new ArrayList<GraphObject>();
+ for (Compound c: compoundList) {
+ nodeSelection.add(c.getSource());
+ }
+ this.canceled = false;
+ this.compoundCount = 0;
+ this.settingsDialog = settingsDialog;
+ this.removeCustomGraphics = remove;
+ customGraphicsMap.put(view, this);
+ }
+
public String getTitle() {
return "Creating Custom Node Graphics";
}
@@ -198,7 +215,6 @@
public void run() {
CyAttributes networkAttributes =
Cytoscape.getNetworkAttributes();
CyAttributes nodeAttributes = Cytoscape.getNodeAttributes();
- CyNetworkView view = Cytoscape.getCurrentNetworkView();
if (monitor != null)
monitor.setPercentCompleted(0);
@@ -228,12 +244,16 @@
return;
}
- totalObjects = nodeSelection.size();
objectCount = 0;
- List<Compound>cList = getCompounds(nodeSelection,
nodeAttributes,
-
settingsDialog.getCompoundAttributes("node",AttriType.smiles),
-
settingsDialog.getCompoundAttributes("node",AttriType.inchi));
+ List<Compound>cList = compoundList;
+ if (cList == null) {
+ cList = getCompounds(nodeSelection, nodeAttributes,
+
settingsDialog.getCompoundAttributes("node",AttriType.smiles),
+
settingsDialog.getCompoundAttributes("node",AttriType.inchi));
+ }
+ totalObjects = cList.size();
+
if (viewMap == null)
viewMap = new HashMap();
--
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.