Mercurial > repos > yufei-luo > s_mart
comparison SMART/Java/Python/test/Test_F_GetRandomSubset.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.GetRandomSubset import GetRandomSubset | |
4 from commons.core.parsing.BedParser import BedParser | |
5 from commons.core.parsing.GffParser import GffParser | |
6 | |
7 class Test_F_GetRandomSubset(unittest.TestCase): | |
8 | |
9 def setUp(self): | |
10 self._inputFileName = "inputFileTest.bed" | |
11 self._writeInputFile() | |
12 self._outputFileName = "output.gff3" | |
13 | |
14 def tearDown(self): | |
15 os.remove(self._inputFileName) | |
16 os.remove(self._outputFileName) | |
17 | |
18 def test_run_simple(self): | |
19 nbElements = 2 | |
20 inputTranscripts = [] | |
21 parser = BedParser(self._inputFileName, 0) | |
22 for transcript in parser.getIterator(): | |
23 inputTranscripts.append(transcript) | |
24 grs = GetRandomSubset(0) | |
25 grs.setInputFile(self._inputFileName, "bed") | |
26 grs.setNumber(nbElements, None) | |
27 grs.setOutputFile(self._outputFileName) | |
28 grs.run() | |
29 outputTranscripts = [] | |
30 parser = GffParser(self._outputFileName, 0) | |
31 for transcript in parser.getIterator(): | |
32 outputTranscripts.append(transcript) | |
33 self.assertEqual(len(outputTranscripts), nbElements) | |
34 for outputTranscript in outputTranscripts: | |
35 for inputTranscript in inputTranscripts: | |
36 if outputTranscript.getChromosome() == inputTranscript.getChromosome() and outputTranscript.getDirection() == inputTranscript.getDirection() and outputTranscript.getStart() == inputTranscript.getStart() and outputTranscript.getEnd() == inputTranscript.getEnd() and outputTranscript.getName() == inputTranscript.getName(): | |
37 break | |
38 else: | |
39 self.fail() | |
40 | |
41 def _writeInputFile(self): | |
42 f = open(self._inputFileName, "w") | |
43 f.write("arm_X\t10000100\t10000200\ttest1.1\t100\t+\t10000100\t10000200\t0\t1\t100,\t0,\n") | |
44 f.write("arm_X\t10000100\t10000200\ttest1.2\t100\t-\t10000100\t10000200\t0\t1\t100,\t0,\n") | |
45 f.write("arm_2R\t10000100\t10000200\ttest1.3\t100\t+\t10000100\t10000200\t0\t1\t100,\t0,\n") | |
46 f.write("arm_X\t10000000\t10000100\ttest1.4\t100\t+\t10000000\t10000100\t0\t1\t100,\t0,\n") | |
47 f.write("arm_X\t10000200\t10000300\ttest1.5\t100\t+\t10000200\t10000300\t0\t1\t100,\t0,\n") | |
48 f.write("arm_X\t9999900\t9999950\ttest1.6\t100\t+\t9999900\t9999950\t0\t1\t50,\t0,\n") | |
49 f.write("arm_X\t10000000\t10000050\ttest1.7\t100\t-\t10000000\t10000050\t0\t1\t50,\t0,\n") | |
50 f.close() | |
51 | |
52 | |
53 | |
54 if __name__ == "__main__": | |
55 unittest.main() |