comparison SMART/Java/Python/test/Test_F_getRandomRegions.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 commons.core.parsing.GffParser import GffParser
4 from SMART.Java.Python.getRandomRegions import RandomRegionsGenerator
5
6 MIN_SIZE = 36
7 MAX_SIZE = 100
8 CHR = "chr1"
9 CHR_SIZE = 1000000
10 NB_READS = 1000
11
12 class Test_F_getRandomRegions(unittest.TestCase):
13
14 def setUp(self):
15 self._outputFileName = 'output.gff3'
16
17 def tearDown(self):
18 for fileName in [self._outputFileName]:
19 if os.path.exists(fileName):
20 os.remove(fileName)
21
22 def test_simple(self):
23 iRR = RandomRegionsGenerator(0)
24 iRR.setMinSize(MIN_SIZE)
25 iRR.setMaxSize(MAX_SIZE)
26 iRR.setGenomeSize(CHR_SIZE)
27 iRR.setChromosomeName(CHR)
28 iRR.setStrands(False)
29 iRR.setNumber(NB_READS)
30 iRR.setOutputFile(self._outputFileName)
31 iRR.run()
32 parser = GffParser(self._outputFileName, 0)
33 starts = set()
34 self.assertTrue(parser.getNbTranscripts(), CHR_SIZE)
35 for transcript in parser.getIterator():
36 start = transcript.getStart()
37 end = transcript.getEnd()
38 size = transcript.getSize()
39 chromosome = transcript.getChromosome()
40 strand = transcript.getDirection()
41 self.assertTrue(start not in starts)
42 self.assertTrue(start >= 1)
43 self.assertTrue(end <= CHR_SIZE)
44 self.assertEquals(chromosome, CHR)
45 self.assertEquals(strand, 1)
46 starts.add(start)
47
48 def test_both_strands(self):
49 iRR = RandomRegionsGenerator(0)
50 iRR.setMinSize(MIN_SIZE)
51 iRR.setMaxSize(MAX_SIZE)
52 iRR.setGenomeSize(CHR_SIZE)
53 iRR.setChromosomeName(CHR)
54 iRR.setStrands(True)
55 iRR.setNumber(NB_READS)
56 iRR.setOutputFile(self._outputFileName)
57 iRR.run()
58 parser = GffParser(self._outputFileName, 0)
59 strands = set()
60 for transcript in parser.getIterator():
61 strands.add(transcript.getDirection())
62 self.assertTrue(1 in strands)
63 self.assertTrue(-1 in strands)
64
65 if __name__ == "__main__":
66 unittest.main()