Class SequenceTools

java.lang.Object
org.biojava.bio.seq.SequenceTools

public final class SequenceTools extends Object
Methods for manipulating sequences.
Author:
Matthew Pocock
  • Method Details

    • 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-sequence
      start - the first index to include in the sub-sequence
      end - 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 invalid input: '<' 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-sequence
      start - the first index to include in the sub-sequence
      end - the last index to include in the sub-sequence
      name - 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 invalid input: '<' 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-sequence
      start - the first index to include in the sub-sequence
      end - the last index to include in the sub-sequence
      name - a new name to give to this sub-sequence
      strand - 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 invalid input: '<' start
      IllegalAlphabetException
    • reverseComplement

      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 view
      name - 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 wrap
      fr - 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

      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 mask
      loc - the region to retain
      Returns:
      a Sequence viewing just the retained portion of seq
      Throws:
      IndexOutOfBoundsException - if loc is not totaly within seq
      IllegalArgumentException - 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 sequence
      name - 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 over
      length - the length of the sequence
      sym - the symbol returned by every call to symbolAt
      uri - the URI of the sequence
      name - 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 to
      fh - the features to add
      Throws:
      ChangeVetoException - if the sequence could not be modified
      BioException - if there was an error creating the features