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 key for Phase designed not to conflict with real GFF data
40 private static final String PHASE = "!Phase";
42 private static final String ATTRIBUTES = "ATTRIBUTES";
52 public String description;
54 public Map<String, Object> otherDetails;
56 public Vector<String> links;
58 // Feature group can be set from a features file
59 // as a group of features between STARTGROUP and ENDGROUP markers
60 public String featureGroup;
62 public SequenceFeature()
67 * Constructs a duplicate feature. Note: Uses makes a shallow copy of the
68 * otherDetails map, so the new and original SequenceFeature may reference the
69 * same objects in the map.
73 public SequenceFeature(SequenceFeature cpy)
82 type = new String(cpy.type);
84 if (cpy.description != null)
86 description = new String(cpy.description);
88 if (cpy.featureGroup != null)
90 featureGroup = new String(cpy.featureGroup);
92 if (cpy.otherDetails != null)
96 otherDetails = (Map<String, Object>) ((HashMap<String, Object>) cpy.otherDetails)
103 if (cpy.links != null && cpy.links.size() > 0)
105 links = new Vector<String>();
106 for (int i = 0, iSize = cpy.links.size(); i < iSize; i++)
108 links.addElement(cpy.links.elementAt(i));
114 public SequenceFeature(String type, String desc, String status,
115 int begin, int end, String featureGroup)
118 this.description = desc;
119 setValue(STATUS, status);
122 this.featureGroup = featureGroup;
125 public SequenceFeature(String type, String desc, int begin, int end,
126 float score, String featureGroup)
129 this.description = desc;
133 this.featureGroup = featureGroup;
136 public boolean equals(SequenceFeature sf)
138 if (begin != sf.begin || end != sf.end || score != sf.score)
143 if (!(type + description + featureGroup).equals(sf.type
144 + sf.description + sf.featureGroup))
155 * @return DOCUMENT ME!
157 public int getBegin()
162 public void setBegin(int start)
170 * @return DOCUMENT ME!
177 public void setEnd(int end)
185 * @return DOCUMENT ME!
187 public String getType()
192 public void setType(String type)
200 * @return DOCUMENT ME!
202 public String getDescription()
207 public void setDescription(String desc)
212 public String getFeatureGroup()
217 public void setFeatureGroup(String featureGroup)
219 this.featureGroup = featureGroup;
222 public void addLink(String labelLink)
226 links = new Vector<String>();
229 links.insertElementAt(labelLink, 0);
232 public float getScore()
237 public void setScore(float value)
243 * Used for getting values which are not in the basic set. eg STRAND, PHASE
249 public Object getValue(String key)
251 if (otherDetails == null)
257 return otherDetails.get(key);
262 * Returns a property value for the given key if known, else the specified
266 * @param defaultValue
269 public Object getValue(String key, Object defaultValue)
271 Object value = getValue(key);
272 return value == null ? defaultValue : value;
276 * Used for setting values which are not in the basic set. eg STRAND, FRAME
284 public void setValue(String key, Object value)
288 if (otherDetails == null)
290 otherDetails = new HashMap<String, Object>();
293 otherDetails.put(key, value);
298 * The following methods are added to maintain the castor Uniprot mapping file
301 public void setStatus(String status)
303 setValue(STATUS, status);
306 public String getStatus()
308 return (String) getValue(STATUS);
311 public void setAttributes(String attr)
313 setValue(ATTRIBUTES, attr);
316 public String getAttributes()
318 return (String) getValue(ATTRIBUTES);
321 public void setPosition(int pos)
327 public int getPosition()
333 * Return 1 for forward strand ('+' in GFF), -1 for reverse strand ('-' in
334 * GFF), and 0 for unknown or not (validly) specified
338 public int getStrand()
341 if (otherDetails != null)
343 Object str = otherDetails.get(STRAND);
348 else if ("+".equals(str))
356 public void setStrand(String strand)
358 setValue(STRAND, strand);
361 public void setPhase(String phase)
363 setValue(PHASE, phase);
366 public String getPhase()
368 return (String) getValue(PHASE);
372 * Readable representation, for debug only, not guaranteed not to change
376 public String toString()
378 return String.format("%d %d %s %s", getBegin(), getEnd(), getType(),