package jalview.datamodel.features;
+import jalview.datamodel.ContiguousI;
import jalview.datamodel.SequenceFeature;
import java.util.ArrayList;
}
/**
- * Scans all positional features to check whether the given feature group is
- * found, and returns true if found, else false
- *
- * @param featureGroup
- * @return
- */
- protected boolean findFeatureGroup(String featureGroup)
- {
- for (SequenceFeature sf : getPositionalFeatures())
- {
- String group = sf.getFeatureGroup();
- if (group == featureGroup
- || (group != null && group.equals(featureGroup)))
- {
- return true;
- }
- }
- return false;
- }
-
- /**
* Answers true if this store has no features, else false
*
* @return
{
return positional ? positionalMaxScore : nonPositionalMaxScore;
}
+
+ /**
+ * Answers a list of all either positional or non-positional features whose
+ * feature group matches the given group (which may be null)
+ *
+ * @param positional
+ * @param group
+ * @return
+ */
+ public List<SequenceFeature> getFeaturesForGroup(boolean positional,
+ String group)
+ {
+ List<SequenceFeature> result = new ArrayList<SequenceFeature>();
+
+ /*
+ * if we know features don't include the target group, no need
+ * to inspect them for matches
+ */
+ if (positional && !positionalFeatureGroups.contains(group)
+ || !positional && !nonPositionalFeatureGroups.contains(group))
+ {
+ return result;
+ }
+
+ List<SequenceFeature> sfs = positional ? getPositionalFeatures()
+ : getNonPositionalFeatures();
+ for (SequenceFeature sf : sfs)
+ {
+ String featureGroup = sf.getFeatureGroup();
+ if (group == null && featureGroup == null || group != null
+ && group.equals(featureGroup))
+ {
+ result.add(sf);
+ }
+ }
+ return result;
+ }
+
+ /**
+ * Adds the shift value to the start and end of all positional features.
+ * Returns true if at least one feature was updated, else false.
+ *
+ * @param shift
+ * @return
+ */
+ public synchronized boolean shiftFeatures(int shift)
+ {
+ /*
+ * Because begin and end are final fields (to ensure the data store's
+ * integrity), we have to delete each feature and re-add it as amended.
+ * (Although a simple shift of all values would preserve data integrity!)
+ */
+ boolean modified = false;
+ for (SequenceFeature sf : getPositionalFeatures())
+ {
+ modified = true;
+ int newBegin = sf.getBegin() + shift;
+ int newEnd = sf.getEnd() + shift;
+
+ /*
+ * sanity check: don't shift left of the first residue
+ */
+ if (newEnd > 0)
+ {
+ newBegin = Math.max(1, newBegin);
+ SequenceFeature sf2 = new SequenceFeature(sf, newBegin, newEnd,
+ sf.getFeatureGroup(), sf.getScore());
+ addFeature(sf2);
+ }
+ delete(sf);
+ }
+ return modified;
+ }
}