javagene.seq
Class FeatureList

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractList<E>
          extended by java.util.ArrayList<FeatureI>
              extended by javagene.seq.FeatureList
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.lang.Iterable<FeatureI>, java.util.Collection<FeatureI>, java.util.List<FeatureI>, java.util.RandomAccess

public class FeatureList
extends java.util.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.

See Also:
Serialized Form

Field Summary
 
Fields inherited from class java.util.AbstractList
modCount
 
Constructor Summary
FeatureList()
          Construct an empty list.
FeatureList(java.util.Collection<FeatureI> features)
          Construct a new list containing the same features as the specified list.
 
Method Summary
 void add(java.util.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.
 java.util.Collection<java.lang.String> attributeValues(java.lang.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.
 java.util.Collection<java.lang.String> groupValues()
          Create a collection of all unique group ids in the list, as defined by the group() method of the features.
 boolean hasAttribute(java.lang.String key)
          Check if any feature in list has the specified attribute key.
 boolean hasAttribute(java.lang.String key, java.lang.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(Location location, boolean useBothStrands)
          Create a list of all features that do not overlap the specified location.
 FeatureList selectByAttribute(java.lang.String key)
          Create a list of all features that include the specified attribute key.
 FeatureList selectByAttribute(java.lang.String key, java.lang.String value)
          Create a list of all features that include the specified attribute key/value pair.
 FeatureList selectByGroup(java.lang.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(java.lang.String type)
          Create a list of all features that are of the specified type, as defined by the type() method of the features.
 FeatureList selectOverlapping(Location location, boolean useBothStrands)
          Create a list of all features that overlap the specified location.
 FeatureList sortByStart()
          Create a new list that is ordered by the starting index of the features' locations.
 java.lang.String splice(SeqI sequence)
          Concatenate successive portions of the specified sequence using the feature locations in the list.
 java.lang.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, get, indexOf, isEmpty, lastIndexOf, remove, remove, removeRange, set, size, toArray, toArray, trimToSize
 
Methods inherited from class java.util.AbstractList
equals, hashCode, iterator, listIterator, listIterator, subList
 
Methods inherited from class java.util.AbstractCollection
containsAll, removeAll, retainAll
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.List
containsAll, equals, hashCode, iterator, listIterator, listIterator, removeAll, retainAll, subList
 

Constructor Detail

FeatureList

public FeatureList()
Construct an empty list.


FeatureList

public FeatureList(java.util.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 void add(java.util.Collection<FeatureI> list)
Add all features in the specified list or collection to this list.

Parameters:
list - The collection of FeatureI objects.

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.

Specified by:
add in interface java.util.Collection<FeatureI>
Specified by:
add in interface java.util.List<FeatureI>
Overrides:
add in class java.util.ArrayList<FeatureI>
Parameters:
feature - The FeatureI object to add.
Returns:
True if the feature was added.

attributeValues

public java.util.Collection<java.lang.String> attributeValues(java.lang.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.

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.

groupValues

public java.util.Collection<java.lang.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.

hasAttribute

public boolean hasAttribute(java.lang.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(java.lang.String key,
                            java.lang.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.

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.

omitOverlapping

public FeatureList omitOverlapping(Location location,
                                   boolean useBothStrands)
Create a list of all features that do not overlap the specified location.

Parameters:
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.

selectByAttribute

public FeatureList selectByAttribute(java.lang.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.

selectByAttribute

public FeatureList selectByAttribute(java.lang.String key,
                                     java.lang.String value)
Create a list of all features that include the specified attribute key/value pair.

Parameters:
key - The key to consider.
value - The value to consider.
Returns:
A list of features that include the key/value pair.

selectByGroup

public FeatureList selectByGroup(java.lang.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(java.lang.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.

selectOverlapping

public FeatureList selectOverlapping(Location location,
                                     boolean useBothStrands)
                              throws java.lang.Exception
Create a list of all features that overlap the specified location.

Parameters:
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.
Throws:
java.lang.Exception

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.

Returns:
An ordered list.
Throws:
java.lang.IndexOutOfBoundsException - Cannot compare/sort features whose locations are on opposite strands.

splice

public java.lang.String splice(SeqI 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:
java.lang.IllegalStateException - Out of order or overlapping FeatureI locations detected.

toString

public java.lang.String toString()
Return a string representation of all features in this list.

Overrides:
toString in class java.util.AbstractCollection<FeatureI>
Returns:
A string.