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