JAL-2480 cache min-max score values per sequence and feature type
[jalview.git] / src / jalview / datamodel / features / SequenceFeatures.java
index 6165d0a..c825761 100644 (file)
@@ -19,7 +19,7 @@ import java.util.Set;
  * @author gmcarstairs
  *
  */
-public class SequenceFeatures
+public class SequenceFeatures implements SequenceFeaturesI
 {
 
   /*
@@ -37,13 +37,9 @@ public class SequenceFeatures
   }
 
   /**
-   * Adds one sequence feature to the store, and returns true, unless the
-   * feature is already contained in the store, in which case this method
-   * returns false. Containment is determined by SequenceFeature.equals()
-   * comparison.
-   * 
-   * @param sf
+   * {@inheritDoc}
    */
+  @Override
   public boolean add(SequenceFeature sf)
   {
     String type = sf.getType();
@@ -56,15 +52,9 @@ public class SequenceFeatures
   }
 
   /**
-   * Returns a (possibly empty) list of features, optionally restricted to
-   * specified types, which overlap the given (inclusive) sequence position
-   * range
-   * 
-   * @param from
-   * @param to
-   * @param type
-   * @return
+   * {@inheritDoc}
    */
+  @Override
   public List<SequenceFeature> findFeatures(int from, int to,
           String... type)
   {
@@ -83,12 +73,9 @@ public class SequenceFeatures
   }
 
   /**
-   * Answers a list of all features stored, optionally restricted to specified
-   * types, in no particular guaranteed order
-   * 
-   * @param type
-   * @return
+   * {@inheritDoc}
    */
+  @Override
   public List<SequenceFeature> getAllFeatures(String... type)
   {
     List<SequenceFeature> result = new ArrayList<SequenceFeature>();
@@ -101,12 +88,48 @@ public class SequenceFeatures
   }
 
   /**
-   * Answers a list of all positional features, optionally restricted to
-   * specified types, in no particular guaranteed order
-   * 
-   * @param type
-   * @return
+   * {@inheritDoc}
+   */
+  @Override
+  public int getFeatureCount(boolean positional, String... type)
+  {
+    int result = 0;
+
+    for (String featureType : varargToTypes(type))
+    {
+      FeatureStore featureSet = featureStore.get(featureType);
+      if (featureSet != null)
+      {
+        result += featureSet.getFeatureCount(positional);
+      }
+    }
+    return result;
+  }
+
+  /**
+   * {@inheritDoc}
+   */
+  @Override
+  public int getTotalFeatureLength(String... type)
+  {
+    int result = 0;
+
+    for (String featureType : varargToTypes(type))
+    {
+      FeatureStore featureSet = featureStore.get(featureType);
+      if (featureSet != null)
+      {
+        result += featureSet.getTotalFeatureLength();
+      }
+    }
+    return result;
+
+  }
+
+  /**
+   * {@inheritDoc}
    */
+  @Override
   public List<SequenceFeature> getPositionalFeatures(String... type)
   {
     List<SequenceFeature> result = new ArrayList<SequenceFeature>();
@@ -137,11 +160,9 @@ public class SequenceFeatures
   }
 
   /**
-   * Answers a list of all contact features, optionally restricted to specified
-   * types, in no particular guaranteed order
-   * 
-   * @return
+   * {@inheritDoc}
    */
+  @Override
   public List<SequenceFeature> getContactFeatures(String... type)
   {
     List<SequenceFeature> result = new ArrayList<SequenceFeature>();
@@ -158,13 +179,9 @@ public class SequenceFeatures
   }
 
   /**
-   * Answers a list of all non-positional features, optionally restricted to
-   * specified types, in no particular guaranteed order
-   * 
-   * @param type
-   *          if no type is specified, all are returned
-   * @return
+   * {@inheritDoc}
    */
+  @Override
   public List<SequenceFeature> getNonPositionalFeatures(String... type)
   {
     List<SequenceFeature> result = new ArrayList<SequenceFeature>();
@@ -181,13 +198,9 @@ public class SequenceFeatures
   }
 
   /**
-   * Deletes the given feature from the store, returning true if it was found
-   * (and deleted), else false. This method makes no assumption that the feature
-   * is in the 'expected' place in the store, in case it has been modified since
-   * it was added.
-   * 
-   * @param sf
+   * {@inheritDoc}
    */
+  @Override
   public boolean delete(SequenceFeature sf)
   {
     for (FeatureStore featureSet : featureStore.values())
@@ -201,10 +214,9 @@ public class SequenceFeatures
   }
 
   /**
-   * Answers true if this store contains at least one feature, else false
-   * 
-   * @return
+   * {@inheritDoc}
    */
+  @Override
   public boolean hasFeatures()
   {
     for (FeatureStore featureSet : featureStore.values())
@@ -218,16 +230,9 @@ public class SequenceFeatures
   }
 
   /**
-   * Returns a set of the distinct feature groups present in the collection. The
-   * set may include null. The boolean parameter determines whether the groups
-   * for positional or for non-positional features are returned. The optional
-   * type parameter may be used to restrict to groups for specified feature
-   * types.
-   * 
-   * @param positionalFeatures
-   * @param type
-   * @return
+   * {@inheritDoc}
    */
+  @Override
   public Set<String> getFeatureGroups(boolean positionalFeatures,
           String... type)
   {
@@ -248,15 +253,9 @@ public class SequenceFeatures
   }
 
   /**
-   * Answers the set of distinct feature types for which there is at least one
-   * feature with one of the given feature group(s). The parameter determines
-   * whether the groups for positional or for non-positional features are
-   * returned.
-   * 
-   * @param positionalFeatures
-   * @param groups
-   * @return
+   * {@inheritDoc}
    */
+  @Override
   public Set<String> getFeatureTypesForGroups(boolean positionalFeatures,
           String... groups)
   {
@@ -281,4 +280,51 @@ public class SequenceFeatures
 
     return result;
   }
+
+  /**
+   * {@inheritDoc}
+   */
+  @Override
+  public Set<String> getFeatureTypes()
+  {
+    Set<String> types = new HashSet<String>();
+    for (Entry<String, FeatureStore> entry : featureStore.entrySet())
+    {
+      if (!entry.getValue().isEmpty())
+      {
+        types.add(entry.getKey());
+      }
+    }
+    return types;
+  }
+
+  /**
+   * Answers the minimum score held for positional or non-positional features
+   * for the specified type. This may be Float.NaN if there are no features, or
+   * none has a non-NaN score.
+   * 
+   * @param type
+   * @param positional
+   * @return
+   */
+  public float getMinimumScore(String type, boolean positional)
+  {
+    return featureStore.containsKey(type) ? featureStore.get(type)
+            .getMinimumScore(positional) : Float.NaN;
+  }
+
+  /**
+   * Answers the maximum score held for positional or non-positional features
+   * for the specified type. This may be Float.NaN if there are no features, or
+   * none has a non-NaN score.
+   * 
+   * @param type
+   * @param positional
+   * @return
+   */
+  public float getMaximumScore(String type, boolean positional)
+  {
+    return featureStore.containsKey(type) ? featureStore.get(type)
+            .getMaximumScore(positional) : Float.NaN;
+  }
 }