+ return (String) getValue(PHASE);
+ }
+
+ /**
+ * Sets the 'raw' ENA format location specifier e.g. join(12..45,89..121)
+ *
+ * @param loc
+ */
+ public void setEnaLocation(String loc)
+ {
+ setValue(LOCATION, loc);
+ }
+
+ /**
+ * Gets the 'raw' ENA format location specifier e.g. join(12..45,89..121)
+ *
+ * @param loc
+ */
+ public String getEnaLocation()
+ {
+ return (String) getValue(LOCATION);
+ }
+
+ /**
+ * 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());
+ }
+
+ /**
+ * Overridden to ensure that whenever two objects are equal, they have the
+ * same hashCode
+ */
+ @Override
+ public int hashCode()
+ {
+ String s = getType() + getDescription() + getFeatureGroup()
+ + getValue("ID") + getValue("Name") + getValue("Parent")
+ + getPhase();
+ return s.hashCode() + getBegin() + getEnd() + (int) getScore()
+ + getStrand();
+ }
+
+ /**
+ * Answers true if the feature's start/end values represent two related
+ * positions, rather than ends of a range. Such features may be visualised or
+ * reported differently to features on a range.
+ */
+ @Override
+ public boolean isContactFeature()
+ {
+ return contactFeature;
+ }
+
+ /**
+ * Answers true if the sequence has zero start and end position
+ *
+ * @return
+ */
+ public boolean isNonPositional()
+ {
+ return begin == 0 && end == 0;
+ }
+
+ /**
+ * Answers an html-formatted report of feature details
+ *
+ * @return
+ */
+ public String getDetailsReport()
+ {
+ FeatureSourceI metadata = FeatureSources.getInstance()
+ .getSource(source);
+
+ StringBuilder sb = new StringBuilder(128);
+ sb.append("<br>");
+ sb.append("<table>");
+ sb.append(String.format(ROW_DATA, "Type", type, ""));
+ sb.append(String.format(ROW_DATA, "Start/end", begin == end ? begin
+ : begin + (isContactFeature() ? ":" : "-") + end, ""));
+ String desc = StringUtils.stripHtmlTags(description);
+ sb.append(String.format(ROW_DATA, "Description", desc, ""));
+ if (!Float.isNaN(score) && score != 0f)
+ {
+ sb.append(String.format(ROW_DATA, "Score", score, ""));
+ }
+ if (featureGroup != null)
+ {
+ sb.append(String.format(ROW_DATA, "Group", featureGroup, ""));
+ }
+
+ if (otherDetails != null)
+ {
+ TreeMap<String, Object> ordered = new TreeMap<>(
+ String.CASE_INSENSITIVE_ORDER);
+ ordered.putAll(otherDetails);
+
+ for (Entry<String, Object> entry : ordered.entrySet())
+ {
+ String key = entry.getKey();
+ if (ATTRIBUTES.equals(key))
+ {
+ continue; // to avoid double reporting
+ }
+
+ Object value = entry.getValue();
+ if (value instanceof Map<?, ?>)
+ {
+ /*
+ * expand values in a Map attribute across separate lines
+ * copy to a TreeMap for alphabetical ordering
+ */
+ Map<String, Object> values = (Map<String, Object>) value;
+ SortedMap<String, Object> sm = new TreeMap<>(
+ String.CASE_INSENSITIVE_ORDER);
+ sm.putAll(values);
+ for (Entry<?, ?> e : sm.entrySet())
+ {
+ sb.append(String.format(ROW_DATA, key, e.getKey().toString(), e
+ .getValue().toString()));
+ }
+ }
+ else
+ {
+ // tried <td title="key"> but it failed to provide a tooltip :-(
+ String attDesc = null;
+ if (metadata != null)
+ {
+ attDesc = metadata.getAttributeName(key);
+ }
+ String s = entry.getValue().toString();
+ if (isValueInteresting(key, s, metadata))
+ {
+ sb.append(String.format(ROW_DATA, key, attDesc == null ? ""
+ : attDesc, s));
+ }
+ }
+ }
+ }
+ sb.append("</table>");
+
+ String text = sb.toString();
+ return text;
+ }
+
+ /**
+ * Answers true if we judge the value is worth displaying, by some heuristic
+ * rules, else false
+ *
+ * @param key
+ * @param value
+ * @param metadata
+ * @return
+ */
+ boolean isValueInteresting(String key, String value,
+ FeatureSourceI metadata)
+ {
+ /*
+ * currently suppressing zero values as well as null or empty
+ */
+ if (value == null || "".equals(value) || ".".equals(value)
+ || "0".equals(value))
+ {
+ return false;
+ }
+
+ if (metadata == null)
+ {
+ return true;
+ }
+
+ FeatureAttributeType attType = metadata.getAttributeType(key);
+ if (attType != null
+ && (attType == FeatureAttributeType.Float || attType
+ .equals(FeatureAttributeType.Integer)))
+ {
+ try
+ {
+ float fval = Float.valueOf(value);
+ if (fval == 0f)
+ {
+ return false;
+ }
+ } catch (NumberFormatException e)
+ {
+ // ignore
+ }
+ }
+
+ return true; // default to interesting
+ }
+
+ /**
+ * Sets the feature source identifier
+ *
+ * @param theSource
+ */
+ public void setSource(String theSource)
+ {
+ source = theSource;
+ }
+}
+
+class SFSortByEnd implements Comparator<SequenceFeature>
+{
+ @Override
+ public int compare(SequenceFeature a, SequenceFeature b)
+ {
+ return a.getEnd() - b.getEnd();