annotate tests/test_riboseqr.py @ 6:5a242f289347 default tip

Merge
author Vimalkumar Velayudhan <vimalkumarvelayudhan@gmail.com>
date Tue, 27 Oct 2015 12:29:39 +0000
parents 423ad61697c4
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
c34c364ce75d First commit
Vimalkumar Velayudhan <vimal@biotechcoder.com>
parents:
diff changeset
1 """riboSeqR Galaxy unit tests"""
5
423ad61697c4 Bugfix 1: [triplet] Lengths (frameCounting) if given should be a range (not zero).
Vimalkumar Velayudhan <vimalkumarvelayudhan@gmail.com>
parents: 0
diff changeset
2 import os
423ad61697c4 Bugfix 1: [triplet] Lengths (frameCounting) if given should be a range (not zero).
Vimalkumar Velayudhan <vimalkumarvelayudhan@gmail.com>
parents: 0
diff changeset
3 import shutil
0
c34c364ce75d First commit
Vimalkumar Velayudhan <vimal@biotechcoder.com>
parents:
diff changeset
4 import unittest
5
423ad61697c4 Bugfix 1: [triplet] Lengths (frameCounting) if given should be a range (not zero).
Vimalkumar Velayudhan <vimalkumarvelayudhan@gmail.com>
parents: 0
diff changeset
5 import tempfile
423ad61697c4 Bugfix 1: [triplet] Lengths (frameCounting) if given should be a range (not zero).
Vimalkumar Velayudhan <vimalkumarvelayudhan@gmail.com>
parents: 0
diff changeset
6 from riboseqr import utils, triplet, ribosome_profile
423ad61697c4 Bugfix 1: [triplet] Lengths (frameCounting) if given should be a range (not zero).
Vimalkumar Velayudhan <vimalkumarvelayudhan@gmail.com>
parents: 0
diff changeset
7
423ad61697c4 Bugfix 1: [triplet] Lengths (frameCounting) if given should be a range (not zero).
Vimalkumar Velayudhan <vimalkumarvelayudhan@gmail.com>
parents: 0
diff changeset
8 DATA_DIR = 'test-data'
0
c34c364ce75d First commit
Vimalkumar Velayudhan <vimal@biotechcoder.com>
parents:
diff changeset
9
c34c364ce75d First commit
Vimalkumar Velayudhan <vimal@biotechcoder.com>
parents:
diff changeset
10
c34c364ce75d First commit
Vimalkumar Velayudhan <vimal@biotechcoder.com>
parents:
diff changeset
11 class PrepareTestCase(unittest.TestCase):
c34c364ce75d First commit
Vimalkumar Velayudhan <vimal@biotechcoder.com>
parents:
diff changeset
12
c34c364ce75d First commit
Vimalkumar Velayudhan <vimal@biotechcoder.com>
parents:
diff changeset
13 def test_process_args(self):
c34c364ce75d First commit
Vimalkumar Velayudhan <vimal@biotechcoder.com>
parents:
diff changeset
14 """Test processing arguments. """
c34c364ce75d First commit
Vimalkumar Velayudhan <vimal@biotechcoder.com>
parents:
diff changeset
15 # "ATG" -> c("ATG")
c34c364ce75d First commit
Vimalkumar Velayudhan <vimal@biotechcoder.com>
parents:
diff changeset
16 rs = utils.process_args('ATG', ret_mode='charvector')
5
423ad61697c4 Bugfix 1: [triplet] Lengths (frameCounting) if given should be a range (not zero).
Vimalkumar Velayudhan <vimalkumarvelayudhan@gmail.com>
parents: 0
diff changeset
17 self.assertEqual(rs, 'c("ATG")', 'Return string as a character vector.')
0
c34c364ce75d First commit
Vimalkumar Velayudhan <vimal@biotechcoder.com>
parents:
diff changeset
18
c34c364ce75d First commit
Vimalkumar Velayudhan <vimal@biotechcoder.com>
parents:
diff changeset
19 # stop codons "TAG,TAA,TGA" -> c("TAG", "TAA", "TGA"). Also
c34c364ce75d First commit
Vimalkumar Velayudhan <vimal@biotechcoder.com>
parents:
diff changeset
20 # replicate names, seqnames.
c34c364ce75d First commit
Vimalkumar Velayudhan <vimal@biotechcoder.com>
parents:
diff changeset
21 rs = utils.process_args('TAG,TAA,TGA', ret_mode='charvector')
c34c364ce75d First commit
Vimalkumar Velayudhan <vimal@biotechcoder.com>
parents:
diff changeset
22 self.assertEqual(
c34c364ce75d First commit
Vimalkumar Velayudhan <vimal@biotechcoder.com>
parents:
diff changeset
23 rs, "c('TAG', 'TAA', 'TGA')",
c34c364ce75d First commit
Vimalkumar Velayudhan <vimal@biotechcoder.com>
parents:
diff changeset
24 'Return comma separated strings as a character vector.')
c34c364ce75d First commit
Vimalkumar Velayudhan <vimal@biotechcoder.com>
parents:
diff changeset
25
c34c364ce75d First commit
Vimalkumar Velayudhan <vimal@biotechcoder.com>
parents:
diff changeset
26 # "" -> None
c34c364ce75d First commit
Vimalkumar Velayudhan <vimal@biotechcoder.com>
parents:
diff changeset
27 rs = utils.process_args('')
c34c364ce75d First commit
Vimalkumar Velayudhan <vimal@biotechcoder.com>
parents:
diff changeset
28 self.assertIsNone(rs, 'Return empty string as None.')
c34c364ce75d First commit
Vimalkumar Velayudhan <vimal@biotechcoder.com>
parents:
diff changeset
29
c34c364ce75d First commit
Vimalkumar Velayudhan <vimal@biotechcoder.com>
parents:
diff changeset
30 # "27,28" -> c(27, 28)
c34c364ce75d First commit
Vimalkumar Velayudhan <vimal@biotechcoder.com>
parents:
diff changeset
31 rs = utils.process_args("27,28", ret_type='int', ret_mode='charvector')
c34c364ce75d First commit
Vimalkumar Velayudhan <vimal@biotechcoder.com>
parents:
diff changeset
32 self.assertEqual(
c34c364ce75d First commit
Vimalkumar Velayudhan <vimal@biotechcoder.com>
parents:
diff changeset
33 rs, "c(27, 28)", 'Return number strings as a character vector.')
c34c364ce75d First commit
Vimalkumar Velayudhan <vimal@biotechcoder.com>
parents:
diff changeset
34
c34c364ce75d First commit
Vimalkumar Velayudhan <vimal@biotechcoder.com>
parents:
diff changeset
35 # "27,28" -> [27, 28]
c34c364ce75d First commit
Vimalkumar Velayudhan <vimal@biotechcoder.com>
parents:
diff changeset
36 rs = utils.process_args("27,28", ret_type='int', ret_mode='list')
c34c364ce75d First commit
Vimalkumar Velayudhan <vimal@biotechcoder.com>
parents:
diff changeset
37 self.assertEqual(rs, [27, 28], 'Return number strings as a list.')
c34c364ce75d First commit
Vimalkumar Velayudhan <vimal@biotechcoder.com>
parents:
diff changeset
38
c34c364ce75d First commit
Vimalkumar Velayudhan <vimal@biotechcoder.com>
parents:
diff changeset
39 # "0,2" -> list(0,2)
c34c364ce75d First commit
Vimalkumar Velayudhan <vimal@biotechcoder.com>
parents:
diff changeset
40 rs = utils.process_args("0,2", ret_type='int', ret_mode='listvector')
c34c364ce75d First commit
Vimalkumar Velayudhan <vimal@biotechcoder.com>
parents:
diff changeset
41 self.assertEqual(
c34c364ce75d First commit
Vimalkumar Velayudhan <vimal@biotechcoder.com>
parents:
diff changeset
42 rs, "list(0, 2)", 'Return number strings as a list vector.')
c34c364ce75d First commit
Vimalkumar Velayudhan <vimal@biotechcoder.com>
parents:
diff changeset
43
c34c364ce75d First commit
Vimalkumar Velayudhan <vimal@biotechcoder.com>
parents:
diff changeset
44 # "50" -> 50
c34c364ce75d First commit
Vimalkumar Velayudhan <vimal@biotechcoder.com>
parents:
diff changeset
45 rs = utils.process_args("50", ret_type='int')
c34c364ce75d First commit
Vimalkumar Velayudhan <vimal@biotechcoder.com>
parents:
diff changeset
46 self.assertEqual(rs, 50, 'Return number string as a number.')
c34c364ce75d First commit
Vimalkumar Velayudhan <vimal@biotechcoder.com>
parents:
diff changeset
47
c34c364ce75d First commit
Vimalkumar Velayudhan <vimal@biotechcoder.com>
parents:
diff changeset
48 # "-200" -> -200
c34c364ce75d First commit
Vimalkumar Velayudhan <vimal@biotechcoder.com>
parents:
diff changeset
49 rs = utils.process_args("-200", ret_type='int')
c34c364ce75d First commit
Vimalkumar Velayudhan <vimal@biotechcoder.com>
parents:
diff changeset
50 self.assertEqual(rs, -200, 'Return number string as a number.')
c34c364ce75d First commit
Vimalkumar Velayudhan <vimal@biotechcoder.com>
parents:
diff changeset
51
c34c364ce75d First commit
Vimalkumar Velayudhan <vimal@biotechcoder.com>
parents:
diff changeset
52 # "TRUE" -> TRUE
c34c364ce75d First commit
Vimalkumar Velayudhan <vimal@biotechcoder.com>
parents:
diff changeset
53 rs = utils.process_args("TRUE", ret_type='bool')
c34c364ce75d First commit
Vimalkumar Velayudhan <vimal@biotechcoder.com>
parents:
diff changeset
54 self.assertEqual(rs, 'TRUE', 'Return bool string as bool.')
c34c364ce75d First commit
Vimalkumar Velayudhan <vimal@biotechcoder.com>
parents:
diff changeset
55
c34c364ce75d First commit
Vimalkumar Velayudhan <vimal@biotechcoder.com>
parents:
diff changeset
56 # 'chlamy17,chlamy3' -> 'chlamy17,chlamy3' for ribo and rna names
c34c364ce75d First commit
Vimalkumar Velayudhan <vimal@biotechcoder.com>
parents:
diff changeset
57 rs = utils.process_args('chlamy17,chlamy3')
c34c364ce75d First commit
Vimalkumar Velayudhan <vimal@biotechcoder.com>
parents:
diff changeset
58 self.assertEqual(rs, 'chlamy17,chlamy3', 'Return csv string as string.')
c34c364ce75d First commit
Vimalkumar Velayudhan <vimal@biotechcoder.com>
parents:
diff changeset
59
c34c364ce75d First commit
Vimalkumar Velayudhan <vimal@biotechcoder.com>
parents:
diff changeset
60 # 'chlamy17.idx, chlamy3.idx' -> ['chlamy17.idx', 'chlamy3.idx']
c34c364ce75d First commit
Vimalkumar Velayudhan <vimal@biotechcoder.com>
parents:
diff changeset
61 rs = utils.process_args('chlamy17.idx, chlamy3.idx', ret_mode='list')
c34c364ce75d First commit
Vimalkumar Velayudhan <vimal@biotechcoder.com>
parents:
diff changeset
62 self.assertEqual(rs, ['chlamy17.idx', 'chlamy3.idx'],
c34c364ce75d First commit
Vimalkumar Velayudhan <vimal@biotechcoder.com>
parents:
diff changeset
63 'Return files as a list.')
5
423ad61697c4 Bugfix 1: [triplet] Lengths (frameCounting) if given should be a range (not zero).
Vimalkumar Velayudhan <vimalkumarvelayudhan@gmail.com>
parents: 0
diff changeset
64
423ad61697c4 Bugfix 1: [triplet] Lengths (frameCounting) if given should be a range (not zero).
Vimalkumar Velayudhan <vimalkumarvelayudhan@gmail.com>
parents: 0
diff changeset
65
423ad61697c4 Bugfix 1: [triplet] Lengths (frameCounting) if given should be a range (not zero).
Vimalkumar Velayudhan <vimalkumarvelayudhan@gmail.com>
parents: 0
diff changeset
66 class TripletTestCase(unittest.TestCase):
423ad61697c4 Bugfix 1: [triplet] Lengths (frameCounting) if given should be a range (not zero).
Vimalkumar Velayudhan <vimalkumarvelayudhan@gmail.com>
parents: 0
diff changeset
67 """Test triple periodicity"""
423ad61697c4 Bugfix 1: [triplet] Lengths (frameCounting) if given should be a range (not zero).
Vimalkumar Velayudhan <vimalkumarvelayudhan@gmail.com>
parents: 0
diff changeset
68 html_file = None
423ad61697c4 Bugfix 1: [triplet] Lengths (frameCounting) if given should be a range (not zero).
Vimalkumar Velayudhan <vimalkumarvelayudhan@gmail.com>
parents: 0
diff changeset
69 output_path = None
423ad61697c4 Bugfix 1: [triplet] Lengths (frameCounting) if given should be a range (not zero).
Vimalkumar Velayudhan <vimalkumarvelayudhan@gmail.com>
parents: 0
diff changeset
70 rdata_load = os.path.join(DATA_DIR, 'Prepare riboSeqR input (R data file)')
423ad61697c4 Bugfix 1: [triplet] Lengths (frameCounting) if given should be a range (not zero).
Vimalkumar Velayudhan <vimalkumarvelayudhan@gmail.com>
parents: 0
diff changeset
71 rdata_save = None
423ad61697c4 Bugfix 1: [triplet] Lengths (frameCounting) if given should be a range (not zero).
Vimalkumar Velayudhan <vimalkumarvelayudhan@gmail.com>
parents: 0
diff changeset
72 include_lengths = '25:30'
423ad61697c4 Bugfix 1: [triplet] Lengths (frameCounting) if given should be a range (not zero).
Vimalkumar Velayudhan <vimalkumarvelayudhan@gmail.com>
parents: 0
diff changeset
73 analyze_plot_lengths = '26:30'
423ad61697c4 Bugfix 1: [triplet] Lengths (frameCounting) if given should be a range (not zero).
Vimalkumar Velayudhan <vimalkumarvelayudhan@gmail.com>
parents: 0
diff changeset
74
423ad61697c4 Bugfix 1: [triplet] Lengths (frameCounting) if given should be a range (not zero).
Vimalkumar Velayudhan <vimalkumarvelayudhan@gmail.com>
parents: 0
diff changeset
75 def setUp(self):
423ad61697c4 Bugfix 1: [triplet] Lengths (frameCounting) if given should be a range (not zero).
Vimalkumar Velayudhan <vimalkumarvelayudhan@gmail.com>
parents: 0
diff changeset
76 self.html_file, self.output_path = tempfile.mkstemp()[1], tempfile.mkdtemp()
423ad61697c4 Bugfix 1: [triplet] Lengths (frameCounting) if given should be a range (not zero).
Vimalkumar Velayudhan <vimalkumarvelayudhan@gmail.com>
parents: 0
diff changeset
77 self.rdata_save = os.path.join(self.output_path, 'Periodicity.rda')
423ad61697c4 Bugfix 1: [triplet] Lengths (frameCounting) if given should be a range (not zero).
Vimalkumar Velayudhan <vimalkumarvelayudhan@gmail.com>
parents: 0
diff changeset
78
423ad61697c4 Bugfix 1: [triplet] Lengths (frameCounting) if given should be a range (not zero).
Vimalkumar Velayudhan <vimalkumarvelayudhan@gmail.com>
parents: 0
diff changeset
79 def tearDown(self):
423ad61697c4 Bugfix 1: [triplet] Lengths (frameCounting) if given should be a range (not zero).
Vimalkumar Velayudhan <vimalkumarvelayudhan@gmail.com>
parents: 0
diff changeset
80 os.remove(self.html_file)
423ad61697c4 Bugfix 1: [triplet] Lengths (frameCounting) if given should be a range (not zero).
Vimalkumar Velayudhan <vimalkumarvelayudhan@gmail.com>
parents: 0
diff changeset
81 shutil.rmtree(self.output_path)
423ad61697c4 Bugfix 1: [triplet] Lengths (frameCounting) if given should be a range (not zero).
Vimalkumar Velayudhan <vimalkumarvelayudhan@gmail.com>
parents: 0
diff changeset
82
423ad61697c4 Bugfix 1: [triplet] Lengths (frameCounting) if given should be a range (not zero).
Vimalkumar Velayudhan <vimalkumarvelayudhan@gmail.com>
parents: 0
diff changeset
83 def test_triplet_periodicity(self):
423ad61697c4 Bugfix 1: [triplet] Lengths (frameCounting) if given should be a range (not zero).
Vimalkumar Velayudhan <vimalkumarvelayudhan@gmail.com>
parents: 0
diff changeset
84 """Given a prepared RDA file, produce triplet periodicity output (R data file and plots).
423ad61697c4 Bugfix 1: [triplet] Lengths (frameCounting) if given should be a range (not zero).
Vimalkumar Velayudhan <vimalkumarvelayudhan@gmail.com>
parents: 0
diff changeset
85
423ad61697c4 Bugfix 1: [triplet] Lengths (frameCounting) if given should be a range (not zero).
Vimalkumar Velayudhan <vimalkumarvelayudhan@gmail.com>
parents: 0
diff changeset
86 Note: only checks for the presence of program outputs
423ad61697c4 Bugfix 1: [triplet] Lengths (frameCounting) if given should be a range (not zero).
Vimalkumar Velayudhan <vimalkumarvelayudhan@gmail.com>
parents: 0
diff changeset
87 """
423ad61697c4 Bugfix 1: [triplet] Lengths (frameCounting) if given should be a range (not zero).
Vimalkumar Velayudhan <vimalkumarvelayudhan@gmail.com>
parents: 0
diff changeset
88 triplet.find_periodicity(
423ad61697c4 Bugfix 1: [triplet] Lengths (frameCounting) if given should be a range (not zero).
Vimalkumar Velayudhan <vimalkumarvelayudhan@gmail.com>
parents: 0
diff changeset
89 rdata_load=self.rdata_load,
423ad61697c4 Bugfix 1: [triplet] Lengths (frameCounting) if given should be a range (not zero).
Vimalkumar Velayudhan <vimalkumarvelayudhan@gmail.com>
parents: 0
diff changeset
90 fasta_file=os.path.join(DATA_DIR, 'rsem_chlamy236_deNovo.transcripts.fa'),
423ad61697c4 Bugfix 1: [triplet] Lengths (frameCounting) if given should be a range (not zero).
Vimalkumar Velayudhan <vimalkumarvelayudhan@gmail.com>
parents: 0
diff changeset
91 include_lengths=self.include_lengths, analyze_plot_lengths=self.analyze_plot_lengths,
423ad61697c4 Bugfix 1: [triplet] Lengths (frameCounting) if given should be a range (not zero).
Vimalkumar Velayudhan <vimalkumarvelayudhan@gmail.com>
parents: 0
diff changeset
92 html_file=self.html_file, output_path=self.output_path,
423ad61697c4 Bugfix 1: [triplet] Lengths (frameCounting) if given should be a range (not zero).
Vimalkumar Velayudhan <vimalkumarvelayudhan@gmail.com>
parents: 0
diff changeset
93 rdata_save=self.rdata_save)
423ad61697c4 Bugfix 1: [triplet] Lengths (frameCounting) if given should be a range (not zero).
Vimalkumar Velayudhan <vimalkumarvelayudhan@gmail.com>
parents: 0
diff changeset
94
423ad61697c4 Bugfix 1: [triplet] Lengths (frameCounting) if given should be a range (not zero).
Vimalkumar Velayudhan <vimalkumarvelayudhan@gmail.com>
parents: 0
diff changeset
95 for output in ('periodicity.R', 'Periodicity.rda', 'Periodicity-plot.pdf', 'Periodicity-plot.png'):
423ad61697c4 Bugfix 1: [triplet] Lengths (frameCounting) if given should be a range (not zero).
Vimalkumar Velayudhan <vimalkumarvelayudhan@gmail.com>
parents: 0
diff changeset
96 self.assertTrue(os.path.exists(os.path.join(self.output_path, output)))
423ad61697c4 Bugfix 1: [triplet] Lengths (frameCounting) if given should be a range (not zero).
Vimalkumar Velayudhan <vimalkumarvelayudhan@gmail.com>
parents: 0
diff changeset
97
423ad61697c4 Bugfix 1: [triplet] Lengths (frameCounting) if given should be a range (not zero).
Vimalkumar Velayudhan <vimalkumarvelayudhan@gmail.com>
parents: 0
diff changeset
98 def test_transcript_name(self):
423ad61697c4 Bugfix 1: [triplet] Lengths (frameCounting) if given should be a range (not zero).
Vimalkumar Velayudhan <vimalkumarvelayudhan@gmail.com>
parents: 0
diff changeset
99 """Check that the transcript name is the same in the SAM and FASTA file. If not, raise an error."""
423ad61697c4 Bugfix 1: [triplet] Lengths (frameCounting) if given should be a range (not zero).
Vimalkumar Velayudhan <vimalkumarvelayudhan@gmail.com>
parents: 0
diff changeset
100 self.assertRaises(
423ad61697c4 Bugfix 1: [triplet] Lengths (frameCounting) if given should be a range (not zero).
Vimalkumar Velayudhan <vimalkumarvelayudhan@gmail.com>
parents: 0
diff changeset
101 triplet.TripletPeriodicityError, triplet.find_periodicity,
423ad61697c4 Bugfix 1: [triplet] Lengths (frameCounting) if given should be a range (not zero).
Vimalkumar Velayudhan <vimalkumarvelayudhan@gmail.com>
parents: 0
diff changeset
102 rdata_load=self.rdata_load,
423ad61697c4 Bugfix 1: [triplet] Lengths (frameCounting) if given should be a range (not zero).
Vimalkumar Velayudhan <vimalkumarvelayudhan@gmail.com>
parents: 0
diff changeset
103 fasta_file=os.path.join(DATA_DIR, 'rsem_chlamy236_deNovo.transcripts_mod.fa'),
423ad61697c4 Bugfix 1: [triplet] Lengths (frameCounting) if given should be a range (not zero).
Vimalkumar Velayudhan <vimalkumarvelayudhan@gmail.com>
parents: 0
diff changeset
104 include_lengths=self.include_lengths, analyze_plot_lengths=self.analyze_plot_lengths,
423ad61697c4 Bugfix 1: [triplet] Lengths (frameCounting) if given should be a range (not zero).
Vimalkumar Velayudhan <vimalkumarvelayudhan@gmail.com>
parents: 0
diff changeset
105 html_file=self.html_file, output_path=self.output_path,
423ad61697c4 Bugfix 1: [triplet] Lengths (frameCounting) if given should be a range (not zero).
Vimalkumar Velayudhan <vimalkumarvelayudhan@gmail.com>
parents: 0
diff changeset
106 rdata_save=self.rdata_save)
423ad61697c4 Bugfix 1: [triplet] Lengths (frameCounting) if given should be a range (not zero).
Vimalkumar Velayudhan <vimalkumarvelayudhan@gmail.com>
parents: 0
diff changeset
107
423ad61697c4 Bugfix 1: [triplet] Lengths (frameCounting) if given should be a range (not zero).
Vimalkumar Velayudhan <vimalkumarvelayudhan@gmail.com>
parents: 0
diff changeset
108
423ad61697c4 Bugfix 1: [triplet] Lengths (frameCounting) if given should be a range (not zero).
Vimalkumar Velayudhan <vimalkumarvelayudhan@gmail.com>
parents: 0
diff changeset
109 class RibosomeProfileTestCase(unittest.TestCase):
423ad61697c4 Bugfix 1: [triplet] Lengths (frameCounting) if given should be a range (not zero).
Vimalkumar Velayudhan <vimalkumarvelayudhan@gmail.com>
parents: 0
diff changeset
110 """Test plot ribosome profile."""
423ad61697c4 Bugfix 1: [triplet] Lengths (frameCounting) if given should be a range (not zero).
Vimalkumar Velayudhan <vimalkumarvelayudhan@gmail.com>
parents: 0
diff changeset
111 html_file = None
423ad61697c4 Bugfix 1: [triplet] Lengths (frameCounting) if given should be a range (not zero).
Vimalkumar Velayudhan <vimalkumarvelayudhan@gmail.com>
parents: 0
diff changeset
112 output_path = None
423ad61697c4 Bugfix 1: [triplet] Lengths (frameCounting) if given should be a range (not zero).
Vimalkumar Velayudhan <vimalkumarvelayudhan@gmail.com>
parents: 0
diff changeset
113 rdata_load = os.path.join(DATA_DIR, 'Metagene analysis (R data file)')
423ad61697c4 Bugfix 1: [triplet] Lengths (frameCounting) if given should be a range (not zero).
Vimalkumar Velayudhan <vimalkumarvelayudhan@gmail.com>
parents: 0
diff changeset
114
423ad61697c4 Bugfix 1: [triplet] Lengths (frameCounting) if given should be a range (not zero).
Vimalkumar Velayudhan <vimalkumarvelayudhan@gmail.com>
parents: 0
diff changeset
115 def setUp(self):
423ad61697c4 Bugfix 1: [triplet] Lengths (frameCounting) if given should be a range (not zero).
Vimalkumar Velayudhan <vimalkumarvelayudhan@gmail.com>
parents: 0
diff changeset
116 self.html_file, self.output_path = tempfile.mkstemp()[1], tempfile.mkdtemp()
423ad61697c4 Bugfix 1: [triplet] Lengths (frameCounting) if given should be a range (not zero).
Vimalkumar Velayudhan <vimalkumarvelayudhan@gmail.com>
parents: 0
diff changeset
117
423ad61697c4 Bugfix 1: [triplet] Lengths (frameCounting) if given should be a range (not zero).
Vimalkumar Velayudhan <vimalkumarvelayudhan@gmail.com>
parents: 0
diff changeset
118 def tearDown(self):
423ad61697c4 Bugfix 1: [triplet] Lengths (frameCounting) if given should be a range (not zero).
Vimalkumar Velayudhan <vimalkumarvelayudhan@gmail.com>
parents: 0
diff changeset
119 os.remove(self.html_file)
423ad61697c4 Bugfix 1: [triplet] Lengths (frameCounting) if given should be a range (not zero).
Vimalkumar Velayudhan <vimalkumarvelayudhan@gmail.com>
parents: 0
diff changeset
120 shutil.rmtree(self.output_path)
423ad61697c4 Bugfix 1: [triplet] Lengths (frameCounting) if given should be a range (not zero).
Vimalkumar Velayudhan <vimalkumarvelayudhan@gmail.com>
parents: 0
diff changeset
121
423ad61697c4 Bugfix 1: [triplet] Lengths (frameCounting) if given should be a range (not zero).
Vimalkumar Velayudhan <vimalkumarvelayudhan@gmail.com>
parents: 0
diff changeset
122 def test_plot_ribosome_profile(self):
423ad61697c4 Bugfix 1: [triplet] Lengths (frameCounting) if given should be a range (not zero).
Vimalkumar Velayudhan <vimalkumarvelayudhan@gmail.com>
parents: 0
diff changeset
123 """Given the right transcript name, produce a profile plot. """
423ad61697c4 Bugfix 1: [triplet] Lengths (frameCounting) if given should be a range (not zero).
Vimalkumar Velayudhan <vimalkumarvelayudhan@gmail.com>
parents: 0
diff changeset
124 ribosome_profile.plot_transcript(
423ad61697c4 Bugfix 1: [triplet] Lengths (frameCounting) if given should be a range (not zero).
Vimalkumar Velayudhan <vimalkumarvelayudhan@gmail.com>
parents: 0
diff changeset
125 rdata_load=self.rdata_load, transcript_name='CUFF.37930.1',
423ad61697c4 Bugfix 1: [triplet] Lengths (frameCounting) if given should be a range (not zero).
Vimalkumar Velayudhan <vimalkumarvelayudhan@gmail.com>
parents: 0
diff changeset
126 transcript_length='27', transcript_cap='200', html_file=self.html_file,
423ad61697c4 Bugfix 1: [triplet] Lengths (frameCounting) if given should be a range (not zero).
Vimalkumar Velayudhan <vimalkumarvelayudhan@gmail.com>
parents: 0
diff changeset
127 output_path=self.output_path)
423ad61697c4 Bugfix 1: [triplet] Lengths (frameCounting) if given should be a range (not zero).
Vimalkumar Velayudhan <vimalkumarvelayudhan@gmail.com>
parents: 0
diff changeset
128
423ad61697c4 Bugfix 1: [triplet] Lengths (frameCounting) if given should be a range (not zero).
Vimalkumar Velayudhan <vimalkumarvelayudhan@gmail.com>
parents: 0
diff changeset
129 for output in ('ribosome-profile.R', 'Ribosome-profile-plot.pdf', 'Ribosome-profile-plot_1.png',
423ad61697c4 Bugfix 1: [triplet] Lengths (frameCounting) if given should be a range (not zero).
Vimalkumar Velayudhan <vimalkumarvelayudhan@gmail.com>
parents: 0
diff changeset
130 'Ribosome-profile-plot_2.png', 'Ribosome-profile-plot_3.png', 'Ribosome-profile-plot_4.png'):
423ad61697c4 Bugfix 1: [triplet] Lengths (frameCounting) if given should be a range (not zero).
Vimalkumar Velayudhan <vimalkumarvelayudhan@gmail.com>
parents: 0
diff changeset
131 self.assertTrue(os.path.exists(os.path.join(self.output_path, output)))
423ad61697c4 Bugfix 1: [triplet] Lengths (frameCounting) if given should be a range (not zero).
Vimalkumar Velayudhan <vimalkumarvelayudhan@gmail.com>
parents: 0
diff changeset
132
423ad61697c4 Bugfix 1: [triplet] Lengths (frameCounting) if given should be a range (not zero).
Vimalkumar Velayudhan <vimalkumarvelayudhan@gmail.com>
parents: 0
diff changeset
133 def test_invalid_transcript(self):
423ad61697c4 Bugfix 1: [triplet] Lengths (frameCounting) if given should be a range (not zero).
Vimalkumar Velayudhan <vimalkumarvelayudhan@gmail.com>
parents: 0
diff changeset
134 """If a transcript is missing, produce an error message."""
423ad61697c4 Bugfix 1: [triplet] Lengths (frameCounting) if given should be a range (not zero).
Vimalkumar Velayudhan <vimalkumarvelayudhan@gmail.com>
parents: 0
diff changeset
135 self.assertRaises(
423ad61697c4 Bugfix 1: [triplet] Lengths (frameCounting) if given should be a range (not zero).
Vimalkumar Velayudhan <vimalkumarvelayudhan@gmail.com>
parents: 0
diff changeset
136 ribosome_profile.RibosomeProfileError, ribosome_profile.plot_transcript,
423ad61697c4 Bugfix 1: [triplet] Lengths (frameCounting) if given should be a range (not zero).
Vimalkumar Velayudhan <vimalkumarvelayudhan@gmail.com>
parents: 0
diff changeset
137 rdata_load=self.rdata_load, transcript_name='MCUFF.37930.1',
423ad61697c4 Bugfix 1: [triplet] Lengths (frameCounting) if given should be a range (not zero).
Vimalkumar Velayudhan <vimalkumarvelayudhan@gmail.com>
parents: 0
diff changeset
138 transcript_length='27', transcript_cap='200', html_file=self.html_file,
423ad61697c4 Bugfix 1: [triplet] Lengths (frameCounting) if given should be a range (not zero).
Vimalkumar Velayudhan <vimalkumarvelayudhan@gmail.com>
parents: 0
diff changeset
139 output_path=self.output_path)