*/
package jalview.datamodel;
-import java.util.Hashtable;
+import java.util.HashMap;
+import java.util.Map;
import java.util.Vector;
/**
*/
public class SequenceFeature
{
+ private static final String STATUS = "status";
+
+ private static final String STRAND = "STRAND";
+
+ // private key for Phase designed not to conflict with real GFF data
+ private static final String PHASE = "!Phase";
+
+ private static final String ATTRIBUTES = "ATTRIBUTES";
+
public int begin;
public int end;
public String description;
- public Hashtable otherDetails;
+ public Map<String, Object> otherDetails;
public Vector<String> links;
}
/**
- * Constructs a duplicate feature. Note: Uses clone on the otherDetails so
- * only shallow copies are made of additional properties and method will
- * silently fail if unclonable objects are found in the hash.
+ * Constructs a duplicate feature. Note: Uses makes a shallow copy of the
+ * otherDetails map, so the new and original SequenceFeature may reference the
+ * same objects in the map.
*
* @param cpy
*/
{
try
{
- otherDetails = (Hashtable) cpy.otherDetails.clone();
+ otherDetails = (Map<String, Object>) ((HashMap<String, Object>) cpy.otherDetails)
+ .clone();
} catch (Exception e)
{
- // Uncloneable objects in the otherDetails - don't complain
+ // ignore
}
}
if (cpy.links != null && cpy.links.size() > 0)
{
this.type = type;
this.description = desc;
- setValue("status", status);
+ setValue(STATUS, status);
this.begin = begin;
this.end = end;
this.featureGroup = featureGroup;
}
/**
- * Used for getting values which are not in the basic set. eg STRAND, FRAME
+ * Used for getting values which are not in the basic set. eg STRAND, PHASE
* for GFF file
*
* @param key
}
/**
+ * Returns a property value for the given key if known, else the specified
+ * default value
+ *
+ * @param key
+ * @param defaultValue
+ * @return
+ */
+ public Object getValue(String key, Object defaultValue)
+ {
+ Object value = getValue(key);
+ return value == null ? defaultValue : value;
+ }
+
+ /**
* Used for setting values which are not in the basic set. eg STRAND, FRAME
* for GFF file
*
{
if (otherDetails == null)
{
- otherDetails = new Hashtable();
+ otherDetails = new HashMap<String, Object>();
}
otherDetails.put(key, value);
*/
public void setStatus(String status)
{
- setValue("status", status);
+ setValue(STATUS, status);
}
public String getStatus()
{
- if (otherDetails != null)
- {
- String stat = (String) otherDetails.get("status");
- if (stat != null)
- {
- return new String(stat);
- }
- }
- return null;
+ return (String) getValue(STATUS);
+ }
+
+ public void setAttributes(String attr)
+ {
+ setValue(ATTRIBUTES, attr);
+ }
+
+ public String getAttributes()
+ {
+ return (String) getValue(ATTRIBUTES);
}
public void setPosition(int pos)
return begin;
}
+ /**
+ * Return 1 for forward strand ('+' in GFF), -1 for reverse strand ('-' in
+ * GFF), and 0 for unknown or not (validly) specified
+ *
+ * @return
+ */
+ public int getStrand()
+ {
+ int strand = 0;
+ if (otherDetails != null)
+ {
+ Object str = otherDetails.get(STRAND);
+ if ("-".equals(str))
+ {
+ strand = -1;
+ }
+ else if ("+".equals(str))
+ {
+ strand = 1;
+ }
+ }
+ return strand;
+ }
+
+ public void setStrand(String strand)
+ {
+ setValue(STRAND, strand);
+ }
+
+ public void setPhase(String phase)
+ {
+ setValue(PHASE, phase);
+ }
+
+ public String getPhase()
+ {
+ return (String) getValue(PHASE);
+ }
+
+ /**
+ * Readable representation, for debug only, not guaranteed not to change
+ * between versions
+ */
+ @Override
+ public String toString()
+ {
+ return String.format("%d %d %s %s", getBegin(), getEnd(), getType(),
+ getDescription());
+ }
}