{
if (nestedFeatures == null)
{
- nestedFeatures = new NCList<SequenceFeature>(feature);
+ nestedFeatures = new NCList<>(feature);
return true;
}
return nestedFeatures.add(feature, false);
*/
public List<SequenceFeature> findOverlappingFeatures(long start, long end)
{
- List<SequenceFeature> result = new ArrayList<SequenceFeature>();
+ List<SequenceFeature> result = new ArrayList<>();
findNonNestedFeatures(start, end, result);
/*
* add non-nested features (may be all features for many cases)
*/
- List<SequenceFeature> result = new ArrayList<SequenceFeature>();
+ List<SequenceFeature> result = new ArrayList<>();
result.addAll(nonNestedFeatures);
/*
{
return Collections.emptyList();
}
- return new ArrayList<SequenceFeature>(contactFeatureStarts);
+ return new ArrayList<>(contactFeatureStarts);
}
/**
{
return Collections.emptyList();
}
- return new ArrayList<SequenceFeature>(nonPositionalFeatures);
+ return new ArrayList<>(nonPositionalFeatures);
}
/**
public List<SequenceFeature> getFeaturesForGroup(boolean positional,
String group)
{
- List<SequenceFeature> result = new ArrayList<SequenceFeature>();
+ List<SequenceFeature> result = new ArrayList<>();
/*
* if we know features don't include the target group, no need
public NCList(T entry)
{
this();
- subranges.add(new NCNode<T>(entry));
+ subranges.add(new NCNode<>(entry));
size = 1;
}
*/
protected List<Range> buildSubranges(List<T> ranges)
{
- List<Range> sublists = new ArrayList<Range>();
+ List<Range> sublists = new ArrayList<>();
if (ranges.isEmpty())
{
/*
* all subranges precede this one - add it on the end
*/
- subranges.add(new NCNode<T>(entry));
+ subranges.add(new NCNode<>(entry));
return true;
}
/*
* new entry lies between subranges j-1 j
*/
- subranges.add(j, new NCNode<T>(entry));
+ subranges.add(j, new NCNode<>(entry));
return true;
}
* entry spans two subranges but doesn't enclose any
* so just add it
*/
- subranges.add(j, new NCNode<T>(entry));
+ subranges.add(j, new NCNode<>(entry));
return true;
}
}
}
else
{
- subranges.add(new NCNode<T>(entry));
+ subranges.add(new NCNode<>(entry));
}
return true;
protected synchronized void addEnclosingRange(T entry, final int i,
final int j)
{
- NCList<T> newNCList = new NCList<T>();
+ NCList<T> newNCList = new NCList<>();
newNCList.addNodes(subranges.subList(i, j + 1));
- NCNode<T> newNode = new NCNode<T>(entry, newNCList);
+ NCNode<T> newNode = new NCNode<>(entry, newNCList);
for (int k = j; k >= i; k--)
{
subranges.remove(k);
*/
public List<T> findOverlaps(long from, long to)
{
- List<T> result = new ArrayList<T>();
+ List<T> result = new ArrayList<>();
findOverlaps(from, to, result);
*/
public List<T> getEntries()
{
- List<T> result = new ArrayList<T>();
+ List<T> result = new ArrayList<>();
getEntries(result);
return result;
}
*/
NCNode(V range)
{
- List<V> ranges = new ArrayList<V>();
+ List<V> ranges = new ArrayList<>();
ranges.add(range);
build(ranges);
}
public List<SequenceFeature> findFeatures(int from, int to,
String... type)
{
- List<SequenceFeature> result = new ArrayList<SequenceFeature>();
+ List<SequenceFeature> 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;
@Override
public List<SequenceFeature> getAllFeatures(String... type)
{
- List<SequenceFeature> result = new ArrayList<SequenceFeature>();
+ List<SequenceFeature> result = new ArrayList<>();
result.addAll(getPositionalFeatures(type));
{
if (ontologyTerm == null || ontologyTerm.length == 0)
{
- return new ArrayList<SequenceFeature>();
+ return new ArrayList<>();
}
Set<String> featureTypes = getFeatureTypes(ontologyTerm);
{
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;
}
{
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;
-
}
/**
@Override
public List<SequenceFeature> getPositionalFeatures(String... type)
{
- List<SequenceFeature> result = new ArrayList<SequenceFeature>();
+ List<SequenceFeature> 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<String> varargToTypes(String... type)
+ protected Iterable<FeatureStore> 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<String> types = new ArrayList<String>(Arrays.asList(type));
- types.remove(null);
- Collections.sort(types);
+ List<FeatureStore> types = new ArrayList<>();
+ List<String> args = Arrays.asList(type);
+ for (Entry<String, FeatureStore> featureType : featureStore.entrySet())
+ {
+ if (args.contains(featureType.getKey()))
+ {
+ types.add(featureType.getValue());
+ }
+ }
return types;
}
@Override
public List<SequenceFeature> getContactFeatures(String... type)
{
- List<SequenceFeature> result = new ArrayList<SequenceFeature>();
+ List<SequenceFeature> 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;
}
@Override
public List<SequenceFeature> getNonPositionalFeatures(String... type)
{
- List<SequenceFeature> result = new ArrayList<SequenceFeature>();
+ List<SequenceFeature> 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;
}
public Set<String> getFeatureGroups(boolean positionalFeatures,
String... type)
{
- Set<String> groups = new HashSet<String>();
+ Set<String> groups = new HashSet<>();
- Iterable<String> types = varargToTypes(type);
-
- 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;
public Set<String> getFeatureTypesForGroups(boolean positionalFeatures,
String... groups)
{
- Set<String> result = new HashSet<String>();
+ Set<String> result = new HashSet<>();
for (Entry<String, FeatureStore> featureType : featureStore.entrySet())
{
@Override
public Set<String> getFeatureTypes(String... soTerm)
{
- Set<String> types = new HashSet<String>();
+ Set<String> types = new HashSet<>();
for (Entry<String, FeatureStore> entry : featureStore.entrySet())
{
String type = entry.getKey();
public List<SequenceFeature> getFeaturesForGroup(boolean positional,
String group, String... type)
{
- List<SequenceFeature> result = new ArrayList<SequenceFeature>();
- Iterable<String> types = varargToTypes(type);
-
- for (String featureType : types)
+ List<SequenceFeature> 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;
sq.sequenceChanged();
assertEquals(12, sq.findPosition(8));
cursor = (SequenceCursor) PA.getValue(sq, "cursor");
- assertEquals("test:Pos12:Col9:startCol3:endCol10:tok1",
+ // sequenceChanged() invalidates cursor.lastResidueColumn
+ cursor = (SequenceCursor) PA.getValue(sq, "cursor");
+ assertEquals("test:Pos12:Col9:startCol3:endCol0:tok1",
cursor.toString());
// findPosition with cursor accepts base 1 column values
assertEquals(13, ((Sequence) sq).findPosition(10, cursor));
- assertEquals(13, sq.findPosition(9));
+ assertEquals(13, sq.findPosition(9)); // F13
+ // lastResidueColumn has now been found and saved in cursor
assertEquals("test:Pos13:Col10:startCol3:endCol10:tok1",
PA.getValue(sq, "cursor").toString());
}
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
+import java.util.Map;
import java.util.Set;
+import junit.extensions.PA;
+
import org.testng.annotations.Test;
public class SequenceFeaturesTest
* no type specified - get all types stored
* they are returned in keyset (alphabetical) order
*/
- Iterable<String> types = sf.varargToTypes();
- Iterator<String> iterator = types.iterator();
+ Map<String, FeatureStore> featureStores = (Map<String, FeatureStore>) PA
+ .getValue(sf, "featureStore");
+
+ Iterable<FeatureStore> types = sf.varargToTypes();
+ Iterator<FeatureStore> iterator = types.iterator();
assertTrue(iterator.hasNext());
- assertEquals(iterator.next(), "Cath");
+ assertSame(iterator.next(), featureStores.get("Cath"));
assertTrue(iterator.hasNext());
- assertEquals(iterator.next(), "Metal");
+ assertSame(iterator.next(), featureStores.get("Metal"));
assertFalse(iterator.hasNext());
/*
types = sf.varargToTypes(new String[] {});
iterator = types.iterator();
assertTrue(iterator.hasNext());
- assertEquals(iterator.next(), "Cath");
+ assertSame(iterator.next(), featureStores.get("Cath"));
assertTrue(iterator.hasNext());
- assertEquals(iterator.next(), "Metal");
+ assertSame(iterator.next(), featureStores.get("Metal"));
assertFalse(iterator.hasNext());
/*
types = sf.varargToTypes((String[]) null);
iterator = types.iterator();
assertTrue(iterator.hasNext());
- assertEquals(iterator.next(), "Cath");
+ assertSame(iterator.next(), featureStores.get("Cath"));
assertTrue(iterator.hasNext());
- assertEquals(iterator.next(), "Metal");
+ assertSame(iterator.next(), featureStores.get("Metal"));
assertFalse(iterator.hasNext());
/*
types = sf.varargToTypes("Metal");
iterator = types.iterator();
assertTrue(iterator.hasNext());
- assertEquals(iterator.next(), "Metal");
+ assertSame(iterator.next(), featureStores.get("Metal"));
assertFalse(iterator.hasNext());
/*
* two types specified - get sorted alphabetically
*/
- types = sf.varargToTypes("Metal", "Helix");
+ types = sf.varargToTypes("Metal", "Cath");
iterator = types.iterator();
assertTrue(iterator.hasNext());
- assertEquals(iterator.next(), "Helix");
+ assertSame(iterator.next(), featureStores.get("Cath"));
assertTrue(iterator.hasNext());
- assertEquals(iterator.next(), "Metal");
+ assertSame(iterator.next(), featureStores.get("Metal"));
assertFalse(iterator.hasNext());
/*
- * null type included - should get removed
+ * null type included - should be ignored
*/
types = sf.varargToTypes("Metal", null, "Helix");
iterator = types.iterator();
assertTrue(iterator.hasNext());
- assertEquals(iterator.next(), "Helix");
- assertTrue(iterator.hasNext());
- assertEquals(iterator.next(), "Metal");
+ assertSame(iterator.next(), featureStores.get("Metal"));
assertFalse(iterator.hasNext());
}