class biotite.sequence.NucleotideSequence(sequence=[], ambiguous=False)[source]

Bases: biotite.sequence.sequence.Sequence

Representation of a nucleotide sequence (DNA or RNA).

This class may one of two different alphabets: unambiguous_alphabet() contains only the unambiguous DNA letters ‘A’, ‘C’, ‘G’ and ‘T’. ambiguous_alphabet() uses an extended alphabet for ambiguous letters.

sequence : iterable object, optional

The initial DNA sequence. This may either be a list or a string. May take upper or lower case letters. By default the sequence is empty.

ambiguous : bool, optional

If true, the ambiguous alphabet is used. By default the object tries to use the unambiguous alphabet. If this fails due ambiguous letters in the sequence, the ambiguous alphabet is used.


Get the Alphabet of the Sequence.

This method must be overwritten, when subclassing Sequence.

alphabet : Alphabet

Sequence alphabet.


Get the complement nucleotide sequence.

complement : NucleotideSequence

The complement sequence.


>>> dna_seq = NucleotideSequence("ACGCTT")
>>> print(dna_seq.complement())
>>> print(dna_seq.reverse().complement())
translate(complete=False, codon_table=None, met_start=False)[source]

Translate the nucleotide sequence into a protein sequence.

If complete is true, the entire sequence is translated, beginning with the first codon and ending with the last codon, even if stop codons occur during the translation.

Otherwise this method returns possible ORFs in the sequence, even if not stop codon occurs in an ORF.

complete : bool, optional

If true, the complete sequence is translated. In this case the sequence length must be a multiple of 3. Otherwise all ORFs are translated. (Default: False)

codon_table : CodonTable, optional

The codon table to be used. By default the default table will be used (NCBI “Standard” table with “ATG” as single start codon).

met_start : bool, optional

If true, the translation starts always with a ‘methionine’, even if the start codon codes for another amino acid. Otherwise the translation starts with the amino acid the codon codes for. Only applies, if complete is false. (Default: False)

protein : ProteinSequence or list of ProteinSequence

The translated protein sequence. If complete is true, only a single ProteinSequence is returned. Otherwise a list of ProteinSequence is returned, which contains every ORF.

pos : list of tuple (int, int)

Is only returned if complete is false. The list contains a tuple for each ORF. The first element of the tuple is the index of the RNASequence`, where the translation starts. The second element is the exclusive stop index, therefore it represents the first nucleotide in the RNASequence after a stop codon.


>>> dna_seq = NucleotideSequence("AATGATGCTATAGAT")
>>> prot_seq = dna_seq.translate(complete=True)
>>> print(prot_seq)
>>> prot_seqs, pos = dna_seq.translate(complete=False)
>>> for seq in prot_seqs:
...    print(seq)
static unambiguous_alphabet()[source]
static ambiguous_alphabet()[source]

Copy the object.

new_seq_code : ndarray, optional

If this parameter is set, the sequence code is set to this value, rather than the original sequence code.


A copy of this object.


Get the number of occurences of each symbol in the sequence.

If a symbol does not occur in the sequence, but it is in the alphabet, its number of occurences is 0.

frequency : dict

A dictionary containing the symbols as keys and the corresponding number of occurences in the sequence as values.


Check, if the sequence contains a valid sequence code.

A sequence code is valid, if at each sequence position the code is smaller than the size of the alphabet.

Invalid code means that the code cannot be decoded into symbols. Furthermore invalid code can lead to serious errors in alignments, since the substitution matrix is indexed with an invalid index.

valid : bool

True, if the sequence is valid, false otherwise.


Reverse the Sequence.

reversed : Sequence

The reversed Sequence.


>>> dna_seq = NucleotideSequence("ACGTA")
>>> dna_seq_rev = dna_seq.reverse()
>>> print(dna_seq_rev)