Author: chinmoy
Date: 2009-08-07 15:24:27 -0700 (Fri, 07 Aug 2009)
New Revision: 17740
Modified:
csplugins/trunk/soc/chinmoy/phylotree/src/org/cytoscape/phylotree/actions/PhyloTreeImportAction.java
csplugins/trunk/soc/chinmoy/phylotree/src/org/cytoscape/phylotree/layout/CommonFunctions.java
csplugins/trunk/soc/chinmoy/phylotree/src/org/cytoscape/phylotree/visualstyle/DepthwiseColor.java
Log:
Bug fixes for depthwise color visual style.
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-08-07 22:12:37 UTC (rev 17739)
+++
csplugins/trunk/soc/chinmoy/phylotree/src/org/cytoscape/phylotree/actions/PhyloTreeImportAction.java
2009-08-07 22:24:27 UTC (rev 17740)
@@ -124,7 +124,7 @@
// Apply visual style
- Cytoscape.firePropertyChange(Cytoscape.VIZMAP_LOADED, null,
"phyloVizMap.props");
+ // Cytoscape.firePropertyChange(Cytoscape.VIZMAP_LOADED, null,
"phyloVizMap.props");
}
@@ -505,8 +505,12 @@
if(branchData.getBranchWidth()!=null)
edgeAttributes.setAttribute(edgeID, "branchLength",
branchData.getBranchWidth().getValue());
else
- edgeAttributes.setAttribute(edgeID, "branchLength",
node.getDistanceToParent());
-
+ {
+ if(node.getDistanceToParent()>=0)
+ edgeAttributes.setAttribute(edgeID,
"branchLength", node.getDistanceToParent());
+ else
+ edgeAttributes.setAttribute(edgeID,
"branchLength", 0.0);
+ }
if(branchData.getBranchColor()!=null)
edgeAttributes.setAttribute(edgeID, "Color",
branchData.getBranchColor().getValue().toString());
Modified:
csplugins/trunk/soc/chinmoy/phylotree/src/org/cytoscape/phylotree/layout/CommonFunctions.java
===================================================================
---
csplugins/trunk/soc/chinmoy/phylotree/src/org/cytoscape/phylotree/layout/CommonFunctions.java
2009-08-07 22:12:37 UTC (rev 17739)
+++
csplugins/trunk/soc/chinmoy/phylotree/src/org/cytoscape/phylotree/layout/CommonFunctions.java
2009-08-07 22:24:27 UTC (rev 17740)
@@ -13,8 +13,12 @@
import giny.view.Bend;
public class CommonFunctions {
-
-
+
+
+ /**
+ * @param network - the network to be probed
+ * @return true if network has a leaf (node with outDegree = 0)
+ */
public boolean hasLeaf(CyNetwork network)
{
// Get all nodes
@@ -25,11 +29,15 @@
Node node = nodesListIterator.next();
if(network.getOutDegree(node)==0)
return true;
-
+
}
return false;
}
-
+
+ /**
+ * @param network - the network to be probed
+ * @return true if network is a tree (all nodes have inDegree = 1)
+ */
public boolean isTree(CyNetwork network)
{
// Get all nodes
@@ -72,7 +80,7 @@
return null;
}
-
+
/**
* traverse(network, node)
* Recursively performs a post-order traversal of tree from node arg
@@ -85,7 +93,7 @@
{
List<Node> list = new LinkedList<Node>();
-
+
// Find all outgoing edges
int[] outgoingEdgesArray =
network.getAdjacentEdgeIndicesArray(node.getRootGraphIndex(), false, false,
true);
@@ -97,13 +105,13 @@
{
Edge edge =
network.getEdge(outgoingEdgesArray[i]);
//networkView.getEdgeView(edge).clearBends();
-
+
list.addAll(postOrderTraverse(network,
edge.getTarget()));
}
// Traverse the parent last
list.add(node);
return list;
-
+
}
// Base case: if node is a leaf
else if(outgoingEdgesArray.length == 0)
@@ -115,9 +123,9 @@
return null;
}
-
-
-
+
+
+
/**
* preOrderTraverse(network, Node)
* Recursively performs a post-order traversal of tree from node arg
@@ -138,8 +146,8 @@
if(outgoingEdgesArray.length!=0)
{
list.add(node);
-
-
+
+
// Traverse every child
for(int i = 0; i<outgoingEdgesArray.length; i++)
{
@@ -152,15 +160,15 @@
// Base case: if node is a leaf
else if(outgoingEdgesArray.length == 0)
{
-
+
list.add(node);
return list;
}
return null;
}
-
-
+
+
/**
* getLeaves(network, Node)
* Recursively populates List with leaves on a path from Node
@@ -171,7 +179,7 @@
public List<Node> getLeaves(CyNetwork network, Node node)
{
List<Node> list = new LinkedList<Node>();
-
+
// Get all children
int[] edges =
network.getAdjacentEdgeIndicesArray(node.getRootGraphIndex(), false, false,
true);
for(int i = 0; i<edges.length; i++)
@@ -186,37 +194,37 @@
else
{
// Otherwise, probe the subtree rooted at the
child
-
+
list.addAll(getLeaves(network, child));
-
+
}
-
+
}
return list;
}
-
-
+
+
public List<Node> getAncestors(CyNetwork network, Node node)
{
List<Node> list = new LinkedList<Node>();
-
+
while(network.getAdjacentEdgeIndicesArray(node.getRootGraphIndex(), false,
true, false).length>0)
{
int[] incomingEdges=
network.getAdjacentEdgeIndicesArray(node.getRootGraphIndex(), false, true,
false);
-
- if(incomingEdges.length>0)
- {
- Node ancestor =
network.getEdge(incomingEdges[0]).getSource();
- list.add(ancestor);
- node = ancestor;
+
+ if(incomingEdges.length>0)
+ {
+ Node ancestor =
network.getEdge(incomingEdges[0]).getSource();
+ list.add(ancestor);
+ node = ancestor;
+ }
+
}
-
- }
return list;
}
-
+
/**
* Find the vertical midpoint of a list of leaves
* @param networkView - the networkView containing the leaves
@@ -230,9 +238,9 @@
Node firstLeaf = it.next();
double highestY,lowestY;
highestY = lowestY =
networkView.getNodeView(firstLeaf).getYPosition();
-
-
+
+
while(it.hasNext())
{
Node leaf = it.next();
@@ -250,7 +258,7 @@
}
return (highestY+lowestY)/2.0;
}
-
+
/**
* Obtain the length of the edge incident onto the node
* @param network - the network in which the node is situated
@@ -310,23 +318,17 @@
public int getDepth(CyNetwork network, Node node)
{
if(network.getInDegree(node, false) == 0)
- {
+ {
return 0;
- }
+ }
else
{
int [] incomingEdges =
network.getAdjacentEdgeIndicesArray(node.getRootGraphIndex(), false, true,
false);
- int max = 0;
- for (int i = 0; i < incomingEdges.length; i++)
- {
- int depth = getLevel(network,
network.getEdge(incomingEdges[i]).getSource());
- if(depth > max)
- max = depth;
- }
-
- return max+1;
+ int depth = getDepth(network,
network.getEdge(incomingEdges[0]).getSource());
+
+ return depth+1;
}
}
/**
@@ -350,8 +352,8 @@
return numLeaves;
}
-
-
+
+
/**
* Calculates the optimum factor by which edges must be scaled to
obtain an optimum view
* @param network - the network from which the scaling factor is to be
calculated
@@ -359,14 +361,14 @@
*/
public double getScalingFactor(CyNetwork network)
{
-
-
+
+
double factor = 1.0;
// Find the smallest edge
List<Edge> allEdges = network.edgesList();
Iterator<Edge> edgesIterator = allEdges.iterator();
-
-
+
+
double smallestLength = Double.MAX_VALUE;
while(edgesIterator.hasNext())
{
@@ -376,16 +378,16 @@
if(length<smallestLength)
smallestLength = length;
}
-
+
// Calculate the scaling factor
-
+
while(smallestLength * factor <= 50.0) //50
factor *= 10.0; //10
-
-
+
+
return factor;
}
-
+
/**
* Adds the bends to make the edges look rectangular
* @param network - the network on which the bends are to be added
@@ -394,29 +396,29 @@
*/
public void addRectangularBends(CyNetwork network, CyNetworkView
networkView, Edge edge)
{
-
- Node source = edge.getSource();
- Node target = edge.getTarget();
-
- // Check if the target is a reticulate node (indegree>1)
- // If yes, don't bend the edge
- if(network.getInDegree(target.getRootGraphIndex(),
false) <= 1 && source.getRootGraphIndex()!=target.getRootGraphIndex())
- {
- // For each edge, get the source node's X
position
- double cornerX =
networkView.getNodeView(source).getXPosition();
- // For each edge, get the target node's Y
position
- double cornerY =
networkView.getNodeView(target).getYPosition();
+ Node source = edge.getSource();
+ Node target = edge.getTarget();
+ // Check if the target is a reticulate node (indegree>1)
+ // If yes, don't bend the edge
+ if(network.getInDegree(target.getRootGraphIndex(), false) <= 1
&& source.getRootGraphIndex()!=target.getRootGraphIndex())
+ {
+ // For each edge, get the source node's X position
+ double cornerX =
networkView.getNodeView(source).getXPosition();
- // Bend the edge
- Bend rectangularBend =
networkView.getEdgeView(edge).getBend();
-
- rectangularBend.addHandle(new
Point2D.Double(cornerX, cornerY));
-
- }
+ // For each edge, get the target node's Y position
+ double cornerY =
networkView.getNodeView(target).getYPosition();
+
+
+ // Bend the edge
+ Bend rectangularBend =
networkView.getEdgeView(edge).getBend();
+
+ rectangularBend.addHandle(new Point2D.Double(cornerX,
cornerY));
+
+ }
}
-
+
/**
* Adds the bends to make the edges look circular
* @param network - the network on which the bends are to be added
@@ -425,71 +427,71 @@
*/
public void addCircularBends(CyNetwork network, CyNetworkView
networkView, Edge edge)
{
-
- Node source = edge.getSource();
- Node target = edge.getTarget();
-
- // Check if the target is a reticulate node (indegree>1)
- // If yes, don't bend the edge
- if(network.getInDegree(target.getRootGraphIndex(),
false) <= 1 && source.getRootGraphIndex()!=target.getRootGraphIndex())
- {
-
- double sourceX =
networkView.getNodeView(source).getXPosition();
- double sourceY =
networkView.getNodeView(source).getYPosition();
- // Get the radius of the source
- double radius = Math.sqrt(sourceX*sourceX +
sourceY*sourceY);
+ Node source = edge.getSource();
+ Node target = edge.getTarget();
- // And the angle of the source
- double sourceAngle = Math.atan2(sourceY,
sourceX);
-
-
- // And the angle of the target
- double angle =
Math.atan2(networkView.getNodeView(target).getYPosition(),
networkView.getNodeView(target).getXPosition());
-
- //Bend the edge
- Bend circularBend =
networkView.getEdgeView(edge).getBend();
- Point2D handlePoint = new
Point2D.Double(radius*Math.cos(angle),radius*Math.sin(angle));
- Point2D sourcePoint = new
Point2D.Double(sourceX, sourceY);
- circularBend.addHandle(handlePoint);
-
- // Algorithm to draw arcs:
- // Find the length of the chord from the source
to the first handle in the bend
- // Find the length of the segment that would
produce an arc of the desired handleInterval
- // Divide the length of the chord and the
subSegment to calculate how many subSegments are required
- // Number of subSegments on chord = number of
handles to produce the arc from the bend
-
- double chordLength =
handlePoint.distance(sourcePoint);
-
- double handleInterval = Math.PI/18.0;
- double subSegmentLength =
2*radius*Math.sin(handleInterval/2.0);
-
- int iterations =
(int)(chordLength/subSegmentLength);
-
- if(compareAngles(angle,sourceAngle)==0)
+ // Check if the target is a reticulate node (indegree>1)
+ // If yes, don't bend the edge
+ if(network.getInDegree(target.getRootGraphIndex(), false) <= 1
&& source.getRootGraphIndex()!=target.getRootGraphIndex())
+ {
- {
- for(int i = 0;i<iterations; i
++)
- {
- angle =
angle+(handleInterval);
-
circularBend.addHandle(new
Point2D.Double(radius*Math.cos(angle),radius*Math.sin(angle)));
- }
- }
- else
if(compareAngles(angle,sourceAngle)==1)
- {
- for(int i =0; i<iterations; i++)
- {
- angle =
angle-(handleInterval);
-
circularBend.addHandle(new
Point2D.Double(radius*Math.cos(angle),radius*Math.sin(angle)));
+ double sourceX =
networkView.getNodeView(source).getXPosition();
+ double sourceY =
networkView.getNodeView(source).getYPosition();
+ // Get the radius of the source
+ double radius = Math.sqrt(sourceX*sourceX +
sourceY*sourceY);
- }
- }
-
+ // And the angle of the source
+ double sourceAngle = Math.atan2(sourceY, sourceX);
+
+
+ // And the angle of the target
+ double angle =
Math.atan2(networkView.getNodeView(target).getYPosition(),
networkView.getNodeView(target).getXPosition());
+
+ //Bend the edge
+ Bend circularBend =
networkView.getEdgeView(edge).getBend();
+ Point2D handlePoint = new
Point2D.Double(radius*Math.cos(angle),radius*Math.sin(angle));
+ Point2D sourcePoint = new Point2D.Double(sourceX,
sourceY);
+ circularBend.addHandle(handlePoint);
+
+ // Algorithm to draw arcs:
+ // Find the length of the chord from the source to the
first handle in the bend
+ // Find the length of the segment that would produce an
arc of the desired handleInterval
+ // Divide the length of the chord and the subSegment to
calculate how many subSegments are required
+ // Number of subSegments on chord = number of handles
to produce the arc from the bend
+
+ double chordLength = handlePoint.distance(sourcePoint);
+
+ double handleInterval = Math.PI/18.0;
+ double subSegmentLength =
2*radius*Math.sin(handleInterval/2.0);
+
+ int iterations = (int)(chordLength/subSegmentLength);
+
+ if(compareAngles(angle,sourceAngle)==0)
+
+ {
+ for(int i = 0;i<iterations; i ++)
+ {
+ angle = angle+(handleInterval);
+ circularBend.addHandle(new
Point2D.Double(radius*Math.cos(angle),radius*Math.sin(angle)));
+
+ }
}
+ else if(compareAngles(angle,sourceAngle)==1)
+ {
+ for(int i =0; i<iterations; i++)
+ {
+ angle = angle-(handleInterval);
+ circularBend.addHandle(new
Point2D.Double(radius*Math.cos(angle),radius*Math.sin(angle)));
+
+ }
+ }
+
+ }
}
-
-
+
+
/**
* Important for the functioning of addCircularBends
* Given the angle of the initial handle in the bend(arc) and the angle
of the source node
@@ -516,10 +518,10 @@
{
result = 1;
}
-
- return result;
-
-
+
+ return result;
+
+
}
-
+
}
Modified:
csplugins/trunk/soc/chinmoy/phylotree/src/org/cytoscape/phylotree/visualstyle/DepthwiseColor.java
===================================================================
---
csplugins/trunk/soc/chinmoy/phylotree/src/org/cytoscape/phylotree/visualstyle/DepthwiseColor.java
2009-08-07 22:12:37 UTC (rev 17739)
+++
csplugins/trunk/soc/chinmoy/phylotree/src/org/cytoscape/phylotree/visualstyle/DepthwiseColor.java
2009-08-07 22:24:27 UTC (rev 17740)
@@ -109,7 +109,6 @@
Node node = nodeListIterator.next();
int depth = cf.getDepth(network, node);
-
nodeAttributes.setAttribute(node.getIdentifier(),
"Depth", depth);
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---