Author: scooter
Date: 2011-09-16 18:31:19 -0700 (Fri, 16 Sep 2011)
New Revision: 26853
Modified:
csplugins/trunk/ucsf/scooter/structureViz/src/structureViz/actions/Chimera.java
csplugins/trunk/ucsf/scooter/structureViz/src/structureViz/actions/CyChimera.java
csplugins/trunk/ucsf/scooter/structureViz/src/structureViz/actions/OpenTask.java
csplugins/trunk/ucsf/scooter/structureViz/src/structureViz/model/Structure.java
csplugins/trunk/ucsf/scooter/structureViz/src/structureViz/ui/StructureVizMenuHandler.java
csplugins/trunk/ucsf/scooter/structureViz/src/structureViz/ui/StructureVizMenuListener.java
Log:
Updated to handle selection of parts of models. The next step is to
add Cytoscape selection listeners to select model parts automagically
Modified:
csplugins/trunk/ucsf/scooter/structureViz/src/structureViz/actions/Chimera.java
===================================================================
---
csplugins/trunk/ucsf/scooter/structureViz/src/structureViz/actions/Chimera.java
2011-09-17 00:39:29 UTC (rev 26852)
+++
csplugins/trunk/ucsf/scooter/structureViz/src/structureViz/actions/Chimera.java
2011-09-17 01:31:19 UTC (rev 26853)
@@ -154,6 +154,20 @@
}
/**
+ * Return true if this structure is currently open
+ *
+ * @param structure the Structure we're inquiring about
+ * @return true if open
+ */
+ public boolean isOpen(Structure structure) {
+ // Get the model number
+ int modelNumber = structure.modelNumber();
+ if (modelHash.containsKey(modelNumber))
+ return true;
+ return false;
+ }
+
+ /**
* Return our network view
*
* @return the network view we were created with
@@ -537,7 +551,7 @@
model.setStructure(s);
} else {
// This will return a new Structure if we don't
know about it
- Structure s =
CyChimera.findStructureForModel(networkView, model.getModelName());
+ Structure s =
CyChimera.findStructureForModel(networkView, model.getModelName(), true);
s.setModelNumber(model.getModelNumber(),
model.getSubModelNumber());
model.setStructure(s);
}
Modified:
csplugins/trunk/ucsf/scooter/structureViz/src/structureViz/actions/CyChimera.java
===================================================================
---
csplugins/trunk/ucsf/scooter/structureViz/src/structureViz/actions/CyChimera.java
2011-09-17 00:39:29 UTC (rev 26852)
+++
csplugins/trunk/ucsf/scooter/structureViz/src/structureViz/actions/CyChimera.java
2011-09-17 01:31:19 UTC (rev 26853)
@@ -109,7 +109,8 @@
* @param overNodeOnly only look for structures in the node we're over
* @return a list of Structures associated with this node
*/
- public static List<Structure>getSelectedStructures(NodeView nodeView,
boolean overNodeOnly) {
+ public static List<Structure>getSelectedStructures(NodeView nodeView,
+ boolean
overNodeOnly) {
List<Structure>structureList = new ArrayList<Structure>();
//get the network object; this contains the graph
CyNetwork network = Cytoscape.getCurrentNetwork();
@@ -118,7 +119,9 @@
//get the list of node attributes
cyAttributes = Cytoscape.getNodeAttributes();
//can't continue if any of these is null
- if (network == null || view == null || cyAttributes == null) {return
structureList;}
+ if (network == null || view == null || cyAttributes == null) {
+ return structureList;
+ }
List<NodeView> selectedNodes = null;
if (!overNodeOnly || nodeView == null)
@@ -250,9 +253,11 @@
*
* @param networkView the CyNetworkView that contains the nodes
* @param name the model name we're looking for
+ * @param create if true, create a structure if one doesn't exist
* @return the Structure object containing the name and referending the
node
*/
- public static Structure findStructureForModel(CyNetworkView
networkView, String name) {
+ public static Structure findStructureForModel(CyNetworkView
networkView,
+ String name, boolean
create) {
// Do we already know about this model?
if (pdbStructureMap.containsKey(name))
return pdbStructureMap.get(name);
@@ -260,6 +265,8 @@
if (smilesStructureMap.containsKey(name))
return smilesStructureMap.get(name);
+ if (!create) return null;
+
// Apparently not. Iterate over all of our nodes and get the
structures
cyAttributes = Cytoscape.getNodeAttributes();
for (CyNode node:
((List<CyNode>)networkView.getNetwork().nodesList())) {
@@ -267,7 +274,11 @@
if (sList != null && sList.size() > 0)
return sList.get(0);
}
- Structure s = Structure.getStructure(name, (CyNode)null,
Structure.StructureType.PDB_MODEL);
+
+ // We don't know anything about this structure -- assume it's a
PDB file loaded
+ // into Chimera
+ Structure s = Structure.getStructure(name, (CyNode)null,
+
Structure.StructureType.PDB_MODEL);
pdbStructureMap.put(name, s);
return s;
}
@@ -359,7 +370,7 @@
for (ChimeraModel model: chimeraModels) {
if (model == null) continue;
Structure st = model.getStructure();
- if (!modelsToSelect.containsKey(model)) {
+ if (modelsToSelect.containsKey(model)) {
// Deselect everything in this structure
graphObjectList.addAll(st.getGraphObjectList());
}
@@ -450,7 +461,8 @@
}
private static List<Structure> getStructures(CyNode node,
- List<Structure>
structureList, String matchName) {
+ List<Structure>
structureList,
+ String matchName) {
if (structureList == null) {
structureList = new ArrayList<Structure>();
}
@@ -500,7 +512,8 @@
return structureList;
}
- private static void setSelectedState(CyNetworkView view,
List<GraphObject> goList, boolean state) {
+ private static void setSelectedState(CyNetworkView view,
List<GraphObject> goList,
+ boolean state) {
for (GraphObject obj: goList) {
if (obj instanceof Node) {
// Handle secondary paint??
Modified:
csplugins/trunk/ucsf/scooter/structureViz/src/structureViz/actions/OpenTask.java
===================================================================
---
csplugins/trunk/ucsf/scooter/structureViz/src/structureViz/actions/OpenTask.java
2011-09-17 00:39:29 UTC (rev 26852)
+++
csplugins/trunk/ucsf/scooter/structureViz/src/structureViz/actions/OpenTask.java
2011-09-17 01:31:19 UTC (rev 26853)
@@ -59,24 +59,19 @@
structList.add((Structure)userData);
}
- // Get the list of structures we already have open
- List<Structure>openStructs = chimera.getOpenStructs();
-
// Send initial commands
for (Structure structure: structList) {
- boolean open = false;
String structureName = structure.name();
- for (Structure openStructure: openStructs) {
- if (structureName.equals(openStructure.name()))
{
- // Map the model numbers
-
structure.setModelNumber(openStructure.modelNumber(),
openStructure.subModelNumber());
- open = true;
- break;
- }
+ // System.out.println("Looking at structure
"+structure.name());
+ // See if this structure is already open somewhere
+ Structure s = CyChimera.findStructureForModel(null,
structureName, false);
+ if (s != null) {
+ // System.out.println("Found existing
structure: "+s.toString());
+ s.addStructure(structure);
+ structure = s;
}
- if (open == false) {
+ if (!chimera.isOpen(structure))
chimera.open(structure);
- }
}
}
}
Modified:
csplugins/trunk/ucsf/scooter/structureViz/src/structureViz/model/Structure.java
===================================================================
---
csplugins/trunk/ucsf/scooter/structureViz/src/structureViz/model/Structure.java
2011-09-17 00:39:29 UTC (rev 26852)
+++
csplugins/trunk/ucsf/scooter/structureViz/src/structureViz/model/Structure.java
2011-09-17 01:31:19 UTC (rev 26853)
@@ -33,6 +33,7 @@
package structureViz.model;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -51,7 +52,7 @@
static Map<String, Structure> structureMap = new HashMap<String,
Structure>();
String structureName;
Map<GraphObject, List<String>> residueMap;
- List<GraphObject> graphObjectList;
+ Map<GraphObject, GraphObject> graphObjectMap;
int modelNumber;
int subModelNumber;
StructureType type;
@@ -65,9 +66,12 @@
*/
public static int getNextModel() {return nextModel++;}
- public static Structure getStructure(String name, CyNode node,
StructureType type) {
+ public static Structure getStructure(String name, CyNode node,
+ StructureType type) {
+ // System.out.println("Getting structure for "+name);
if (structureMap.containsKey(name)) {
Structure s = structureMap.get(name);
+ // System.out.println("Already have it: "+s.toString());
s.addGraphObject(node);
return s;
}
@@ -80,24 +84,29 @@
* @param name the name of the structure
* @param node the CyNode that this structure points to
*/
- protected Structure (String name, CyNode node, StructureType type) {
- this(name, new ArrayList<GraphObject>(), type);
+ protected Structure (String name, GraphObject node, StructureType type)
{
+ this(name, new HashMap<GraphObject, GraphObject>(), type);
if (node != null)
this.setNode(node);
}
- protected Structure (String name, List<GraphObject> nodeList,
StructureType type) {
+ protected Structure (String name, Map<GraphObject, GraphObject> goMap,
+ StructureType type) {
this.structureName = name;
this.modelNumber = nextModel;
this.subModelNumber = 0;
this.residueMap = new HashMap<GraphObject, List<String>>();
this.type = type;
- this.graphObjectList = nodeList;
+ if (goMap != null)
+ this.graphObjectMap = goMap;
+ else
+ this.graphObjectMap = new HashMap<GraphObject,
GraphObject>();
+ structureMap.put(name,this);
}
public Structure makeSubModel(int subModelNumber) {
- Structure st = new Structure(this.structureName,
this.graphObjectList, this.type);
- st.setModelNumber(this.modelNumber, subModelNumber);
+ Structure st = new Structure(structureName, graphObjectMap,
type);
+ st.setModelNumber(modelNumber, subModelNumber);
return st;
}
@@ -114,8 +123,10 @@
* @return the CyNode this structure is an attribute of
*/
public CyNode node() {
- if (graphObjectList.get(0) instanceof CyNode)
- return (CyNode)graphObjectList.get(0);
+ for (GraphObject obj: graphObjectMap.keySet()) {
+ if (obj instanceof CyNode)
+ return (CyNode)obj;
+ }
return null;
}
@@ -124,23 +135,45 @@
*
* @param node the CyNode this structure is an attribute of
*/
- public void setNode(CyNode node) {this.graphObjectList.add(0,node);}
+ public void setNode(GraphObject node) {
+ graphObjectMap.put(node,node);
+ }
/**
* Add a CyNode or CyEdge to the list of graph objects this structure
is associated with
*
* @param node the GraphObject this structure is an attribute of
*/
- public void addGraphObject(GraphObject go)
{this.graphObjectList.add(go);}
+ public void addGraphObject(GraphObject go) {
+ // System.out.println("Adding "+go.getIdentifier()+" to
"+this.toString());
+ if (!graphObjectMap.containsKey(go))
+ graphObjectMap.put(go, go);
+ }
/**
+ * Add the Objects and residues from a Structure to this Structure
+ *
+ * @param structure the structure we're adding
+ */
+ public void addStructure(Structure structure) {
+ // Add any graph objects...
+ for (GraphObject obj: structure.getGraphObjectList()) {
+ if (!graphObjectMap.containsKey(obj)) {
+ // New graph object -- add the object and it's
residues
+ graphObjectMap.put(obj, obj);
+ residueMap.put(obj,
structure.getResidueList(obj));
+ }
+ }
+ }
+
+ /**
* Remove a Graph Object from the list of objects this structure is
associated with
*
* @param node the Graph Object to remove from this structure's list
*/
public void removeGraphObject(GraphObject go) {
- if (graphObjectList.contains(go))
- graphObjectList.remove(go);
+ if (graphObjectMap.containsKey(go))
+ graphObjectMap.remove(go);
}
/**
@@ -148,7 +181,9 @@
*
* @return objList the GraphObjects this structure is an attribute of
*/
- public List<GraphObject> getGraphObjectList() {return
this.graphObjectList;}
+ public List<GraphObject> getGraphObjectList() {
+ return new ArrayList<GraphObject>(graphObjectMap.values());
+ }
/**
* Get the list of GraphObjects for this structure that match a list
@@ -162,7 +197,7 @@
if (residueList == null || residueList.size() == 0)
return goList;
- for (GraphObject obj: graphObjectList) {
+ for (GraphObject obj: graphObjectMap.values()) {
if (residuesMatch(obj, residueList)) {
// System.out.println("Found match for
"+obj.getIdentifier());
goList.add(obj);
@@ -203,12 +238,18 @@
* @return identifier of the Graph Object as a String
*/
public String getIdentifier() {
- if (graphObjectList == null || graphObjectList.size() == 0)
+ if (graphObjectMap == null || graphObjectMap.size() == 0)
return "(none)";
- else if (graphObjectList.size() == 1)
- return graphObjectList.get(0).getIdentifier();
- else
- return constructListOfGraphObjects(graphObjectList);
+ else if (graphObjectMap.size() == 1) {
+ // Weird construct, but no easy way to get the value...
+ String id = "";
+ for (GraphObject obj: graphObjectMap.keySet()) {
+ id = obj.getIdentifier();
+ break;
+ }
+ return id;
+ }
+ return constructListOfGraphObjects(graphObjectMap.values());
}
/**
@@ -312,7 +353,7 @@
residueMap.put(obj, residueList);
}
- private String constructListOfGraphObjects(List<GraphObject> objList) {
+ private String constructListOfGraphObjects(Collection<GraphObject>
objList) {
String list = null;
for (GraphObject obj: objList) {
if (list == null)
@@ -323,7 +364,8 @@
return list;
}
- private boolean residuesMatch(GraphObject obj,
List<ChimeraResidue>residueList) {
+ private boolean residuesMatch(GraphObject obj,
+ List<ChimeraResidue>residueList) {
if (!residueMap.containsKey(obj))
return true;
Modified:
csplugins/trunk/ucsf/scooter/structureViz/src/structureViz/ui/StructureVizMenuHandler.java
===================================================================
---
csplugins/trunk/ucsf/scooter/structureViz/src/structureViz/ui/StructureVizMenuHandler.java
2011-09-17 00:39:29 UTC (rev 26852)
+++
csplugins/trunk/ucsf/scooter/structureViz/src/structureViz/ui/StructureVizMenuHandler.java
2011-09-17 01:31:19 UTC (rev 26853)
@@ -56,9 +56,12 @@
import cytoscape.view.CytoscapeDesktop;
import cytoscape.view.CyNetworkView;
+import giny.model.GraphObject;
+
// structureViz imports
import structureViz.StructureViz;
import structureViz.actions.Chimera;
+import structureViz.actions.CyChimera;
import structureViz.actions.OpenTask;
import structureViz.model.Structure;
import structureViz.ui.ModelNavigatorDialog;
@@ -77,6 +80,7 @@
private int command;
private static boolean showModelWarning = true;
private Object userData = null; // Either a Structure or an ArrayList
+ private GraphObject context = null; // Usually a node or edge context
private CyLogger logger;
private OpenTask openTask = null;
@@ -86,6 +90,14 @@
this.logger = logger;
}
+ public StructureVizMenuHandler(int command, Object userData,
+ GraphObject context, CyLogger logger) {
+ this.command = command;
+ this.userData = userData;
+ this.context = context;
+ this.logger = logger;
+ }
+
/**
* This method is called when the user selects the menu item.
*/
@@ -185,8 +197,9 @@
String ident = node.getIdentifier();
if (ident.startsWith("gi"))
ident = ident.substring(2);
- Structure struct = Structure.getStructure(ident, node,
Structure.StructureType.MODBASE_MODEL);
- userData = struct;
+ Structure structure = Structure.getStructure(ident, node,
+
Structure.StructureType.MODBASE_MODEL);
+ userData = structure;
openAction(ident, null, false);
}
@@ -205,12 +218,12 @@
* structures.
*/
private void selectResiduesAction() {
- List<Structure> structuresList = (List<Structure>)userData;
+ List<Structure>structuresList = (List<Structure>)userData;
String command = "select ";
for (Structure structure: structuresList) {
// Select the residues
- List<String> residueL = structure.getResidueList();
+ List<String> residueL =
structure.getResidueList(context);
if (residueL == null || residueL.size() == 0) continue;
// OK, we have a residue list, make sure the structure
is open
@@ -282,7 +295,8 @@
/**
* Open a pdb model in Chimera
*/
- private void openAction(String commandLabel, Object dataOverride,
boolean wait) {
+ private void openAction(String commandLabel, Object dataOverride,
+ boolean wait) {
// Make sure chimera is launched
if (chimera == null || !chimera.isLaunched())
chimera = launchChimera();
Modified:
csplugins/trunk/ucsf/scooter/structureViz/src/structureViz/ui/StructureVizMenuListener.java
===================================================================
---
csplugins/trunk/ucsf/scooter/structureViz/src/structureViz/ui/StructureVizMenuListener.java
2011-09-17 00:39:29 UTC (rev 26852)
+++
csplugins/trunk/ucsf/scooter/structureViz/src/structureViz/ui/StructureVizMenuListener.java
2011-09-17 01:31:19 UTC (rev 26853)
@@ -130,7 +130,9 @@
if (structures.size() > 0) {
JMenuItem item = new JMenuItem("Select
residues");
StructureVizMenuHandler l =
- new
StructureVizMenuHandler(StructureViz.SELECTRES, structures, logger);
+ new
StructureVizMenuHandler(StructureViz.SELECTRES,
+
structures, (CyNode)overNode.getNode(),
+
logger);
item.addActionListener(l);
m.add(item);
}
--
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.