Biopython SeqIO processing NNNNN in *.ab1 files
Question: Thanks for your help. I apologize in advance if there is a function built into
Biopython that handles this, I read the whole manual and couldn't find
anything.

**Goal:** Read in a raw sequencing file (*.ab1) and process using
sequence.seq.translate(11) However, I get this error -
"Bio.Data.CodonTable.TranslationError: Codon 'NNN' is invalid"

**My Solution:** I added an additional table to the CodonTable and commented
out the ambiguous checker in Bio.Data.CodonTable (had to do this to make it
work)

    
    
    register_ncbi_table(
        name = 'bacteria sequencing table',
        alt_name = None,
        id = 24,
        table = {
            'TTT': 'F', 'TTC': 'F', 'TTA': 'L', 'TTG': 'L', 'TCT': 'S',
            'TCC': 'S', 'TCA': 'S', 'TCG': 'S', 'TAT': 'Y', 'TAC': 'Y',
            'TGT': 'C', 'TGC': 'C', 'TGG': 'W', 'CTT': 'L', 'CTC': 'L',
            'CTA': 'L', 'CTG': 'L', 'CCT': 'P', 'CCC': 'P', 'CCA': 'P',
            'CCG': 'P', 'CAT': 'H', 'CAC': 'H', 'CAA': 'Q', 'CAG': 'Q',
            'CGT': 'R', 'CGC': 'R', 'CGA': 'R', 'CGG': 'R', 'ATT': 'I',
            'ATC': 'I', 'ATA': 'I', 'ATG': 'M', 'ACT': 'T', 'ACC': 'T',
            'ACA': 'T', 'ACG': 'T', 'AAT': 'N', 'AAC': 'N', 'AAA': 'K',
            'AAG': 'K', 'AGT': 'S', 'AGC': 'S', 'AGA': 'R', 'AGG': 'R',
            'GTT': 'V', 'GTC': 'V', 'GTA': 'V', 'GTG': 'V', 'GCT': 'A',
            'GCC': 'A', 'GCA': 'A', 'GCG': 'A', 'GAT': 'D', 'GAC': 'D',
            'GAA': 'E', 'GAG': 'E', 'GGT': 'G', 'GGC': 'G', 'GGA': 'G',
            'GGG': 'G', 'AAN': 'X', 'TAN': 'X', 'GAN': 'X', 'CAN': 'X',
            'ATN': 'X', 'TTN': 'X', 'GTN': 'X', 'CTN': 'X', 'ACN': 'X', 
            'TCN': 'X', 'GCN': 'X', 'CCN': 'X', 'AGN': 'X', 'TGN': 'X',
            'GGN': 'X', 'CGN': 'X', 'ANA': 'X', 'TNA': 'X', 'GNA': 'X',
            'CNA': 'X', 'ANT': 'X', 'TNT': 'X', 'GNT': 'X', 'CNT': 'X',
            'ANC': 'X', 'TNC': 'X', 'GNC': 'X', 'CNC': 'X', 'ANG': 'X', 
            'TNG': 'X', 'GNG': 'X', 'CNG': 'X', 'NAA': 'X', 'NTA': 'X', 
            'NGA': 'X', 'NCA': 'X', 'NAT': 'X', 'NTT': 'X', 'NGT': 'X', 
            'NCT': 'X', 'NAC': 'X', 'NTC': 'X', 'NGC': 'X', 'NCC': 'X',
            'NAG': 'X', 'NTG': 'X', 'NGG': 'X', 'NCG': 'X', 'NNN': 'X',
            'ANN': 'X', 'TNN': 'X', 'GNN': 'X', 'CNN': 'X', 'NAN': 'X',
            'NTN': 'X', 'NGN': 'X', 'NCN': 'X', 'NNA': 'X', 'NNT': 'X',
            'NNG': 'X', 'NNC': 'X', 'NNN': 'X'},
        stop_codons = ['TAA', 'TAG', 'TGA'],
        start_codons = ['TTG', 'CTG', 'ATT', 'ATC', 'ATA', 'ATG', 'GTG'])
    

**ambiguous checker**

    
    
    for n in ambiguous_generic_by_id:
    
        assert ambiguous_rna_by_id[n].forward_table["GUU"] == "V"
        assert ambiguous_rna_by_id[n].forward_table["GUN"] == "V"
        if n != 23 :
            #For table 23, UUN = F, L or stop.
            assert ambiguous_rna_by_id[n].forward_table["UUN"] == "X"  # F or L
    
            #R = A or G, so URR = UAA or UGA / TRA = TAA or TGA = stop codons
        if "UAA" in unambiguous_rna_by_id[n].stop_codons and\
           "UGA" in unambiguous_rna_by_id[n].stop_codons:
           try:
               print(ambiguous_dna_by_id[n].forward_table["TRA"])
               assert False, "Should be a stop only"
            except KeyError:
                pass
        assert "URA" in ambiguous_generic_by_id[n].stop_codons
        assert "URA" in ambiguous_rna_by_id[n].stop_codons
        assert "TRA" in ambiguous_generic_by_id[n].stop_codons
        assert "TRA" in ambiguous_dna_by_id[n].stop_codons
    
        del n
    

**Question 1:** I would prefer not to edit the root `CodonTable.py` file. Any
suggestions on how to avoid that?

**Question 2:** I really don't want to comment out the ambiguous checker. Can
someone help me write an exception to the ambiguous checker that will ignore
my new codon table?


Answer: When you load an ABI file, Biopython set the Seq alphabet as
`IUPACUnambiguousDNA()`. My first approach is to set the alphabet to
`SingleLetterAlphabet()`:

    
    
    from Bio import SeqIO
    from Bio.Alphabet import SingleLetterAlphabet
    
    for rec in SeqIO.parse("prots.ab1", "abi", alphabet=SingleLetterAlphabet()):
        print rec.seq.translate(11)
    

Now the seq translates with "X" and "N".

