Author: chinmoy
Date: 2009-06-30 21:03:40 -0700 (Tue, 30 Jun 2009)
New Revision: 17176

Modified:
   
csplugins/trunk/soc/chinmoy/phylotree/src/org/cytoscape/phylotree/actions/PhyloTreeImportAction.java
   
csplugins/trunk/soc/chinmoy/phylotree/src/org/cytoscape/phylotree/parser/PhylipTreeImpl.java
Log:
Network creation and attributes added to ImportTreeFromFile

Modified: 
csplugins/trunk/soc/chinmoy/phylotree/src/org/cytoscape/phylotree/actions/PhyloTreeImportAction.java
===================================================================
--- 
csplugins/trunk/soc/chinmoy/phylotree/src/org/cytoscape/phylotree/actions/PhyloTreeImportAction.java
        2009-07-01 03:07:32 UTC (rev 17175)
+++ 
csplugins/trunk/soc/chinmoy/phylotree/src/org/cytoscape/phylotree/actions/PhyloTreeImportAction.java
        2009-07-01 04:03:40 UTC (rev 17176)
@@ -1,10 +1,20 @@
 package org.cytoscape.phylotree.actions;
 
 import java.awt.event.ActionEvent;
+
+import cytoscape.CyEdge;
+import cytoscape.CyNetwork;
+import cytoscape.CyNode;
+import cytoscape.Cytoscape;
+import cytoscape.data.CyAttributes;
+import cytoscape.data.Semantics;
 import cytoscape.util.CytoscapeAction;
 import org.cytoscape.phylotree.PhylotreePlugin;
 import org.cytoscape.phylotree.ui.PhyloFileDialog;
+import org.cytoscape.phylotree.parser.*;
 import java.io.File;
+import java.util.List;
+import java.util.Iterator;
 
 public class PhyloTreeImportAction extends CytoscapeAction{
        
@@ -27,14 +37,50 @@
                                
                if (pFormat.equalsIgnoreCase("Phylip")){
                
-                       // use the parser to read the file
+                       // Use the parser to read the file
                        
+                       // Parse the file
+                       PhylipTreeImpl phylipParser = new PhylipTreeImpl(pFile);
                        
-                       // create a network
+                       CyNetwork cyNetwork = 
Cytoscape.createNetwork(pFile.getName(), true);
+                       CyAttributes cyAttributes = 
Cytoscape.getEdgeAttributes();
                        
                        
-                       // create attribute
+                       // Get all nodes in the PHYLIP tree
+                       List<PhylotreeNode> nodeList = 
phylipParser.getNodeList();
                        
+                       // For each node, get all edges
+                       for(Iterator<PhylotreeNode> nodeListIterator = 
nodeList.iterator(); nodeListIterator.hasNext();)
+                       {
+                               PhylotreeNode pNode = nodeListIterator.next();
+                               
+                               // Get edges
+                               List<PhylotreeEdge> edgeList = 
phylipParser.getEdges(pNode);
+                               
+                               // For each edge, create the two nodes 
connected if they do not exist
+                               for(Iterator<PhylotreeEdge> edgeListIterator = 
edgeList.iterator(); edgeListIterator.hasNext();)
+                               {
+                                       PhylotreeEdge pEdge = 
edgeListIterator.next();
+
+                                       CyNode node2 = 
Cytoscape.getCyNode(pEdge.getSourceNode().getName(), true);
+                                       CyNode node1 = 
Cytoscape.getCyNode(pEdge.getTargetNode().getName(), true);
+                                               
+                                       CyEdge cyEdge = 
Cytoscape.getCyEdge(node1, node2, Semantics.INTERACTION, "pp", true, false);
+                                       
+                                       // Get edge attributes and set them
+                                       List<Object> edgeAttributes = 
phylipParser.getEdgeAttribute(pEdge);
+                                       
cyAttributes.setAttribute(cyEdge.getIdentifier(), "branchLength", 
(Double)edgeAttributes.get(0));
+                                       cyNetwork.addEdge(cyEdge);
+                               }
+                               
+
+                       }
+                       
+                       cyAttributes.setUserEditable("branchLength", false);
+                       cyAttributes.setUserVisible("branchLength", true);
+                       
+                       
+                       
                }
        }
 }

Modified: 
csplugins/trunk/soc/chinmoy/phylotree/src/org/cytoscape/phylotree/parser/PhylipTreeImpl.java
===================================================================
--- 
csplugins/trunk/soc/chinmoy/phylotree/src/org/cytoscape/phylotree/parser/PhylipTreeImpl.java
        2009-07-01 03:07:32 UTC (rev 17175)
+++ 
csplugins/trunk/soc/chinmoy/phylotree/src/org/cytoscape/phylotree/parser/PhylipTreeImpl.java
        2009-07-01 04:03:40 UTC (rev 17176)
@@ -35,6 +35,7 @@
        public PhylipTreeImpl(File pTreeFile){
 
                treeStr = getTreeTextFromFile(pTreeFile);
+               nodeList = new LinkedList<PhylotreeNode>();
                parse();
        }
 


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