JAL-1432 updated copyright notices
[jalview.git] / src / jalview / datamodel / SequenceFeature.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.util.*;
22
23 /**
24  * DOCUMENT ME!
25  * 
26  * @author $author$
27  * @version $Revision$
28  */
29 public class SequenceFeature
30 {
31   public int begin;
32
33   public int end;
34
35   public float score;
36
37   public String type;
38
39   public String description;
40
41   public Hashtable otherDetails;
42
43   public java.util.Vector links;
44
45   // Feature group can be set from a features file
46   // as a group of features between STARTGROUP and ENDGROUP markers
47   public String featureGroup;
48
49   public SequenceFeature()
50   {
51   }
52
53   /**
54    * Constructs a duplicate feature. Note: Uses clone on the otherDetails so
55    * only shallow copies are made of additional properties and method will
56    * silently fail if unclonable objects are found in the hash.
57    * 
58    * @param cpy
59    */
60   public SequenceFeature(SequenceFeature cpy)
61   {
62     if (cpy != null)
63     {
64       begin = cpy.begin;
65       end = cpy.end;
66       score = cpy.score;
67       if (cpy.type != null)
68       {
69         type = new String(cpy.type);
70       }
71       if (cpy.description != null)
72       {
73         description = new String(cpy.description);
74       }
75       if (cpy.featureGroup != null)
76       {
77         featureGroup = new String(cpy.featureGroup);
78       }
79       if (cpy.otherDetails != null)
80       {
81         try
82         {
83           otherDetails = (Hashtable) cpy.otherDetails.clone();
84         } catch (Exception e)
85         {
86           // Uncloneable objects in the otherDetails - don't complain
87         }
88       }
89       if (cpy.links != null && cpy.links.size() > 0)
90       {
91         links = new Vector();
92         for (int i = 0, iSize = cpy.links.size(); i < iSize; i++)
93         {
94           links.addElement(cpy.links.elementAt(i));
95         }
96       }
97     }
98   }
99
100   public SequenceFeature(String type, String desc, String status,
101           int begin, int end, String featureGroup)
102   {
103     this.type = type;
104     this.description = desc;
105     setValue("status", status);
106     this.begin = begin;
107     this.end = end;
108     this.featureGroup = featureGroup;
109   }
110
111   public SequenceFeature(String type, String desc, int begin, int end,
112           float score, String featureGroup)
113   {
114     this.type = type;
115     this.description = desc;
116     this.begin = begin;
117     this.end = end;
118     this.score = score;
119     this.featureGroup = featureGroup;
120   }
121
122   public boolean equals(SequenceFeature sf)
123   {
124     if (begin != sf.begin || end != sf.end || score != sf.score)
125     {
126       return false;
127     }
128
129     if (!(type + description + featureGroup).equals(sf.type
130             + sf.description + sf.featureGroup))
131     {
132       return false;
133     }
134
135     return true;
136   }
137
138   /**
139    * DOCUMENT ME!
140    * 
141    * @return DOCUMENT ME!
142    */
143   public int getBegin()
144   {
145     return begin;
146   }
147
148   public void setBegin(int start)
149   {
150     this.begin = start;
151   }
152
153   /**
154    * DOCUMENT ME!
155    * 
156    * @return DOCUMENT ME!
157    */
158   public int getEnd()
159   {
160     return end;
161   }
162
163   public void setEnd(int end)
164   {
165     this.end = end;
166   }
167
168   /**
169    * DOCUMENT ME!
170    * 
171    * @return DOCUMENT ME!
172    */
173   public String getType()
174   {
175     return type;
176   }
177
178   public void setType(String type)
179   {
180     this.type = type;
181   }
182
183   /**
184    * DOCUMENT ME!
185    * 
186    * @return DOCUMENT ME!
187    */
188   public String getDescription()
189   {
190     return description;
191   }
192
193   public void setDescription(String desc)
194   {
195     description = desc;
196   }
197
198   public String getFeatureGroup()
199   {
200     return featureGroup;
201   }
202
203   public void setFeatureGroup(String featureGroup)
204   {
205     this.featureGroup = featureGroup;
206   }
207
208   public void addLink(String labelLink)
209   {
210     if (links == null)
211     {
212       links = new java.util.Vector();
213     }
214
215     links.insertElementAt(labelLink, 0);
216   }
217
218   public float getScore()
219   {
220     return score;
221   }
222
223   public void setScore(float value)
224   {
225     score = value;
226   }
227
228   /**
229    * Used for getting values which are not in the basic set. eg STRAND, FRAME
230    * for GFF file
231    * 
232    * @param key
233    *          String
234    */
235   public Object getValue(String key)
236   {
237     if (otherDetails == null)
238     {
239       return null;
240     }
241     else
242     {
243       return otherDetails.get(key);
244     }
245   }
246
247   /**
248    * Used for setting values which are not in the basic set. eg STRAND, FRAME
249    * for GFF file
250    * 
251    * @param key
252    *          eg STRAND
253    * @param value
254    *          eg +
255    */
256   public void setValue(String key, Object value)
257   {
258     if (value != null)
259     {
260       if (otherDetails == null)
261       {
262         otherDetails = new Hashtable();
263       }
264
265       otherDetails.put(key, value);
266     }
267   }
268
269   /*
270    * The following methods are added to maintain the castor Uniprot mapping file
271    * for the moment.
272    */
273   public void setStatus(String status)
274   {
275     setValue("status", status);
276   }
277
278   public String getStatus()
279   {
280     if (otherDetails != null)
281     {
282       String stat = (String) otherDetails.get("status");
283       if (stat != null)
284         return new String(stat);
285     }
286     return null;
287   }
288
289   public void setPosition(int pos)
290   {
291     begin = pos;
292     end = pos;
293   }
294
295   public int getPosition()
296   {
297     return begin;
298   }
299
300 }