JAL-1432 updated copyright notices
[jalview.git] / src / jalview / datamodel / SequenceNode.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.0b1)
3  * Copyright (C) 2014 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 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  * The Jalview Authors are detailed in the 'AUTHORS' file.
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 trees
106    */
107   public boolean isDummy()
108   {
109     return dummy;
110   }
111
112   /*
113    * @param placeholder is true if the sequence refered to in the element node
114    * is not actually present in the associated alignment
115    */
116   public boolean isPlaceholder()
117   {
118     return placeholder;
119   }
120
121   /**
122    * DOCUMENT ME!
123    * 
124    * @param newstate
125    *          DOCUMENT ME!
126    * 
127    * @return DOCUMENT ME!
128    */
129   public boolean setDummy(boolean newstate)
130   {
131     boolean oldstate = dummy;
132     dummy = newstate;
133
134     return oldstate;
135   }
136
137   /**
138    * DOCUMENT ME!
139    * 
140    * @param Placeholder
141    *          DOCUMENT ME!
142    */
143   public void setPlaceholder(boolean Placeholder)
144   {
145     this.placeholder = Placeholder;
146   }
147
148   /**
149    * ascends the tree but doesn't stop until a non-dummy node is discovered.
150    * This will probably break if the tree is a mixture of BinaryNodes and
151    * SequenceNodes.
152    */
153   public SequenceNode AscendTree()
154   {
155     SequenceNode c = this;
156
157     do
158     {
159       c = (SequenceNode) c.parent();
160     } while ((c != null) && c.dummy);
161
162     return c;
163   }
164
165   /**
166    * test if this node has a name that might be a label rather than a bootstrap
167    * value
168    * 
169    * @return true if node has a non-numeric label
170    */
171   public boolean isSequenceLabel()
172   {
173     if (name != null && name.length() > 0)
174     {
175       for (int c = 0, s = name.length(); c < s; c++)
176       {
177         char q = name.charAt(c);
178         if ('0' <= q && q <= '9')
179           continue;
180         return true;
181       }
182     }
183     return false;
184   }
185 }