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