import jalview.datamodel.SequenceFeature;
import jalview.io.gff.SequenceOntologyFactory;
import jalview.io.gff.SequenceOntologyI;
+import jalview.util.Platform;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
*/
public class SequenceFeatures implements SequenceFeaturesI
{
-
/*
* map from feature type to structured store of features for that type
* null types are permitted (but not a good idea!)
List<SequenceFeature> result = new ArrayList<>();
for (FeatureStore featureSet : varargToTypes(type))
{
- result.addAll(featureSet.findOverlappingFeatures(from, to));
+ featureSet.findFeatures(from, to, result);
}
return result;
}
return new ArrayList<>();
}
- return getAllFeatures(featureTypes.toArray(new String[featureTypes
- .size()]));
+ return getAllFeatures(
+ featureTypes.toArray(new String[featureTypes.size()]));
}
/**
for (FeatureStore featureSet : varargToTypes(type))
{
- result.addAll(featureSet.getPositionalFeatures());
+ featureSet.getPositionalFeatures(result);
}
return result;
}
return featureStore.values();
}
-
List<FeatureStore> types = new ArrayList<>();
List<String> args = Arrays.asList(type);
for (Entry<String, FeatureStore> featureType : featureStore.entrySet())
for (FeatureStore featureSet : varargToTypes(type))
{
- result.addAll(featureSet.getContactFeatures());
+ featureSet.getContactFeatures(result);
}
return result;
}
for (FeatureStore featureSet : varargToTypes(type))
{
- result.addAll(featureSet.getNonPositionalFeatures());
+ featureSet.getNonPositionalFeatures(result);
}
return result;
}
public Set<String> getFeatureGroups(boolean positionalFeatures,
String... type)
{
- Set<String> groups = new HashSet<>();
+ // BH 2020.03.21 This is the set that orders the list of groups
+ // at the top of the FeatureSettings panel.
+ Set<String> groups = Platform.getJavaOrderedHashSet();
for (FeatureStore featureSet : varargToTypes(type))
{
public Set<String> getFeatureTypesForGroups(boolean positionalFeatures,
String... groups)
{
- Set<String> result = new HashSet<>();
+ // BH 2020.03.21 This set is the one that sets the initial ordering for
+ // feature rendering. We set it to new HashSet<>(16,0.75) to force it to
+ // be backed by a Java hash-ordered HashMap instead of a JavaScript Map.
+ Set<String> result = Platform.getJavaOrderedHashSet();
for (Entry<String, FeatureStore> featureType : featureStore.entrySet())
{
- Set<String> featureGroups = featureType.getValue().getFeatureGroups(
- positionalFeatures);
+ Set<String> featureGroups = featureType.getValue()
+ .getFeatureGroups(positionalFeatures);
for (String group : groups)
{
if (featureGroups.contains(group))
@Override
public Set<String> getFeatureTypes(String... soTerm)
{
- Set<String> types = new HashSet<>();
+ Set<String> types = new HashSet<>(15, 0.75f);
for (Entry<String, FeatureStore> entry : featureStore.entrySet())
{
String type = entry.getKey();
@Override
public float getMinimumScore(String type, boolean positional)
{
- return featureStore.containsKey(type) ? featureStore.get(type)
- .getMinimumScore(positional) : Float.NaN;
+ return featureStore.containsKey(type)
+ ? featureStore.get(type).getMinimumScore(positional)
+ : Float.NaN;
}
/**
@Override
public float getMaximumScore(String type, boolean positional)
{
- return featureStore.containsKey(type) ? featureStore.get(type)
- .getMaximumScore(positional) : Float.NaN;
+ return featureStore.containsKey(type)
+ ? featureStore.get(type).getMaximumScore(positional)
+ : Float.NaN;
}
/**
public static void sortFeatures(List<? extends IntervalI> features,
final boolean forwardStrand)
{
- IntervalI.sortIntervals(features, forwardStrand);
+ Collections.sort(features,
+ forwardStrand ? IntervalI.COMPARE_BEGIN_ASC
+ : IntervalI.COMPARE_END_DESC);
}
/**
featureStore.clear();
}
- /**
- * Simplified find for features associated with a given position.
- *
- * @author Bob Hanson 2019.07.30
- */
@Override
- public void findFeatures(int pos, String type, List<SequenceFeature> list)
+ public List<SequenceFeature> findFeatures(int pos, String type,
+ List<SequenceFeature> list)
{
FeatureStore fs = featureStore.get(type);
- if (fs != null)
+ if (fs == null)
{
- fs.findOverlappingFeatures(pos, list);
+ return list == null ? new ArrayList<>() : list;
}
+ return fs.findFeatures(pos, pos, list);
}
+ @Override
+ public boolean hasFeatures(String type)
+ {
+ return featureStore.containsKey(type)
+ && !featureStore.get(type).isEmpty();
+ }
}