Trees | Indices | Help |
---|
|
object --+ | Seq
A read-only sequence object (essentially a string with an alphabet).
Like normal python strings, our basic sequence object is immutable. This prevents you from doing my_seq[5] = "A" for example, but does allow Seq objects to be used as dictionary keys.
The Seq object provides a number of string like methods (such as count, find, split and strip), which are alphabet aware where appropriate.
The Seq object also provides some biological methods, such as complement, reverse_complement, transcribe, back_transcribe and translate (which are not applicable to sequences with a protein alphabet).
|
|||
|
|||
|
|||
|
|||
|
|||
translation table (PRIVATE) |
|
||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
Inherited from |
|
|||
data Sequence as a string (DEPRECATED) |
|||
Inherited from |
|
Create a Seq object. Arguments: seq - Sequence, required (string) alphabet - Optional argument, an Alphabet object from Bio.Alphabet You will typically use Bio.SeqIO to read in sequences from files as SeqRecord objects, whose sequence will be exposed as a Seq object via the seq property. However, will often want to create your own Seq objects directly: >>> from Bio.Seq import Seq >>> from Bio.Alphabet import IUPAC >>> my_seq = Seq("MKQHKAMIVALIVICITAVVAALVTRKDLCEVHIRTGQTEVAVF", IUPAC.protein) >>> my_seq Seq('MKQHKAMIVALIVICITAVVAALVTRKDLCEVHIRTGQTEVAVF', IUPACProtein()) >>> print my_seq MKQHKAMIVALIVICITAVVAALVTRKDLCEVHIRTGQTEVAVF
|
Return a translation table for use with complement() and reverse_complement(). Compatible with lower case and upper case sequences. alphabet is a dictionary as implement in Data.IUPACData For internal use only.
|
Returns a (truncated) representation of the sequence for debugging.
|
Returns the full sequence as a python string. Note that Biopython 1.44 and earlier would give a truncated version of repr(my_seq) for str(my_seq). If you are writing code which need to be backwards compatible with old Biopython, you should continue to use my_seq.tostring() rather than str(my_seq)
|
string/Seq/MutableSeq to string, checking alphabet (PRIVATE). For a string argument, returns the string. For a Seq or MutableSeq, it checks the alphabet is compatible (raising an exception if it isn't), and then returns a string. |
Returns the DNA sequence from an RNA sequence. New Seq object. >>> from Bio.Seq import Seq >>> from Bio.Alphabet import IUPAC >>> messenger_rna = Seq("AUGGCCAUUGUAAUGGGCCGCUGAAAGGGUGCCCGAUAG", IUPAC.unambiguous_rna) >>> messenger_rna Seq('AUGGCCAUUGUAAUGGGCCGCUGAAAGGGUGCCCGAUAG', IUPACUnambiguousRNA()) >>> messenger_rna.back_transcribe() Seq('ATGGCCATTGTAATGGGCCGCTGAAAGGGTGCCCGATAG', IUPACUnambiguousDNA()) Trying to back-transcribe a protein or DNA sequence raises an exception. >>> my_protein = Seq("MAIVMGR", IUPAC.protein) >>> my_protein.back_transcribe() Traceback (most recent call last): ... ValueError: Proteins cannot be back transcribed! |
Returns the complement sequence. New Seq object. >>> from Bio.Seq import Seq >>> from Bio.Alphabet import IUPAC >>> my_dna = Seq("CCCCCGATAG", IUPAC.unambiguous_dna) >>> my_dna Seq('CCCCCGATAG', IUPACUnambiguousDNA()) >>> my_dna.complement() Seq('GGGGGCTATC', IUPACUnambiguousDNA()) Trying to complement a protein sequence raises an exception. >>> my_protein = Seq("MAIVMGR", IUPAC.protein) >>> my_protein.complement() Traceback (most recent call last): ... ValueError: Proteins do not have complements! |
Count method, like that of a python string. This behaves like the python string method of the same name. Returns an integer, the number of occurrences of substring argument sub in the (sub)sequence given by [start:end]. Optional arguments start and end are interpreted as in slice notation. sub - a string or another Seq object to look for start - optional integer, slice start end - optional integer, slice end e.g. >>> from Bio.Seq import Seq >>> my_seq = Seq("AAAATGA") >>> print my_seq.count("A") 5 >>> print my_seq.count("ATG") 1 >>> print my_seq.count(Seq("AT")) 1 >>> print my_seq.count("AT", 2, -1) 1 |
Find method, like that of a python string. This behaves like the python string method of the same name. Returns an integer, the index of the first occurrence of substring argument sub in the (sub)sequence given by [start:end]. sub - a string or another Seq object to look for start - optional integer, slice start end - optional integer, slice end Returns -1 if the subsequence is NOT found. e.g. Locating the first typical start codon, AUG, in an RNA sequence: >>> from Bio.Seq import Seq >>> my_rna = Seq("GUCAUGGCCAUUGUAAUGGGCCGCUGAAAGGGUGCCCGAUAGUUG") >>> my_rna.find("AUG") 3 |
Returns a new Seq object with leading (left) end stripped. This behaves like the python string method of the same name. Optional argument chars defines which characters to remove. If ommitted or None (default) then as for the python string method, this defaults to removing any white space. e.g. print my_seq.lstrip("-") See also the strip and rstrip methods. |
Returns the reverse complement sequence. New Seq object. >>> from Bio.Seq import Seq >>> from Bio.Alphabet import IUPAC >>> my_dna = Seq("CCCCCGATAG", IUPAC.unambiguous_dna) >>> my_dna Seq('CCCCCGATAG', IUPACUnambiguousDNA()) >>> my_dna.reverse_complement() Seq('CTATCGGGGG', IUPACUnambiguousDNA()) Trying to complement a protein sequence raises an exception. >>> my_protein = Seq("MAIVMGR", IUPAC.protein) >>> my_protein.reverse_complement() Traceback (most recent call last): ... ValueError: Proteins do not have complements! |
Find from right method, like that of a python string. This behaves like the python string method of the same name. Returns an integer, the index of the last (right most) occurrence of substring argument sub in the (sub)sequence given by [start:end]. sub - a string or another Seq object to look for start - optional integer, slice start end - optional integer, slice end Returns -1 if the subsequence is NOT found. |
Right split method, like that of a python string. This behaves like the python string method of the same name. Return a list of the 'words' in the string (as Seq objects), using sep as the delimiter string. If maxsplit is given, at most maxsplit splits are done COUNTING FROM THE RIGHT. If maxsplit is ommited, all splits are made. Following the python string method, sep will by default be any white space (tabs, spaces, newlines) but this is unlikely to apply to biological sequences. e.g. print my_seq.rsplit("*",1) See also the split method. |
Returns a new Seq object with trailing (right) end stripped. This behaves like the python string method of the same name. Optional argument chars defines which characters to remove. If ommitted or None (default) then as for the python string method, this defaults to removing any white space. e.g. Removing a nucleotide sequence's polyadenylation (poly-A tail): >>> from Bio.Alphabet import IUPAC >>> from Bio.Seq import Seq >>> my_seq = Seq("CGGTACGCTTATGTCACGTAGAAAAAA", IUPAC.unambiguous_dna) >>> my_seq Seq('CGGTACGCTTATGTCACGTAGAAAAAA', IUPACUnambiguousDNA()) >>> my_seq.rstrip("A") Seq('CGGTACGCTTATGTCACGTAG', IUPACUnambiguousDNA()) See also the strip and lstrip methods. |
Split method, like that of a python string. This behaves like the python string method of the same name. Return a list of the 'words' in the string (as Seq objects), using sep as the delimiter string. If maxsplit is given, at most maxsplit splits are done. If maxsplit is ommited, all splits are made. Following the python string method, sep will by default be any white space (tabs, spaces, newlines) but this is unlikely to apply to biological sequences. e.g. >>> from Bio.Seq import Seq >>> my_rna = Seq("GUCAUGGCCAUUGUAAUGGGCCGCUGAAAGGGUGCCCGAUAGUUG") >>> my_aa = my_rna.translate() >>> my_aa Seq('VMAIVMGR*KGAR*L', HasStopCodon(ExtendedIUPACProtein(), '*')) >>> my_aa.split("*") [Seq('VMAIVMGR', HasStopCodon(ExtendedIUPACProtein(), '*')), Seq('KGAR', HasStopCodon(ExtendedIUPACProtein(), '*')), Seq('L', HasStopCodon(ExtendedIUPACProtein(), '*'))] >>> my_aa.split("*",1) [Seq('VMAIVMGR', HasStopCodon(ExtendedIUPACProtein(), '*')), Seq('KGAR*L', HasStopCodon(ExtendedIUPACProtein(), '*'))] See also the rsplit method: >>> my_aa.rsplit("*",1) [Seq('VMAIVMGR*KGAR', HasStopCodon(ExtendedIUPACProtein(), '*')), Seq('L', HasStopCodon(ExtendedIUPACProtein(), '*'))] |
Returns a new Seq object with leading and trailing ends stripped. This behaves like the python string method of the same name. Optional argument chars defines which characters to remove. If ommitted or None (default) then as for the python string method, this defaults to removing any white space. e.g. print my_seq.strip("-") See also the lstrip and rstrip methods. |
Returns the full sequence as a MutableSeq object. >>> from Bio.Seq import Seq >>> from Bio.Alphabet import IUPAC >>> my_seq = Seq("MKQHKAMIVALIVICITAVVAAL", IUPAC.protein) >>> my_seq Seq('MKQHKAMIVALIVICITAVVAAL', IUPACProtein()) >>> my_seq.tomutable() MutableSeq('MKQHKAMIVALIVICITAVVAAL', IUPACProtein()) Note that the alphabet is preserved. |
Returns the full sequence as a python string. Although not formally deprecated, you are now encouraged to use str(my_seq) instead of my_seq.tostring(). |
Returns the RNA sequence from a DNA sequence. New Seq object. >>> from Bio.Seq import Seq >>> from Bio.Alphabet import IUPAC >>> coding_dna = Seq("ATGGCCATTGTAATGGGCCGCTGAAAGGGTGCCCGATAG", IUPAC.unambiguous_dna) >>> coding_dna Seq('ATGGCCATTGTAATGGGCCGCTGAAAGGGTGCCCGATAG', IUPACUnambiguousDNA()) >>> coding_dna.transcribe() Seq('AUGGCCAUUGUAAUGGGCCGCUGAAAGGGUGCCCGAUAG', IUPACUnambiguousRNA()) Trying to transcribe a protein or RNA sequence raises an exception: >>> my_protein = Seq("MAIVMGR", IUPAC.protein) >>> my_protein.transcribe() Traceback (most recent call last): ... ValueError: Proteins cannot be transcribed! |
Turns a nucleotide sequence into a protein sequence. New Seq object. Trying to back-transcribe a protein sequence raises an exception. This method will translate DNA or RNA sequences. Trying to translate a protein sequence raises an exception. table - Which codon table to use? This can be either a name (string) or an NCBI identifier (integer). This defaults to the "Standard" table. stop_symbol - Single character string, what to use for terminators. This defaults to the asterisk, "*". to_stop - Boolean, defaults to False meaning do a full translation continuing on past any stop codons (translated as the specified stop_symbol). If True, translation is terminated at the first in frame stop codon (and the stop_symbol is not appended to the returned protein sequence). e.g. Using the standard table, >>> coding_dna = Seq("GTGGCCATTGTAATGGGCCGCTGAAAGGGTGCCCGATAG") >>> coding_dna.translate() Seq('VAIVMGR*KGAR*', HasStopCodon(ExtendedIUPACProtein(), '*')) >>> coding_dna.translate(stop_symbol="@") Seq('VAIVMGR@KGAR@', HasStopCodon(ExtendedIUPACProtein(), '@')) >>> coding_dna.translate(to_stop=True) Seq('VAIVMGR', ExtendedIUPACProtein()) Now using NCBI table 2, where TGA is not a stop codon: >>> coding_dna.translate(table=2) Seq('VAIVMGRWKGAR*', HasStopCodon(ExtendedIUPACProtein(), '*')) >>> coding_dna.translate(table=2, to_stop=True) Seq('VAIVMGRWKGAR', ExtendedIUPACProtein()) If the sequence has no in-frame stop codon, then the to_stop argument has no effect: >>> coding_dna2 = Seq("TTGGCCATTGTAATGGGCCGC") >>> coding_dna2.translate() Seq('LAIVMGR', ExtendedIUPACProtein()) >>> coding_dna2.translate(to_stop=True) Seq('LAIVMGR', ExtendedIUPACProtein()) NOTE - Ambiguous codons like "TAN" or "NNN" could be an amino acid or a stop codon. These are translated as "X". Any invalid codon (e.g. "TA?" or "T-A") will throw a TranslationError. NOTE - Does NOT support gapped sequences. NOTE - This does NOT behave like the python string's translate method. For that use str(my_seq).translate(...) instead. |
|
dataSequence as a string (DEPRECATED)
|
Trees | Indices | Help |
---|
Generated by Epydoc 3.0.1 on Thu Dec 25 10:56:35 2008 | http://epydoc.sourceforge.net |