From: gmungoc Date: Tue, 23 May 2017 09:54:15 +0000 (+0100) Subject: JAL-2480 methods to get features for group X-Git-Tag: Release_2_10_3b1~248 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=c8863c027ddace3961405ed0051f104f1ec99581;p=jalview.git JAL-2480 methods to get features for group --- diff --git a/src/jalview/datamodel/features/FeatureStore.java b/src/jalview/datamodel/features/FeatureStore.java index 432f62d..c6a49db 100644 --- a/src/jalview/datamodel/features/FeatureStore.java +++ b/src/jalview/datamodel/features/FeatureStore.java @@ -980,4 +980,41 @@ public class FeatureStore { return positional ? positionalMaxScore : nonPositionalMaxScore; } + + /** + * Answers a list of all either positional or non-positional features whose + * feature group matches the given group (which may be null) + * + * @param positional + * @param group + * @return + */ + public List getFeaturesForGroup(boolean positional, + String group) + { + List result = new ArrayList(); + + /* + * if we know features don't include the target group, no need + * to inspect them for matches + */ + if (positional && !positionalFeatureGroups.contains(group) + || !positional && !nonPositionalFeatureGroups.contains(group)) + { + return result; + } + + List sfs = positional ? getPositionalFeatures() + : getNonPositionalFeatures(); + for (SequenceFeature sf : sfs) + { + String featureGroup = sf.getFeatureGroup(); + if (group == null && featureGroup == null || group != null + && group.equals(featureGroup)) + { + result.add(sf); + } + } + return result; + } } diff --git a/src/jalview/datamodel/features/SequenceFeatures.java b/src/jalview/datamodel/features/SequenceFeatures.java index af99ada..34470cc 100644 --- a/src/jalview/datamodel/features/SequenceFeatures.java +++ b/src/jalview/datamodel/features/SequenceFeatures.java @@ -425,4 +425,38 @@ 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. + *

+ * 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 getFeaturesForGroup(boolean positional, + String group, String... type) + { + List result = new ArrayList(); + Iterable 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; + } } \ No newline at end of file diff --git a/src/jalview/datamodel/features/SequenceFeaturesI.java b/src/jalview/datamodel/features/SequenceFeaturesI.java index 281743e..c423391 100644 --- a/src/jalview/datamodel/features/SequenceFeaturesI.java +++ b/src/jalview/datamodel/features/SequenceFeaturesI.java @@ -46,6 +46,22 @@ public interface SequenceFeaturesI List getAllFeatures(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 getFeaturesForGroup(boolean positional, + String group, String... type); + + /** * Answers a list of all features stored, whose type either matches one of the * given ontology terms, or is a specialisation of a term in the Sequence * Ontology. Results are returned in no particular guaranteed order.