import jalview.api.analysis.ScoreModelI;
import jalview.api.analysis.SimilarityParamsI;
-import jalview.datamodel.SequenceNode;
+import jalview.datamodel.BinaryNode;
import jalview.viewmodel.AlignmentViewport;
/**
* {@inheritDoc}
*/
@Override
- protected void findNewDistances(SequenceNode nodei, SequenceNode nodej,
+ protected void findNewDistances(BinaryNode nodei, BinaryNode nodej,
double dist)
{
double ih = 0;
double jh = 0;
- SequenceNode sni = nodei;
- SequenceNode snj = nodej;
+ BinaryNode sni = nodei;
+ BinaryNode snj = nodej;
while (sni != null)
{
ih = ih + sni.dist;
- sni = (SequenceNode) sni.left();
+ sni = (BinaryNode) sni.left();
}
while (snj != null)
{
jh = jh + snj.dist;
- snj = (SequenceNode) snj.left();
+ snj = (BinaryNode) snj.left();
}
nodei.dist = ((dist / 2) - ih);
import jalview.api.analysis.ScoreModelI;
import jalview.api.analysis.SimilarityParamsI;
-import jalview.datamodel.SequenceNode;
+import jalview.datamodel.BinaryNode;
import jalview.viewmodel.AlignmentViewport;
/**
* {@inheritDoc}
*/
@Override
- protected void findNewDistances(SequenceNode nodei, SequenceNode nodej,
+ protected void findNewDistances(BinaryNode nodei, BinaryNode nodej,
double dist)
{
nodei.dist = ((dist + ri) - rj) / 2;
import jalview.api.analysis.ScoreModelI;
import jalview.api.analysis.SimilarityParamsI;
import jalview.datamodel.AlignmentView;
+import jalview.datamodel.BinaryNode;
import jalview.datamodel.CigarArray;
import jalview.datamodel.SeqCigar;
import jalview.datamodel.SequenceI;
protected double rj;
- SequenceNode maxdist;
+ BinaryNode maxdist;
- SequenceNode top;
+ BinaryNode top;
double maxDistValue;
*
* @return DOCUMENT ME!
*/
- double findHeight(SequenceNode nd)
+ double findHeight(BinaryNode nd)
{
if (nd == null)
{
if ((nd.left() == null) && (nd.right() == null))
{
- nd.height = ((SequenceNode) nd.parent()).height + nd.dist;
+ nd.height = ((BinaryNode) nd.parent()).height + nd.dist;
if (nd.height > maxheight)
{
{
if (nd.parent() != null)
{
- nd.height = ((SequenceNode) nd.parent()).height + nd.dist;
+ nd.height = ((BinaryNode) nd.parent()).height + nd.dist;
}
else
{
nd.height = (float) 0.0;
}
- maxheight = findHeight((SequenceNode) (nd.left()));
- maxheight = findHeight((SequenceNode) (nd.right()));
+ maxheight = findHeight((BinaryNode) (nd.left()));
+ maxheight = findHeight((BinaryNode) (nd.right()));
}
return maxheight;
* @param nd
* DOCUMENT ME!
*/
- void reCount(SequenceNode nd)
+ void reCount(BinaryNode nd)
{
ycount = 0;
// _lycount = 0;
* @param nd
* DOCUMENT ME!
*/
- void _reCount(SequenceNode nd)
+ void _reCount(BinaryNode nd)
{
// if (_lycount<_lylimit)
// {
if ((nd.left() != null) && (nd.right() != null))
{
- _reCount((SequenceNode) nd.left());
- _reCount((SequenceNode) nd.right());
+ _reCount(nd.left());
+ _reCount((BinaryNode) nd.right());
- SequenceNode l = (SequenceNode) nd.left();
- SequenceNode r = (SequenceNode) nd.right();
+ BinaryNode l = nd.left();
+ BinaryNode r = nd.right();
nd.count = l.count + r.count;
nd.ycount = (l.ycount + r.ycount) / 2;
*
* @return DOCUMENT ME!
*/
- public SequenceNode getTopNode()
+ public BinaryNode getTopNode()
{
return top;
}
*
* @param nd
*/
- void findMaxDist(SequenceNode nd)
+ void findMaxDist(BinaryNode nd)
{
if (nd == null)
{
}
else
{
- findMaxDist((SequenceNode) nd.left());
- findMaxDist((SequenceNode) nd.right());
+ findMaxDist((BinaryNode) nd.left());
+ findMaxDist((BinaryNode) nd.right());
}
}
sn.setLeft((node.elementAt(i)));
sn.setRight((node.elementAt(j)));
- SequenceNode tmpi = (node.elementAt(i));
- SequenceNode tmpj = (node.elementAt(j));
+ BinaryNode tmpi = (node.elementAt(i));
+ BinaryNode tmpj = (node.elementAt(j));
findNewDistances(tmpi, tmpj, dist);
* Computes and stores new distances for nodei and nodej, given the previous
* distance between them
*/
- protected abstract void findNewDistances(SequenceNode nodei,
- SequenceNode nodej, double previousDistance);
+ protected abstract void findNewDistances(BinaryNode nodei,
+ BinaryNode nodej, double previousDistance);
/**
* Calculates and saves the distance between the combination of cluster(i) and
*/
public TreeModel(TreeBuilder tree)
{
- this(tree.getSequences(), tree.getTopNode(), tree.hasDistances(),
+ this(tree.getSequences(), (SequenceNode) tree.getTopNode(), tree.hasDistances(),
tree.hasBootstrap(), tree.hasRootDistance());
seqData = tree.getOriginalData();
}
* @param nd
* SequenceNode
*/
- void printNode(SequenceNode nd)
+ void printNode(BinaryNode nd)
{
if (nd == null)
{
else
{
System.out.println("Dist " + nd.dist);
- printNode((SequenceNode) nd.left());
- printNode((SequenceNode) nd.right());
+ printNode((BinaryNode) nd.left());
+ printNode((BinaryNode) nd.right());
}
}
*
* @return DOCUMENT ME!
*/
- public double findHeight(SequenceNode nd)
+ public double findHeight(BinaryNode nd)
{
if (nd == null)
{
if ((nd.left() == null) && (nd.right() == null))
{
- nd.height = ((SequenceNode) nd.parent()).height + nd.dist;
+ nd.height = ((BinaryNode) nd.parent()).height + nd.dist;
if (nd.height > maxheight)
{
{
if (nd.parent() != null)
{
- nd.height = ((SequenceNode) nd.parent()).height + nd.dist;
+ nd.height = ((BinaryNode) nd.parent()).height + nd.dist;
}
else
{
nd.height = (float) 0.0;
}
- maxheight = findHeight((SequenceNode) (nd.left()));
- maxheight = findHeight((SequenceNode) (nd.right()));
+ maxheight = findHeight((BinaryNode) (nd.left()));
+ maxheight = findHeight((BinaryNode) (nd.right()));
}
return maxheight;
* @param nd
* DOCUMENT ME!
*/
- void printN(SequenceNode nd)
+ void printN(BinaryNode nd)
{
if (nd == null)
{
if ((nd.left() != null) && (nd.right() != null))
{
- printN((SequenceNode) nd.left());
- printN((SequenceNode) nd.right());
+ printN((BinaryNode) nd.left());
+ printN((BinaryNode) nd.right());
}
else
{
* @param nd
* DOCUMENT ME!
*/
- public void reCount(SequenceNode nd)
+ public void reCount(BinaryNode nd)
{
ycount = 0;
// _lycount = 0;
* @param nd
* DOCUMENT ME!
*/
- void _reCount(SequenceNode nd)
+ void _reCount(BinaryNode nd)
{
// if (_lycount<_lylimit)
// {
if ((nd.left() != null) && (nd.right() != null))
{
- _reCount((SequenceNode) nd.left());
- _reCount((SequenceNode) nd.right());
+ _reCount((BinaryNode) nd.left());
+ _reCount((BinaryNode) nd.right());
- SequenceNode l = (SequenceNode) nd.left();
- SequenceNode r = (SequenceNode) nd.right();
+ BinaryNode l = (BinaryNode) nd.left();
+ BinaryNode r = (BinaryNode) nd.right();
nd.count = l.count + r.count;
nd.ycount = (l.ycount + r.ycount) / 2;
* @param nd
* DOCUMENT ME!
*/
- public void swapNodes(SequenceNode nd)
+ public void swapNodes(BinaryNode nd)
{
if (nd == null)
{
return;
}
- SequenceNode tmp = (SequenceNode) nd.left();
+ BinaryNode tmp = (BinaryNode) nd.left();
nd.setLeft(nd.right());
nd.setRight(tmp);
* @param dir
* DOCUMENT ME!
*/
- void changeDirection(SequenceNode nd, SequenceNode dir)
+ void changeDirection(BinaryNode nd, BinaryNode dir)
{
if (nd == null)
{
if (nd.parent() != top)
{
- changeDirection((SequenceNode) nd.parent(), nd);
+ changeDirection((BinaryNode) nd.parent(), nd);
- SequenceNode tmp = (SequenceNode) nd.parent();
+ BinaryNode tmp = (BinaryNode) nd.parent();
if (dir == nd.left())
{
import jalview.analysis.Conservation;
import jalview.analysis.TreeModel;
import jalview.api.AlignViewportI;
+import jalview.datamodel.BinaryNode;
import jalview.datamodel.Sequence;
import jalview.datamodel.SequenceGroup;
import jalview.datamodel.SequenceI;
}
int ystart = (int) (node.left() == null ? 0
- : (((SequenceNode) node.left()).ycount * chunk)) + offy;
+ : (((BinaryNode) node.left()).ycount * chunk)) + offy;
int yend = (int) (node.right() == null ? 0
- : (((SequenceNode) node.right()).ycount * chunk)) + offy;
+ : (((BinaryNode) node.right()).ycount * chunk)) + offy;
Rectangle pos = new Rectangle(xend - 2, ypos - 2, 5, 5);
nodeHash.put(node, pos);
int width = getSize().width;
int height = getSize().height;
- SequenceNode top = tree.getTopNode();
+ BinaryNode top = tree.getTopNode();
double wscale = (float) (width * .8 - offx * 2) / tree.getMaxHeight();
if (top.count == 0)
{
- top.count = ((SequenceNode) top.left()).count
- + ((SequenceNode) top.right()).count;
+ top.count = ((BinaryNode) top.left()).count
+ + ((BinaryNode) top.right()).count;
}
float chunk = (float) (height - offy) / top.count;
pickNode(pickBox, top, chunk, wscale, width, offx, offy);
}
- public void pickNode(Rectangle pickBox, SequenceNode node, float chunk,
+ public void pickNode(Rectangle pickBox, BinaryNode node, float chunk,
double scale, int width, int offx, int offy)
{
if (node == null)
}
else
{
- pickNode(pickBox, (SequenceNode) node.left(), chunk, scale, width,
+ pickNode(pickBox, (BinaryNode) node.left(), chunk, scale, width,
offx, offy);
- pickNode(pickBox, (SequenceNode) node.right(), chunk, scale, width,
+ pickNode(pickBox, (BinaryNode) node.right(), chunk, scale, width,
offx, offy);
}
}
- public void setColor(SequenceNode node, Color c)
+ public void setColor(BinaryNode node, Color c)
{
if (node == null)
{
else
{
node.color = c;
- setColor((SequenceNode) node.left(), c);
- setColor((SequenceNode) node.right(), c);
+ setColor((BinaryNode) node.left(), c);
+ setColor((BinaryNode) node.right(), c);
}
}
double wscale = (width - labelLength - offx * 2) / tree.getMaxHeight();
- SequenceNode top = tree.getTopNode();
+ BinaryNode top = tree.getTopNode();
if (top.count == 0)
{
- top.count = ((SequenceNode) top.left()).count
- + ((SequenceNode) top.right()).count;
+ top.count = ((BinaryNode) top.left()).count
+ + ((BinaryNode) top.right()).count;
}
float chunk = (float) (height - offy) / top.count;
*/
package jalview.datamodel;
+import java.awt.Color;
+
/**
* DOCUMENT ME!
*
/** DOCUMENT ME!! */
public int bootstrap;
+ /** DOCUMENT ME!! */
+ public double dist;
+
+ /** DOCUMENT ME!! */
+ public int count;
+
+ /** DOCUMENT ME!! */
+ public double height;
+
+ /** DOCUMENT ME!! */
+ public float ycount;
+
+ /** DOCUMENT ME!! */
+ public Color color = Color.black;
+
+ /** DOCUMENT ME!! */
+ public boolean dummy = false;
+
/**
* Creates a new BinaryNode object.
*/
{
return bootstrap;
}
+
+ /**
+ * ascends the tree but doesn't stop until a non-dummy node is discovered.
+ *
+ */
+ public BinaryNode AscendTree()
+ {
+ BinaryNode c = this;
+
+ do
+ {
+ c = c.parent();
+ } while ((c != null) && c.dummy);
+
+ return c;
+ }
}
*/
package jalview.datamodel;
-import java.awt.Color;
-
/**
* DOCUMENT ME!
*
*/
public class SequenceNode extends BinaryNode
{
- /** DOCUMENT ME!! */
- public double dist;
-
- /** DOCUMENT ME!! */
- public int count;
-
- /** DOCUMENT ME!! */
- public double height;
-
- /** DOCUMENT ME!! */
- public float ycount;
-
- /** DOCUMENT ME!! */
- public Color color = Color.black;
-
- /** DOCUMENT ME!! */
- public boolean dummy = false;
-
private boolean placeholder = false;
/**
* @param name
* DOCUMENT ME!
*/
- public SequenceNode(Object val, SequenceNode parent, double dist,
+ public SequenceNode(Object val, BinaryNode parent, double dist,
String name)
{
super(val, parent, name);
* @param dummy
* DOCUMENT ME!
*/
- public SequenceNode(Object val, SequenceNode parent, String name,
+ public SequenceNode(Object val, BinaryNode parent, String name,
double dist, int bootstrap, boolean dummy)
{
super(val, parent, name);
}
/**
- * ascends the tree but doesn't stop until a non-dummy node is discovered.
- * This will probably break if the tree is a mixture of BinaryNodes and
- * SequenceNodes.
- */
- public SequenceNode AscendTree()
- {
- SequenceNode c = this;
-
- do
- {
- c = (SequenceNode) c.parent();
- } while ((c != null) && c.dummy);
-
- return c;
- }
-
- /**
* test if this node has a name that might be a label rather than a bootstrap
* value
*
import jalview.analysis.Conservation;
import jalview.analysis.TreeModel;
import jalview.api.AlignViewportI;
+import jalview.datamodel.BinaryNode;
import jalview.datamodel.Sequence;
import jalview.datamodel.SequenceGroup;
import jalview.datamodel.SequenceI;
}
int ystart = (node.left() == null ? 0
- : (int) (((SequenceNode) node.left()).ycount * chunk)) + offy;
+ : (int) (((BinaryNode) node.left()).ycount * chunk)) + offy;
int yend = (node.right() == null ? 0
- : (int) (((SequenceNode) node.right()).ycount * chunk))
+ : (int) (((BinaryNode) node.right()).ycount * chunk))
+ offy;
Rectangle pos = new Rectangle(xend - 2, ypos - 2, 5, 5);
int width = getWidth();
int height = getHeight();
- SequenceNode top = tree.getTopNode();
+ BinaryNode top = tree.getTopNode();
double wscale = ((width * .8) - (offx * 2)) / tree.getMaxHeight();
if (top.count == 0)
{
- top.count = ((SequenceNode) top.left()).count
- + ((SequenceNode) top.right()).count;
+ top.count = ((BinaryNode) top.left()).count
+ + ((BinaryNode) top.right()).count;
}
float chunk = (float) (height - (offy)) / top.count;
* @param offy
* DOCUMENT ME!
*/
- public void pickNode(Rectangle pickBox, SequenceNode node, float chunk,
+ public void pickNode(Rectangle pickBox, BinaryNode node, float chunk,
double wscale, int width, int offx, int offy)
{
if (node == null)
}
else
{
- pickNode(pickBox, (SequenceNode) node.left(), chunk, wscale, width,
+ pickNode(pickBox, (BinaryNode) node.left(), chunk, wscale, width,
offx, offy);
- pickNode(pickBox, (SequenceNode) node.right(), chunk, wscale, width,
+ pickNode(pickBox, (BinaryNode) node.right(), chunk, wscale, width,
offx, offy);
}
}
* @param c
* DOCUMENT ME!
*/
- public void setColor(SequenceNode node, Color c)
+ public void setColor(BinaryNode node, Color c)
{
if (node == null)
{
}
}
}
- setColor((SequenceNode) node.left(), c);
- setColor((SequenceNode) node.right(), c);
+ setColor((BinaryNode) node.left(), c);
+ setColor((BinaryNode) node.right(), c);
}
/**
double wscale = (width - labelLength - (offx * 2))
/ tree.getMaxHeight();
- SequenceNode top = tree.getTopNode();
+ BinaryNode top = tree.getTopNode();
if (top.count == 0)
{
- top.count = ((SequenceNode) top.left()).count
- + ((SequenceNode) top.right()).count;
+ top.count = ((BinaryNode) top.left()).count
+ + ((BinaryNode) top.right()).count;
}
float chunk = (float) (height - (offy)) / top.count;
&& !((SequenceNode) node).isDummy())
{
String newname = null;
- SequenceI sq = (SequenceI) ((SequenceNode) node).element();
+ SequenceI sq = (SequenceI) ((BinaryNode) node).element();
if (sq != null)
{
// search dbrefs, features and annotation
{
// String oldname = ((SequenceNode) node).getName();
// TODO : save oldname in the undo object for this modification.
- ((SequenceNode) node).setName(newname);
+ ((BinaryNode) node).setName(newname);
}
}
}
import java.util.Locale;
+import jalview.datamodel.BinaryNode;
import jalview.datamodel.SequenceNode;
import jalview.util.MessageManager;
root = new SequenceNode();
- SequenceNode realroot = null;
- SequenceNode c = root;
+ BinaryNode realroot = null;
+ BinaryNode c = root;
int d = -1;
int cp = 0;
{
c.setRight(new SequenceNode(null, c, null, DefDistance,
DefBootstrap, false));
- c = (SequenceNode) c.right();
+ c = (BinaryNode) c.right();
}
else
{
if (c.left() != null)
{
// Dummy node for polytomy - keeps c.left free for new node
- SequenceNode tmpn = new SequenceNode(null, c, null, 0, 0, true);
+ BinaryNode tmpn = new SequenceNode(null, c, null, 0, 0, true);
tmpn.SetChildren(c.left(), c.right());
c.setRight(tmpn);
}
c.setLeft(new SequenceNode(null, c, null, DefDistance,
DefBootstrap, false));
- c = (SequenceNode) c.left();
+ c = (BinaryNode) c.left();
}
if (realroot == null)
else
{
// Find a place to put the leaf
- SequenceNode newnode = new SequenceNode(null, c, nodename,
+ BinaryNode newnode = new SequenceNode(null, c, nodename,
(HasDistances) ? distance : DefDistance,
(HasBootstrap) ? bootstrap : DefBootstrap, false);
parseNHXNodeProps(c, commentString2);
{
// Insert a dummy node for polytomy
// dummy nodes have distances
- SequenceNode newdummy = new SequenceNode(null, c, null,
+ BinaryNode newdummy = new SequenceNode(null, c, null,
(HasDistances ? 0 : DefDistance), 0, true);
newdummy.SetChildren(c.left(), newnode);
c.setLeft(newdummy);
// Just advance focus, if we need to
if ((c.left() != null) && (!c.left().isLeaf()))
{
- c = (SequenceNode) c.left();
+ c = (BinaryNode) c.left();
}
}
}
* @param commentString
* @param commentString2
*/
- private void parseNHXNodeProps(SequenceNode c, String commentString)
+ private void parseNHXNodeProps(BinaryNode c, String commentString)
{
// TODO: store raw comment on the sequenceNode so it can be recovered when
// tree is output
*
* @return DOCUMENT ME!
*/
- private String printNodeField(SequenceNode c)
+ private String printNodeField(BinaryNode c)
{
return ((c.getName() == null) ? "" : nodeName(c.getName()))
+ ((HasBootstrap) ? ((c.getBootstrap() > -1)
*
* @return DOCUMENT ME!
*/
- private String printRootField(SequenceNode root)
+ private String printRootField(BinaryNode root)
{
return (printRootInfo)
? (((root.getName() == null) ? "" : nodeName(root.getName()))
{
if (!((jalview.datamodel.SequenceNode) tnode).isPlaceholder())
{
- Object assocseq = ((jalview.datamodel.SequenceNode) tnode)
+ Object assocseq = ((BinaryNode) tnode)
.element();
if (assocseq instanceof SequenceI)
{
import jalview.analysis.SequenceIdMatcher;
import jalview.analysis.TreeModel;
+import jalview.datamodel.BinaryNode;
import jalview.datamodel.SequenceI;
import jalview.datamodel.SequenceNode;
import jalview.gui.JvOptionPane;
stage + "Newick file is invalid ('"
+ nf_regen.getWarningMessage() + "')",
nf_regen.isValid());
- SequenceNode tree_regen = nf.getTree();
+ BinaryNode tree_regen = nf.getTree();
AssertJUnit.assertTrue(stage + "Null Tree", tree_regen != null);
stage = "Compare original and generated tree" + treename;