annotate SMART/Java/Python/test/Test_F_CollapseReads.py @ 25:7809e72960fe

Deleted selected files
author m-zytnicki
date Mon, 29 Apr 2013 03:29:14 -0400
parents 94ab73e8a190
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
18
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
1 import unittest
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
2 import os
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
3 from SMART.Java.Python.CollapseReads import CollapseReads
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
4 from SMART.Java.Python.misc import Utils
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
5 from commons.core.utils.FileUtils import FileUtils
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
6 from SMART.Java.Python.ncList.test.MockFindOverlaps_randomExample import MockFindOverlaps_randomExample_NonOrder
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
7
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
8 class Test_F_CollapseReads(unittest.TestCase):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
9
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
10 def setUp(self):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
11 self._inputFileName = 'inputCR.gff3'
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
12 self._writeInput(self._inputFileName)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
13 self._outputFileName = 'outputCR.gff3'
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
14 self._expOutputFileName = 'expOutputCR.gff3'
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
15
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
16 def tearDown(self):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
17 return
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
18
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
19 def test_run_default_option(self):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
20 iCR = CollapseReads(0)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
21 iCR.setInputFile(self._inputFileName, 'gff3')
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
22 iCR.setOutputFile(self._outputFileName)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
23 iCR.strands = False
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
24 iCR.collapse()
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
25 self._writeExp_strand_False(self._expOutputFileName)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
26 self.assertTrue(Utils.diff(self._expOutputFileName, self._outputFileName))
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
27
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
28 def test_run_strand_option(self):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
29 iCR = CollapseReads(0)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
30 iCR.setInputFile(self._inputFileName, 'gff3')
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
31 iCR.setOutputFile(self._outputFileName)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
32 iCR.strands = True
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
33 iCR.collapse()
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
34 self._writeExp_strand_True(self._expOutputFileName)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
35 self.assertTrue(Utils.diff(self._expOutputFileName, self._outputFileName))
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
36
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
37 def test_run_asScript_default_option(self):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
38 cmd = 'python ../CollapseReads.py -i %s -f gff3 -o %s -v 0' % (self._inputFileName, self._outputFileName)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
39 os.system(cmd)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
40 self._writeExp_strand_True(self._expOutputFileName)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
41 self.assertTrue(Utils.diff(self._expOutputFileName, self._outputFileName))
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
42
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
43 def test_run_asScript_strand_option(self):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
44 cmd = 'python ../CollapseReads.py -i %s -f gff3 -o %s -s -v 0' % (self._inputFileName, self._outputFileName)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
45 os.system(cmd)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
46 self._writeExp_strand_False(self._expOutputFileName)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
47 self.assertTrue(Utils.diff(self._expOutputFileName, self._outputFileName))
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
48
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
49 def test_run_toOrderGff(self):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
50 iMRE = MockFindOverlaps_randomExample_NonOrder(self._inputFileName, 'chrom', 10, 1000)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
51 iMRE.write()
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
52 iCR = CollapseReads(0)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
53 iCR.setInputFile(self._inputFileName, 'gff3')
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
54 iCR.setOutputFile(self._outputFileName)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
55 iCR.strands = False
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
56 iCR.collapse()
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
57 f = open(self._expOutputFileName, "w")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
58 f.close()
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
59 cmd = 'sort -f -n -k4 -k5.4rn -o %s %s'%(self._expOutputFileName, self._inputFileName)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
60 os.system(cmd)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
61
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
62 def _writeInput(self, fileName):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
63 f = open(fileName, 'w')
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
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")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
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")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
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")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
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")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
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")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
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")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
70 f.close()
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
71
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
72 def _writeExp_strand_False(self, fileName):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
73 f = open(fileName, 'w')
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
74 f.write("""chr1 S-MART match 6155418 6155441 . - . nbElements=3.000000;ID=test3/1;Name=test3/1--test3/1--test1/1
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
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
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
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
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
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
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
78 """)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
79 f.close()
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
80
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
81 def _writeExp_strand_True(self, fileName):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
82 f = open(fileName, 'w')
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
83 f.write("""chr1 S-MART match 6155418 6155441 . + . nbElements=2.000000;ID=test3/1;Name=test3/1--test1/1
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
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
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
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
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
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
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
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
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
88 """)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
89 f.close()
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
90
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
91 if __name__ == "__main__":
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
92 unittest.main()