6
|
1 # Copyright INRA (Institut National de la Recherche Agronomique)
|
|
2 # http://www.inra.fr
|
|
3 # http://urgi.versailles.inra.fr
|
|
4 #
|
|
5 # This software is governed by the CeCILL license under French law and
|
|
6 # abiding by the rules of distribution of free software. You can use,
|
|
7 # modify and/ or redistribute the software under the terms of the CeCILL
|
|
8 # license as circulated by CEA, CNRS and INRIA at the following URL
|
|
9 # "http://www.cecill.info".
|
|
10 #
|
|
11 # As a counterpart to the access to the source code and rights to copy,
|
|
12 # modify and redistribute granted by the license, users are provided only
|
|
13 # with a limited warranty and the software's author, the holder of the
|
|
14 # economic rights, and the successive licensors have only limited
|
|
15 # liability.
|
|
16 #
|
|
17 # In this respect, the user's attention is drawn to the risks associated
|
|
18 # with loading, using, modifying and/or developing or reproducing the
|
|
19 # software by the user in light of its specific status of free software,
|
|
20 # that may mean that it is complicated to manipulate, and that also
|
|
21 # therefore means that it is reserved for developers and experienced
|
|
22 # professionals having in-depth computer knowledge. Users are therefore
|
|
23 # encouraged to load and test the software's suitability as regards their
|
|
24 # requirements in conditions enabling the security of their systems and/or
|
|
25 # data to be ensured and, more generally, to use and operate it in the
|
|
26 # same conditions as regards security.
|
|
27 #
|
|
28 # The fact that you are presently reading this means that you have had
|
|
29 # knowledge of the CeCILL license and that you accept its terms.
|
|
30
|
|
31
|
|
32 import unittest
|
|
33 from commons.core.coord.Path import Path
|
|
34 from commons.core.coord.Align import Align
|
|
35 from commons.core.coord.Set import Set
|
|
36
|
|
37
|
|
38 class Test_Path( unittest.TestCase ):
|
|
39
|
|
40 def setUp( self ):
|
|
41 self._path = Path()
|
|
42
|
|
43 def test_setFromTuple( self ):
|
|
44 line = "1\tchr1\t1\t10\tTE2\t11\t17\t1e-20\t30\t90.2"
|
|
45 self._path.setFromTuple( line.split("\t") )
|
|
46 self.assertEqual( self._path.id, 1 )
|
|
47 self.assertEqual( self._path.range_query.seqname, "chr1" )
|
|
48 self.assertEqual( self._path.range_query.start, 1 )
|
|
49 self.assertEqual( self._path.range_query.end, 10 )
|
|
50 self.assertEqual( self._path.range_subject.seqname, "TE2" )
|
|
51 self.assertEqual( self._path.range_subject.start, 11 )
|
|
52 self.assertEqual( self._path.range_subject.end, 17 )
|
|
53 self.assertEqual( self._path.e_value, float("1e-20") )
|
|
54 self.assertEqual( self._path.score, float("30") )
|
|
55 self.assertEqual( self._path.identity, float("90.2") )
|
|
56
|
|
57 def test___eq__( self ):
|
|
58 self._path.setFromString( "1\tchr1\t1\t6\tTE2\t11\t16\t1e-20\t30\t90.2\n" )
|
|
59 o = Path()
|
|
60 o.setFromString( "1\tchr1\t1\t6\tTE2\t11\t16\t1e-20\t30\t90.2\n" )
|
|
61 self.assertEqual( self._path, o )
|
|
62 o.setFromString( "2\tchr1\t1\t6\tTE2\t11\t16\t1e-20\t30\t90.2\n" )
|
|
63 self.assertNotEqual( self._path, o )
|
|
64 o.setFromString( "1\tchr1\t1\t6\tTE2\t11\t16\t1e-20\t3000000\t90.2\n" )
|
|
65 self.assertNotEqual( self._path, o )
|
|
66
|
|
67 def test_canMerge( self ):
|
|
68 tuple = ("1", "chr1","1", "10","TE2","11","17","1e-20","30","90.2")
|
|
69 self._path.setFromTuple(tuple)
|
|
70 tuple = ("2", "chr1","2", "9","TE2","10","13","1e-20","30","90.2")
|
|
71 o = Path()
|
|
72 o.setFromTuple(tuple)
|
|
73 self.assertTrue(self._path.canMerge(o))
|
|
74
|
|
75 def test_canMerge_on_same_id ( self ):
|
|
76 tuple = ("1", "chr1","1", "10","TE2","11","17","1e-20","30","90.2")
|
|
77 self._path.setFromTuple(tuple)
|
|
78 tuple = ("1", "chr1","2", "9","TE2","10","13","1e-20","30","90.2")
|
|
79 o = Path()
|
|
80 o.setFromTuple(tuple)
|
|
81 self.assertFalse(self._path.canMerge(o))
|
|
82
|
|
83 def test_canMerge_on_same_chr( self ):
|
|
84 tuple = ("1", "chr1","1", "10","TE2","11","17","1e-20","30","90.2")
|
|
85 self._path.setFromTuple(tuple)
|
|
86 tuple = ("2", "chr2","2", "9","TE2","10","13","1e-20","30","90.2")
|
|
87 o = Path()
|
|
88 o.setFromTuple(tuple)
|
|
89 self.assertFalse(self._path.canMerge(o))
|
|
90
|
|
91 def test_canMerge_on_diff_subj( self ):
|
|
92 tuple = ("1", "chr1","1", "10","TE2","11","17","1e-20","30","90.2")
|
|
93 self._path.setFromTuple(tuple)
|
|
94 tuple = ("2", "chr1","2", "9","TE3","10","13","1e-20","30","90.2")
|
|
95 o = Path()
|
|
96 o.setFromTuple(tuple)
|
|
97 self.assertFalse(self._path.canMerge(o))
|
|
98
|
|
99 def test_canMerge_on_queries_that_do_not_overlap( self ):
|
|
100 tuple = ("1", "chr1","5", "11","TE2","11","17","1e-20","30","90.2")
|
|
101 self._path.setFromTuple(tuple)
|
|
102 tuple = ("2", "chr1","1", "4","TE2","10","13","1e-20","30","90.2")
|
|
103 o = Path()
|
|
104 o.setFromTuple(tuple)
|
|
105 self.assertFalse(self._path.canMerge(o))
|
|
106
|
|
107 def test_canMerge_on_subjects_that_do_not_overlap( self ):
|
|
108 tuple = ("1", "chr1","1", "10","TE2","11","17","1e-20","30","90.2")
|
|
109 self._path.setFromTuple(tuple)
|
|
110 tuple = ("2", "chr1","2", "9","TE2","1","10","1e-20","30","90.2")
|
|
111 o = Path()
|
|
112 o.setFromTuple(tuple)
|
|
113 self.assertFalse(self._path.canMerge(o))
|
|
114
|
|
115 def test_getSubjectAsSetOfQuery( self ):
|
|
116 tuple = ("1","chr1","1","10","TE2","11","17","1e-20","30","90.2")
|
|
117 self._path.setFromTuple(tuple)
|
|
118 exp = Set(1,"TE2","chr1",1,10)
|
|
119 obs = self._path.getSubjectAsSetOfQuery()
|
|
120 self.assertEqual( exp, obs )
|
|
121
|
|
122 def test_getSubjectAsSetOfQuery_on_neg_strand( self ):
|
|
123 tuple = ("1","chr1","10","1","TE2","11","17","1e-20","30","90.2")
|
|
124 self._path.setFromTuple(tuple)
|
|
125 exp = Set(1,"TE2","chr1",10,1)
|
|
126 obs = self._path.getSubjectAsSetOfQuery()
|
|
127 self.assertEqual( exp, obs )
|
|
128
|
|
129 def test_toString( self ):
|
|
130 self._path.setFromString( "1\tchr1\t1\t10\tTE3\t11\t17\t1e-20\t30\t85.2\n" )
|
|
131 exp = "1\tchr1\t1\t10\tTE3\t11\t17\t%g\t30\t%f" % ( 1e-20, 85.2 )
|
|
132 obs = self._path.toString()
|
|
133 self.assertEqual( obs, exp )
|
|
134
|
|
135 def test_getAlignInstance( self ):
|
|
136 self._path.setFromTuple( ( "2", "chr3", "250", "151", "seq5", "1", "100", "1e-32", "147", "87.9" ) )
|
|
137 expAlign = Align()
|
|
138 expAlign.setFromTuple( ( "chr3", "151", "250", "seq5", "100", "1", "1e-32", "147", "87.9" ) )
|
|
139 obsAlign = self._path.getAlignInstance()
|
|
140 self.assertEqual( expAlign, obsAlign )
|
|
141
|
|
142
|
|
143 test_suite = unittest.TestSuite()
|
|
144 test_suite.addTest( unittest.makeSuite( Test_Path ) )
|
|
145 if __name__ == "__main__":
|
|
146 unittest.TextTestRunner(verbosity=2).run( test_suite )
|