Back to index

python-biopython  1.60
test_CodonTable.py
Go to the documentation of this file.
00001 # Copyright 2008 by Peter Cock.  All rights reserved.
00002 # This code is part of the Biopython distribution and governed by its
00003 # license.  Please see the LICENSE file that should have been included
00004 # as part of this package.
00005 
00006 from Bio.Data.CodonTable import *
00007 
00008 #Check the extension of stop codons to include well defined ambiguous ones
00009 assert list_ambiguous_codons(['TGA', 'TAA'],IUPACData.ambiguous_dna_values) == ['TGA', 'TAA', 'TRA']
00010 assert list_ambiguous_codons(['TAG', 'TGA'],IUPACData.ambiguous_dna_values) == ['TAG', 'TGA']
00011 assert list_ambiguous_codons(['TAG', 'TAA'],IUPACData.ambiguous_dna_values) == ['TAG', 'TAA', 'TAR']
00012 assert list_ambiguous_codons(['UAG', 'UAA'],IUPACData.ambiguous_rna_values) == ['UAG', 'UAA', 'UAR']
00013 assert list_ambiguous_codons(['TGA', 'TAA', 'TAG'],IUPACData.ambiguous_dna_values) == ['TGA', 'TAA', 'TAG', 'TAR', 'TRA']
00014 
00015 
00016 #Basic sanity test,
00017 for n in ambiguous_generic_by_id.keys():
00018     assert ambiguous_rna_by_id[n].forward_table["GUU"] == "V"
00019     assert ambiguous_rna_by_id[n].forward_table["GUN"] == "V"
00020     if n != 23 :
00021         assert ambiguous_rna_by_id[n].forward_table["UUN"] == "X" #F or L
00022 
00023     assert ambiguous_dna_by_id[n].forward_table["GTT"] == "V"
00024     if n != 23 :
00025         assert ambiguous_dna_by_id[n].forward_table["TTN"] == "X" #F or L
00026     assert ambiguous_dna_by_id[n].forward_table["GTN"] == "V"
00027 
00028     if n != 23 :
00029         assert ambiguous_generic_by_id[n].forward_table.get("TTN") == "X"
00030     assert ambiguous_generic_by_id[n].forward_table["ACN"] == "T"
00031     assert ambiguous_generic_by_id[n].forward_table["GUU"] == "V"
00032     assert ambiguous_generic_by_id[n].forward_table["GUN"] == "V"
00033     if n != 23 :
00034         assert ambiguous_generic_by_id[n].forward_table["UUN"] == "X" #F or L
00035     assert ambiguous_generic_by_id[n].forward_table["GTT"] == "V"
00036     if n != 23 :
00037         assert ambiguous_generic_by_id[n].forward_table["TTN"] == "X" #F or L
00038     assert ambiguous_generic_by_id[n].forward_table["GTN"] == "V"
00039     #And finally something evil, an RNA-DNA mixture:
00040     if n != 23 :
00041         assert ambiguous_generic_by_id[n].forward_table["UTN"] == "X" #F or L
00042     assert ambiguous_generic_by_id[n].forward_table["UTU"] == "F"
00043 
00044     #R = A or G, so URR = UAA or UGA / TRA = TAA or TGA = stop codons
00045     if "UAA" in unambiguous_rna_by_id[n].stop_codons \
00046     and "UGA" in unambiguous_rna_by_id[n].stop_codons:
00047         try:
00048             print ambiguous_dna_by_id[n].forward_table["TRA"]
00049             assert False, "Should be a stop only"
00050         except KeyError:
00051             pass
00052         try:
00053             print ambiguous_rna_by_id[n].forward_table["URA"]
00054             assert False, "Should be a stop only"
00055         except KeyError:
00056             pass
00057         try:
00058             print ambiguous_generic_by_id[n].forward_table["URA"]
00059             assert False, "Should be a stop only"
00060         except KeyError:
00061             pass
00062         assert "URA" in ambiguous_generic_by_id[n].stop_codons
00063         assert "URA" in ambiguous_rna_by_id[n].stop_codons
00064         assert "TRA" in ambiguous_generic_by_id[n].stop_codons
00065         assert "TRA" in ambiguous_dna_by_id[n].stop_codons
00066 
00067     if "UAG" in unambiguous_rna_by_id[n].stop_codons \
00068     and "UAA" in unambiguous_rna_by_id[n].stop_codons \
00069     and "UGA" in unambiguous_rna_by_id[n].stop_codons:
00070         try:
00071             print ambiguous_dna_by_id[n].forward_table["TAR"]
00072             assert False, "Should be a stop only"
00073         except KeyError:
00074             pass
00075         try:
00076             print ambiguous_rna_by_id[n].forward_table["UAR"]
00077             assert False, "Should be a stop only"
00078         except KeyError:
00079             pass
00080         try:
00081             print ambiguous_generic_by_id[n].forward_table["UAR"]
00082             assert False, "Should be a stop only"
00083         except KeyError:
00084             pass
00085         try:
00086             print ambiguous_generic_by_id[n].forward_table["URR"]
00087             assert False, "Should be a stop OR an amino"
00088         except TranslationError:
00089             pass
00090         assert "UAR" in ambiguous_generic_by_id[n].stop_codons
00091         assert "UAR" in ambiguous_rna_by_id[n].stop_codons
00092         assert "TAR" in ambiguous_generic_by_id[n].stop_codons
00093         assert "TAR" in ambiguous_dna_by_id[n].stop_codons
00094         assert "URA" in ambiguous_generic_by_id[n].stop_codons
00095         assert "URA" in ambiguous_rna_by_id[n].stop_codons
00096         assert "TRA" in ambiguous_generic_by_id[n].stop_codons
00097         assert "TRA" in ambiguous_dna_by_id[n].stop_codons
00098 
00099     if "UUG" in unambiguous_rna_by_id[n].start_codons \
00100     and "CUG" in unambiguous_rna_by_id[n].start_codons \
00101     and "AUG" in unambiguous_rna_by_id[n].start_codons \
00102     and "UUG" not in unambiguous_rna_by_id[n].start_codons:
00103         assert "NUG" not in ambiguous_dna_by_id[n].start_codons
00104         assert "RUG" not in ambiguous_dna_by_id[n].start_codons
00105         assert "WUG" not in ambiguous_dna_by_id[n].start_codons
00106         assert "KUG" not in ambiguous_dna_by_id[n].start_codons
00107         assert "SUG" not in ambiguous_dna_by_id[n].start_codons
00108         assert "DUG" not in ambiguous_dna_by_id[n].start_codons
00109 del n
00110 
00111 #Table 2 Vertebrate Mitochondrial has
00112 #TAA and TAG -> TAR, plus AGA and AGG -> AGR
00113 assert "AGR" in ambiguous_dna_by_id[2].stop_codons
00114 assert "TAR" in ambiguous_dna_by_id[2].stop_codons
00115 assert "AGR" in ambiguous_rna_by_id[2].stop_codons
00116 assert "UAR" in ambiguous_rna_by_id[2].stop_codons
00117 assert "AGR" in ambiguous_generic_by_id[2].stop_codons
00118 assert "UAR" in ambiguous_generic_by_id[2].stop_codons
00119 assert "TAR" in ambiguous_generic_by_id[2].stop_codons
00120 assert ambiguous_generic_by_id[1].stop_codons == ambiguous_generic_by_name["Standard"].stop_codons
00121 assert ambiguous_generic_by_id[4].stop_codons == ambiguous_generic_by_name["SGC3"].stop_codons
00122 assert ambiguous_generic_by_id[15].stop_codons == ambiguous_generic_by_name['Blepharisma Macronuclear'].stop_codons
00123 
00124 print "Done"