Class SequenceTools


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

      • 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 < 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 < 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 < start
        IllegalAlphabetException
      • 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
      • 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