Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 121 lines (97 sloc) 3.985 kB
e555f19 @peterjc Add missing licence headers (specific copyright still needed)
peterjc authored
1 # This code is part of the Biopython distribution and governed by its
2 # license. Please see the LICENSE file that should have been included
3 # as part of this package.
4 #
5
05f9ba2 Added Restriction enzyme package contributed by Frederic Sohm. This i…
chapmanb authored
6 """Testing code for Restriction enzyme classes of Biopython.
7 """
8
9 import unittest
10
11 from Bio.Restriction import *
12 from Bio.Seq import Seq
13 from Bio.Alphabet.IUPAC import IUPACAmbiguousDNA
14
15
16 class SimpleEnzyme(unittest.TestCase):
17 """Tests for dealing with basic enzymes using the Restriction package.
18 """
19 def setUp(self):
20 base_seq = Seq("AAAA", IUPACAmbiguousDNA())
21 self.ecosite_seq = base_seq + Seq(EcoRI.site,
22 IUPACAmbiguousDNA()) + base_seq
23
675ed08 Rename all unittest test methods from t_* to test_* so that run_tests.py
mdehoon authored
24 def test_eco_cutting(self):
05f9ba2 Added Restriction enzyme package contributed by Frederic Sohm. This i…
chapmanb authored
25 """Test basic cutting with EcoRI.
26 """
4b4bf33 @etal test_Restriction.py: Converted to use unittest methods instead of assert
etal authored
27 self.assertEqual(EcoRI.site, 'GAATTC')
28 self.assertFalse(EcoRI.is_blunt())
29 self.assertTrue(EcoRI.is_5overhang())
30 self.assertFalse(EcoRI.is_3overhang())
31 self.assertEqual(EcoRI.elucidate(), "G^AATT_C")
32 self.assertEqual(EcoRI.search(self.ecosite_seq), [6])
05f9ba2 Added Restriction enzyme package contributed by Frederic Sohm. This i…
chapmanb authored
33
34 parts = EcoRI.catalyse(self.ecosite_seq)
4b4bf33 @etal test_Restriction.py: Converted to use unittest methods instead of assert
etal authored
35 self.assertEqual(len(parts), 2)
79842f4 @bow Updates all unchanged Bio.Seq.tostring() to str(Bio.Seq)
bow authored
36 self.assertEqual(str(parts[1]), "AATTCAAAA")
05f9ba2 Added Restriction enzyme package contributed by Frederic Sohm. This i…
chapmanb authored
37 parts = EcoRI.catalyze(self.ecosite_seq)
4b4bf33 @etal test_Restriction.py: Converted to use unittest methods instead of assert
etal authored
38 self.assertEqual(len(parts), 2)
05f9ba2 Added Restriction enzyme package contributed by Frederic Sohm. This i…
chapmanb authored
39
675ed08 Rename all unittest test methods from t_* to test_* so that run_tests.py
mdehoon authored
40 def test_circular_sequences(self):
05f9ba2 Added Restriction enzyme package contributed by Frederic Sohm. This i…
chapmanb authored
41 """Deal with cutting circular sequences.
42 """
65d5d63 @carlosp420 PEP8 fixes, various test files
carlosp420 authored
43 parts = EcoRI.catalyse(self.ecosite_seq, linear=False)
4b4bf33 @etal test_Restriction.py: Converted to use unittest methods instead of assert
etal authored
44 self.assertEqual(len(parts), 1)
65d5d63 @carlosp420 PEP8 fixes, various test files
carlosp420 authored
45 locations = EcoRI.search(parts[0], linear=False)
4b4bf33 @etal test_Restriction.py: Converted to use unittest methods instead of assert
etal authored
46 self.assertEqual(locations, [1])
47
05f9ba2 Added Restriction enzyme package contributed by Frederic Sohm. This i…
chapmanb authored
48
49 class EnzymeComparison(unittest.TestCase):
50 """Tests for comparing various enzymes.
51 """
675ed08 Rename all unittest test methods from t_* to test_* so that run_tests.py
mdehoon authored
52 def test_basic_isochizomers(self):
05f9ba2 Added Restriction enzyme package contributed by Frederic Sohm. This i…
chapmanb authored
53 """Test to be sure isochizomer and neoschizomers are as expected.
54 """
4b4bf33 @etal test_Restriction.py: Converted to use unittest methods instead of assert
etal authored
55 self.assertEqual(Acc65I.isoschizomers(), [Asp718I, KpnI])
56 self.assertEqual(Acc65I.elucidate(), 'G^GTAC_C')
57 self.assertEqual(Asp718I.elucidate(), 'G^GTAC_C')
58 self.assertEqual(KpnI.elucidate(), 'G_GTAC^C')
05f9ba2 Added Restriction enzyme package contributed by Frederic Sohm. This i…
chapmanb authored
59
675ed08 Rename all unittest test methods from t_* to test_* so that run_tests.py
mdehoon authored
60 def test_comparisons(self):
05f9ba2 Added Restriction enzyme package contributed by Frederic Sohm. This i…
chapmanb authored
61 """Comparison operators between iso and neoschizomers.
62 """
be60222 @peterjc Avoid deprecated unittest assert_ method
peterjc authored
63 self.assertEqual(Acc65I, Acc65I)
64 self.assertNotEqual(Acc65I, KpnI)
65 self.assertFalse(Acc65I == Asp718I)
66 self.assertFalse(Acc65I != Asp718I)
67 self.assertNotEqual(Acc65I, EcoRI)
05f9ba2 Added Restriction enzyme package contributed by Frederic Sohm. This i…
chapmanb authored
68
be60222 @peterjc Avoid deprecated unittest assert_ method
peterjc authored
69 self.assertTrue(Acc65I >> KpnI)
70 self.assertFalse(Acc65I >> Asp718I)
4b4bf33 @etal test_Restriction.py: Converted to use unittest methods instead of assert
etal authored
71
be60222 @peterjc Avoid deprecated unittest assert_ method
peterjc authored
72 self.assertTrue(Acc65I % Asp718I)
73 self.assertTrue(Acc65I % Acc65I)
74 self.assertFalse(Acc65I % KpnI)
05f9ba2 Added Restriction enzyme package contributed by Frederic Sohm. This i…
chapmanb authored
75
76
77 class RestrictionBatches(unittest.TestCase):
78 """Tests for dealing with batches of restriction enzymes.
79 """
675ed08 Rename all unittest test methods from t_* to test_* so that run_tests.py
mdehoon authored
80 def test_creating_batch(self):
05f9ba2 Added Restriction enzyme package contributed by Frederic Sohm. This i…
chapmanb authored
81 """Creating and modifying a restriction batch.
82 """
83 batch = RestrictionBatch([EcoRI])
84 batch.add(KpnI)
85 batch += EcoRV
4b4bf33 @etal test_Restriction.py: Converted to use unittest methods instead of assert
etal authored
86 self.assertEqual(len(batch), 3)
05f9ba2 Added Restriction enzyme package contributed by Frederic Sohm. This i…
chapmanb authored
87
eb1c163 @etal test_Restriction.py: Added more tests for batch membership
etal authored
88 # The usual way to test batch membership
be60222 @peterjc Avoid deprecated unittest assert_ method
peterjc authored
89 self.assertTrue(EcoRV in batch)
90 self.assertTrue(EcoRI in batch)
91 self.assertTrue(KpnI in batch)
92 self.assertTrue(SmaI not in batch)
eb1c163 @etal test_Restriction.py: Added more tests for batch membership
etal authored
93 # Syntax sugar for the above
be60222 @peterjc Avoid deprecated unittest assert_ method
peterjc authored
94 self.assertTrue('EcoRV' in batch)
95 self.assertFalse('SmaI' in batch)
eb1c163 @etal test_Restriction.py: Added more tests for batch membership
etal authored
96
05f9ba2 Added Restriction enzyme package contributed by Frederic Sohm. This i…
chapmanb authored
97 batch.get(EcoRV)
4b4bf33 @etal test_Restriction.py: Converted to use unittest methods instead of assert
etal authored
98 self.assertRaises(ValueError, batch.get, SmaI)
05f9ba2 Added Restriction enzyme package contributed by Frederic Sohm. This i…
chapmanb authored
99
100 batch.remove(EcoRV)
4b4bf33 @etal test_Restriction.py: Converted to use unittest methods instead of assert
etal authored
101 self.assertEqual(len(batch), 2)
05f9ba2 Added Restriction enzyme package contributed by Frederic Sohm. This i…
chapmanb authored
102
be60222 @peterjc Avoid deprecated unittest assert_ method
peterjc authored
103 self.assertTrue(EcoRV not in batch)
104 self.assertTrue('EcoRV' not in batch)
eb1c163 @etal test_Restriction.py: Added more tests for batch membership
etal authored
105
675ed08 Rename all unittest test methods from t_* to test_* so that run_tests.py
mdehoon authored
106 def test_batch_analysis(self):
05f9ba2 Added Restriction enzyme package contributed by Frederic Sohm. This i…
chapmanb authored
107 """Sequence analysis with a restriction batch.
108 """
109 seq = Seq("AAAA" + EcoRV.site + "AAAA" + EcoRI.site + "AAAA",
110 IUPACAmbiguousDNA())
111 batch = RestrictionBatch([EcoRV, EcoRI])
112
113 hits = batch.search(seq)
4b4bf33 @etal test_Restriction.py: Converted to use unittest methods instead of assert
etal authored
114 self.assertEqual(hits[EcoRV], [8])
115 self.assertEqual(hits[EcoRI], [16])
05f9ba2 Added Restriction enzyme package contributed by Frederic Sohm. This i…
chapmanb authored
116
117
118 if __name__ == "__main__":
b67cebf @peterjc Fix common PEP8 violation in unittest verbosity argument
peterjc authored
119 runner = unittest.TextTestRunner(verbosity=2)
675ed08 Rename all unittest test methods from t_* to test_* so that run_tests.py
mdehoon authored
120 unittest.main(testRunner=runner)
Something went wrong with that request. Please try again.