Mercurial > repos > yufei-luo > s_mart
comparison SMART/Java/Python/test/Test_F_mergeSlidingWindowsClusters.py @ 18:94ab73e8a190
Uploaded
author | m-zytnicki |
---|---|
date | Mon, 29 Apr 2013 03:20:15 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
17:b0e8584489e6 | 18:94ab73e8a190 |
---|---|
1 import unittest | |
2 import os | |
3 from SMART.Java.Python.mergeSlidingWindowsClusters import MergeSlidingWindowsClusters | |
4 from SMART.Java.Python.misc import Utils | |
5 | |
6 class Test_F_mergeSlidingWindowsClusters(unittest.TestCase): | |
7 | |
8 | |
9 def setUp(self): | |
10 self._outputFileName = 'outputMSWC' | |
11 self._inputFileName1 = 'inputMSWC1.gff3' | |
12 self._inputFileName2 = 'inputMSWC2.gff3' | |
13 self._writeInput1(self._inputFileName1) | |
14 self._writeInput2(self._inputFileName2) | |
15 self._expOutput = 'expOutputMSWC.gff3' | |
16 self._writeExpOutput(self._expOutput) | |
17 | |
18 def tearDown(self): | |
19 os.remove(self._inputFileName1) | |
20 os.remove(self._inputFileName2) | |
21 os.remove(self._outputFileName+'.gff3') | |
22 os.remove(self._expOutput) | |
23 | |
24 | |
25 def test_run(self): | |
26 iMSWC = MergeSlidingWindowsClusters(0) | |
27 iMSWC.addInput(self._inputFileName1, 'gff3') | |
28 iMSWC.addInput(self._inputFileName2, 'gff3') | |
29 iMSWC.setOutput(self._outputFileName) | |
30 iMSWC.merge() | |
31 self.assertTrue(Utils.diff(self._outputFileName+'.gff3', self._expOutput)) | |
32 | |
33 def test_run_asScript(self): | |
34 cmd = 'python ../mergeSlidingWindowsClusters.py -i %s -f gff3 -j %s -g gff3 -o outputMSWC.gff3 --galaxy -v 0' % (self._inputFileName1, self._inputFileName2) | |
35 os.system(cmd) | |
36 self.assertTrue(Utils.diff(self._outputFileName+'.gff3', self._expOutput)) | |
37 | |
38 def _writeInput1(self, fileName): | |
39 f = open(fileName, 'w') | |
40 f.write("chr1\ttest\tmatch\t6155418\t6155441\t24\t+\t.\tName=test1/1;occurrence=1;rank=1;bestRegion=(self);nbGaps=0;nbOccurrences=1;nbMismatches=0;ID=test1/1;identity=100\n") | |
41 f.write("chr2\ttest\tmatch\t26303950\t26303981\t32\t+\t.\tName=test2/1;occurrence=1;rank=1;bestRegion=(self);nbGaps=0;nbOccurrences=3;nbMismatches=2;ID=test2/1-1;identity=93\n") | |
42 f.write("chr3\ttest\tmatch\t28320540\t28320574\t35\t+\t.\tName=test2/1;occurrence=2;bestRegion=chr2:26303950-26303981;nbGaps=0;nbOccurrences=3;nbMismatches=2;ID=test2/1-2;identity=94\n") | |
43 f.write("chr4\ttest\tmatch\t28565007\t28565041\t35\t+\t.\tName=test2/1;occurrence=3;rank=3;bestRegion=chr2:26303950-26303981;nbGaps=0;nbOccurrences=3;nbMismatches=4;ID=test2/1-3;identity=88\n") | |
44 f.write("chr6\ttest\tmatch\t48565007\t48565041\t35\t+\t.\tName=test2/1;occurrence=3;rank=3;bestRegion=chr2:26303950-26303981;nbGaps=0;nbOccurrences=3;nbMismatches=3;ID=test2/1-4;identity=80\n") | |
45 f.close() | |
46 | |
47 def _writeInput2(self, fileName): | |
48 f = open(fileName, 'w') | |
49 f.write("chr1\ttest\tmatch\t6155418\t6155441\t24\t+\t.\tName=test1/1;occurrence=1;rank=1;bestRegion=(self);nbGaps=0;nbOccurrences=1;nbMismatches=0;ID=test1/1;identity=100\n") | |
50 f.write("chr2\ttest\tmatch\t26303990\t26304021\t32\t+\t.\tName=test2/1;occurrence=1;rank=1;bestRegion=(self);nbGaps=0;nbOccurrences=3;nbMismatches=2;ID=test2/1-1;identity=93\n") | |
51 f.write("chr3\ttest\tmatch\t28320540\t28320574\t35\t+\t.\tName=test2/1;occurrence=2;bestRegion=chr2:26303950-26303981;nbGaps=0;nbOccurrences=3;nbMismatches=2;ID=test2/1-2;identity=94\n") | |
52 f.write("chr4\ttest\tmatch\t28565017\t28565051\t35\t+\t.\tName=test2/1;occurrence=3;rank=3;bestRegion=chr2:26303950-26303981;nbGaps=0;nbOccurrences=3;nbMismatches=4;ID=test2/1-3;identity=88\n") | |
53 f.write("chr5\ttest\tmatch\t30000000\t30000050\t50\t+\t.\tName=test3/1;occurrence=3;rank=3;bestRegion=chr2:26303950-26303981;nbGaps=0;nbOccurrences=3;nbMismatches=1;ID=test3/1-4;identity=50\n") | |
54 f.close() | |
55 | |
56 def _writeExpOutput(self, fileName): | |
57 f = open(fileName, 'w') | |
58 f.write("""chr6 S-MART match 48565007 48565041 35 + . occurrence=3;rank=3;bestRegion=chr2:26303950-26303981;nbGaps=0;nbOccurrences=3;nbMismatches=3;ID=test2/1-4;identity=80;Name=region_1 | |
59 chr5 S-MART match 30000000 30000050 50 + . occurrence=3;rank=3;bestRegion=chr2:26303950-26303981;nbGaps=0;nbOccurrences=3;nbMismatches=1;ID=test3/1-4;identity=50;Name=region_2 | |
60 chr4 S-MART match 28565017 28565051 35 + . occurrence=3;rank=3;bestRegion=chr2:26303950-26303981;nbGaps=0;nbOccurrences=3;nbMismatches=4;ID=test2/1-3;identity=88;Name=region_3 | |
61 chr4 S-MART match 28565007 28565041 35 + . occurrence=3;rank=3;bestRegion=chr2:26303950-26303981;nbGaps=0;nbOccurrences=3;nbMismatches=4;ID=test2/1-3;identity=88;Name=region_4 | |
62 chr3 S-MART match 28320540 28320574 35 + . occurrence=2;bestRegion=chr2:26303950-26303981;nbGaps=0;nbOccurrences=3;nbMismatches=2;ID=test2/1-2;identity=94;Name=region_5 | |
63 chr2 S-MART match 26303990 26304021 32 + . occurrence=1;rank=1;bestRegion=(self);nbGaps=0;nbOccurrences=3;nbMismatches=2;ID=test2/1-1;identity=93;Name=region_6 | |
64 chr2 S-MART match 26303950 26303981 32 + . occurrence=1;rank=1;bestRegion=(self);nbGaps=0;nbOccurrences=3;nbMismatches=2;ID=test2/1-1;identity=93;Name=region_7 | |
65 chr1 S-MART match 6155418 6155441 24 + . occurrence=1;rank=1;bestRegion=(self);nbGaps=0;nbOccurrences=1;nbMismatches=0;ID=test1/1;identity=100;Name=region_8 | |
66 """) | |
67 # f.write("chr6\tS-MART\tmatch\t48565007\t48565041\t35\t+\t.\tName=region_1;occurrence=3;feature=match;rank=3;score=35;bestRegion=chr2:26303950-26303981;nbGaps=0;nbOccurrences=3;nbMismatches=3;ID=test2/1-4;identity=80\n") | |
68 # f.write("chr5\tS-MART\tmatch\t30000000\t30000050\t50\t+\t.\tName=region_2;occurrence=3;feature=match;rank=3;score=50;bestRegion=chr2:26303950-26303981;nbGaps=0;nbOccurrences=3;nbMismatches=1;ID=test3/1-4;identity=50\n") | |
69 # f.write("chr4\tS-MART\tmatch\t28565017\t28565051\t35\t+\t.\tName=region_3;occurrence=3;feature=match;rank=3;score=35;bestRegion=chr2:26303950-26303981;nbGaps=0;nbOccurrences=3;nbMismatches=4;ID=test2/1-3;identity=88\n") | |
70 # f.write("chr4\tS-MART\tmatch\t28565007\t28565041\t35\t+\t.\tName=region_4;occurrence=3;feature=match;rank=3;score=35;bestRegion=chr2:26303950-26303981;nbGaps=0;nbOccurrences=3;nbMismatches=4;ID=test2/1-3;identity=88\n") | |
71 # f.write("chr3\tS-MART\tmatch\t28320540\t28320574\t35\t+\t.\tName=region_5;occurrence=2;feature=match;score=35;bestRegion=chr2:26303950-26303981;nbGaps=0;nbOccurrences=3;nbMismatches=2;ID=test2/1-2;identity=94\n") | |
72 # f.write("chr2\tS-MART\tmatch\t26303990\t26304021\t32\t+\t.\tName=region_6;occurrence=1;feature=match;rank=1;score=32;bestRegion=(self);nbGaps=0;nbOccurrences=3;nbMismatches=2;ID=test2/1-1;identity=93\n") | |
73 # f.write("chr2\tS-MART\tmatch\t26303950\t26303981\t32\t+\t.\tName=region_7;occurrence=1;feature=match;rank=1;score=32;bestRegion=(self);nbGaps=0;nbOccurrences=3;nbMismatches=2;ID=test2/1-1;identity=93\n") | |
74 # f.write("chr1\tS-MART\tmatch\t6155418\t6155441\t24\t+\t.\tName=region_8;occurrence=1;feature=match;rank=1;score=24;bestRegion=(self);nbGaps=0;nbOccurrences=1;nbMismatches=0;ID=test1/1;identity=100\n") | |
75 f.close() | |
76 | |
77 | |
78 | |
79 if __name__ == "__main__": | |
80 unittest.main() |