1 package jalview.datamodel.features;
3 import jalview.datamodel.SequenceFeature;
5 import java.util.ArrayList;
6 import java.util.Collections;
7 import java.util.HashMap;
12 * A class that stores sequence features in a way that supports efficient
13 * querying by type and location (overlap). Intended for (but not limited to)
14 * storage of features for one sequence.
19 public class SequenceFeatures
23 * map from feature type to structured store of features for that type
24 * null types are permitted (but not a good idea!)
26 private Map<String, FeatureStore> featureStore;
31 public SequenceFeatures()
33 featureStore = new HashMap<String, FeatureStore>();
37 * Add one sequence feature to the store
41 public void add(SequenceFeature sf)
43 String type = sf.getType();
45 if (featureStore.get(type) == null)
47 featureStore.put(type, new FeatureStore());
49 featureStore.get(type).addFeature(sf);
53 * Returns a (possibly empty) list of features of the given type which overlap
54 * the (inclusive) sequence position range
61 public List<SequenceFeature> findFeatures(String type, int from,
64 FeatureStore features = featureStore.get(type);
67 return Collections.emptyList();
69 return features.findOverlappingFeatures(from, to);
73 * Answers a list of all features stored (including non-positional), in no
74 * particular guaranteed order
78 public List<SequenceFeature> getFeatures()
80 List<SequenceFeature> result = new ArrayList<SequenceFeature>();
81 for (FeatureStore featureSet : featureStore.values())
83 result.addAll(featureSet.getFeatures());
89 * Answers a list of all non-positional features stored, in no particular
94 public List<SequenceFeature> getNonPositionalFeatures()
96 List<SequenceFeature> result = new ArrayList<SequenceFeature>();
97 for (FeatureStore featureSet : featureStore.values())
99 result.addAll(featureSet.getNonPositionalFeatures());
105 * Answers a list of all contact features stored, in no particular guaranteed
110 public List<SequenceFeature> getContactFeatures()
112 List<SequenceFeature> result = new ArrayList<SequenceFeature>();
113 for (FeatureStore featureSet : featureStore.values())
115 result.addAll(featureSet.getContactFeatures());
121 * Answers a list of all features of the given type (including
122 * non-positional), in no particular guaranteed order
126 public List<SequenceFeature> getFeatures(String type)
128 List<SequenceFeature> result = new ArrayList<SequenceFeature>();
129 FeatureStore featureSet = featureStore.get(type);
130 if (featureSet != null)
132 result.addAll(featureSet.getFeatures());
138 * Answers a list of all contact features of the given type, in no particular
143 public List<SequenceFeature> getContactFeatures(String type)
145 List<SequenceFeature> result = new ArrayList<SequenceFeature>();
146 FeatureStore featureSet = featureStore.get(type);
147 if (featureSet != null)
149 result.addAll(featureSet.getContactFeatures());
155 * Answers a list of all non-positional features of the given type, in no
156 * particular guaranteed order
160 public List<SequenceFeature> getNonPositionalFeatures(String type)
162 List<SequenceFeature> result = new ArrayList<SequenceFeature>();
163 FeatureStore featureSet = featureStore.get(type);
164 if (featureSet != null)
166 result.addAll(featureSet.getNonPositionalFeatures());