7d644e8476a27b6de229381d4c3f8053e88dc5eb
[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.Hashtable;
22
23 /**
24  * DOCUMENT ME!
25  *
26  * @author $author$
27  * @version $Revision$
28  */
29 public class SequenceFeature
30 {
31     public int begin;
32     public int end;
33     public float score;
34     public String type;
35     public String description;
36     public Hashtable otherDetails;
37     public java.util.Vector links;
38
39     // Feature group can be set from a features file
40     // as a group of features between STARTGROUP and ENDGROUP markers
41     public String featureGroup;
42
43     public SequenceFeature()
44     {}
45
46     public SequenceFeature(String type,
47                            String desc,
48                            String status,
49                            int begin, int end,
50                            String featureGroup)
51     {
52       this.type = type;
53       this.description = desc;
54       setValue("status", status);
55       this.begin = begin;
56       this.end = end;
57       this.featureGroup = featureGroup;
58     }
59
60     public SequenceFeature(String type,
61                            String desc,
62                            int begin, int end,
63                            float score,
64                            String featureGroup)
65     {
66       this.type = type;
67       this.description = desc;
68       this.begin = begin;
69       this.end = end;
70       this.score = score;
71       this.featureGroup = featureGroup;
72     }
73
74     public boolean equals(SequenceFeature sf)
75     {
76       if (begin != sf.begin
77           || end != sf.end
78           || score != sf.score)
79         return false;
80
81       if(!(type+description+featureGroup).equals
82          (sf.type+sf.description+sf.featureGroup))
83         return false;
84
85       return true;
86     }
87
88
89     /**
90      * DOCUMENT ME!
91      *
92      * @return DOCUMENT ME!
93      */
94     public int getBegin()
95     {
96         return begin;
97     }
98
99     public void setBegin(int start)
100     {
101       this.begin = start;
102     }
103
104     /**
105      * DOCUMENT ME!
106      *
107      * @return DOCUMENT ME!
108      */
109     public int getEnd()
110     {
111         return end;
112     }
113
114     public void setEnd(int end)
115     {
116       this.end = end;
117     }
118
119     /**
120      * DOCUMENT ME!
121      *
122      * @return DOCUMENT ME!
123      */
124     public String getType()
125     {
126         return type;
127     }
128
129     public void setType(String type)
130     {
131       this.type = type;
132     }
133
134     /**
135      * DOCUMENT ME!
136      *
137      * @return DOCUMENT ME!
138      */
139     public String getDescription()
140     {
141         return description;
142     }
143
144     public void setDescription(String desc)
145     {
146       description = desc;
147     }
148
149     public String getFeatureGroup()
150     {
151       return featureGroup;
152     }
153
154     public void setFeatureGroup(String featureGroup)
155     {
156       this.featureGroup = featureGroup;
157     }
158
159     public void addLink(String labelLink)
160     {
161       if(links==null)
162         links = new java.util.Vector();
163
164       links.insertElementAt(labelLink,0);
165     }
166
167     public float getScore()
168     {
169       return score;
170     }
171
172     public void setScore(float value)
173     {
174       score = value;
175     }
176
177     /**
178      * Used for getting values which are not in the
179      * basic set. eg STRAND, FRAME for GFF file
180      * @param key String
181      */
182     public Object getValue(String key)
183     {
184       if(otherDetails==null)
185         return null;
186       else
187         return otherDetails.get(key);
188     }
189
190     /**
191      * Used for setting values which are not in the
192      * basic set. eg STRAND, FRAME for GFF file
193      * @param key   eg STRAND
194      * @param value eg +
195      */
196     public void setValue(String key, Object value)
197     {
198       if(value!=null)
199       {
200         if (otherDetails == null)
201           otherDetails = new Hashtable();
202
203         otherDetails.put(key, value);
204       }
205     }
206
207
208     /*
209      * The following methods are added to maintain
210      * the castor Uniprot mapping file for the moment.
211      */
212     public void setStatus(String status)
213     {
214       setValue("status", status);
215     }
216
217     public String getStatus()
218     {
219       if (otherDetails != null)
220         return otherDetails.get("status").toString();
221       else
222         return null;
223     }
224
225     public void setPosition(int pos)
226     {
227       begin = pos;
228       end = pos;
229     }
230
231     public int getPosition()
232     {
233       return begin;
234     }
235
236 }