Class FeatureList
- java.lang.Object
-
- java.util.AbstractCollection<E>
-
- java.util.AbstractList<E>
-
- java.util.ArrayList<FeatureI>
-
- org.biojava.nbio.genome.parsers.gff.FeatureList
-
- All Implemented Interfaces:
Serializable
,Cloneable
,Iterable<FeatureI>
,Collection<FeatureI>
,List<FeatureI>
,RandomAccess
public class FeatureList extends ArrayList<FeatureI>
A list of FeatureI objects implemented using a Java ArrayList; corresponds to a GFF file. This class is implemented entirely using FeatureI objects, so everything here will work correctly if you choose to implement your own feature class -- there are no dependencies on JavaGene's native Feature class.- Author:
- Hanno Hinsch, Carmelo Foti
- See Also:
- Serialized Form
-
-
Field Summary
-
Fields inherited from class java.util.AbstractList
modCount
-
-
Constructor Summary
Constructors Constructor Description FeatureList()
Construct an empty list.FeatureList(Collection<FeatureI> features)
Construct a new list containing the same features as the specified list.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
add(Collection<FeatureI> list)
Add all features in the specified list or collection to this list.boolean
add(FeatureI feature)
Add specified feature to the end of the list.void
addIndex(String index)
Add an attribute that will be used as index for queriesvoid
addIndexes(List<String> indexes)
Add a list of attributes that will be used as indexes for queriesCollection<String>
attributeValues(String key)
Create a collection of the unique values for the specified key.Location
bounds()
The union of all locations of all features in this list, mapped to the positive strand.Collection<String>
groupValues()
Create a collection of all unique group ids in the list, as defined by the group() method of the features.boolean
hasAttribute(String key)
Check if any feature in list has the specified attribute key.boolean
hasAttribute(String key, String value)
Check if any feature in list has the specified attribute key/value pair.boolean
hasGaps(int gapLength)
Check size of gaps between successive features in list.FeatureList
omitOverlapping(String seqname, Location location, boolean useBothStrands)
Create a list of all features that do not overlap the specified location on the specified sequence.FeatureList
selectByAttribute(String key)
Create a list of all features that include the specified attribute key.FeatureList
selectByAttribute(String key, String value)
Create a list of all features that include the specified attribute key/value pair.FeatureList
selectByGroup(String groupid)
Create a list of all features that have the specified group id, as defined by the group() method of the features.FeatureList
selectByType(String type)
Create a list of all features that are of the specified type, as defined by the type() method of the features.FeatureList
selectByUserData(String key)
Create a list of all features that include the specified key in their userMap().FeatureList
selectByUserData(String key, Object value)
Create a list of all features that include the specified key/value pair in their userMap().FeatureList
selectOverlapping(String seqname, Location location, boolean useBothStrands)
Create a list of all features that overlap the specified location on the specified sequence.FeatureList
sortByStart()
Create a new list that is ordered by the starting index of the features' locations.String
splice(DNASequence sequence)
Concatenate successive portions of the specified sequence using the feature locations in the list.String
toString()
Return a string representation of all features in this list.-
Methods inherited from class java.util.ArrayList
add, addAll, addAll, clear, clone, contains, ensureCapacity, equals, forEach, get, hashCode, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, remove, remove, removeAll, removeIf, removeRange, replaceAll, retainAll, set, size, sort, spliterator, subList, toArray, toArray, trimToSize
-
Methods inherited from class java.util.AbstractCollection
containsAll
-
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.util.Collection
parallelStream, stream, toArray
-
Methods inherited from interface java.util.List
containsAll
-
-
-
-
Constructor Detail
-
FeatureList
public FeatureList()
Construct an empty list.
-
FeatureList
public FeatureList(Collection<FeatureI> features)
Construct a new list containing the same features as the specified list.- Parameters:
features
- An existing list or collection of FeatureI objects.
-
-
Method Detail
-
add
public boolean add(FeatureI feature)
Add specified feature to the end of the list. Updates the bounding location of the feature list, if needed.
-
add
public void add(Collection<FeatureI> list)
Add all features in the specified list or collection to this list.- Parameters:
list
- The collection of FeatureI objects.
-
bounds
public Location bounds()
The union of all locations of all features in this list, mapped to the positive strand. If an added feature is on the negative strand, its positive strand image is added to the union. The bounding location is not updated when a feature is removed from the list, so it is not guaranteed to be the minimal bounding location.- Returns:
- A location that is the union of all feature locations in the list.
-
hasGaps
public boolean hasGaps(int gapLength)
Check size of gaps between successive features in list. The features in the list are assumed to be appropriately ordered.- Parameters:
gapLength
- The minimum gap length to consider. Use a gapLength of 0 to check if features are contiguous.- Returns:
- True if list has any gaps equal to or greater than gapLength.
-
splice
public String splice(DNASequence sequence)
Concatenate successive portions of the specified sequence using the feature locations in the list. The list is assumed to be appropriately ordered.- Parameters:
sequence
- The source sequence from which portions should be selected.- Returns:
- The spliced data.
- Throws:
IllegalStateException
- Out of order or overlapping FeatureI locations detected.
-
groupValues
public Collection<String> groupValues()
Create a collection of all unique group ids in the list, as defined by the group() method of the features. For example, if the features are from a GFF1 file, then each group id identifies a particular gene, and this method returns a collection of all gene ids.- Returns:
- A collection (suitable for iteration using Java's "for" loop) of all the group ids found in this list. The order of the values is undefined; it will not match the order of features in the list.
-
attributeValues
public Collection<String> attributeValues(String key)
Create a collection of the unique values for the specified key. Example: For GTF files, using the "gene_id" key will give the names of all the genes in this list.- Returns:
- A collection (suitable for iteration using Java's "for" loop) of all the values found for this key. The order of the values is undefined; it will not match the order of features in the list.
-
selectByGroup
public FeatureList selectByGroup(String groupid)
Create a list of all features that have the specified group id, as defined by the group() method of the features.- Parameters:
groupid
- The group to match.- Returns:
- A list of features having the specified group id.
-
selectByType
public FeatureList selectByType(String type)
Create a list of all features that are of the specified type, as defined by the type() method of the features. This might be, for example, "exon" or "CDS".- Parameters:
type
- The type to match.- Returns:
- A list of features of the specified type.
-
selectByAttribute
public FeatureList selectByAttribute(String key, String value)
Create a list of all features that include the specified attribute key/value pair. This method now properly supports adding the index before or after adding the features. Adding features, then then index, then more features is still not supported.- Parameters:
key
- The key to consider.value
- The value to consider.- Returns:
- A list of features that include the key/value pair.
-
selectByAttribute
public FeatureList selectByAttribute(String key)
Create a list of all features that include the specified attribute key.- Parameters:
key
- The key to consider.- Returns:
- A list of features that include the key.
-
selectByUserData
public FeatureList selectByUserData(String key, Object value)
Create a list of all features that include the specified key/value pair in their userMap().- Parameters:
key
- The key to consider.value
- The value to consider.- Returns:
- A list of features that include the key/value pair.
-
selectByUserData
public FeatureList selectByUserData(String key)
Create a list of all features that include the specified key in their userMap().- Parameters:
key
- The key to consider.- Returns:
- A list of features that include the key.
-
selectOverlapping
public FeatureList selectOverlapping(String seqname, Location location, boolean useBothStrands) throws Exception
Create a list of all features that overlap the specified location on the specified sequence.- Parameters:
seqname
- The sequence name. Only features with this sequence name will be checked for overlap.location
- The location to check.useBothStrands
- If true, locations are mapped to their positive strand image before being checked for overlap. If false, only features whose locations are on the same strand as the specified location will be considered for inclusion.- Returns:
- The new list of features that overlap the location.
- Throws:
Exception
-
omitOverlapping
public FeatureList omitOverlapping(String seqname, Location location, boolean useBothStrands)
Create a list of all features that do not overlap the specified location on the specified sequence.- Parameters:
seqname
- The sequence name. Only features with this sequence name will be checked for overlap.location
- The location to check.useBothStrands
- If true, locations are mapped to their positive strand image before being checked for overlap. If false, all features whose locations are on the opposite strand from the specified location will be considered non-overlapping.- Returns:
- The new list of features that do not overlap the location.
-
hasAttribute
public boolean hasAttribute(String key)
Check if any feature in list has the specified attribute key.- Parameters:
key
- The attribute key to consider.- Returns:
- True if at least one feature has the attribute key.
-
hasAttribute
public boolean hasAttribute(String key, String value)
Check if any feature in list has the specified attribute key/value pair.- Parameters:
key
- The attribute key to consider.value
- The attribute value to consider.- Returns:
- True if at least one feature has the key/value pair.
-
toString
public String toString()
Return a string representation of all features in this list.- Overrides:
toString
in classAbstractCollection<FeatureI>
- Returns:
- A string.
-
sortByStart
public FeatureList sortByStart()
Create a new list that is ordered by the starting index of the features' locations. All locations must be on the same strand of the same sequence.- Returns:
- An ordered list.
- Throws:
IndexOutOfBoundsException
- Cannot compare/sort features whose locations are on opposite strands, or whose seqnames differ.
-
addIndexes
public void addIndexes(List<String> indexes)
Add a list of attributes that will be used as indexes for queries- Parameters:
indexes
- the List containing the attribute_id
-
-