added sequence feature copy constructor.
[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     public SequenceFeature(SequenceFeature cpy) {
48         if (cpy!=null) {
49             begin = cpy.begin;
50             end = cpy.end;
51             score = cpy.score;
52             type = new String(cpy.type);
53             description = new String(cpy.description);
54             featureGroup = new String(cpy.featureGroup);
55             if (cpy.otherDetails!=null) {
56                 try {
57                     otherDetails = (Hashtable) cpy.otherDetails.clone();
58                 } catch (Exception e) {
59                     // Uncloneable objects in the otherDetails - don't complain
60                 }
61             }
62             if (cpy.links!=null && cpy.links.size()>0) {
63                 links=new Vector();
64                 for (int i=0,iSize=cpy.links.size(); i<iSize; i++) {
65                     links.setElementAt(cpy.links.elementAt(i), i);
66                 }
67             }
68         }
69     }
70     public SequenceFeature(String type,
71                            String desc,
72                            String status,
73                            int begin, int end,
74                            String featureGroup)
75     {
76       this.type = type;
77       this.description = desc;
78       setValue("status", status);
79       this.begin = begin;
80       this.end = end;
81       this.featureGroup = featureGroup;
82     }
83
84     public SequenceFeature(String type,
85                            String desc,
86                            int begin, int end,
87                            float score,
88                            String featureGroup)
89     {
90       this.type = type;
91       this.description = desc;
92       this.begin = begin;
93       this.end = end;
94       this.score = score;
95       this.featureGroup = featureGroup;
96     }
97
98     public boolean equals(SequenceFeature sf)
99     {
100       if (begin != sf.begin
101           || end != sf.end
102           || score != sf.score)
103         return false;
104
105       if(!(type+description+featureGroup).equals
106          (sf.type+sf.description+sf.featureGroup))
107         return false;
108
109       return true;
110     }
111
112
113     /**
114      * DOCUMENT ME!
115      *
116      * @return DOCUMENT ME!
117      */
118     public int getBegin()
119     {
120         return begin;
121     }
122
123     public void setBegin(int start)
124     {
125       this.begin = start;
126     }
127
128     /**
129      * DOCUMENT ME!
130      *
131      * @return DOCUMENT ME!
132      */
133     public int getEnd()
134     {
135         return end;
136     }
137
138     public void setEnd(int end)
139     {
140       this.end = end;
141     }
142
143     /**
144      * DOCUMENT ME!
145      *
146      * @return DOCUMENT ME!
147      */
148     public String getType()
149     {
150         return type;
151     }
152
153     public void setType(String type)
154     {
155       this.type = type;
156     }
157
158     /**
159      * DOCUMENT ME!
160      *
161      * @return DOCUMENT ME!
162      */
163     public String getDescription()
164     {
165         return description;
166     }
167
168     public void setDescription(String desc)
169     {
170       description = desc;
171     }
172
173     public String getFeatureGroup()
174     {
175       return featureGroup;
176     }
177
178     public void setFeatureGroup(String featureGroup)
179     {
180       this.featureGroup = featureGroup;
181     }
182
183     public void addLink(String labelLink)
184     {
185       if(links==null)
186         links = new java.util.Vector();
187
188       links.insertElementAt(labelLink,0);
189     }
190
191     public float getScore()
192     {
193       return score;
194     }
195
196     public void setScore(float value)
197     {
198       score = value;
199     }
200
201     /**
202      * Used for getting values which are not in the
203      * basic set. eg STRAND, FRAME for GFF file
204      * @param key String
205      */
206     public Object getValue(String key)
207     {
208       if(otherDetails==null)
209         return null;
210       else
211         return otherDetails.get(key);
212     }
213
214     /**
215      * Used for setting values which are not in the
216      * basic set. eg STRAND, FRAME for GFF file
217      * @param key   eg STRAND
218      * @param value eg +
219      */
220     public void setValue(String key, Object value)
221     {
222       if(value!=null)
223       {
224         if (otherDetails == null)
225           otherDetails = new Hashtable();
226
227         otherDetails.put(key, value);
228       }
229     }
230
231
232     /*
233      * The following methods are added to maintain
234      * the castor Uniprot mapping file for the moment.
235      */
236     public void setStatus(String status)
237     {
238       setValue("status", status);
239     }
240
241     public String getStatus()
242     {
243       if (otherDetails != null)
244         return otherDetails.get("status").toString();
245       else
246         return null;
247     }
248
249     public void setPosition(int pos)
250     {
251       begin = pos;
252       end = pos;
253     }
254
255     public int getPosition()
256     {
257       return begin;
258     }
259
260 }