Back to index

python-biopython  1.60
test_Restriction.py
Go to the documentation of this file.
00001 """Testing code for Restriction enzyme classes of Biopython.
00002 """
00003 
00004 import unittest
00005 
00006 from Bio.Restriction import *
00007 from Bio.Seq import Seq
00008 from Bio.Alphabet.IUPAC import IUPACAmbiguousDNA
00009 
00010 
00011 class SimpleEnzyme(unittest.TestCase):
00012     """Tests for dealing with basic enzymes using the Restriction package.
00013     """
00014     def setUp(self):
00015         base_seq = Seq("AAAA", IUPACAmbiguousDNA())
00016         self.ecosite_seq = base_seq + Seq(EcoRI.site,
00017                 IUPACAmbiguousDNA()) + base_seq
00018 
00019     def test_eco_cutting(self):
00020         """Test basic cutting with EcoRI.
00021         """
00022         self.assertEqual(EcoRI.site, 'GAATTC')
00023         self.assertFalse(EcoRI.is_blunt())
00024         self.assertTrue(EcoRI.is_5overhang())
00025         self.assertFalse(EcoRI.is_3overhang())
00026         self.assertEqual(EcoRI.elucidate(), "G^AATT_C")
00027         self.assertEqual(EcoRI.search(self.ecosite_seq), [6])
00028 
00029         parts = EcoRI.catalyse(self.ecosite_seq)
00030         self.assertEqual(len(parts), 2)
00031         self.assertEqual(parts[1].tostring(), "AATTCAAAA")
00032         parts = EcoRI.catalyze(self.ecosite_seq)
00033         self.assertEqual(len(parts), 2)
00034 
00035     def test_circular_sequences(self):
00036         """Deal with cutting circular sequences.
00037         """
00038         parts = EcoRI.catalyse(self.ecosite_seq, linear = False)
00039         self.assertEqual(len(parts), 1)
00040         locations = EcoRI.search(parts[0], linear = False)
00041         self.assertEqual(locations, [1])
00042 
00043 
00044 class EnzymeComparison(unittest.TestCase):
00045     """Tests for comparing various enzymes.
00046     """
00047     def test_basic_isochizomers(self):
00048         """Test to be sure isochizomer and neoschizomers are as expected.
00049         """
00050         self.assertEqual(Acc65I.isoschizomers(), [Asp718I, KpnI])
00051         self.assertEqual(Acc65I.elucidate(), 'G^GTAC_C')
00052         self.assertEqual(Asp718I.elucidate(), 'G^GTAC_C')
00053         self.assertEqual(KpnI.elucidate(), 'G_GTAC^C')
00054 
00055     def test_comparisons(self):
00056         """Comparison operators between iso and neoschizomers.
00057         """
00058         self.assertEqual(Acc65I, Acc65I)
00059         self.assertNotEqual(Acc65I, KpnI)
00060         self.assertFalse(Acc65I == Asp718I)
00061         self.assertFalse(Acc65I != Asp718I)
00062         self.assertNotEqual(Acc65I, EcoRI)
00063 
00064         self.assertTrue(Acc65I >> KpnI)
00065         self.assertFalse(Acc65I >> Asp718I)
00066 
00067         self.assertTrue(Acc65I % Asp718I)
00068         self.assertTrue(Acc65I % Acc65I)
00069         self.assertFalse(Acc65I % KpnI)
00070 
00071 
00072 class RestrictionBatches(unittest.TestCase):
00073     """Tests for dealing with batches of restriction enzymes.
00074     """
00075     def test_creating_batch(self):
00076         """Creating and modifying a restriction batch.
00077         """
00078         batch = RestrictionBatch([EcoRI])
00079         batch.add(KpnI)
00080         batch += EcoRV
00081         self.assertEqual(len(batch), 3)
00082 
00083         # The usual way to test batch membership
00084         self.assertTrue(EcoRV in batch)
00085         self.assertTrue(EcoRI in batch)
00086         self.assertTrue(KpnI in batch)
00087         self.assertTrue(SmaI not in batch)
00088         # Syntax sugar for the above
00089         self.assertTrue('EcoRV' in batch)
00090         self.assertFalse('SmaI' in batch)
00091 
00092         batch.get(EcoRV)
00093         self.assertRaises(ValueError, batch.get, SmaI)
00094 
00095         batch.remove(EcoRV)
00096         self.assertEqual(len(batch), 2)
00097 
00098         self.assertTrue(EcoRV not in batch)
00099         self.assertTrue('EcoRV' not in batch)
00100 
00101     def test_batch_analysis(self):
00102         """Sequence analysis with a restriction batch.
00103         """
00104         seq = Seq("AAAA" + EcoRV.site + "AAAA" + EcoRI.site + "AAAA",
00105                 IUPACAmbiguousDNA())
00106         batch = RestrictionBatch([EcoRV, EcoRI])
00107 
00108         hits = batch.search(seq)
00109         self.assertEqual(hits[EcoRV], [8])
00110         self.assertEqual(hits[EcoRI], [16])
00111 
00112 
00113 if __name__ == "__main__":
00114     runner = unittest.TextTestRunner(verbosity = 2)
00115     unittest.main(testRunner=runner)