Formatting
[jalview.git] / src / jalview / datamodel / SequenceFeature.java
1 /*\r
2  * Jalview - A Sequence Alignment Editor and Viewer\r
3  * Copyright (C) 2007 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
4  *\r
5  * This program is free software; you can redistribute it and/or\r
6  * modify it under the terms of the GNU General Public License\r
7  * as published by the Free Software Foundation; either version 2\r
8  * of the License, or (at your option) any later version.\r
9  *\r
10  * This program is distributed in the hope that it will be useful,\r
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
13  * GNU General Public License for more details.\r
14  *\r
15  * You should have received a copy of the GNU General Public License\r
16  * along with this program; if not, write to the Free Software\r
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA\r
18  */\r
19 package jalview.datamodel;\r
20 \r
21 import java.util.*;\r
22 \r
23 /**\r
24  * DOCUMENT ME!\r
25  *\r
26  * @author $author$\r
27  * @version $Revision$\r
28  */\r
29 public class SequenceFeature\r
30 {\r
31   public int begin;\r
32   public int end;\r
33   public float score;\r
34   public String type;\r
35   public String description;\r
36   public Hashtable otherDetails;\r
37   public java.util.Vector links;\r
38 \r
39   // Feature group can be set from a features file\r
40   // as a group of features between STARTGROUP and ENDGROUP markers\r
41   public String featureGroup;\r
42 \r
43   public SequenceFeature()\r
44   {}\r
45 \r
46   /**\r
47    * Constructs a duplicate feature.\r
48    * Note: Uses clone on the otherDetails so only shallow copies are made\r
49    * of additional properties and method will silently fail if unclonable\r
50    * objects are found in the hash.\r
51    * @param cpy\r
52    */\r
53   public SequenceFeature(SequenceFeature cpy)\r
54   {\r
55     if (cpy != null)\r
56     {\r
57       begin = cpy.begin;\r
58       end = cpy.end;\r
59       score = cpy.score;\r
60       if (cpy.type != null)\r
61       {\r
62         type = new String(cpy.type);\r
63       }\r
64       if (cpy.description != null)\r
65       {\r
66         description = new String(cpy.description);\r
67       }\r
68       if (cpy.featureGroup != null)\r
69       {\r
70         featureGroup = new String(cpy.featureGroup);\r
71       }\r
72       if (cpy.otherDetails != null)\r
73       {\r
74         try\r
75         {\r
76           otherDetails = (Hashtable) cpy.otherDetails.clone();\r
77         }\r
78         catch (Exception e)\r
79         {\r
80           // Uncloneable objects in the otherDetails - don't complain\r
81         }\r
82       }\r
83       if (cpy.links != null && cpy.links.size() > 0)\r
84       {\r
85         links = new Vector();\r
86         for (int i = 0, iSize = cpy.links.size(); i < iSize; i++)\r
87         {\r
88           links.setElementAt(cpy.links.elementAt(i), i);\r
89         }\r
90       }\r
91     }\r
92   }\r
93 \r
94   public SequenceFeature(String type,\r
95                          String desc,\r
96                          String status,\r
97                          int begin, int end,\r
98                          String featureGroup)\r
99   {\r
100     this.type = type;\r
101     this.description = desc;\r
102     setValue("status", status);\r
103     this.begin = begin;\r
104     this.end = end;\r
105     this.featureGroup = featureGroup;\r
106   }\r
107 \r
108   public SequenceFeature(String type,\r
109                          String desc,\r
110                          int begin, int end,\r
111                          float score,\r
112                          String featureGroup)\r
113   {\r
114     this.type = type;\r
115     this.description = desc;\r
116     this.begin = begin;\r
117     this.end = end;\r
118     this.score = score;\r
119     this.featureGroup = featureGroup;\r
120   }\r
121 \r
122   public boolean equals(SequenceFeature sf)\r
123   {\r
124     if (begin != sf.begin\r
125         || end != sf.end\r
126         || score != sf.score)\r
127     {\r
128       return false;\r
129     }\r
130 \r
131     if (! (type + description + featureGroup).equals\r
132         (sf.type + sf.description + sf.featureGroup))\r
133     {\r
134       return false;\r
135     }\r
136 \r
137     return true;\r
138   }\r
139 \r
140   /**\r
141    * DOCUMENT ME!\r
142    *\r
143    * @return DOCUMENT ME!\r
144    */\r
145   public int getBegin()\r
146   {\r
147     return begin;\r
148   }\r
149 \r
150   public void setBegin(int start)\r
151   {\r
152     this.begin = start;\r
153   }\r
154 \r
155   /**\r
156    * DOCUMENT ME!\r
157    *\r
158    * @return DOCUMENT ME!\r
159    */\r
160   public int getEnd()\r
161   {\r
162     return end;\r
163   }\r
164 \r
165   public void setEnd(int end)\r
166   {\r
167     this.end = end;\r
168   }\r
169 \r
170   /**\r
171    * DOCUMENT ME!\r
172    *\r
173    * @return DOCUMENT ME!\r
174    */\r
175   public String getType()\r
176   {\r
177     return type;\r
178   }\r
179 \r
180   public void setType(String type)\r
181   {\r
182     this.type = type;\r
183   }\r
184 \r
185   /**\r
186    * DOCUMENT ME!\r
187    *\r
188    * @return DOCUMENT ME!\r
189    */\r
190   public String getDescription()\r
191   {\r
192     return description;\r
193   }\r
194 \r
195   public void setDescription(String desc)\r
196   {\r
197     description = desc;\r
198   }\r
199 \r
200   public String getFeatureGroup()\r
201   {\r
202     return featureGroup;\r
203   }\r
204 \r
205   public void setFeatureGroup(String featureGroup)\r
206   {\r
207     this.featureGroup = featureGroup;\r
208   }\r
209 \r
210   public void addLink(String labelLink)\r
211   {\r
212     if (links == null)\r
213     {\r
214       links = new java.util.Vector();\r
215     }\r
216 \r
217     links.insertElementAt(labelLink, 0);\r
218   }\r
219 \r
220   public float getScore()\r
221   {\r
222     return score;\r
223   }\r
224 \r
225   public void setScore(float value)\r
226   {\r
227     score = value;\r
228   }\r
229 \r
230   /**\r
231    * Used for getting values which are not in the\r
232    * basic set. eg STRAND, FRAME for GFF file\r
233    * @param key String\r
234    */\r
235   public Object getValue(String key)\r
236   {\r
237     if (otherDetails == null)\r
238     {\r
239       return null;\r
240     }\r
241     else\r
242     {\r
243       return otherDetails.get(key);\r
244     }\r
245   }\r
246 \r
247   /**\r
248    * Used for setting values which are not in the\r
249    * basic set. eg STRAND, FRAME for GFF file\r
250    * @param key   eg STRAND\r
251    * @param value eg +\r
252    */\r
253   public void setValue(String key, Object value)\r
254   {\r
255     if (value != null)\r
256     {\r
257       if (otherDetails == null)\r
258       {\r
259         otherDetails = new Hashtable();\r
260       }\r
261 \r
262       otherDetails.put(key, value);\r
263     }\r
264   }\r
265 \r
266   /*\r
267    * The following methods are added to maintain\r
268    * the castor Uniprot mapping file for the moment.\r
269    */\r
270   public void setStatus(String status)\r
271   {\r
272     setValue("status", status);\r
273   }\r
274 \r
275   public String getStatus()\r
276   {\r
277     if (otherDetails != null)\r
278     {\r
279       return otherDetails.get("status").toString();\r
280     }\r
281     else\r
282     {\r
283       return null;\r
284     }\r
285   }\r
286 \r
287   public void setPosition(int pos)\r
288   {\r
289     begin = pos;\r
290     end = pos;\r
291   }\r
292 \r
293   public int getPosition()\r
294   {\r
295     return begin;\r
296   }\r
297 \r
298 }\r