JAL-2505 JAL-2542 SequenceFeatures.shift() to shift all positional
[jalview.git] / src / jalview / datamodel / features / SequenceFeatures.java
index af99ada..f263938 100644 (file)
@@ -220,9 +220,11 @@ public class SequenceFeatures implements SequenceFeaturesI
     /*
      * else make a copy of the list, and remove any null value just in case,
      * as it would cause errors looking up the features Map
+     * sort in alphabetical order for consistent output behaviour
      */
     List<String> types = new ArrayList<String>(Arrays.asList(type));
     types.remove(null);
+    Collections.sort(types);
     return types;
   }
 
@@ -425,4 +427,52 @@ public class SequenceFeatures implements SequenceFeaturesI
     Collections.sort(features, forwardStrand ? FORWARD_STRAND
             : REVERSE_STRAND);
   }
+
+  /**
+   * {@inheritDoc} This method is 'semi-optimised': it only inspects features
+   * for types that include the specified group, but has to inspect every
+   * feature of those types for matching feature group. This is efficient unless
+   * a sequence has features that share the same type but are in different
+   * groups - an unlikely case.
+   * <p>
+   * For example, if RESNUM feature is created with group = PDBID, then features
+   * would only be retrieved for those sequences associated with the target
+   * PDBID (group).
+   */
+  @Override
+  public List<SequenceFeature> getFeaturesForGroup(boolean positional,
+          String group, String... type)
+  {
+    List<SequenceFeature> result = new ArrayList<SequenceFeature>();
+    Iterable<String> types = varargToTypes(type);
+
+    for (String featureType : types)
+    {
+      /*
+       * check whether the feature type is present, and also
+       * whether it has features for the specified group
+       */
+      FeatureStore features = featureStore.get(featureType);
+      if (features != null
+              && features.getFeatureGroups(positional).contains(group))
+      {
+        result.addAll(features.getFeaturesForGroup(positional, group));
+      }
+    }
+    return result;
+  }
+
+  /**
+   * {@inheritDoc}
+   */
+  @Override
+  public boolean shiftFeatures(int shift)
+  {
+    boolean modified = false;
+    for (FeatureStore fs : featureStore.values())
+    {
+      modified |= fs.shiftFeatures(shift);
+    }
+    return modified;
+  }
 }
\ No newline at end of file