File: nucmer_test.py

package info (click to toggle)
python-pymummer 0.11.0-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 320 kB
  • sloc: python: 1,074; sh: 55; makefile: 6
file content (99 lines) | stat: -rw-r--r-- 4,533 bytes parent folder | download | duplicates (6)
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import unittest
import os
import filecmp
from pymummer import nucmer

modules_dir = os.path.dirname(os.path.abspath(nucmer.__file__))
data_dir = os.path.join(modules_dir, 'tests', 'data')


class TestRunner(unittest.TestCase):
    def test_nucmer_command(self):
        '''test _nucmer_command'''
        tests = [
            [nucmer.Runner('ref', 'qry', 'outfile'), 'nucmer -p pre ref qry'],
            [nucmer.Runner('ref', 'qry', 'outfile', breaklen=42), 'nucmer -p pre -b 42 ref qry'],
            [nucmer.Runner('ref', 'qry', 'outfile', diagdiff=11), 'nucmer -p pre -D 11 ref qry'],
            [nucmer.Runner('ref', 'qry', 'outfile', diagdiff=11, promer=True), 'promer -p pre ref qry'],
            [nucmer.Runner('ref', 'qry', 'outfile', maxmatch=True), 'nucmer -p pre --maxmatch ref qry'],
            [nucmer.Runner('ref', 'qry', 'outfile', mincluster=42), 'nucmer -p pre -c 42 ref qry'],
            [nucmer.Runner('ref', 'qry', 'outfile', simplify=False), 'nucmer -p pre --nosimplify ref qry'],
            [nucmer.Runner('ref', 'qry', 'outfile', promer=True), 'promer -p pre ref qry'],
            [nucmer.Runner('ref', 'qry', 'outfile', promer=True, breaklen=42), 'promer -p pre -b 42 ref qry'],
            [nucmer.Runner('ref', 'qry', 'outfile', promer=True, maxmatch=True), 'promer -p pre --maxmatch ref qry'],
            [nucmer.Runner('ref', 'qry', 'outfile', promer=True, simplify=False), 'promer -p pre ref qry']
        ]

        for l in tests:
            self.assertEqual(l[0]._nucmer_command('ref', 'qry', 'pre'), l[1])


    def test_delta_filter_command(self):
        '''test _delta_filter_command'''
        tests = [
            [nucmer.Runner('ref', 'qry', 'outfile'), 'delta-filter infile > outfile'],
            [nucmer.Runner('ref', 'qry', 'outfile', min_id=42), 'delta-filter -i 42 infile > outfile'],
            [nucmer.Runner('ref', 'qry', 'outfile', min_length=43), 'delta-filter -l 43 infile > outfile'],
        ]

        for l in tests:
            self.assertEqual(l[0]._delta_filter_command('infile', 'outfile'), l[1])


    def test_show_coords_command(self):
        '''test _show_coords_command'''
        tests = [
            [nucmer.Runner('ref', 'qry', 'outfile', coords_header=False), 'show-coords -dTlro -H infile > outfile'],
            [nucmer.Runner('ref', 'qry', 'outfile'), 'show-coords -dTlro infile > outfile']
        ]

        for l in tests:
            self.assertEqual(l[0]._show_coords_command('infile', 'outfile'), l[1])


    def test_show_snps_command(self):
        '''test _show_snps_command'''
        tests = [
            [nucmer.Runner('ref', 'qry', 'outfile', snps_header=False), 'show-snps -TClr -H infile > outfile'],
            [nucmer.Runner('ref', 'qry', 'outfile'), 'show-snps -TClr infile > outfile'],
            [nucmer.Runner('ref', 'qry', 'outfile', show_snps_C=False), 'show-snps -Tlr infile > outfile']
        ]

        for nuc_obj, expected in tests:
            self.assertEqual(nuc_obj._show_snps_command('infile', 'outfile'), expected)


    def test_write_script_no_snps(self):
       '''test _write_script no snps'''
       tmp_script = 'tmp.script.sh'
       r = nucmer.Runner('ref', 'qry', 'outfile')
       r._write_script(tmp_script, 'ref', 'qry', 'outfile')
       expected = os.path.join(data_dir, 'nucmer_test_write_script_no_snps.sh')
       self.assertTrue(filecmp.cmp(expected, tmp_script, shallow=False))
       os.unlink(tmp_script)


    def test_write_script_with_snps(self):
       '''test _write_script with snps'''
       tmp_script = 'tmp.script.sh'
       r = nucmer.Runner('ref', 'qry', 'outfile', show_snps='outfile.snps')
       r._write_script(tmp_script, 'ref', 'qry', 'outfile')
       expected = os.path.join(data_dir, 'nucmer_test_write_script_with_snps.sh')
       self.assertTrue(filecmp.cmp(expected, tmp_script, shallow=False))
       os.unlink(tmp_script)


    def test_run_nucmer(self):
        '''test run_nucmer'''
        qry = os.path.join(data_dir, 'nucmer_test_qry.fa')
        ref = os.path.join(data_dir, 'nucmer_test_ref.fa')
        tmp_out = 'tmp.nucmer.out'
        runner = nucmer.Runner(ref, qry, tmp_out, coords_header=False, show_snps=True, snps_header=False)
        runner.run()
        expected = os.path.join(data_dir, 'nucmer_test_out.coords')
        self.assertTrue(filecmp.cmp(tmp_out, expected, shallow=False))
        self.assertTrue(filecmp.cmp(tmp_out + '.snps', expected + '.snps', shallow=False))
        os.unlink(tmp_out)
        os.unlink(tmp_out + '.snps')