Merge branch 'bug/JAL-2791exportFilteredFeature' into merge/JAL-2791
[jalview.git] / src / jalview / datamodel / features / SequenceFeaturesI.java
index 5f904da..ca0283e 100644 (file)
@@ -1,3 +1,23 @@
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
+ * 
+ * This file is part of Jalview.
+ * 
+ * Jalview is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License 
+ * as published by the Free Software Foundation, either version 3
+ * of the License, or (at your option) any later version.
+ *  
+ * Jalview is distributed in the hope that it will be useful, but 
+ * WITHOUT ANY WARRANTY; without even the implied warranty 
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
+ * PURPOSE.  See the GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
+ */
 package jalview.datamodel.features;
 
 import jalview.datamodel.SequenceFeature;
@@ -12,11 +32,12 @@ public interface SequenceFeaturesI
    * 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.
+   * comparison. Answers false, and does not add the feature, if feature type is
+   * null.
    * 
    * @param sf
    */
-  public abstract boolean add(SequenceFeature sf);
+  boolean add(SequenceFeature sf);
 
   /**
    * Returns a (possibly empty) list of features, optionally restricted to
@@ -28,19 +49,66 @@ public interface SequenceFeaturesI
    * @param type
    * @return
    */
-  public abstract List<SequenceFeature> findFeatures(int from, int to,
+  List<SequenceFeature> findFeatures(int from, int to,
           String... type);
 
   /**
-   * Answers a list of all features stored, optionally restricted to specified
-   * types, in no particular guaranteed order
+   * Answers a list of all features stored, in no particular guaranteed order.
+   * Positional features may optionally be restricted to specified types, but
+   * all non-positional features (if any) are always returned.
+   * <p>
+   * To filter non-positional features by type, use
+   * getNonPositionalFeatures(type).
    * 
    * @param type
    * @return
    */
-  public abstract List<SequenceFeature> getAllFeatures(String... type);
+  List<SequenceFeature> getAllFeatures(String... type);
 
-  public abstract int getFeatureCount(boolean positional, String... type);
+  /**
+   * Answers a list of all positional (or non-positional) features which are in
+   * the specified feature group, optionally restricted to features of specified
+   * types.
+   * 
+   * @param positional
+   *          if true returns positional features, else non-positional features
+   * @param group
+   *          the feature group to be matched (which may be null)
+   * @param type
+   *          optional feature types to filter by
+   * @return
+   */
+  List<SequenceFeature> getFeaturesForGroup(boolean positional,
+          String group, String... type);
+
+  /**
+   * Answers a list of all features stored, whose type either matches, or is a
+   * specialisation (in the Sequence Ontology) of, one of the given terms.
+   * Results are returned in no particular order.
+   * 
+   * @param ontologyTerm
+   * @return
+   */
+  List<SequenceFeature> getFeaturesByOntology(String... ontologyTerm);
+
+  /**
+   * Answers the number of (positional or non-positional) features, optionally
+   * restricted to specified feature types. Contact features are counted as 1.
+   * 
+   * @param positional
+   * @param type
+   * @return
+   */
+  int getFeatureCount(boolean positional, String... type);
+
+  /**
+   * Answers the total length of positional features, optionally restricted to
+   * specified feature types. Contact features are counted as length 1.
+   * 
+   * @param type
+   * @return
+   */
+  int getTotalFeatureLength(String... type);
 
   /**
    * Answers a list of all positional features, optionally restricted to
@@ -49,7 +117,7 @@ public interface SequenceFeaturesI
    * @param type
    * @return
    */
-  public abstract List<SequenceFeature> getPositionalFeatures(
+  List<SequenceFeature> getPositionalFeatures(
           String... type);
 
   /**
@@ -58,7 +126,7 @@ public interface SequenceFeaturesI
    * 
    * @return
    */
-  public abstract List<SequenceFeature> getContactFeatures(String... type);
+  List<SequenceFeature> getContactFeatures(String... type);
 
   /**
    * Answers a list of all non-positional features, optionally restricted to
@@ -68,7 +136,7 @@ public interface SequenceFeaturesI
    *          if no type is specified, all are returned
    * @return
    */
-  public abstract List<SequenceFeature> getNonPositionalFeatures(
+  List<SequenceFeature> getNonPositionalFeatures(
           String... type);
 
   /**
@@ -79,14 +147,14 @@ public interface SequenceFeaturesI
    * 
    * @param sf
    */
-  public abstract boolean delete(SequenceFeature sf);
+  boolean delete(SequenceFeature sf);
 
   /**
    * Answers true if this store contains at least one feature, else false
    * 
    * @return
    */
-  public abstract boolean hasFeatures();
+  boolean hasFeatures();
 
   /**
    * Returns a set of the distinct feature groups present in the collection. The
@@ -99,7 +167,7 @@ public interface SequenceFeaturesI
    * @param type
    * @return
    */
-  public abstract Set<String> getFeatureGroups(boolean positionalFeatures,
+  Set<String> getFeatureGroups(boolean positionalFeatures,
           String... type);
 
   /**
@@ -112,14 +180,52 @@ public interface SequenceFeaturesI
    * @param groups
    * @return
    */
-  public abstract Set<String> getFeatureTypesForGroups(
+  Set<String> getFeatureTypesForGroups(
           boolean positionalFeatures, String... groups);
 
   /**
-   * Answers a set of the distinct feature types for which a feature is stored
+   * Answers a set of the distinct feature types for which a feature is stored.
+   * The types may optionally be restricted to those which match, or are a
+   * subtype of, given sequence ontology terms
    * 
    * @return
    */
-  public abstract Set<String> getFeatureTypes();
+  Set<String> getFeatureTypes(String... soTerm);
 
-}
\ No newline at end of file
+  /**
+   * 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
+   */
+  float getMinimumScore(String type, boolean positional);
+
+  /**
+   * 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
+   */
+  float getMaximumScore(String type, boolean positional);
+
+  /**
+   * Adds the shift amount to the start and end of all positional features whose
+   * start position is at or after fromPosition. Returns true if at least one
+   * feature was shifted, else false.
+   * 
+   * @param fromPosition
+   * @param shiftBy
+   */
+  boolean shiftFeatures(int fromPosition, int shiftBy);
+
+  /**
+   * Deletes all positional and non-positional features
+   */
+  void deleteAll();
+}