Back to index

python-biopython  1.60
test_EmbossPrimer.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 """Tests for Primer-based programs in the Emboss suite.
00003 """
00004 # standard library
00005 import sys
00006 import os
00007 import unittest
00008 
00009 # local stuff
00010 from Bio.Emboss import PrimerSearch, Primer3
00011 
00012 
00013 class Primer3ParseTest(unittest.TestCase):
00014     def setUp(self):
00015         self.test_files = \
00016           [os.path.join("Emboss", "bac_find.primer3"),
00017            os.path.join("Emboss", "cds_forward.primer3"),
00018            os.path.join("Emboss", "cds_reverse.primer3"),
00019            os.path.join("Emboss", "short.primer3"),
00020            os.path.join("Emboss", "internal_oligo.primer3"),
00021            ]
00022 
00023     def test_simple_parse(self):
00024         """Make sure that we can use all single target primer3 files.
00025         """
00026         for file in self.test_files:
00027             # First using read...
00028             h = open(file, "r")
00029             Primer3.read(h)
00030             h.close()
00031             # Now using parse...
00032             h = open(file, "r")
00033             self.assertEqual(1, len(list(Primer3.parse(h))))
00034             h.close()
00035 
00036     def test_indepth_regular_parse(self):
00037         """Make sure we get the data from normal primer3 files okay.
00038         """
00039         regular_file = self.test_files[0]
00040         h = open(regular_file, "r")
00041         primer_info = Primer3.read(h)
00042         h.close()
00043 
00044         self.assertEqual(len(primer_info.primers), 5)
00045         self.assertEqual(primer_info.comments,
00046                          "# PRIMER3 RESULTS FOR AC074298\n")
00047         self.assertEqual(primer_info.primers[1].forward_seq,
00048                          "CCGGTTTCTCTGGTTGAAAA")
00049         self.assertEqual(primer_info.primers[2].reverse_seq,
00050                          "TCACATTCCCAAATGTAGATCG")
00051         self.assertEqual(primer_info.primers[0].size, 218)
00052         self.assertEqual(len(primer_info.primers[0]), 218)
00053         self.assertEqual(primer_info.primers[3].forward_start, 112)
00054         self.assertEqual(primer_info.primers[3].forward_length, 20)
00055         self.assertEqual(primer_info.primers[3].forward_tm, 59.57)
00056         self.assertEqual(primer_info.primers[3].forward_gc, 45.00)
00057         self.assertEqual(primer_info.primers[4].reverse_start, 304)
00058         self.assertEqual(primer_info.primers[4].reverse_length, 22)
00059         self.assertEqual(primer_info.primers[4].reverse_tm, 59.61)
00060         self.assertEqual(primer_info.primers[4].reverse_gc, 40.91)
00061 
00062     def test_in_depth_single_parse(self):
00063         """Make sure we get info right from a single primer find.
00064         """
00065         file = self.test_files[1]
00066         h = open(file, "r")
00067         primer_info = Primer3.read(h)
00068         h.close()
00069 
00070         self.assertEqual(len(primer_info.primers), 5)
00071         self.assertEqual(primer_info.comments,
00072                          "# PRIMER3 RESULTS FOR 26964-28647#\n")
00073         self.assertEqual(primer_info.primers[1].reverse_seq, "")
00074         self.assertEqual(primer_info.primers[1].internal_seq, "")
00075         self.assertEqual(primer_info.primers[3].forward_seq, "TGTGATTGCTTGAGCTGGAC")
00076         self.assertEqual(primer_info.primers[3].internal_seq, "")
00077         self.assertEqual(primer_info.primers[3].forward_start, 253)
00078 
00079     def test_internal_oligo_single_parse(self):
00080         ''' Make sure we can parse an internal oligo file correctly '''
00081         # these files are generated when designing hybridization probes.
00082         file = self.test_files[4]
00083         h = open(file, "r")
00084         primer_info = Primer3.read(h)
00085         h.close()
00086 
00087         self.assertEqual(len(primer_info.primers), 5)
00088         self.assertEqual(primer_info.comments,
00089                          "# EPRIMER3 RESULTS FOR YNL138W-A\n")
00090         self.assertEqual(primer_info.primers[0].internal_length, 22)
00091         self.assertEqual(primer_info.primers[1].internal_seq,
00092                          'TTGCGCTTTAGTTTGAATTGAA')
00093         self.assertEqual(primer_info.primers[2].internal_tm, 58.62)
00094         self.assertEqual(primer_info.primers[3].internal_start, 16)
00095         self.assertEqual(primer_info.primers[4].internal_gc, 35.00)
00096 
00097     def test_mutli_record_fwd(self):
00098         """Test parsing multiple primer sets (NirK forward)"""
00099         h = open(os.path.join("Emboss", "NirK.primer3"))
00100         targets = list(Primer3.parse(h))
00101         h.close()
00102 
00103         self.assertEqual(len(targets), 16)
00104         for target in targets:
00105             self.assertEqual(len(target.primers), 5)
00106 
00107         self.assertEqual(targets[0].primers[0].forward_seq,
00108                          "GCAAACTGAAAAGCGGACTC")
00109         self.assertEqual(targets[0].primers[1].forward_seq,
00110                          "GGGACGTACTTTCGCACAAT")
00111         self.assertEqual(targets[0].primers[2].forward_seq,
00112                          "GTCTTATGCGTGGTGGAGGT")
00113         self.assertEqual(targets[0].primers[3].forward_seq,
00114                          "GTACATCAACATCCGCAACG")
00115         self.assertEqual(targets[0].primers[4].forward_seq,
00116                          "CGTACATCAACATCCGCAAC")
00117 
00118         self.assertEqual(targets[1].primers[0].forward_seq,
00119                          "GGAAGTGCTTCTCGTTTTCG")
00120         self.assertEqual(targets[1].primers[1].forward_seq,
00121                          "TACAGAGCGTCACGGATGAG")
00122         self.assertEqual(targets[1].primers[2].forward_seq,
00123                          "TTGTCATCGTGCTCTTCGTC")
00124         self.assertEqual(targets[1].primers[3].forward_seq,
00125                          "GACTCCAACCTCAGCTTTCG")
00126         self.assertEqual(targets[1].primers[4].forward_seq,
00127                          "GGCACGAAGAAGGACAGAAG")
00128 
00129         self.assertEqual(targets[15].primers[0].forward_seq,
00130                          "TGCTTGAAAATGACGCACTC")
00131         self.assertEqual(targets[15].primers[1].forward_seq,
00132                          "CTCGCTGGCTAGGTCATAGG")
00133         self.assertEqual(targets[15].primers[2].forward_seq,
00134                          "TATCGCACCAAACACGGTAA")
00135         self.assertEqual(targets[15].primers[3].forward_seq,
00136                          "CGATTACCCTCACCGTCACT")
00137         self.assertEqual(targets[15].primers[4].forward_seq,
00138                          "TATCGCAACCACTGAGCAAG")
00139 
00140 
00141     def test_mutli_record_full(self):
00142         """Test parsing multiple primer sets (NirK full)"""
00143         h = open(os.path.join("Emboss", "NirK_full.primer3"))
00144         targets = list(Primer3.parse(h))
00145         h.close()
00146 
00147         self.assertEqual(len(targets), 16)
00148         for target in targets:
00149             self.assertEqual(len(target.primers), 5)
00150 
00151         self.assertEqual(targets[15].primers[0].forward_seq,
00152                          "ACTCACTTCGGCTGAATGCT")
00153         self.assertEqual(targets[15].primers[1].forward_seq,
00154                          "GGCGATTAGCGCTGTCTATC")
00155         self.assertEqual(targets[15].primers[2].forward_seq,
00156                          "ACTCACTTCGGCTGAATGCT")
00157         self.assertEqual(targets[15].primers[3].forward_seq,
00158                          "TAGGCGTATAGACCGGGTTG")
00159         self.assertEqual(targets[15].primers[4].forward_seq,
00160                          "AGCAAGCTGACCACTGGTTT")
00161 
00162         self.assertEqual(targets[15].primers[0].reverse_seq,
00163                          "CATTTAATCCGGATGCCAAC")
00164         self.assertEqual(targets[15].primers[1].reverse_seq,
00165                          "TGGCCTTTCTCTCCTCTTCA")
00166         self.assertEqual(targets[15].primers[2].reverse_seq,
00167                          "ATTTAATCCGGATGCCAACA")
00168         self.assertEqual(targets[15].primers[3].reverse_seq,
00169                          "CACACATTATTGGCGGTCAC")
00170         self.assertEqual(targets[15].primers[4].reverse_seq,
00171                          "TCTGAAACCACCAAGGAAGC")
00172 
00173         self.assertEqual(targets[15].primers[0].internal_seq,
00174                          "CCCACCAATATTTGGCTAGC")
00175         self.assertEqual(targets[15].primers[1].internal_seq,
00176                          "AATCTTCTGTGCACCTTGCC")
00177         self.assertEqual(targets[15].primers[2].internal_seq,
00178                          "CCCACCAATATTTGGCTAGC")
00179         self.assertEqual(targets[15].primers[3].internal_seq,
00180                          "TGAGCCTGTGTTCCACACAT")
00181         self.assertEqual(targets[15].primers[4].internal_seq,
00182                          "CTATGCCCTTCTGCCACAAT")
00183 
00184 
00185 class PrimersearchParseTest(unittest.TestCase):
00186     def setUp(self):
00187         self.test_files = \
00188           [os.path.join("Emboss", "bac_find.psearch")]
00189 
00190     def test_simple_parse(self):
00191         """Make sure that we can parse all primersearch files.
00192         """
00193         for file in self.test_files:
00194             h = open(file, "r")
00195             PrimerSearch.read(h)
00196             h.close()
00197 
00198     def test_in_depth_normal_parse(self):
00199         """Make sure the output from a simple primersearch file is correct.
00200         """
00201         file = self.test_files[0]
00202         h = open(file, "r")
00203         amp_info = PrimerSearch.read(h)
00204         h.close()
00205 
00206         self.assertEqual(len(amp_info.amplifiers), 1)
00207         self.assertTrue("Test" in amp_info.amplifiers)
00208         self.assertEqual(len(amp_info.amplifiers["Test"]), 1)
00209 
00210         self.assertEqual(amp_info.amplifiers["Test"][0].length, 218)
00211         self.assertEqual(amp_info.amplifiers["Test"][0].hit_info,
00212           "AC074298 AC074298 \n"
00213           "\tTelomere associated sequence for Arabidopsis thaliana "
00214           "TEL1N from chromosome I, complete sequence.\n"
00215           "\tCCGGTTTCTCTGGTTGAAAA hits forward strand at 114 with "
00216           "0 mismatches\n"
00217           "\tTCACATTCCCAAATGTAGATCG hits reverse strand at [114] with "
00218           "0 mismatches")
00219 
00220 class PrimerSearchInputTest(unittest.TestCase):
00221     """Test creating input files for primersearch.
00222     """
00223     def setUp(self):
00224         pass
00225 
00226     def test_primer_representation(self):
00227         """Make sure we can output primer information correctly.
00228         """
00229         p_info = PrimerSearch.InputRecord()
00230         p_info.add_primer_set("Test", "GATC", "CATG")
00231         p_info.add_primer_set("Test2", "AATA", "TTAT")
00232 
00233         output = str(p_info)
00234         self.assertEqual(output,
00235                          "Test GATC CATG\n"
00236                          "Test2 AATA TTAT\n")
00237 
00238 if __name__ == "__main__":
00239     runner = unittest.TextTestRunner(verbosity = 2)
00240     unittest.main(testRunner=runner)