18
|
1 import unittest
|
|
2 import os
|
|
3 from SMART.Java.Python.CollapseReads import CollapseReads
|
|
4 from SMART.Java.Python.misc import Utils
|
|
5 from commons.core.utils.FileUtils import FileUtils
|
|
6 from SMART.Java.Python.ncList.test.MockFindOverlaps_randomExample import MockFindOverlaps_randomExample_NonOrder
|
|
7
|
|
8 class Test_F_CollapseReads(unittest.TestCase):
|
|
9
|
|
10 def setUp(self):
|
|
11 self._inputFileName = 'inputCR.gff3'
|
|
12 self._writeInput(self._inputFileName)
|
|
13 self._outputFileName = 'outputCR.gff3'
|
|
14 self._expOutputFileName = 'expOutputCR.gff3'
|
|
15
|
|
16 def tearDown(self):
|
|
17 return
|
|
18
|
|
19 def test_run_default_option(self):
|
|
20 iCR = CollapseReads(0)
|
|
21 iCR.setInputFile(self._inputFileName, 'gff3')
|
|
22 iCR.setOutputFile(self._outputFileName)
|
|
23 iCR.strands = False
|
|
24 iCR.collapse()
|
|
25 self._writeExp_strand_False(self._expOutputFileName)
|
|
26 self.assertTrue(Utils.diff(self._expOutputFileName, self._outputFileName))
|
|
27
|
|
28 def test_run_strand_option(self):
|
|
29 iCR = CollapseReads(0)
|
|
30 iCR.setInputFile(self._inputFileName, 'gff3')
|
|
31 iCR.setOutputFile(self._outputFileName)
|
|
32 iCR.strands = True
|
|
33 iCR.collapse()
|
|
34 self._writeExp_strand_True(self._expOutputFileName)
|
|
35 self.assertTrue(Utils.diff(self._expOutputFileName, self._outputFileName))
|
|
36
|
|
37 def test_run_asScript_default_option(self):
|
|
38 cmd = 'python ../CollapseReads.py -i %s -f gff3 -o %s -v 0' % (self._inputFileName, self._outputFileName)
|
|
39 os.system(cmd)
|
|
40 self._writeExp_strand_True(self._expOutputFileName)
|
|
41 self.assertTrue(Utils.diff(self._expOutputFileName, self._outputFileName))
|
|
42
|
|
43 def test_run_asScript_strand_option(self):
|
|
44 cmd = 'python ../CollapseReads.py -i %s -f gff3 -o %s -s -v 0' % (self._inputFileName, self._outputFileName)
|
|
45 os.system(cmd)
|
|
46 self._writeExp_strand_False(self._expOutputFileName)
|
|
47 self.assertTrue(Utils.diff(self._expOutputFileName, self._outputFileName))
|
|
48
|
|
49 def test_run_toOrderGff(self):
|
|
50 iMRE = MockFindOverlaps_randomExample_NonOrder(self._inputFileName, 'chrom', 10, 1000)
|
|
51 iMRE.write()
|
|
52 iCR = CollapseReads(0)
|
|
53 iCR.setInputFile(self._inputFileName, 'gff3')
|
|
54 iCR.setOutputFile(self._outputFileName)
|
|
55 iCR.strands = False
|
|
56 iCR.collapse()
|
|
57 f = open(self._expOutputFileName, "w")
|
|
58 f.close()
|
|
59 cmd = 'sort -f -n -k4 -k5.4rn -o %s %s'%(self._expOutputFileName, self._inputFileName)
|
|
60 os.system(cmd)
|
|
61
|
|
62 def _writeInput(self, fileName):
|
|
63 f = open(fileName, 'w')
|
|
64 f.write("chr1\ttest\tmatch\t6155418\t6155441\t.\t+\t.\toccurrence=1;rank=1;bestRegion=(self);nbGaps=0;nbOccurrences=1;nbMismatches=0;ID=test1/1;identity=100;Name=test1/1\n")
|
|
65 f.write("chr2\ttest\tmatch\t26303950\t26303981\t.\t+\t.\toccurrence=1;rank=1;bestRegion=(self);nbGaps=0;nbOccurrences=3;nbMismatches=2;ID=test2/1-1;identity=93;Name=test2/1\n")
|
|
66 f.write("chr3\ttest\tmatch\t28320540\t28320574\t.\t+\t.\toccurrence=2;bestRegion=chr2:26303950-26303981;nbGaps=0;nbOccurrences=3;nbMismatches=2;ID=test2/1-2;identity=94;Name=test2/1\n")
|
|
67 f.write("chr4\ttest\tmatch\t28565007\t28565041\t.\t+\t.\toccurrence=3;rank=3;bestRegion=chr2:26303950-26303981;nbGaps=0;nbOccurrences=3;nbMismatches=4;ID=test2/1-3;identity=88;Name=test2/1\n")
|
|
68 f.write("chr1\ttest\tmatch\t6155418\t6155441\t.\t+\t.\toccurrence=2;rank=2;bestRegion=(self);nbGaps=0;nbOccurrences=1;nbMismatches=1;ID=test3/1;identity=50;Name=test3/1\n")
|
|
69 f.write("chr1\ttest\tmatch\t6155418\t6155441\t.\t-\t.\toccurrence=2;rank=2;bestRegion=(self);nbGaps=0;nbOccurrences=1;nbMismatches=1;ID=test3/1;identity=50;Name=test3/1\n")
|
|
70 f.close()
|
|
71
|
|
72 def _writeExp_strand_False(self, fileName):
|
|
73 f = open(fileName, 'w')
|
|
74 f.write("""chr1 S-MART match 6155418 6155441 . - . nbElements=3.000000;ID=test3/1;Name=test3/1--test3/1--test1/1
|
|
75 chr2 S-MART match 26303950 26303981 . + . occurrence=1;rank=1;bestRegion=(self);nbGaps=0;nbOccurrences=3;nbMismatches=2;ID=test2/1-1;identity=93;Name=test2/1
|
|
76 chr3 S-MART match 28320540 28320574 . + . occurrence=2;bestRegion=chr2:26303950-26303981;nbGaps=0;nbOccurrences=3;nbMismatches=2;ID=test2/1-2;identity=94;Name=test2/1
|
|
77 chr4 S-MART match 28565007 28565041 . + . occurrence=3;rank=3;bestRegion=chr2:26303950-26303981;nbGaps=0;nbOccurrences=3;nbMismatches=4;ID=test2/1-3;identity=88;Name=test2/1
|
|
78 """)
|
|
79 f.close()
|
|
80
|
|
81 def _writeExp_strand_True(self, fileName):
|
|
82 f = open(fileName, 'w')
|
|
83 f.write("""chr1 S-MART match 6155418 6155441 . + . nbElements=2.000000;ID=test3/1;Name=test3/1--test1/1
|
|
84 chr1 S-MART match 6155418 6155441 . - . occurrence=2;rank=2;bestRegion=(self);nbGaps=0;nbOccurrences=1;nbMismatches=1;ID=test3/1;identity=50;Name=test3/1
|
|
85 chr2 S-MART match 26303950 26303981 . + . occurrence=1;rank=1;bestRegion=(self);nbGaps=0;nbOccurrences=3;nbMismatches=2;ID=test2/1-1;identity=93;Name=test2/1
|
|
86 chr3 S-MART match 28320540 28320574 . + . occurrence=2;bestRegion=chr2:26303950-26303981;nbGaps=0;nbOccurrences=3;nbMismatches=2;ID=test2/1-2;identity=94;Name=test2/1
|
|
87 chr4 S-MART match 28565007 28565041 . + . occurrence=3;rank=3;bestRegion=chr2:26303950-26303981;nbGaps=0;nbOccurrences=3;nbMismatches=4;ID=test2/1-3;identity=88;Name=test2/1
|
|
88 """)
|
|
89 f.close()
|
|
90
|
|
91 if __name__ == "__main__":
|
|
92 unittest.main()
|