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