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