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