File: test_mer_file.py

package info (click to toggle)
jellyfish 2.2.10-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 3,320 kB
  • sloc: cpp: 35,615; sh: 963; ruby: 578; makefile: 372; python: 165; perl: 36
file content (59 lines) | stat: -rw-r--r-- 1,849 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
import unittest
import sys
import os
from collections import Counter

import dna_jellyfish as jf


class TestMerFile(unittest.TestCase):
    def setUp(self):
        self.mf = jf.ReadMerFile(os.path.join(data, "swig_python.jf"))

    def test_histo(self):
        histo = Counter()
        while self.mf.next_mer():
            histo[self.mf.count()] += 1

        jf_histo = Counter()
        with open(os.path.join(data, "swig_python.histo")) as f:
            for line in f:
                num, count = [int(n) for n in line.split()]
                self.assertEqual(count, histo[num])

    def test_dump(self):
        good = True
        with open(os.path.join(data, "swig_python.dump")) as f:
            for line in f:
                good = good and self.mf.next_mer()
                if not good: break
                a = line.split()
                good = good and a[0] == str(self.mf.mer()) and int(a[1]) == self.mf.count()
                if not good: break
        self.assertTrue(good)

    def test_iter(self):
        good = True
        with open(os.path.join(data, "swig_python.dump")) as f:
            for mer, count in self.mf:
                line = f.readline()
                good = good and line
                if not good: break
                fmer, fcount = line.split()
                good = good and fmer == str(mer) and int(fcount) == count
                if not good: break
            self.assertTrue(good)
            line = f.readline()
            self.assertTrue(not line)

    def test_query(self):
        good = True
        qf   = jf.QueryMerFile(os.path.join(data, "swig_python.jf"))
        for mer, count in self.mf:
            good = good and count == qf[mer]
            if not good: break
        self.assertTrue(good)

if __name__ == '__main__':
    data = sys.argv.pop(1)
    unittest.main()