7213cbaf47e5c4117cc61e536883119578f96d35
[jalview.git] / src / jalview / datamodel / features / SequenceFeaturesI.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3  * Copyright (C) $$Year-Rel$$ The Jalview Authors
4  * 
5  * This file is part of Jalview.
6  * 
7  * Jalview is free software: you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License 
9  * as published by the Free Software Foundation, either version 3
10  * of the License, or (at your option) any later version.
11  *  
12  * Jalview is distributed in the hope that it will be useful, but 
13  * WITHOUT ANY WARRANTY; without even the implied warranty 
14  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
15  * PURPOSE.  See the GNU General Public License for more details.
16  * 
17  * You should have received a copy of the GNU General Public License
18  * along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
19  * The Jalview Authors are detailed in the 'AUTHORS' file.
20  */
21 package jalview.datamodel.features;
22
23 import jalview.datamodel.SequenceFeature;
24
25 import java.util.List;
26 import java.util.Set;
27
28 public interface SequenceFeaturesI
29 {
30
31   /**
32    * Adds one sequence feature to the store, and returns true, unless the
33    * feature is already contained in the store, in which case this method
34    * returns false. Containment is determined by SequenceFeature.equals()
35    * comparison. Answers false, and does not add the feature, if feature type is
36    * null.
37    * 
38    * @param sf
39    */
40   boolean add(SequenceFeature sf);
41
42   /**
43    * Returns a (possibly empty) list of features, optionally restricted to
44    * specified types, which overlap the given (inclusive) sequence position
45    * range. If types are specified, features are returned in the order of the
46    * types given.
47    * 
48    * @param from
49    * @param to
50    * @param type
51    * @return
52    */
53   List<SequenceFeature> findFeatures(int from, int to,
54           String... type);
55
56   /**
57    * Answers a list of all features stored, in no particular guaranteed order.
58    * Positional features may optionally be restricted to specified types, but
59    * all non-positional features (if any) are always returned.
60    * <p>
61    * To filter non-positional features by type, use
62    * getNonPositionalFeatures(type).
63    * 
64    * @param type
65    * @return
66    */
67   List<SequenceFeature> getAllFeatures(String... type);
68
69   /**
70    * Answers a list of all positional (or non-positional) features which are in
71    * the specified feature group, optionally restricted to features of specified
72    * types.
73    * 
74    * @param positional
75    *          if true returns positional features, else non-positional features
76    * @param group
77    *          the feature group to be matched (which may be null)
78    * @param type
79    *          optional feature types to filter by
80    * @return
81    */
82   List<SequenceFeature> getFeaturesForGroup(boolean positional,
83           String group, String... type);
84
85   /**
86    * Answers a list of all features stored, whose type either matches, or is a
87    * specialisation (in the Sequence Ontology) of, one of the given terms.
88    * Results are returned in no particular order.
89    * 
90    * @param ontologyTerm
91    * @return
92    */
93   List<SequenceFeature> getFeaturesByOntology(String... ontologyTerm);
94
95   /**
96    * Answers the number of (positional or non-positional) features, optionally
97    * restricted to specified feature types. Contact features are counted as 1.
98    * 
99    * @param positional
100    * @param type
101    * @return
102    */
103   int getFeatureCount(boolean positional, String... type);
104
105   /**
106    * Answers the total length of positional features, optionally restricted to
107    * specified feature types. Contact features are counted as length 1.
108    * 
109    * @param type
110    * @return
111    */
112   int getTotalFeatureLength(String... type);
113
114   /**
115    * Answers a list of all positional features, optionally restricted to
116    * specified types, in no particular guaranteed order
117    * 
118    * @param type
119    * @return
120    */
121   List<SequenceFeature> getPositionalFeatures(
122           String... type);
123
124   /**
125    * Answers a list of all contact features, optionally restricted to specified
126    * types, in no particular guaranteed order
127    * 
128    * @return
129    */
130   List<SequenceFeature> getContactFeatures(String... type);
131
132   /**
133    * Answers a list of all non-positional features, optionally restricted to
134    * specified types, in no particular guaranteed order
135    * 
136    * @param type
137    *          if no type is specified, all are returned
138    * @return
139    */
140   List<SequenceFeature> getNonPositionalFeatures(
141           String... type);
142
143   /**
144    * Deletes the given feature from the store, returning true if it was found
145    * (and deleted), else false. This method makes no assumption that the feature
146    * is in the 'expected' place in the store, in case it has been modified since
147    * it was added.
148    * 
149    * @param sf
150    */
151   boolean delete(SequenceFeature sf);
152
153   /**
154    * Answers true if this store contains at least one feature, else false
155    * 
156    * @return
157    */
158   boolean hasFeatures();
159
160   /**
161    * Returns a set of the distinct feature groups present in the collection. The
162    * set may include null. The boolean parameter determines whether the groups
163    * for positional or for non-positional features are returned. The optional
164    * type parameter may be used to restrict to groups for specified feature
165    * types.
166    * 
167    * @param positionalFeatures
168    * @param type
169    * @return
170    */
171   Set<String> getFeatureGroups(boolean positionalFeatures,
172           String... type);
173
174   /**
175    * Answers the set of distinct feature types for which there is at least one
176    * feature with one of the given feature group(s). The boolean parameter
177    * determines whether the groups for positional or for non-positional features
178    * are returned.
179    * 
180    * @param positionalFeatures
181    * @param groups
182    * @return
183    */
184   Set<String> getFeatureTypesForGroups(
185           boolean positionalFeatures, String... groups);
186
187   /**
188    * Answers a set of the distinct feature types for which a feature is stored.
189    * The types may optionally be restricted to those which match, or are a
190    * subtype of, given sequence ontology terms
191    * 
192    * @return
193    */
194   Set<String> getFeatureTypes(String... soTerm);
195
196   /**
197    * Answers the minimum score held for positional or non-positional features
198    * for the specified type. This may be Float.NaN if there are no features, or
199    * none has a non-NaN score.
200    * 
201    * @param type
202    * @param positional
203    * @return
204    */
205   float getMinimumScore(String type, boolean positional);
206
207   /**
208    * Answers the maximum score held for positional or non-positional features
209    * for the specified type. This may be Float.NaN if there are no features, or
210    * none has a non-NaN score.
211    * 
212    * @param type
213    * @param positional
214    * @return
215    */
216   float getMaximumScore(String type, boolean positional);
217
218   /**
219    * Adds the shift amount to the start and end of all positional features whose
220    * start position is at or after fromPosition. Returns true if at least one
221    * feature was shifted, else false.
222    * 
223    * @param fromPosition
224    * @param shiftBy
225    */
226   boolean shiftFeatures(int fromPosition, int shiftBy);
227
228   /**
229    * Deletes all positional and non-positional features
230    */
231   void deleteAll();
232 }