Author: rodche
Date: 2012-02-01 12:08:28 -0800 (Wed, 01 Feb 2012)
New Revision: 28177

Modified:
   
core3/impl/trunk/biopax-impl/src/main/java/org/cytoscape/biopax/internal/BioPaxMapper.java
   
core3/impl/trunk/biopax-impl/src/main/java/org/cytoscape/biopax/internal/BioPaxReaderTask.java
   
core3/impl/trunk/biopax-impl/src/main/java/org/cytoscape/biopax/internal/BioPaxReaderTaskFactory.java
   
core3/impl/trunk/biopax-impl/src/main/java/org/cytoscape/biopax/internal/CyActivator.java
   
core3/impl/trunk/biopax-impl/src/main/java/org/cytoscape/biopax/internal/action/BioPaxViewTracker.java
   
core3/impl/trunk/biopax-impl/src/main/java/org/cytoscape/biopax/internal/util/BioPaxVisualStyleUtil.java
Log:
Updated BioPAX visual style (node, arrow shapes, etc., which was broken since 
ported to Cy3). Also fixed a NPE bug in the mapper, etc.

Modified: 
core3/impl/trunk/biopax-impl/src/main/java/org/cytoscape/biopax/internal/BioPaxMapper.java
===================================================================
--- 
core3/impl/trunk/biopax-impl/src/main/java/org/cytoscape/biopax/internal/BioPaxMapper.java
  2012-02-01 19:43:07 UTC (rev 28176)
+++ 
core3/impl/trunk/biopax-impl/src/main/java/org/cytoscape/biopax/internal/BioPaxMapper.java
  2012-02-01 20:08:28 UTC (rev 28177)
@@ -3,14 +3,7 @@
 import java.awt.geom.Rectangle2D;
 import java.awt.image.BufferedImage;
 import java.io.ByteArrayOutputStream;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.Stack;
+import java.util.*;
 
 import org.apache.commons.lang.StringUtils;
 import org.biopax.paxtools.controller.AbstractTraverser;
@@ -20,26 +13,8 @@
 import org.biopax.paxtools.io.SimpleIOHandler;
 import org.biopax.paxtools.model.BioPAXElement;
 import org.biopax.paxtools.model.Model;
-import org.biopax.paxtools.model.level3.Catalysis;
-import org.biopax.paxtools.model.level3.CellularLocationVocabulary;
-import org.biopax.paxtools.model.level3.Complex;
-import org.biopax.paxtools.model.level3.Control;
-import org.biopax.paxtools.model.level3.ControlType;
-import org.biopax.paxtools.model.level3.Controller;
-import org.biopax.paxtools.model.level3.Conversion;
-import org.biopax.paxtools.model.level3.Entity;
-import org.biopax.paxtools.model.level3.Interaction;
-import org.biopax.paxtools.model.level3.Pathway;
-import org.biopax.paxtools.model.level3.PhysicalEntity;
+import org.biopax.paxtools.model.level3.*;
 import org.biopax.paxtools.model.level3.Process;
-import org.biopax.paxtools.model.level3.PublicationXref;
-import org.biopax.paxtools.model.level3.RelationshipTypeVocabulary;
-import org.biopax.paxtools.model.level3.RelationshipXref;
-import org.biopax.paxtools.model.level3.SimplePhysicalEntity;
-import org.biopax.paxtools.model.level3.Stoichiometry;
-import org.biopax.paxtools.model.level3.UnificationXref;
-import org.biopax.paxtools.model.level3.XReferrable;
-import org.biopax.paxtools.model.level3.Xref;
 import org.biopax.paxtools.util.ClassFilterSet;
 import org.biopax.paxtools.util.Filter;
 import org.cytoscape.biopax.internal.util.AttributeUtil;
@@ -53,7 +28,6 @@
 import org.cytoscape.model.CyNetworkFactory;
 import org.cytoscape.model.CyNode;
 import org.cytoscape.model.CyRow;
-import org.cytoscape.view.model.CyNetworkView;
 import org.cytoscape.work.TaskMonitor;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -204,6 +178,11 @@
                createInteractionEdges(network);
                createComplexEdges(network);
                
+               // TODO create pathwayComponent edges (requires pathway nodes)?
+               
+               // create PE->memberPE edges (Arghhh!)?
+               createMemberEdges(network);
+               
                // Finally, set network attributes:
                
                // name
@@ -229,6 +208,21 @@
        }
 
        
+       private void createMemberEdges(CyNetwork network) {
+               // for each PE,
+               for (PhysicalEntity par : 
model.getObjects(PhysicalEntity.class)) {
+                       CyNode cyParentNode = uriToCyNodeMap.get(par);
+                       // for each its member PE, add the directed edge
+                       for (PhysicalEntity member : 
par.getMemberPhysicalEntity()) 
+                       {
+                               CyNode cyMemberNode = 
uriToCyNodeMap.get(member);
+                               CyEdge edge = network.addEdge(cyParentNode, 
cyMemberNode, true);
+                               AttributeUtil.set(network, edge, 
BIOPAX_EDGE_TYPE, "member", String.class);
+                       }
+               }
+       }
+
+
        private void createEntityNodes(CyNetwork network) {
                taskMonitor.setStatusMessage("Creating nodes (first pass)...");
                taskMonitor.setProgress(0);
@@ -236,9 +230,12 @@
                int i = 0; //progress counter
                Set<Entity> entities = model.getObjects(Entity.class);
                for(Entity bpe: entities) {     
-                       // skip for pathways
-                       if(bpe instanceof Pathway)
-                               continue;
+                       // do not make nodes for top/main pathways
+                       if(bpe instanceof Pathway) {
+                               if(bpe.getParticipantOf().isEmpty()
+                                       && 
((Process)bpe).getPathwayComponentOf().isEmpty())
+                                       continue;
+                       }
                        
                        //  Create node symbolizing the interaction
                        CyNode node = network.addNode();
@@ -343,7 +340,19 @@
        {       
                // Note: getCyNode also assigns cellular location attribute...
                CyNode nodeA = uriToCyNodeMap.get(bpeA);
+               if(nodeA == null) {
+                       log.debug("linkNodes: no node was created for " 
+                               + bpeA.getModelInterface() + " " + 
bpeA.getRDFId());
+                       return; //e.g., we do not create any pathway nodes 
currently...
+               }
+               
                CyNode nodeB = uriToCyNodeMap.get(bpeB);
+               if(nodeB == null) {
+                       log.debug("linkNodes: no node was created for " 
+                                       + bpeB.getModelInterface() + " " + 
bpeB.getRDFId());
+                       return; //e.g., we do not create any pathway nodes 
currently...
+               }
+               
                CyEdge edge = null;
                if (type.equals("right") || type.equals("cofactor")
                                || type.equals("participant")) {
@@ -533,6 +542,9 @@
                // add xref ids per database and per xref class
                List<Xref> xList = BioPaxUtil.getXRefs(resource, Xref.class);
                for (Xref link : xList) {
+                       if(link.getDb() == null)
+                               continue; // too bad (data issue...); skip it
+                       
                        // per db -
                        String key = BIOPAX_XREF_PREFIX + 
link.getDb().toUpperCase();
                        // Set individual XRefs; Max of 1 per database.
@@ -541,7 +553,6 @@
                                AttributeUtil.set(network, node, key, 
link.getId(), String.class);
                        }
                        
-
                        StringBuffer temp = new StringBuffer();
                        
                        if(!"CPATH".equalsIgnoreCase(link.getDb()))
@@ -589,8 +600,7 @@
        {
                Filter<PropertyEditor> filter = new Filter<PropertyEditor>() {
                        @Override
-                       // skips for entity-range properties 
-                       // (which map to edges rather than attributes!),
+                       // skips for entity-range properties (which map to 
edges rather than attributes!),
                        // and several utility classes range ones 
                        // (for which we do not want generate attributes or do 
another way)
                        public boolean filter(PropertyEditor editor) {
@@ -904,92 +914,4 @@
        }
 
        
-       public static void customNodes(CyNetworkView networkView) {
-               // grab node attributes
-               CyNetwork cyNetwork = networkView.getModel();
-
-               // iterate through the nodes
-               Iterator<CyNode> nodesIt = cyNetwork.getNodeList().iterator();
-               if (nodesIt.hasNext()) {
-                       // grab the node
-                       CyNode node = nodesIt.next();
-
-                       // get chemical modifications
-                       int count = 0;
-                       boolean isPhosphorylated = false;
-                       // TODO: MultiHashMap
-//                     MultiHashMapDefinition mhmdef = 
nodeAttributes.getMultiHashMapDefinition();
-//
-//                     if 
(mhmdef.getAttributeValueType(BIOPAX_CHEMICAL_MODIFICATIONS_MAP) != -1) {
-//                             MultiHashMap mhmap = 
nodeAttributes.getMultiHashMap();
-//                             CountedIterator modsIt = 
mhmap.getAttributeKeyspan(node.getIdentifier(),
-//                               BIOPAX_CHEMICAL_MODIFICATIONS_MAP, null);
-//
-//                             // do we have phosphorylation ?
-//                             while (modsIt.hasNext()) {
-//                                     String modification = (String) 
modsIt.next();
-//
-//                                     if 
(modification.equals(BioPaxUtil.PHOSPHORYLATION_SITE)) {
-//                                             isPhosphorylated = true;
-//
-//                                             Object[] key = { 
BioPaxUtil.PHOSPHORYLATION_SITE };
-//                                             String countStr = (String) 
mhmap.getAttributeValue(node.getIdentifier(),
-//                            BIOPAX_CHEMICAL_MODIFICATIONS_MAP, key);
-//                                             count = ((Integer) 
Integer.valueOf(countStr)).intValue();
-//
-//                                             break;
-//                                     }
-//                             }
-//                     }
-
-                       // if phosphorylated, add custom node
-                       if (isPhosphorylated) {
-                               addCustomShapes(networkView, node, 
"PHOSPHORYLATION_GRAPHICS", count);
-                       }
-               }
-       }
-
-
-       /**
-        * Based on given arguments, adds proper custom node shape to node.
-        */
-       private static void addCustomShapes(CyNetworkView networkView, CyNode 
node, String shapeType,
-                                           int modificationCount) {
-               // TODO: Custom graphics
-//             // create refs to help views
-//             CyNetwork cyNetwork = networkView.getModel();
-//             View<CyNode> nodeView = networkView.getNodeView(node);
-//             DNodeView dingNodeView = (DNodeView) nodeView;
-//
-//             // remove existing custom nodes
-//             Iterator<CustomGraphic> it = 
dingNodeView.customGraphicIterator();
-//             while ( it.hasNext() ) {
-//                     dingNodeView.removeCustomGraphic( it.next() );
-//             }
-//
-//             for (int lc = 0; lc < modificationCount; lc++) {
-//                     // set image
-//                     BufferedImage image = null;
-//
-//                     if (shapeType.equals(PHOSPHORYLATION_GRAPHICS)) {
-//                             image = (cyNetwork.isSelected(node)) ? 
customPhosGraphics[lc] : phosNode;
-//                     }
-//
-//                     // set rect
-//                     Rectangle2D rect = getCustomShapeRect(image, lc);
-//
-//                     // create our texture paint
-//                     Paint paint = null;
-//
-//                     try {
-//                             paint = new java.awt.TexturePaint(image, rect);
-//                     } catch (Exception exc) {
-//                             paint = java.awt.Color.black;
-//                     }
-//
-//                     // add the graphic
-//                     dingNodeView.addCustomGraphic(rect, paint, 
NodeDetails.ANCHOR_CENTER);
-//             }
-       }
-       
 }

Modified: 
core3/impl/trunk/biopax-impl/src/main/java/org/cytoscape/biopax/internal/BioPaxReaderTask.java
===================================================================
--- 
core3/impl/trunk/biopax-impl/src/main/java/org/cytoscape/biopax/internal/BioPaxReaderTask.java
      2012-02-01 19:43:07 UTC (rev 28176)
+++ 
core3/impl/trunk/biopax-impl/src/main/java/org/cytoscape/biopax/internal/BioPaxReaderTask.java
      2012-02-01 20:08:28 UTC (rev 28177)
@@ -1,18 +1,23 @@
 package org.cytoscape.biopax.internal;
 
+import static org.cytoscape.biopax.internal.BioPaxMapper.BIOPAX_ENTITY_TYPE;
+
 import java.io.InputStream;
 
 import org.biopax.paxtools.controller.ModelUtils;
 import org.biopax.paxtools.model.Model;
-import org.cytoscape.biopax.internal.action.BioPaxViewTracker;
 import org.cytoscape.biopax.internal.util.BioPaxUtil;
 import org.cytoscape.biopax.internal.util.BioPaxVisualStyleUtil;
 import org.cytoscape.io.read.CyNetworkReader;
 import org.cytoscape.model.CyNetwork;
 import org.cytoscape.model.CyNetworkFactory;
+import org.cytoscape.model.CyNode;
+import org.cytoscape.model.CyRow;
 import org.cytoscape.session.CyNetworkNaming;
 import org.cytoscape.view.model.CyNetworkView;
 import org.cytoscape.view.model.CyNetworkViewFactory;
+import org.cytoscape.view.model.View;
+import org.cytoscape.view.presentation.property.RichVisualLexicon;
 import org.cytoscape.view.vizmap.VisualMappingManager;
 import org.cytoscape.view.vizmap.VisualStyle;
 import org.cytoscape.work.AbstractTask;
@@ -36,7 +41,6 @@
        private final CyNetworkNaming naming;
        private final VisualMappingManager mappingManager;
        private final BioPaxVisualStyleUtil bioPaxVisualStyleUtil;
-       private final BioPaxViewTracker biopaxViewTracker;
 
        private InputStream stream;
 
@@ -61,15 +65,14 @@
         */
        public BioPaxReaderTask(InputStream stream, String inputName, 
                        CyNetworkFactory networkFactory, CyNetworkViewFactory 
viewFactory, 
-                       CyNetworkNaming naming, BioPaxViewTracker 
networkListener, 
-                       VisualMappingManager mappingManager, 
BioPaxVisualStyleUtil bioPaxVisualStyleUtil) 
+                       CyNetworkNaming naming, VisualMappingManager 
mappingManager, 
+                       BioPaxVisualStyleUtil bioPaxVisualStyleUtil) 
        {
                this.stream = stream;
                this.inputName = inputName;
                this.networkFactory = networkFactory;
                this.viewFactory = viewFactory;
                this.naming = naming;
-               this.biopaxViewTracker = networkListener;
                this.mappingManager = mappingManager;
                this.bioPaxVisualStyleUtil = bioPaxVisualStyleUtil;
        }
@@ -143,12 +146,15 @@
        public CyNetworkView buildCyNetworkView(CyNetwork network) {
                CyNetworkView view = viewFactory.createNetworkView(network);
                
-               //  Set-up the BioPax Visual Style
-               VisualStyle bioPaxVisualStyle = 
bioPaxVisualStyleUtil.getBioPaxVisualStyle();
-//        // set tooltips
-//             BioPaxVisualStyleUtil.setNodeToolTips(view);
-//             // set style
-               mappingManager.setVisualStyle(bioPaxVisualStyle, view);
+               // now everything's done in the listener (BioPaxViewTracker)
+               
+//             // Set-up the BioPax Visual Style
+//             VisualStyle bioPaxVisualStyle = 
bioPaxVisualStyleUtil.getBioPaxVisualStyle();
+//      // set tooltips
+//             setNodeToolTips(view);
+               
+               // set style
+//             mappingManager.setVisualStyle(bioPaxVisualStyle, view);
 
                //  Set up BP UI
 //             CytoscapeWrapper.initBioPaxPlugInUI();

Modified: 
core3/impl/trunk/biopax-impl/src/main/java/org/cytoscape/biopax/internal/BioPaxReaderTaskFactory.java
===================================================================
--- 
core3/impl/trunk/biopax-impl/src/main/java/org/cytoscape/biopax/internal/BioPaxReaderTaskFactory.java
       2012-02-01 19:43:07 UTC (rev 28176)
+++ 
core3/impl/trunk/biopax-impl/src/main/java/org/cytoscape/biopax/internal/BioPaxReaderTaskFactory.java
       2012-02-01 20:08:28 UTC (rev 28177)
@@ -2,7 +2,6 @@
 
 import java.io.InputStream;
 
-import org.cytoscape.biopax.internal.action.BioPaxViewTracker;
 import org.cytoscape.biopax.internal.util.BioPaxVisualStyleUtil;
 import org.cytoscape.io.CyFileFilter;
 import org.cytoscape.io.read.InputStreamTaskFactory;
@@ -18,7 +17,6 @@
        private final CyNetworkFactory networkFactory;
        private final CyNetworkViewFactory viewFactory;
        private final CyNetworkNaming naming;
-       private final BioPaxViewTracker networkTracker;
 
        private InputStream inputStream;
        private String inputName;
@@ -26,13 +24,12 @@
        private BioPaxVisualStyleUtil bioPaxVisualStyleUtil;
 
        public BioPaxReaderTaskFactory(CyFileFilter filter, CyNetworkFactory 
networkFactory, 
-                       CyNetworkViewFactory viewFactory, CyNetworkNaming 
naming, BioPaxViewTracker networkTracker, 
+                       CyNetworkViewFactory viewFactory, CyNetworkNaming 
naming,
                        VisualMappingManager mappingManager, 
BioPaxVisualStyleUtil bioPaxVisualStyleUtil) {
                this.filter = filter;
                this.networkFactory = networkFactory;
                this.viewFactory = viewFactory;
                this.naming = naming;
-               this.networkTracker = networkTracker;
                this.mappingManager = mappingManager;
                this.bioPaxVisualStyleUtil = bioPaxVisualStyleUtil;
                this.inputName = "BioPAX_Network"; //default name fallback
@@ -42,7 +39,7 @@
        public TaskIterator createTaskIterator() {
                BioPaxReaderTask task = new BioPaxReaderTask(
                                inputStream, inputName, networkFactory, 
viewFactory, naming, 
-                               networkTracker, mappingManager, 
bioPaxVisualStyleUtil);
+                               mappingManager, bioPaxVisualStyleUtil);
                return new TaskIterator(task);
        }
 

Modified: 
core3/impl/trunk/biopax-impl/src/main/java/org/cytoscape/biopax/internal/CyActivator.java
===================================================================
--- 
core3/impl/trunk/biopax-impl/src/main/java/org/cytoscape/biopax/internal/CyActivator.java
   2012-02-01 19:43:07 UTC (rev 28176)
+++ 
core3/impl/trunk/biopax-impl/src/main/java/org/cytoscape/biopax/internal/CyActivator.java
   2012-02-01 20:08:28 UTC (rev 28177)
@@ -7,7 +7,6 @@
 import org.cytoscape.io.util.StreamUtil;
 import org.cytoscape.session.CyNetworkNaming;
 import org.cytoscape.application.events.SetCurrentNetworkViewListener;
-import org.cytoscape.application.swing.CyAction;
 import org.cytoscape.application.swing.CySwingApplication;
 import org.cytoscape.application.CyApplicationManager;
 import org.cytoscape.view.vizmap.VisualMappingFunctionFactory;
@@ -70,8 +69,8 @@
                BioPaxContainer bioPaxContainer = new 
BioPaxContainer(launchExternalBrowser,cyApplicationManagerRef,cyNetworkViewManagerRef,bioPaxDetailsPanel,cySwingApplicationRef);
                BioPaxVisualStyleUtil bioPaxVisualStyleUtil = new 
BioPaxVisualStyleUtil(visualStyleFactoryRef,visualMappingManagerRef,discreteMappingFunctionFactoryRef,passthroughMappingFunctionFactoryRef);
                
-               BioPaxViewTracker bioPaxViewTracker = new 
BioPaxViewTracker(bioPaxDetailsPanel,bioPaxContainer, cyApplicationManagerRef);
-               InputStreamTaskFactory inputStreamTaskFactory = new 
BioPaxReaderTaskFactory(bioPaxFilter,cyNetworkFactoryRef,cyNetworkViewFactoryRef,cyNetworkNamingRef,bioPaxViewTracker,visualMappingManagerRef,bioPaxVisualStyleUtil);
+               BioPaxViewTracker bioPaxViewTracker = new 
BioPaxViewTracker(bioPaxDetailsPanel,bioPaxContainer, cyApplicationManagerRef, 
visualMappingManagerRef, bioPaxVisualStyleUtil);
+               InputStreamTaskFactory inputStreamTaskFactory = new 
BioPaxReaderTaskFactory(bioPaxFilter,cyNetworkFactoryRef,cyNetworkViewFactoryRef,cyNetworkNamingRef,visualMappingManagerRef,bioPaxVisualStyleUtil);
                CytoPanelComponent cytoPanelComponent = new 
BioPaxCytoPanelComponent(bioPaxContainer);
                ExportAsBioPAXAction exportAsBioPAXAction = new 
ExportAsBioPAXAction(fileUtilRef, cyApplicationManagerRef, bioPaxFilter, 
taskManagerRef);
                

Modified: 
core3/impl/trunk/biopax-impl/src/main/java/org/cytoscape/biopax/internal/action/BioPaxViewTracker.java
===================================================================
--- 
core3/impl/trunk/biopax-impl/src/main/java/org/cytoscape/biopax/internal/action/BioPaxViewTracker.java
      2012-02-01 19:43:07 UTC (rev 28176)
+++ 
core3/impl/trunk/biopax-impl/src/main/java/org/cytoscape/biopax/internal/action/BioPaxViewTracker.java
      2012-02-01 20:08:28 UTC (rev 28177)
@@ -1,59 +1,37 @@
-// $Id: BioPaxViewTracker.java,v 1.13 2006/06/15 22:02:52 grossb Exp $
-//------------------------------------------------------------------------------
-/** Copyright (c) 2006 Memorial Sloan-Kettering Cancer Center.
- **
- ** Code written by: Ethan Cerami
- ** Authors: Ethan Cerami, Gary Bader, Chris Sander
- **
- ** 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 2.1 of the License, or
- ** 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.  The software and
- ** documentation provided hereunder is on an "as is" basis, and
- ** Memorial Sloan-Kettering Cancer Center
- ** has no obligations to provide maintenance, support,
- ** updates, enhancements or modifications.  In no event shall
- ** Memorial Sloan-Kettering Cancer Center
- ** be liable to any party for direct, indirect, special,
- ** incidental or consequential damages, including lost profits, arising
- ** out of the use of this software and its documentation, even if
- ** Memorial Sloan-Kettering Cancer Center
- ** has been advised of the possibility of such damage.  See
- ** the GNU Lesser General Public License for more details.
- **
- ** You should have received a copy of the GNU Lesser General Public License
- ** along with this library; if not, write to the Free Software Foundation,
- ** Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
- **/
 package org.cytoscape.biopax.internal.action;
 
+import static org.cytoscape.biopax.internal.BioPaxMapper.BIOPAX_ENTITY_TYPE;
+
+import java.util.Iterator;
+
 import org.cytoscape.application.CyApplicationManager;
 import org.cytoscape.application.events.SetCurrentNetworkViewEvent;
 import org.cytoscape.application.events.SetCurrentNetworkViewListener;
-import org.cytoscape.biopax.internal.BioPaxMapper;
 import org.cytoscape.biopax.internal.view.BioPaxContainer;
 import org.cytoscape.biopax.internal.util.BioPaxUtil;
+import org.cytoscape.biopax.internal.util.BioPaxVisualStyleUtil;
 import org.cytoscape.biopax.internal.view.BioPaxDetailsPanel;
 import org.cytoscape.model.CyNetwork;
 import org.cytoscape.model.CyNode;
+import org.cytoscape.model.CyRow;
 import org.cytoscape.model.events.RowsSetEvent;
 import org.cytoscape.model.events.RowsSetListener;
 import org.cytoscape.view.model.CyNetworkView;
+import org.cytoscape.view.model.View;
 import org.cytoscape.view.model.events.NetworkViewAboutToBeDestroyedEvent;
 import org.cytoscape.view.model.events.NetworkViewAboutToBeDestroyedListener;
 import org.cytoscape.view.model.events.NetworkViewAddedEvent;
 import org.cytoscape.view.model.events.NetworkViewAddedListener;
+import org.cytoscape.view.presentation.property.RichVisualLexicon;
+import org.cytoscape.view.vizmap.VisualMappingManager;
+import org.cytoscape.view.vizmap.VisualStyle;
 
 
 /**
  * Listens for Network Events, and takes appropriate Actions.
  * May be subclassed.
  *
- * @author Ethan Cerami / Benjamin Gross / Igor Rodchenkov.
+ * @author Ethan Cerami, Gary Bader, Chris Sander, Benjamin Gross, Igor 
Rodchenkov.
  */
 public class BioPaxViewTracker implements NetworkViewAddedListener,
        NetworkViewAboutToBeDestroyedListener, SetCurrentNetworkViewListener, 
RowsSetListener {
@@ -61,17 +39,25 @@
        private final BioPaxDetailsPanel bpPanel;
        private final BioPaxContainer bpContainer;
        private final CyApplicationManager cyApplicationManager;
+       private final VisualMappingManager visualMappingManager;
+       private final BioPaxVisualStyleUtil bioPaxVisualStyleUtil;
 
        /**
         * Constructor.
         *
         * @param bpPanel BioPaxDetails Panel Object.
         */
-       public BioPaxViewTracker(BioPaxDetailsPanel bpPanel, BioPaxContainer 
bpContainer, CyApplicationManager cyApplicationManager) 
+       public BioPaxViewTracker(BioPaxDetailsPanel bpPanel, 
+                       BioPaxContainer bpContainer, 
+                       CyApplicationManager cyApplicationManager,
+                       VisualMappingManager visualMappingManager,
+                       BioPaxVisualStyleUtil bioPaxVisualStyleUtil) 
        {
                this.bpPanel = bpPanel;
                this.bpContainer = bpContainer;
                this.cyApplicationManager = cyApplicationManager;
+               this.visualMappingManager = visualMappingManager;
+               this.bioPaxVisualStyleUtil = bioPaxVisualStyleUtil;
        }
 
 
@@ -80,9 +66,17 @@
         */
        @Override
        public void handleEvent(NetworkViewAddedEvent e) {      
-               if(BioPaxUtil.isBioPAXNetwork(e.getNetworkView().getModel())) {
+               CyNetworkView view = e.getNetworkView();
+               if(BioPaxUtil.isBioPAXNetwork(view.getModel())) {
                        bpContainer.showLegend();
                        bpPanel.resetText();
+                       
+                       // apply BioPAX visual style and set tool tips
+                       setNodeToolTips(view);
+                       VisualStyle bioPaxVisualStyle = 
bioPaxVisualStyleUtil.getBioPaxVisualStyle();
+                       visualMappingManager.setVisualStyle(bioPaxVisualStyle, 
view);
+                       bioPaxVisualStyle.apply(view);
+                       view.updateView();
                }
        }
 
@@ -136,9 +130,110 @@
                                }
                        } finally {
                                // update custom nodes
-                               BioPaxMapper.customNodes(view);
+                               customNodes(view);
                        }
                }
        }
 
+       
+       private void setNodeToolTips(CyNetworkView networkView) {
+               // iterate through the nodes
+               CyNetwork network = networkView.getModel();
+               for (CyNode node : network.getNodeList()) {
+                       CyRow row = network.getRow(node);
+                       String tip = row.get(BIOPAX_ENTITY_TYPE, String.class) 
+ "\n"
+                                       + row.get("/cellularLocation", 
String.class);
+                       View<CyNode> nodeView = networkView.getNodeView(node);
+                       nodeView.setLockedValue(RichVisualLexicon.NODE_TOOLTIP, 
tip);
+               }
+       }
+       
+       
+       private static void customNodes(CyNetworkView networkView) {
+               // grab node attributes
+               CyNetwork cyNetwork = networkView.getModel();
+
+               // iterate through the nodes
+               Iterator<CyNode> nodesIt = cyNetwork.getNodeList().iterator();
+               if (nodesIt.hasNext()) {
+                       // grab the node
+                       CyNode node = nodesIt.next();
+
+                       // get chemical modifications
+                       int count = 0;
+                       boolean isPhosphorylated = false;
+                       // TODO: MultiHashMap
+//                     MultiHashMapDefinition mhmdef = 
nodeAttributes.getMultiHashMapDefinition();
+//
+//                     if 
(mhmdef.getAttributeValueType(BIOPAX_CHEMICAL_MODIFICATIONS_MAP) != -1) {
+//                             MultiHashMap mhmap = 
nodeAttributes.getMultiHashMap();
+//                             CountedIterator modsIt = 
mhmap.getAttributeKeyspan(node.getIdentifier(),
+//                               BIOPAX_CHEMICAL_MODIFICATIONS_MAP, null);
+//
+//                             // do we have phosphorylation ?
+//                             while (modsIt.hasNext()) {
+//                                     String modification = (String) 
modsIt.next();
+//
+//                                     if 
(modification.equals(BioPaxUtil.PHOSPHORYLATION_SITE)) {
+//                                             isPhosphorylated = true;
+//
+//                                             Object[] key = { 
BioPaxUtil.PHOSPHORYLATION_SITE };
+//                                             String countStr = (String) 
mhmap.getAttributeValue(node.getIdentifier(),
+//                            BIOPAX_CHEMICAL_MODIFICATIONS_MAP, key);
+//                                             count = ((Integer) 
Integer.valueOf(countStr)).intValue();
+//
+//                                             break;
+//                                     }
+//                             }
+//                     }
+
+                       // if phosphorylated, add custom node
+                       if (isPhosphorylated) {
+                               addCustomShapes(networkView, node, 
"PHOSPHORYLATION_GRAPHICS", count);
+                       }
+               }
+       }
+
+
+       /**
+        * Based on given arguments, adds proper custom node shape to node.
+        */
+       private static void addCustomShapes(CyNetworkView networkView, CyNode 
node, String shapeType,
+                                           int modificationCount) {
+               // TODO: Custom graphics
+//             // create refs to help views
+//             CyNetwork cyNetwork = networkView.getModel();
+//             View<CyNode> nodeView = networkView.getNodeView(node);
+//             DNodeView dingNodeView = (DNodeView) nodeView;
+//
+//             // remove existing custom nodes
+//             Iterator<CustomGraphic> it = 
dingNodeView.customGraphicIterator();
+//             while ( it.hasNext() ) {
+//                     dingNodeView.removeCustomGraphic( it.next() );
+//             }
+//
+//             for (int lc = 0; lc < modificationCount; lc++) {
+//                     // set image
+//                     BufferedImage image = null;
+//
+//                     if (shapeType.equals(PHOSPHORYLATION_GRAPHICS)) {
+//                             image = (cyNetwork.isSelected(node)) ? 
customPhosGraphics[lc] : phosNode;
+//                     }
+//
+//                     // set rect
+//                     Rectangle2D rect = getCustomShapeRect(image, lc);
+//
+//                     // create our texture paint
+//                     Paint paint = null;
+//
+//                     try {
+//                             paint = new java.awt.TexturePaint(image, rect);
+//                     } catch (Exception exc) {
+//                             paint = java.awt.Color.black;
+//                     }
+//
+//                     // add the graphic
+//                     dingNodeView.addCustomGraphic(rect, paint, 
NodeDetails.ANCHOR_CENTER);
+//             }
+       }
 }

Modified: 
core3/impl/trunk/biopax-impl/src/main/java/org/cytoscape/biopax/internal/util/BioPaxVisualStyleUtil.java
===================================================================
--- 
core3/impl/trunk/biopax-impl/src/main/java/org/cytoscape/biopax/internal/util/BioPaxVisualStyleUtil.java
    2012-02-01 19:43:07 UTC (rev 28176)
+++ 
core3/impl/trunk/biopax-impl/src/main/java/org/cytoscape/biopax/internal/util/BioPaxVisualStyleUtil.java
    2012-02-01 20:08:28 UTC (rev 28177)
@@ -36,16 +36,18 @@
 
 import org.biopax.paxtools.model.BioPAXElement;
 import org.biopax.paxtools.model.level3.Control;
+import org.biopax.paxtools.model.level3.ControlType;
 import org.biopax.paxtools.model.level3.Interaction;
 import org.biopax.paxtools.model.level3.PhysicalEntity;
 
 import static org.cytoscape.biopax.internal.BioPaxMapper.*;
 
 import org.cytoscape.model.CyNode;
-import org.cytoscape.view.model.CyNetworkView;
+import org.cytoscape.view.presentation.property.ArrowShapeVisualProperty;
 import org.cytoscape.view.presentation.property.MinimalVisualLexicon;
 import org.cytoscape.view.presentation.property.NodeShapeVisualProperty;
 import org.cytoscape.view.presentation.property.RichVisualLexicon;
+import org.cytoscape.view.presentation.property.values.ArrowShape;
 import org.cytoscape.view.presentation.property.values.NodeShape;
 import org.cytoscape.view.vizmap.VisualMappingFunctionFactory;
 import org.cytoscape.view.vizmap.VisualMappingManager;
@@ -155,13 +157,13 @@
        
                                // 
style.getDependency().set(VisualPropertyDependency.Definition.NODE_SIZE_LOCKED,false);
        
-                               createNodeShape(style);
                                createNodeSize(style);
                                createNodeLabel(style);
                                createNodeColor(style);
                                createNodeBorderColor(style);
                                createTargetArrows(style);
-       
+                               createNodeShape(style);
+                               
                                mappingManager.addVisualStyle(style);
                        }
                }
@@ -171,10 +173,10 @@
        
        private void createNodeShape(VisualStyle style) {
                style.setDefaultValue(RichVisualLexicon.NODE_SHAPE,
-                               NodeShapeVisualProperty.RECTANGLE);
+                               NodeShapeVisualProperty.ELLIPSE);
 
                // create a discrete mapper, for mapping a biopax type to a 
shape
-               DiscreteMapping<String, NodeShape> function = 
(DiscreteMapping<String, NodeShape>) discreteFactory
+               DiscreteMapping<String, NodeShape> shape = 
(DiscreteMapping<String, NodeShape>) discreteFactory
                                .createVisualMappingFunction(
                                                BIOPAX_ENTITY_TYPE, 
String.class, null,
                                                RichVisualLexicon.NODE_SHAPE);
@@ -183,11 +185,11 @@
                for (Class<? extends BioPAXElement> claz : 
BioPaxUtil.getSubclassNames(PhysicalEntity.class)) 
                {
                        String name = claz.getSimpleName();
-                       function.putMapValue(name, 
NodeShapeVisualProperty.ELLIPSE);
+                       shape.putMapValue(name, 
NodeShapeVisualProperty.ELLIPSE);
                }
 
                // hack for phosphorylated proteins
-               function.putMapValue(BioPaxUtil.PROTEIN_PHOSPHORYLATED,
+               shape.putMapValue(BioPaxUtil.PROTEIN_PHOSPHORYLATED,
                                NodeShapeVisualProperty.ELLIPSE);
 
                // map all interactions
@@ -196,14 +198,15 @@
                for (Class<?> c : 
BioPaxUtil.getSubclassNames(Interaction.class)) {
                        String entityName = c.getSimpleName();
                        if (Control.class.isAssignableFrom(c)) {
-                               function.putMapValue(entityName,
+                               shape.putMapValue(entityName,
                                                
NodeShapeVisualProperty.TRIANGLE);
                        } else {
-                               function.putMapValue(entityName,
+                               shape.putMapValue(entityName,
                                                
NodeShapeVisualProperty.RECTANGLE);
                        }
                }
-               style.addVisualMappingFunction(function);
+               
+               style.addVisualMappingFunction(shape);
        }
 
        
@@ -231,15 +234,13 @@
                }
 
                // map all complex to required size
-//             for (Class c : BioPaxUtil.getSubclassNames(Complex.class)) {
-                       String entityName = "Complex";//c.getSimpleName();
-                       width.putMapValue(entityName,
-                                       new 
Double(BIO_PAX_VISUAL_STYLE_PHYSICAL_ENTITY_NODE_WIDTH
-                                                       * 
BIO_PAX_VISUAL_STYLE_COMPLEX_NODE_SIZE_SCALE));
-                       height.putMapValue(entityName,
-                                       new 
Double(BIO_PAX_VISUAL_STYLE_PHYSICAL_ENTITY_NODE_HEIGHT
-                                                       * 
BIO_PAX_VISUAL_STYLE_COMPLEX_NODE_SIZE_SCALE));
-//             }
+               String entityName = "Complex";//c.getSimpleName();
+               width.putMapValue(entityName,
+                       new 
Double(BIO_PAX_VISUAL_STYLE_PHYSICAL_ENTITY_NODE_WIDTH
+                               * 
BIO_PAX_VISUAL_STYLE_COMPLEX_NODE_SIZE_SCALE));
+               height.putMapValue(entityName,
+                       new 
Double(BIO_PAX_VISUAL_STYLE_PHYSICAL_ENTITY_NODE_HEIGHT
+                               * 
BIO_PAX_VISUAL_STYLE_COMPLEX_NODE_SIZE_SCALE));
 
                /*
                 * // hack for phosphorylated proteins - make them large so 
label fits
@@ -277,14 +278,14 @@
 
                // create a discrete mapper, for mapping biopax node type
                // to a particular node color
-               DiscreteMapping<String, Paint> function = 
(DiscreteMapping<String, Paint>) discreteFactory
+               DiscreteMapping<String, Paint> color = (DiscreteMapping<String, 
Paint>) discreteFactory
                                .createVisualMappingFunction(
                                                BIOPAX_ENTITY_TYPE, 
String.class, null, 
                                                
MinimalVisualLexicon.NODE_FILL_COLOR);
 
                // map all complex to black
-               function.putMapValue("Complex", COMPLEX_NODE_COLOR);
-               style.addVisualMappingFunction(function);
+               color.putMapValue("Complex", COMPLEX_NODE_COLOR);
+               style.addVisualMappingFunction(color);
        }
 
        
@@ -304,67 +305,43 @@
                style.addVisualMappingFunction(function);
        }
 
-       @Deprecated
+       
        private void createTargetArrows(VisualStyle style) {
-               // DiscreteMapping discreteMapping = new
-               // DiscreteMapping(ArrowShape.NONE,
-               // BioPaxMapper.BIOPAX_EDGE_TYPE,
-               // ObjectMapping.EDGE_MAPPING);
-               //
-               // discreteMapping.putMapValue(BioPaxMapper.RIGHT,
-               // ArrowShape.DELTA);
-               // discreteMapping.putMapValue(BioPaxMapper.CONTROLLED,
-               // ArrowShape.DELTA);
-               // discreteMapping.putMapValue(BioPaxMapper.COFACTOR,
-               // ArrowShape.DELTA);
-               // discreteMapping.putMapValue(BioPaxMapper.CONTAINS,
-               // ArrowShape.CIRCLE);
-               //
-               // // Inhibition Edges
-               // for (ControlType controlType : ControlType.values()) {
-               // if(controlType.toString().startsWith("I")) {
-               // discreteMapping.putMapValue(controlType.toString(), 
ArrowShape.T);
-               // }
-               // }
-               //
-               // // Activation Edges
-               // for (ControlType controlType : ControlType.values()) {
-               // if(controlType.toString().startsWith("A")) {
-               // discreteMapping.putMapValue(controlType.toString(),
-               // ArrowShape.DELTA);
-               // }
-               // }
-               //
-               // Calculator edgeTargetArrowCalculator = new
-               // BasicCalculator("BioPAX Target Arrows"
-               // + VERSION_POST_FIX,
-               // discreteMapping,
-               // VisualPropertyType.EDGE_TGTARROW_SHAPE);
-               // eac.setCalculator(edgeTargetArrowCalculator);
-       }
+               
+               DiscreteMapping<String, ArrowShape> tgtArrowShape = 
+                       (DiscreteMapping<String, ArrowShape>) discreteFactory
+                               .createVisualMappingFunction(
+                                               BIOPAX_EDGE_TYPE, String.class, 
null,
+                                               
RichVisualLexicon.EDGE_TARGET_ARROW_SHAPE);
 
-       @Deprecated
-       public void setNodeToolTips(CyNetworkView networkView) {
-               // // grab node attributes
-               // CyAttributes nodeAttributes = Cytoscape.getNodeAttributes();
-               //
-               // // iterate through the nodes
-               // Iterator<NodeView> nodesIt = 
networkView.getNodeViewsIterator();
-               // while (nodesIt.hasNext()) {
-               // NodeView nodeView = nodesIt.next();
-               // String id = nodeView.getNode().getIdentifier();
-               // String tip =
-               // nodeAttributes.getStringAttribute(id,
-               // BioPaxMapper.BIOPAX_ENTITY_TYPE)
-               // + "\n" +
-               // nodeAttributes.getListAttribute(id,
-               // BioPaxMapper.BIOPAX_CELLULAR_LOCATIONS);
-               //
-               // nodeView.setToolTip(tip);
-               //
-               // if(log.isDebugging())
-               // log.debug("tooltip set "+ tip + " for node " + id);
-               // }
-               // networkView.updateView();
+               tgtArrowShape.putMapValue("right", 
ArrowShapeVisualProperty.DELTA);
+               tgtArrowShape.putMapValue("controlled", 
ArrowShapeVisualProperty.DELTA);
+               tgtArrowShape.putMapValue("cofactor", 
ArrowShapeVisualProperty.DELTA);
+               tgtArrowShape.putMapValue("contains", 
ArrowShapeVisualProperty.CIRCLE);
+
+               // Inhibition Edges
+               for (ControlType controlType : ControlType.values()) {
+                       if (controlType.toString().startsWith("I")) {
+                               
tgtArrowShape.putMapValue(controlType.toString(),
+                                               ArrowShapeVisualProperty.T);
+                       }
+               }
+
+               // Activation Edges
+               for (ControlType controlType : ControlType.values()) {
+                       if (controlType.toString().startsWith("A")) {
+                               
tgtArrowShape.putMapValue(controlType.toString(),
+                                               ArrowShapeVisualProperty.DELTA);
+                       }
+               }
+
+// old piece of code...
+//             Calculator edgeTargetArrowCalculator = new BasicCalculator(
+//                             "BioPAX Target Arrows" + VERSION_POST_FIX, 
tgtArrowShape,
+//                             VisualPropertyType.EDGE_TGTARROW_SHAPE);
+//             eac.setCalculator(edgeTargetArrowCalculator);
+               
+               style.addVisualMappingFunction(tgtArrowShape);
        }
+
 }

-- 
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.

Reply via email to