Class ThinRichSequence

All Implemented Interfaces:
Comparable, Annotatable, FeatureHolder, Sequence, SymbolList, Changeable, BioEntry, RichSequence, RankedCrossRefable, RichAnnotatable
Direct Known Subclasses:
SimpleRichSequence

public class ThinRichSequence extends SimpleBioEntry implements RichSequence
A simple implementation of RichSequence. It has no sequence data, and delegates to a RichSequenceHandler to do sequence handling.
Since:
1.5
Author:
Richard Holland
  • Constructor Details

    • ThinRichSequence

      public ThinRichSequence(Namespace ns, String name, String accession, int version, Alphabet alpha, Double seqversion)
      Creates a new instance of ThinRichSequence. Note the use of Double for seqversion, which indicates that it is nullable.
      Parameters:
      ns - the namespace for this sequence.
      name - the name of the sequence.
      accession - the accession of the sequence.
      version - the version of the sequence.
      seqversion - the version of the symbols for the sequence.
    • ThinRichSequence

      protected ThinRichSequence()
  • Method Details

    • getSeqVersion

      The version of the associated symbol list. Note the use of an object for the value means that it can be nulled.
      Specified by:
      getSeqVersion in interface RichSequence
      Returns:
      the version
    • setSeqVersion

      public void setSeqVersion(Double seqVersion) throws ChangeVetoException
      Sets the version of the associated symbol list. Note the use of an object for the value means that it can be nulled.
      Specified by:
      setSeqVersion in interface RichSequence
      Parameters:
      seqVersion - the version to set.
      Throws:
      ChangeVetoException - if it doesn't want to change.
    • setCircular

      public void setCircular(boolean circular) throws ChangeVetoException
      Circularises the Sequence. The circular length can then be said to be the length of the sequence itself.
      Specified by:
      setCircular in interface RichSequence
      Parameters:
      circular - set to true if you want it to be circular
      Throws:
      ChangeVetoException - if the change is blocked. Some implementations may choose not to support circularisation and should throw an exception here. Some implementations may only support this method for certain Alphabets.
    • getCircular

      public boolean getCircular()
      Is the sequence circular? Circularity has implications for work with locations and any coordinate work eg symbolAt(int i). Classes that allow it should test this method when working with coordinates or locations / features.
      Specified by:
      getCircular in interface RichSequence
      Returns:
      true if the this is circular else false.
    • edit

      Apply an edit to the SymbolList as specified by the edit object.

      Description

      All edits can be broken down into a series of operations that change contiguous blocks of the sequence. This represent a one of those operations.

      When applied, this Edit will replace 'length' number of symbols starting a position 'pos' by the SymbolList 'replacement'. This allow to do insertions (length=0), deletions (replacement=SymbolList.EMPTY_LIST) and replacements (length>=1 and replacement.length()>=1).

      The pos and pos+length should always be valid positions on the SymbolList to:

      • be edited (between 0 and symL.length()+1).
      • To append to a sequence, pos=symL.length()+1, pos=0.
      • To insert something at the beginning of the sequence, set pos=1 and length=0.

      Examples

       SymbolList seq = DNATools.createDNA("atcaaaaacgctagc");
       System.out.println(seq.seqString());
      
       // delete 5 bases from position 4
       Edit ed = new Edit(4, 5, SymbolList.EMPTY_LIST);
       seq.edit(ed);
       System.out.println(seq.seqString());
      
       // delete one base from the start
       ed = new Edit(1, 1, SymbolList.EMPTY_LIST);
       seq.edit(ed);
      
       // delete one base from the end
       ed = new Edit(seq.length(), 1, SymbolList.EMPTY_LIST);
       seq.edit(ed);
       System.out.println(seq.seqString());
      
       // overwrite 2 bases from position 3 with "tt"
       ed = new Edit(3, 2, DNATools.createDNA("tt"));
       seq.edit(ed);
       System.out.println(seq.seqString());
      
       // add 6 bases to the start
       ed = new Edit(1, 0, DNATools.createDNA("aattgg");
       seq.edit(ed);
       System.out.println(seq.seqString());
      
       // add 4 bases to the end
       ed = new Edit(seq.length() + 1, 0, DNATools.createDNA("tttt"));
       seq.edit(ed);
       System.out.println(seq.seqString());
      
       // full edit
       ed = new Edit(3, 2, DNATools.createDNA("aatagaa");
       seq.edit(ed);
       System.out.println(seq.seqString());
       
      Specified by:
      edit in interface SymbolList
      Parameters:
      edit - the Edit to perform
      Throws:
      IndexOutOfBoundsException - if the edit does not lie within the SymbolList
      IllegalAlphabetException - if the SymbolList to insert has an incompatible alphabet
      ChangeVetoException - if either the SymboList does not support the edit, or if the change was vetoed
    • symbolAt

      public Symbol symbolAt(int index) throws IndexOutOfBoundsException
      Return the symbol at index, counting from 1.
      Specified by:
      symbolAt in interface SymbolList
      Parameters:
      index - the offset into this SymbolList
      Returns:
      the Symbol at that index
      Throws:
      IndexOutOfBoundsException - if index is less than 1, or greater than the length of the symbol list
    • toList

      public List toList()
      Returns a List of symbols.

      This is an immutable list of symbols. Do not edit it.

      Specified by:
      toList in interface SymbolList
      Returns:
      a List of Symbols
    • subStr

      public String subStr(int start, int end) throws IndexOutOfBoundsException
      Return a region of this symbol list as a String.

      This should use the same rules as seqString.

      Specified by:
      subStr in interface SymbolList
      Parameters:
      start - the first symbol to include
      end - the last symbol to include
      Returns:
      the string representation
      Throws:
      IndexOutOfBoundsException - if either start or end are not within the SymbolList
    • subList

      public SymbolList subList(int start, int end) throws IndexOutOfBoundsException
      Return a new SymbolList for the symbols start to end inclusive.

      The resulting SymbolList will count from 1 to (end-start + 1) inclusive, and refer to the symbols start to end of the original sequence.

      Specified by:
      subList in interface SymbolList
      Parameters:
      start - the first symbol of the new SymbolList
      end - the last symbol (inclusive) of the new SymbolList
      Throws:
      IndexOutOfBoundsException
    • seqString

      public String seqString()
      Stringify this symbol list.

      It is expected that this will use the symbol's token to render each symbol. It should be parsable back into a SymbolList using the default token parser for this alphabet.

      Specified by:
      seqString in interface SymbolList
      Returns:
      a string representation of the symbol list
    • length

      public int length()
      The number of symbols in this SymbolList.
      Specified by:
      length in interface SymbolList
      Returns:
      the length
    • iterator

      public Iterator iterator()
      An Iterator over all Symbols in this SymbolList.

      This is an ordered iterator over the Symbols. It cannot be used to edit the underlying symbols.

      Specified by:
      iterator in interface SymbolList
      Returns:
      an iterator
    • getAlphabet

      The alphabet that this SymbolList is over.

      Every symbol within this SymbolList is a member of this alphabet. alphabet.contains(symbol) == true for each symbol that is within this sequence.

      Specified by:
      getAlphabet in interface SymbolList
      Returns:
      the alphabet
    • setAlphabetName

      protected void setAlphabetName(String alphaname) throws IllegalSymbolException, BioException
      Throws:
      IllegalSymbolException
      BioException
    • getAlphabetName

      protected String getAlphabetName()
    • setSequenceLength

      protected void setSequenceLength(int length)
    • getSequenceLength

      protected int getSequenceLength()
    • getURN

      public String getURN()
      A Uniform Resource Identifier (URI) which identifies the sequence represented by this object. For sequences in well-known database, this may be a URN, e.g.
       urn:sequence/embl:AL121903
       
      It may also be a URL identifying a specific resource, either locally or over the network
       file:///home/thomas/myseq.fa|seq22
       http://www.mysequences.net/chr22.seq
       
      Specified by:
      getURN in interface Sequence
      Returns:
      the URI as a String
    • filter

      public FeatureHolder filter(FeatureFilter fc, boolean recurse)
      Return a new FeatureHolder that contains all of the children of this one that passed the filter fc. This method is scheduled for deprecation. Use the 1-arg filter instead.
      Specified by:
      filter in interface FeatureHolder
      Parameters:
      fc - the FeatureFilter to apply
      recurse - true if all features-of-features should be scanned, and a single flat collection of features returned, or false if just immediate children should be filtered.
    • createFeature

      Create a new Feature, and add it to this FeatureHolder. This method will generally only work on Sequences, and on some Features which have been attached to Sequences.
      Specified by:
      createFeature in interface FeatureHolder
      Throws:
      BioException - if something went wrong during creating the feature
      ChangeVetoException - if this FeatureHolder does not support creation of new features, or if the change was vetoed
    • removeFeature

      Remove a feature from this FeatureHolder.
      Specified by:
      removeFeature in interface FeatureHolder
      Throws:
      ChangeVetoException - if this FeatureHolder does not support feature removal or if the change was vetoed
      BioException - if there was an error removing the feature
    • containsFeature

      public boolean containsFeature(Feature f)
      Check if the feature is present in this holder.
      Specified by:
      containsFeature in interface FeatureHolder
      Parameters:
      f - the Feature to check
      Returns:
      true if f is in this set
    • filter

      Query this set of features using a supplied FeatureFilter.
      Specified by:
      filter in interface FeatureHolder
      Parameters:
      filter - the FeatureFilter to apply.
      Returns:
      all features in this container which match filter.
    • getFeatureSet

      The features for this sequence. Warning this method gives access to the original Collection not a copy. This is required by Hibernate. If you modify the object directly the behaviour may be unpredictable.
      Specified by:
      getFeatureSet in interface RichSequence
      Returns:
      a set of RichFeature objects.
    • setFeatureSet

      public void setFeatureSet(Set<Feature> features) throws ChangeVetoException
      Sets the features of this sequence. Note that it is not checked to see if the features actually belong to this sequence, you'd best check that yourself and make changes using feature.setParent() if necessary. Warning this method gives access to the original Collection not a copy. This is required by Hibernate. If you modify the object directly the behaviour may be unpredictable.
      Specified by:
      setFeatureSet in interface RichSequence
      Parameters:
      features - the features to assign to this sequence, replacing all others. Must be a set of RichFeature objects.
      Throws:
      ChangeVetoException - if they could not be assigned.
    • getSchema

      Return a schema-filter for this FeatureHolder. This is a filter which all Features immediately contained by this FeatureHolder will match. It need not directly match their child features, but it can (and should!) provide information about them using FeatureFilter.OnlyChildren filters. In cases where there is no feature hierarchy, this can be indicated by including FeatureFilter.leaf in the schema filter.

      For the truly non-informative case, it is possible to return FeatureFilter.all. However, it is almost always possible to provide slightly more information that this. For example, Sequence objects should, at a minimum, return FeatureFilter.top_level. Feature objects should, as a minimum, return FeatureFilter.ByParent(new FeatureFilter.ByFeature(this)).

      Specified by:
      getSchema in interface FeatureHolder
      Returns:
      the schema filter
    • features

      Iterate over the features in no well defined order. Warning this method gives access to the original Collection not a copy. This is required by Hibernate. If you modify the object directly the behaviour may be unpredictable.
      Specified by:
      features in interface FeatureHolder
      Returns:
      an Iterator
    • countFeatures

      public int countFeatures()
      Count how many features are contained.
      Specified by:
      countFeatures in interface FeatureHolder
      Returns:
      a positive integer or zero, equal to the number of features contained
    • getInternalSymbolList

      A special function that returns the SymbolList that this RichSequence is based around. This should _not_ be the RichSequence object itself, as this function is used to perform actions on the symbol list without referring to the RichSequence object directly.
      Specified by:
      getInternalSymbolList in interface RichSequence
      Returns:
      the internal SymbolList of the RichSequence, NOT the RichSequence object itself.