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