File: test_EMBL_unittest.py

package info (click to toggle)
python-biopython 1.73%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 57,852 kB
  • sloc: python: 169,977; xml: 97,539; ansic: 15,653; sql: 1,208; makefile: 159; sh: 63
file content (67 lines) | stat: -rw-r--r-- 2,897 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# Copyright 2015 by Kai Blin.
# This code is part of the Biopython distribution and governed by its
# license.  Please see the LICENSE file that should have been included
# as part of this package.

import unittest
import warnings
from os import path

from Bio import SeqIO
from Bio import BiopythonParserWarning


class EMBLTests(unittest.TestCase):
    def test_embl_content_after_co(self):
        """Test a ValueError is thrown by content after a CO line"""
        def parse_content_after_co():
            rec = SeqIO.read(path.join('EMBL', 'xx_after_co.embl'), 'embl')

        self.assertRaises(ValueError, parse_content_after_co)

        try:
            parse_content_after_co()
        except ValueError as e:
            self.assertEqual(str(e), "Unexpected content after SQ or CO line: 'XX'")
        else:
            self.assertTrue(False, "Error message without explanation raised by content after CO line")

    def test_embl_0_line(self):
        """Test SQ line with 0 length sequence"""
        # Biopython 1.67 and older would parse this file with a warning:
        # 'Expected sequence length 1740, found 1744 (TIR43YW1_CE).' and
        # the coordinates 1740 added to the sequence as four extra letters.
        with warnings.catch_warnings(record=True) as w:
            warnings.simplefilter("always")
            rec = SeqIO.read('EMBL/embl_with_0_line.embl', 'embl')
            self.assertEqual(len(w), 0, "Unexpected parser warnings: " +
                             "\n".join(str(warn.message) for warn in w))
            self.assertEqual(len(rec), 1740)

    def test_embl_no_coords(self):
        """Test sequence lines without coordinates."""
        # Biopython 1.68, 1.69 and 1.70 would ignore these lines
        # giving an unknown sequence!
        with warnings.catch_warnings(record=True) as w:
            warnings.simplefilter("always", BiopythonParserWarning)
            rec = SeqIO.read('EMBL/101ma_no_coords.embl', 'embl')
            self.assertTrue(w, "Expected parser warning")
            self.assertEqual([str(_.message) for _ in w],
                             ["EMBL sequence line missing coordinates"] * 3)
            self.assertEqual(len(rec), 154)
            self.assertEqual(rec.seq[:10], "MVLSEGEWQL")
            self.assertEqual(rec.seq[-10:], "AKYKELGYQG")

    def test_embl_wrong_dr_line(self):
        """Test files with wrong DR lines"""
        with warnings.catch_warnings(record=True) as w:
            warnings.simplefilter("always", BiopythonParserWarning)
            record = SeqIO.read('EMBL/RepBase23.02.embl', 'embl')
            self.assertTrue(w, "Expected parser warning")
            self.assertEqual([str(_.message) for _ in w],
                             ["Malformed DR line in EMBL file."])


if __name__ == "__main__":
    runner = unittest.TextTestRunner(verbosity=2)
    unittest.main(testRunner=runner)