merge from 2_4_Release branch
[jalview.git] / src / jalview / datamodel / SequenceNode.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer (Version 2.4)
3  * Copyright (C) 2008 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
4  * 
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  * 
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  * 
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
18  */
19 package jalview.datamodel;
20
21 import java.awt.*;
22
23 /**
24  * DOCUMENT ME!
25  * 
26  * @author $author$
27  * @version $Revision$
28  */
29 public class SequenceNode extends BinaryNode
30 {
31   /** DOCUMENT ME!! */
32   public float dist;
33
34   /** DOCUMENT ME!! */
35   public int count;
36
37   /** DOCUMENT ME!! */
38   public float height;
39
40   /** DOCUMENT ME!! */
41   public float ycount;
42
43   /** DOCUMENT ME!! */
44   public Color color = Color.black;
45
46   /** DOCUMENT ME!! */
47   public boolean dummy = false;
48
49   private boolean placeholder = false;
50
51   /**
52    * Creates a new SequenceNode object.
53    */
54   public SequenceNode()
55   {
56     super();
57   }
58
59   /**
60    * Creates a new SequenceNode object.
61    * 
62    * @param val
63    *                DOCUMENT ME!
64    * @param parent
65    *                DOCUMENT ME!
66    * @param dist
67    *                DOCUMENT ME!
68    * @param name
69    *                DOCUMENT ME!
70    */
71   public SequenceNode(Object val, SequenceNode parent, float dist,
72           String name)
73   {
74     super(val, parent, name);
75     this.dist = dist;
76   }
77
78   /**
79    * Creates a new SequenceNode object.
80    * 
81    * @param val
82    *                DOCUMENT ME!
83    * @param parent
84    *                DOCUMENT ME!
85    * @param name
86    *                DOCUMENT ME!
87    * @param dist
88    *                DOCUMENT ME!
89    * @param bootstrap
90    *                DOCUMENT ME!
91    * @param dummy
92    *                DOCUMENT ME!
93    */
94   public SequenceNode(Object val, SequenceNode parent, String name,
95           float dist, int bootstrap, boolean dummy)
96   {
97     super(val, parent, name);
98     this.dist = dist;
99     this.bootstrap = bootstrap;
100     this.dummy = dummy;
101   }
102
103   /**
104    * @param dummy
105    *                true if node is created for the representation of polytomous
106    *                trees
107    */
108   public boolean isDummy()
109   {
110     return dummy;
111   }
112
113   /*
114    * @param placeholder is true if the sequence refered to in the element node
115    * is not actually present in the associated alignment
116    */
117   public boolean isPlaceholder()
118   {
119     return placeholder;
120   }
121
122   /**
123    * DOCUMENT ME!
124    * 
125    * @param newstate
126    *                DOCUMENT ME!
127    * 
128    * @return DOCUMENT ME!
129    */
130   public boolean setDummy(boolean newstate)
131   {
132     boolean oldstate = dummy;
133     dummy = newstate;
134
135     return oldstate;
136   }
137
138   /**
139    * DOCUMENT ME!
140    * 
141    * @param Placeholder
142    *                DOCUMENT ME!
143    */
144   public void setPlaceholder(boolean Placeholder)
145   {
146     this.placeholder = Placeholder;
147   }
148
149   /**
150    * ascends the tree but doesn't stop until a non-dummy node is discovered.
151    * This will probably break if the tree is a mixture of BinaryNodes and
152    * SequenceNodes.
153    */
154   public SequenceNode AscendTree()
155   {
156     SequenceNode c = this;
157
158     do
159     {
160       c = (SequenceNode) c.parent();
161     } while ((c != null) && c.dummy);
162
163     return c;
164   }
165
166   /**
167    * test if this node has a name that might be a label rather than a bootstrap
168    * value
169    * 
170    * @return true if node has a non-numeric label
171    */
172   public boolean isSequenceLabel()
173   {
174     if (name != null && name.length() > 0)
175     {
176       for (int c = 0, s = name.length(); c < s; c++)
177       {
178         char q = name.charAt(c);
179         if ('0' <= q && q <= '9')
180           continue;
181         return true;
182       }
183     }
184     return false;
185   }
186 }