JAL-4028 experiment - THISISAPLACEHOLDER sequences get additional sequence data ...
[jalview.git] / src / jalview / datamodel / features / SequenceFeatures.java
index ba8396a..4928f18 100644 (file)
  */
 package jalview.datamodel.features;
 
-import jalview.datamodel.SequenceFeature;
-import jalview.io.gff.SequenceOntologyFactory;
-import jalview.io.gff.SequenceOntologyI;
-
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Collections;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
@@ -34,6 +31,9 @@ import java.util.Set;
 import java.util.TreeMap;
 
 import intervalstore.api.IntervalI;
+import jalview.datamodel.SequenceFeature;
+import jalview.io.gff.SequenceOntologyFactory;
+import jalview.io.gff.SequenceOntologyI;
 
 /**
  * A class that stores sequence features in a way that supports efficient
@@ -45,7 +45,6 @@ import intervalstore.api.IntervalI;
  */
 public class SequenceFeatures implements SequenceFeaturesI
 {
-
   /*
    * map from feature type to structured store of features for that type
    * null types are permitted (but not a good idea!)
@@ -153,8 +152,8 @@ public class SequenceFeatures implements SequenceFeaturesI
       return new ArrayList<>();
     }
 
-    return getAllFeatures(featureTypes.toArray(new String[featureTypes
-            .size()]));
+    return getAllFeatures(
+            featureTypes.toArray(new String[featureTypes.size()]));
   }
 
   /**
@@ -191,6 +190,30 @@ public class SequenceFeatures implements SequenceFeaturesI
    * {@inheritDoc}
    */
   @Override
+  public List<Integer> getFeatureExtent(String... type)
+  {
+    Integer from = 0, to = 0;
+
+    for (FeatureStore featureSet : varargToTypes(type))
+    {
+      if (from == 0)
+      {
+        from = featureSet.getBegin();
+        to = featureSet.getEnd();
+      }
+      else
+      {
+        from = Math.min(from, featureSet.getBegin());
+        to = Math.max(to, featureSet.getEnd());
+      }
+    }
+    return Arrays.asList(from, to);
+  }
+
+  /**
+   * {@inheritDoc}
+   */
+  @Override
   public List<SequenceFeature> getPositionalFeatures(String... type)
   {
     List<SequenceFeature> result = new ArrayList<>();
@@ -204,7 +227,9 @@ public class SequenceFeatures implements SequenceFeaturesI
 
   /**
    * A convenience method that converts a vararg for feature types to an
-   * Iterable over matched feature sets in key order
+   * Iterable over matched feature sets. If no types are specified, all feature
+   * sets are returned. If one or more types are specified, feature sets for
+   * those types are returned, preserving the order of the types.
    * 
    * @param type
    * @return
@@ -220,12 +245,11 @@ public class SequenceFeatures implements SequenceFeaturesI
     }
 
     List<FeatureStore> types = new ArrayList<>();
-    List<String> args = Arrays.asList(type);
-    for (Entry<String, FeatureStore> featureType : featureStore.entrySet())
+    for (String theType : type)
     {
-      if (args.contains(featureType.getKey()))
+      if (theType != null && featureStore.containsKey(theType))
       {
-        types.add(featureType.getValue());
+        types.add(featureStore.get(theType));
       }
     }
     return types;
@@ -321,8 +345,8 @@ public class SequenceFeatures implements SequenceFeaturesI
 
     for (Entry<String, FeatureStore> featureType : featureStore.entrySet())
     {
-      Set<String> featureGroups = featureType.getValue().getFeatureGroups(
-              positionalFeatures);
+      Set<String> featureGroups = featureType.getValue()
+              .getFeatureGroups(positionalFeatures);
       for (String group : groups)
       {
         if (featureGroups.contains(group))
@@ -390,8 +414,9 @@ public class SequenceFeatures implements SequenceFeaturesI
   @Override
   public float getMinimumScore(String type, boolean positional)
   {
-    return featureStore.containsKey(type) ? featureStore.get(type)
-            .getMinimumScore(positional) : Float.NaN;
+    return featureStore.containsKey(type)
+            ? featureStore.get(type).getMinimumScore(positional)
+            : Float.NaN;
   }
 
   /**
@@ -400,8 +425,9 @@ public class SequenceFeatures implements SequenceFeaturesI
   @Override
   public float getMaximumScore(String type, boolean positional)
   {
-    return featureStore.containsKey(type) ? featureStore.get(type)
-            .getMaximumScore(positional) : Float.NaN;
+    return featureStore.containsKey(type)
+            ? featureStore.get(type).getMaximumScore(positional)
+            : Float.NaN;
   }
 
   /**
@@ -414,7 +440,9 @@ public class SequenceFeatures implements SequenceFeaturesI
   public static void sortFeatures(List<? extends IntervalI> features,
           final boolean forwardStrand)
   {
-    IntervalI.sortIntervals(features, forwardStrand);
+    Collections.sort(features,
+            forwardStrand ? IntervalI.COMPARE_BEGIN_ASC_END_DESC
+                    : IntervalI.COMPARE_END_DESC);
   }
 
   /**