2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
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
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 package jalview.datamodel;
23 import java.util.HashMap;
25 import java.util.Vector;
33 public class SequenceFeature
35 private static final String STATUS = "status";
37 private static final String STRAND = "STRAND";
39 private static final String ATTRIBUTES = "ATTRIBUTES";
49 public String description;
51 public Map<String, Object> otherDetails;
53 public Vector<String> links;
55 // Feature group can be set from a features file
56 // as a group of features between STARTGROUP and ENDGROUP markers
57 public String featureGroup;
59 public SequenceFeature()
64 * Constructs a duplicate feature. Note: Uses makes a shallow copy of the
65 * otherDetails map, so the new and original SequenceFeature may reference the
66 * same objects in the map.
70 public SequenceFeature(SequenceFeature cpy)
79 type = new String(cpy.type);
81 if (cpy.description != null)
83 description = new String(cpy.description);
85 if (cpy.featureGroup != null)
87 featureGroup = new String(cpy.featureGroup);
89 if (cpy.otherDetails != null)
93 otherDetails = (Map<String, Object>) ((HashMap<String, Object>) cpy.otherDetails)
100 if (cpy.links != null && cpy.links.size() > 0)
102 links = new Vector<String>();
103 for (int i = 0, iSize = cpy.links.size(); i < iSize; i++)
105 links.addElement(cpy.links.elementAt(i));
111 public SequenceFeature(String type, String desc, String status,
112 int begin, int end, String featureGroup)
115 this.description = desc;
116 setValue(STATUS, status);
119 this.featureGroup = featureGroup;
122 public SequenceFeature(String type, String desc, int begin, int end,
123 float score, String featureGroup)
126 this.description = desc;
130 this.featureGroup = featureGroup;
133 public boolean equals(SequenceFeature sf)
135 if (begin != sf.begin || end != sf.end || score != sf.score)
140 if (!(type + description + featureGroup).equals(sf.type
141 + sf.description + sf.featureGroup))
152 * @return DOCUMENT ME!
154 public int getBegin()
159 public void setBegin(int start)
167 * @return DOCUMENT ME!
174 public void setEnd(int end)
182 * @return DOCUMENT ME!
184 public String getType()
189 public void setType(String type)
197 * @return DOCUMENT ME!
199 public String getDescription()
204 public void setDescription(String desc)
209 public String getFeatureGroup()
214 public void setFeatureGroup(String featureGroup)
216 this.featureGroup = featureGroup;
219 public void addLink(String labelLink)
223 links = new Vector<String>();
226 links.insertElementAt(labelLink, 0);
229 public float getScore()
234 public void setScore(float value)
240 * Used for getting values which are not in the basic set. eg STRAND, FRAME
246 public Object getValue(String key)
248 if (otherDetails == null)
254 return otherDetails.get(key);
259 * Returns a property value for the given key if known, else the specified
263 * @param defaultValue
266 public Object getValue(String key, Object defaultValue)
268 Object value = getValue(key);
269 return value == null ? defaultValue : value;
273 * Used for setting values which are not in the basic set. eg STRAND, FRAME
281 public void setValue(String key, Object value)
285 if (otherDetails == null)
287 otherDetails = new HashMap<String, Object>();
290 otherDetails.put(key, value);
295 * The following methods are added to maintain the castor Uniprot mapping file
298 public void setStatus(String status)
300 setValue(STATUS, status);
303 public String getStatus()
305 return (String) getValue(STATUS);
308 public void setAttributes(String attr)
310 setValue(ATTRIBUTES, attr);
313 public String getAttributes()
315 return (String) getValue(ATTRIBUTES);
318 public void setPosition(int pos)
324 public int getPosition()
330 * Return 1 for forward strand ('+' in GFF), -1 for reverse strand ('-' in
331 * GFF), and 0 for unknown or not (validly) specified
335 public int getStrand()
338 if (otherDetails != null)
340 Object str = otherDetails.get(STRAND);
345 else if ("+".equals(str))
353 public void setStrand(String strand)
355 setValue(STRAND, strand);