X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fdatamodel%2Ffeatures%2FSequenceFeatures.java;h=8d5ba58c57ceee4d566424597dca01339d66dd24;hb=05d220bbea0e8ce667490219436b96ebdf9826df;hp=6955adeae57ea1984847f270b240ebd10e3a4bf0;hpb=df2bf54c7050c42db156e96e73bbabce63e718d7;p=jalview.git diff --git a/src/jalview/datamodel/features/SequenceFeatures.java b/src/jalview/datamodel/features/SequenceFeatures.java index 6955ade..8d5ba58 100644 --- a/src/jalview/datamodel/features/SequenceFeatures.java +++ b/src/jalview/datamodel/features/SequenceFeatures.java @@ -1,5 +1,6 @@ package jalview.datamodel.features; +import jalview.datamodel.ContiguousI; import jalview.datamodel.SequenceFeature; import jalview.io.gff.SequenceOntologyFactory; import jalview.io.gff.SequenceOntologyI; @@ -111,15 +112,11 @@ public class SequenceFeatures implements SequenceFeaturesI public List findFeatures(int from, int to, String... type) { - List result = new ArrayList(); + List result = new ArrayList<>(); - for (String featureType : varargToTypes(type)) + for (FeatureStore featureSet : varargToTypes(type)) { - FeatureStore features = featureStore.get(featureType); - if (features != null) - { - result.addAll(features.findOverlappingFeatures(from, to)); - } + result.addAll(featureSet.findOverlappingFeatures(from, to)); } return result; @@ -131,7 +128,7 @@ public class SequenceFeatures implements SequenceFeaturesI @Override public List getAllFeatures(String... type) { - List result = new ArrayList(); + List result = new ArrayList<>(); result.addAll(getPositionalFeatures(type)); @@ -148,10 +145,18 @@ public class SequenceFeatures implements SequenceFeaturesI { if (ontologyTerm == null || ontologyTerm.length == 0) { - return new ArrayList(); + return new ArrayList<>(); } Set featureTypes = getFeatureTypes(ontologyTerm); + if (featureTypes.isEmpty()) + { + /* + * no features of the specified type or any sub-type + */ + return new ArrayList<>(); + } + return getAllFeatures(featureTypes.toArray(new String[featureTypes .size()])); } @@ -164,13 +169,9 @@ public class SequenceFeatures implements SequenceFeaturesI { int result = 0; - for (String featureType : varargToTypes(type)) + for (FeatureStore featureSet : varargToTypes(type)) { - FeatureStore featureSet = featureStore.get(featureType); - if (featureSet != null) - { - result += featureSet.getFeatureCount(positional); - } + result += featureSet.getFeatureCount(positional); } return result; } @@ -183,16 +184,11 @@ public class SequenceFeatures implements SequenceFeaturesI { int result = 0; - for (String featureType : varargToTypes(type)) + for (FeatureStore featureSet : varargToTypes(type)) { - FeatureStore featureSet = featureStore.get(featureType); - if (featureSet != null) - { - result += featureSet.getTotalFeatureLength(); - } + result += featureSet.getTotalFeatureLength(); } return result; - } /** @@ -201,45 +197,41 @@ public class SequenceFeatures implements SequenceFeaturesI @Override public List getPositionalFeatures(String... type) { - List result = new ArrayList(); + List result = new ArrayList<>(); - for (String featureType : varargToTypes(type)) + for (FeatureStore featureSet : varargToTypes(type)) { - FeatureStore featureSet = featureStore.get(featureType); - if (featureSet != null) - { - result.addAll(featureSet.getPositionalFeatures()); - } + result.addAll(featureSet.getPositionalFeatures()); } return result; } /** * A convenience method that converts a vararg for feature types to an - * Iterable, replacing the value with the stored feature types if it is null - * or empty + * Iterable over matched feature sets in key order * * @param type * @return */ - protected Iterable varargToTypes(String... type) + protected Iterable varargToTypes(String... type) { if (type == null || type.length == 0) { /* - * no vararg parameter supplied + * no vararg parameter supplied - return all */ - return featureStore.keySet(); + return featureStore.values(); } - /* - * else make a copy of the list, and remove any null value just in case, - * as it would cause errors looking up the features Map - * sort in alphabetical order for consistent output behaviour - */ - List types = new ArrayList(Arrays.asList(type)); - types.remove(null); - Collections.sort(types); + List types = new ArrayList<>(); + List args = Arrays.asList(type); + for (Entry featureType : featureStore.entrySet()) + { + if (args.contains(featureType.getKey())) + { + types.add(featureType.getValue()); + } + } return types; } @@ -249,15 +241,11 @@ public class SequenceFeatures implements SequenceFeaturesI @Override public List getContactFeatures(String... type) { - List result = new ArrayList(); + List result = new ArrayList<>(); - for (String featureType : varargToTypes(type)) + for (FeatureStore featureSet : varargToTypes(type)) { - FeatureStore featureSet = featureStore.get(featureType); - if (featureSet != null) - { - result.addAll(featureSet.getContactFeatures()); - } + result.addAll(featureSet.getContactFeatures()); } return result; } @@ -268,15 +256,11 @@ public class SequenceFeatures implements SequenceFeaturesI @Override public List getNonPositionalFeatures(String... type) { - List result = new ArrayList(); + List result = new ArrayList<>(); - for (String featureType : varargToTypes(type)) + for (FeatureStore featureSet : varargToTypes(type)) { - FeatureStore featureSet = featureStore.get(featureType); - if (featureSet != null) - { - result.addAll(featureSet.getNonPositionalFeatures()); - } + result.addAll(featureSet.getNonPositionalFeatures()); } return result; } @@ -320,17 +304,11 @@ public class SequenceFeatures implements SequenceFeaturesI public Set getFeatureGroups(boolean positionalFeatures, String... type) { - Set groups = new HashSet(); - - Iterable types = varargToTypes(type); + Set groups = new HashSet<>(); - for (String featureType : types) + for (FeatureStore featureSet : varargToTypes(type)) { - FeatureStore featureSet = featureStore.get(featureType); - if (featureSet != null) - { - groups.addAll(featureSet.getFeatureGroups(positionalFeatures)); - } + groups.addAll(featureSet.getFeatureGroups(positionalFeatures)); } return groups; @@ -343,7 +321,7 @@ public class SequenceFeatures implements SequenceFeaturesI public Set getFeatureTypesForGroups(boolean positionalFeatures, String... groups) { - Set result = new HashSet(); + Set result = new HashSet<>(); for (Entry featureType : featureStore.entrySet()) { @@ -371,7 +349,7 @@ public class SequenceFeatures implements SequenceFeaturesI @Override public Set getFeatureTypes(String... soTerm) { - Set types = new HashSet(); + Set types = new HashSet<>(); for (Entry entry : featureStore.entrySet()) { String type = entry.getKey(); @@ -458,20 +436,12 @@ public class SequenceFeatures implements SequenceFeaturesI public List getFeaturesForGroup(boolean positional, String group, String... type) { - List result = new ArrayList(); - Iterable types = varargToTypes(type); - - for (String featureType : types) + List result = new ArrayList<>(); + for (FeatureStore featureSet : varargToTypes(type)) { - /* - * 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)) + if (featureSet.getFeatureGroups(positional).contains(group)) { - result.addAll(features.getFeaturesForGroup(positional, group)); + result.addAll(featureSet.getFeaturesForGroup(positional, group)); } } return result;