File: test_pytransit_tools.py

package info (click to toggle)
tnseq-transit 3.3.12-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 122,352 kB
  • sloc: python: 14,793; makefile: 143; sh: 49
file content (127 lines) | stat: -rw-r--r-- 3,633 bytes parent folder | download | duplicates (3)
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
import sys
sys.path.insert(0, '../src/')

import os
import shutil
import unittest
import os
import numpy

from transit_test import *

import pytransit.norm_tools as norm_tools
import pytransit.tnseq_tools as tnseq_tools
import pytransit.stat_tools as stat_tools
import pytransit.transit_tools as transit_tools



class TestTnSeqTools(TransitTestCase):


    def test_read_data(self):
        data,position = tnseq_tools.get_data(all_data_list)
        K,N = data.shape

        self.assertEqual(K, 5)
        self.assertGreater(N, 70000)

    def test_genes_creation_fromwig(self):
        G = tnseq_tools.Genes(all_data_list, annotation)
        N = len(G)
        test_orf = "Rv0001"
        test_name = "dnaA"
        #Test list creation
        self.assertGreater(N, 3000)

        #Test dictionary lookup + data
        self.assertEqual(G[test_orf].orf, test_orf)
        self.assertEqual(G[test_orf].name, test_name)

        #Test list lookup + data
        self.assertEqual(G[0].orf, test_orf)
        self.assertEqual(G[0].name, test_name)


    def test_genes_creation_fromdata(self):
        data,position = tnseq_tools.get_data(all_data_list)
        Kreps,Nsites = data.shape
        G = tnseq_tools.Genes([], annotation, data=data, position=position)
        N = len(G)
        test_orf = "Rv0001"
        test_name = "dnaA"
        #Test list creation
        self.assertGreater(N, 3000)

        #Test dictionary lookup + data
        self.assertEqual(G[test_orf].orf, test_orf)
        self.assertEqual(G[test_orf].name, test_name)

        #Test list lookup + data
        self.assertEqual(G[0].orf, test_orf)
        self.assertEqual(G[0].name, test_name)


    def test_file_types(self):
        types = tnseq_tools.get_file_types(all_data_list)
        types = set(types)
        self.assertEqual(len(types), 1)
        self.assertTrue("himar1" in types)

#

    def test_normalization(self):
        N = len(all_data_list)
        data,position = tnseq_tools.get_data(all_data_list)
        norm_data,factors = norm_tools.normalize_data(data, "TTR")
        self.assertFalse((factors == numpy.ones(N)).all())

#

    def test_cleanargs_negative_arguments(self):
        TEST_RAWARGS = ["test", "-p", "-10"]
        args, kwargs = transit_tools.cleanargs(TEST_RAWARGS)
        self.assertEqual(int(kwargs.get("p",0)), -10)

#

    def test_cleanargs_flag_without_arguments(self):
        TEST_RAWARGS = ["test", "-p"]
        args, kwargs = transit_tools.cleanargs(TEST_RAWARGS)
        self.assertTrue(kwargs.get("p",False))

#

    def test_cleanargs_positional_arguments(self):
        TEST_RAWARGS = ["a", "b", "c", "-d", "1", "e"]
        args, kwargs = transit_tools.cleanargs(TEST_RAWARGS)
        self.assertEqual(args, ["a", "b", "c", "e"])

#

    def test_cleanargs_positional_arguments_w_quotes(self):
        TEST_RAWARGS = ["a", "b", "c", "-d", "1", "test this"]
        args, kwargs = transit_tools.cleanargs(TEST_RAWARGS)
        self.assertEqual(args, ["a", "b", "c", "test this"])

#

    def test_cleanargs_flag_arguments_w_quotes(self):
        TEST_RAWARGS = ["a", "b", "c", "-d", "1", "-p", "test this"]
        args, kwargs = transit_tools.cleanargs(TEST_RAWARGS)
        self.assertEqual(kwargs.get("p"), "test this")

#

    def test_cleanargs_flag_arguments_with_double_dash(self):
        TEST_RAWARGS = ["a", "b", "c", "-d", "1", "--p", "test this"]
        args, kwargs = transit_tools.cleanargs(TEST_RAWARGS)
        self.assertFalse("p" in kwargs)
        self.assertFalse("--p" in kwargs)
        self.assertTrue("-p" in kwargs)




if __name__ == '__main__':
    unittest.main()