Class SequenceTools
- java.lang.Object
-
- org.biojava.bio.seq.SequenceTools
-
public final class SequenceTools extends Object
Methods for manipulating sequences.- Author:
- Matthew Pocock
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
addAllFeatures(Sequence seq, FeatureHolder fh)
Add features to a sequence that contain the same information as all those in a feature holder.static Sequence
createDummy(String uri, String name)
Create a new Sequence that has no annotation, no features and a zero-length symbol list.static Sequence
createDummy(Alphabet alpha, int length, Symbol sym, String uri, String name)
Create a new Sequence that contains a single symbol repeated over and over.static Sequence
createSequence(SymbolList syms, String uri, String name, Annotation ann)
static GappedSequence
gappedView(Sequence seq)
Create a new gapped sequence for a sequence.static Sequence
maskSequence(Sequence seq, RangeLocation loc)
Mask of a sequence.static Sequence
reverseComplement(Sequence seq)
Reverse-complement a sequence, and flip all of its features.static Sequence
subSequence(Sequence seq, int start, int end)
Extract a sub-sequence from a sequence.static Sequence
subSequence(Sequence seq, int start, int end, String name)
Extract a sub-sequence from a sequence.static Sequence
subSequence(Sequence seq, int start, int end, String name, StrandedFeature.Strand strand)
Extract a sub-sequence from a sequence.static ViewSequence
view(Sequence seq)
Create a new sequence that has all of the data in the original, but allows new features and top-level annotations to be added independantly.static ViewSequence
view(Sequence seq, String name)
Create a new sequence that has all of the data in the original, but allows new features and top-level annotations to be added independantly.static ViewSequence
view(Sequence seq, FeatureRealizer fr)
Creates a new Sequence with the data of the old but with a different FeatureRealizer that will be applied to new Features.
-
-
-
Method Detail
-
createSequence
public static Sequence createSequence(SymbolList syms, String uri, String name, Annotation ann)
-
subSequence
public static Sequence subSequence(Sequence seq, int start, int end) throws IndexOutOfBoundsException
Extract a sub-sequence from a sequence.The sub-sequence will be indexed from 1 through to (end-start+1). An index of i in the sub-sequence corresponds to (i+start-1) in the original. All features from the original sequence will be projected down into this co-ordinate system. All features overlapping the edges will be given fuzzy locations.
- Parameters:
seq
- the sequence to sub-sequencestart
- the first index to include in the sub-sequenceend
- the last index to include in the sub-sequence- Returns:
- a view Sequence for this region
- Throws:
IndexOutOfBoundsException
- if start or end are not in seq, or if end < start
-
subSequence
public static Sequence subSequence(Sequence seq, int start, int end, String name) throws IndexOutOfBoundsException
Extract a sub-sequence from a sequence.The sub-sequence will be indexed from 1 through to (end-start+1). An index of i in the sub-sequence corresponds to (i+start-1) in the original. All features from the original sequence will be projected down into this co-ordinate system. All features overlapping the edges will be given fuzzy locations.
- Parameters:
seq
- the sequence to sub-sequencestart
- the first index to include in the sub-sequenceend
- the last index to include in the sub-sequencename
- a new name to give to this sub-sequence- Returns:
- a view Sequence for this region
- Throws:
IndexOutOfBoundsException
- if start or end are not in seq, or if end < start
-
subSequence
public static Sequence subSequence(Sequence seq, int start, int end, String name, StrandedFeature.Strand strand) throws IndexOutOfBoundsException, IllegalAlphabetException
Extract a sub-sequence from a sequence.The sub-sequence will be indexed from 1 through to (end-start+1). If the strand is NEGATIVE, all features will be flipped in the same manner as the reverseComplement method. If it is UNKNOWN or POSITIVE, then this is identical to the other subSequence methods.
- Parameters:
seq
- the sequence to sub-sequencestart
- the first index to include in the sub-sequenceend
- the last index to include in the sub-sequencename
- a new name to give to this sub-sequencestrand
- a StrandedFeature.Strand indicating which strand the sub-sequence should be on- Returns:
- a view Sequence for this region
- Throws:
IndexOutOfBoundsException
- if start or end are not in seq, or if end < startIllegalAlphabetException
-
reverseComplement
public static Sequence reverseComplement(Sequence seq) throws IllegalAlphabetException
Reverse-complement a sequence, and flip all of its features.- Parameters:
seq
- the Sequence to reverse-complement- Returns:
- the flipped Sequence
- Throws:
IllegalAlphabetException
- if the symbols in the sequence can not be complemented
-
view
public static ViewSequence view(Sequence seq)
Create a new sequence that has all of the data in the original, but allows new features and top-level annotations to be added independantly. Use this as a scratch-space.- Parameters:
seq
- the Sequence to view- Returns:
- a new ViewSequence
-
view
public static ViewSequence view(Sequence seq, String name)
Create a new sequence that has all of the data in the original, but allows new features and top-level annotations to be added independantly. Use this as a scratch-space.- Parameters:
seq
- the Sequence to viewname
- a new name for the sequence- Returns:
- a new ViewSequence with the new name
-
view
public static ViewSequence view(Sequence seq, FeatureRealizer fr)
Creates a new Sequence with the data of the old but with a different FeatureRealizer that will be applied to new Features.- Parameters:
seq
- the Sequence to wrapfr
- the new FeatureRealizer- Returns:
- the new ViewSequence
-
gappedView
public static GappedSequence gappedView(Sequence seq)
Create a new gapped sequence for a sequence.The gapped sequence can be used to insert gaps. The features on the underlying sequence will be projected onto the view taking the gaps into account.
- Parameters:
seq
-- Returns:
- a GappedSequence view of seq
-
maskSequence
public static Sequence maskSequence(Sequence seq, RangeLocation loc) throws IndexOutOfBoundsException, IllegalArgumentException
Mask of a sequence.This will return a view of a sequence where everything outside loc is dropped. This includes all symbols, which become gaps, and all features, which behave in a similar manner to those produced by subSequence().
- Parameters:
seq
- the Sequence to maskloc
- the region to retain- Returns:
- a Sequence viewing just the retained portion of seq
- Throws:
IndexOutOfBoundsException
- if loc is not totaly within seqIllegalArgumentException
- fixme: not sure where this comes from
-
createDummy
public static Sequence createDummy(String uri, String name)
Create a new Sequence that has no annotation, no features and a zero-length symbol list. Instantiate this if an API requres a sequence, but you can't be bothered or are not able to provide full sequence information. It is sometimes usefull to create a dummy sequence and then wrap this in a view.- Parameters:
uri
- the URI to give the dummy sequencename
- the name of the dummy sequence- Returns:
- a dummy Sequence
-
createDummy
public static Sequence createDummy(Alphabet alpha, int length, Symbol sym, String uri, String name) throws IllegalSymbolException
Create a new Sequence that contains a single symbol repeated over and over.- Parameters:
alpha
- the Alphabet this sequence is overlength
- the length of the sequencesym
- the symbol returned by every call to symbolAturi
- the URI of the sequencename
- the name of the sequence- Returns:
- a new sequence of the right length
- Throws:
IllegalSymbolException
- if sym is not in alpha- Since:
- 1.4
-
addAllFeatures
public static void addAllFeatures(Sequence seq, FeatureHolder fh) throws ChangeVetoException, BioException
Add features to a sequence that contain the same information as all those in a feature holder.- Parameters:
seq
- the Sequence to add features tofh
- the features to add- Throws:
ChangeVetoException
- if the sequence could not be modifiedBioException
- if there was an error creating the features
-
-