Author: kono
Date: 2010-02-10 23:35:57 -0800 (Wed, 10 Feb 2010)
New Revision: 19290

Modified:
   
csplugins/trunk/ucsd/kono/KGMLReader/src/org/cytoscape/data/reader/kgml/KGMLReader.java
   
csplugins/trunk/ucsd/kono/KGMLReader/src/org/cytoscape/data/reader/kgml/PathwayMapper.java
Log:
Node generator partially finished.

Modified: 
csplugins/trunk/ucsd/kono/KGMLReader/src/org/cytoscape/data/reader/kgml/KGMLReader.java
===================================================================
--- 
csplugins/trunk/ucsd/kono/KGMLReader/src/org/cytoscape/data/reader/kgml/KGMLReader.java
     2010-02-11 02:50:36 UTC (rev 19289)
+++ 
csplugins/trunk/ucsd/kono/KGMLReader/src/org/cytoscape/data/reader/kgml/KGMLReader.java
     2010-02-11 07:35:57 UTC (rev 19290)
@@ -12,17 +12,24 @@
 import org.cytoscape.data.reader.kgml.generated.Pathway;
 
 import cytoscape.CyNetwork;
-import cytoscape.data.readers.GraphReader;
-import cytoscape.layout.CyLayoutAlgorithm;
+import cytoscape.data.readers.AbstractGraphReader;
 import cytoscape.util.URLUtil;
 
-public class KGMLReader implements GraphReader {
+public class KGMLReader extends AbstractGraphReader {
 
        private static final String PACKAGE_NAME = 
"org.cytoscape.data.reader.kgml.generated";
 
        private URL targetURL;
+       
+       private int[] nodeIdx;
+       private int[] edgeIdx;
+       
+       private String networkName;
+       
+       private PathwayMapper mapper;
 
        public KGMLReader(final String fileName) {
+               super(fileName);
                System.out.println("File name = " + fileName);
                try {
                        this.targetURL = (new File(fileName)).toURI().toURL();
@@ -33,33 +40,23 @@
        }
 
        @Override
-       public void doPostProcessing(CyNetwork arg0) {
-               // TODO Auto-generated method stub
-
+       public void doPostProcessing(CyNetwork network) {
+               mapper.updateView(network);
        }
 
        @Override
        public int[] getEdgeIndicesArray() {
-               // TODO Auto-generated method stub
-               return null;
+               return edgeIdx;
        }
 
        @Override
-       public CyLayoutAlgorithm getLayoutAlgorithm() {
-               // TODO Auto-generated method stub
-               return null;
-       }
-
-       @Override
        public String getNetworkName() {
-               // TODO Auto-generated method stub
-               return null;
+               return networkName;
        }
 
        @Override
        public int[] getNodeIndicesArray() {
-               // TODO Auto-generated method stub
-               return null;
+               return nodeIdx;
        }
 
        @Override
@@ -77,6 +74,8 @@
 
                        is = URLUtil.getBasicInputStream(targetURL);
                        pathway = (Pathway) unmarshaller.unmarshal(is);
+                       networkName = pathway.getTitle();
+                       
                } catch (Exception e) {
                        e.printStackTrace();
 
@@ -86,12 +85,10 @@
                                is.close();
                        }
                }
-               
-               System.out.println("Got Pathway: " + pathway.getName());
-               
-               final PathwayMapper mapper = new PathwayMapper(pathway);
+                       
+               mapper = new PathwayMapper(pathway);
                mapper.doMapping();
-                                                                 
+               nodeIdx = mapper.getNodeIdx();
 
        }
 

Modified: 
csplugins/trunk/ucsd/kono/KGMLReader/src/org/cytoscape/data/reader/kgml/PathwayMapper.java
===================================================================
--- 
csplugins/trunk/ucsd/kono/KGMLReader/src/org/cytoscape/data/reader/kgml/PathwayMapper.java
  2010-02-11 02:50:36 UTC (rev 19289)
+++ 
csplugins/trunk/ucsd/kono/KGMLReader/src/org/cytoscape/data/reader/kgml/PathwayMapper.java
  2010-02-11 07:35:57 UTC (rev 19290)
@@ -1,41 +1,111 @@
 package org.cytoscape.data.reader.kgml;
 
+import giny.view.NodeView;
+
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 import org.cytoscape.data.reader.kgml.generated.Entry;
+import org.cytoscape.data.reader.kgml.generated.Graphics;
 import org.cytoscape.data.reader.kgml.generated.Pathway;
 
 import cytoscape.CyEdge;
+import cytoscape.CyNetwork;
 import cytoscape.CyNode;
 import cytoscape.Cytoscape;
+import cytoscape.data.CyAttributes;
+import cytoscape.view.CyNetworkView;
+import cytoscape.visual.NodeShape;
 
 public class PathwayMapper {
        
+       
+       private enum KEGGShape {
+               CIRCLE("circle", NodeShape.ELLIPSE), RECTANGLE("rectangle", 
NodeShape.RECT),
+               ROUND_RECTANGLE("roundrectangle", NodeShape.ROUND_RECT);
+               
+               private String tag;
+               private NodeShape shape;
+               
+               private KEGGShape(final String tag, final NodeShape shape) {
+                       this.shape = shape;
+                       this.tag = tag;
+               }
+               
+               public static int getShape(final String shape) {
+                       for(KEGGShape keggShape: KEGGShape.values()) {
+                               if(keggShape.tag.equals(shape)) {
+                                       return keggShape.shape.getGinyShape();
+                               }
+                       }
+                       
+                       return NodeShape.RECT.getGinyShape();
+               }
+       }
+       
+       
        private Pathway pathway;
        
+       private int[] nodeIdx;
+       private int[] edgeIdx;
+       
        public PathwayMapper(final Pathway pathway) {
                this.pathway = pathway;
        }
 
        public void doMapping() {
                mapNode();
-               
-               
        }
        
+       private final Map<String, Entry> entryMap = new HashMap<String, 
Entry>();
+       final Map<String, CyNode> nodeMap = new HashMap<String, CyNode>();
+       
        private void mapNode() {
+               
+               final String pathwayID = pathway.getName();
                final List<Entry> components = pathway.getEntry();
-               final List<CyNode> nodeList = new ArrayList<CyNode>();
                final List<CyEdge> edgeList = new ArrayList<CyEdge>();
                
+               final CyAttributes nodeAttr = Cytoscape.getNodeAttributes();
+               
                for(final Entry comp:components) {
-                       final CyNode node = Cytoscape.getCyNode(comp.getId(), 
true);
-                       nodeList.add(node);
                        
+                       CyNode node = Cytoscape.getCyNode(pathwayID+ "-" + 
comp.getId(), true);
+                       nodeAttr.setAttribute(node.getIdentifier(), 
"KEGG.name", comp.getName());
+                       nodeMap.put(comp.getId(), node);
+                       entryMap.put(comp.getId(), comp);
                        
                }
-               Cytoscape.createNetwork(nodeList, edgeList, 
pathway.getTitle());                
+               
+               nodeIdx = new int[nodeMap.values().size()];
+               int idx = 0;
+               for(CyNode node: nodeMap.values()) {
+                       nodeIdx[idx] = node.getRootGraphIndex();
+                       idx++;
+               }
        }
        
+       protected void updateView(final CyNetwork network) {
+               
+               final CyNetworkView view = 
Cytoscape.getNetworkView(network.getIdentifier());
+               final CyAttributes nodeAttr = Cytoscape.getNodeAttributes();
+               
+               for (String key:nodeMap.keySet()) {
+                       
+                       final NodeView nv = view.getNodeView(nodeMap.get(key));
+                       Graphics nodeGraphics = entryMap.get(key).getGraphics();
+                       
nv.setXPosition(Double.parseDouble(nodeGraphics.getX()));
+                       
nv.setYPosition(Double.parseDouble(nodeGraphics.getY()));
+                       
nv.setWidth(Double.parseDouble(nodeGraphics.getWidth()));
+                       
nv.setHeight(Double.parseDouble(nodeGraphics.getHeight()));
+                       nv.setShape(KEGGShape.getShape(nodeGraphics.getType()));
+               }
+       }
+
+       public int[] getNodeIdx() {
+               return nodeIdx;
+       }
+       
 }

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