Mercurial > repos > vimalkumarvelayudhan > riboseqr_wrapper
comparison tests/test_riboseqr.py @ 5:423ad61697c4
Bugfix 1: [triplet] Lengths (frameCounting) if given should be a range (not zero).
readingFrame function fails with subscript out of bounds.
Bugfix 2: [triplet] Check if transcript name in SAM matches the name in FASTA. Produce
an error message if it's not. This fixes the problem where an empty plot is
produced (no bars).
[ribosome_profile] - A proper error message is now produced if an invalid transcript name is
provided.
Updated test data
author | Vimalkumar Velayudhan <vimalkumarvelayudhan@gmail.com> |
---|---|
date | Tue, 27 Oct 2015 12:21:50 +0000 |
parents | c34c364ce75d |
children |
comparison
equal
deleted
inserted
replaced
2:b2eb07000039 | 5:423ad61697c4 |
---|---|
1 """riboSeqR Galaxy unit tests""" | 1 """riboSeqR Galaxy unit tests""" |
2 import os | |
3 import shutil | |
2 import unittest | 4 import unittest |
3 from riboseqr import utils | 5 import tempfile |
6 from riboseqr import utils, triplet, ribosome_profile | |
7 | |
8 DATA_DIR = 'test-data' | |
4 | 9 |
5 | 10 |
6 class PrepareTestCase(unittest.TestCase): | 11 class PrepareTestCase(unittest.TestCase): |
7 | 12 |
8 def test_process_args(self): | 13 def test_process_args(self): |
9 """Test processing arguments. """ | 14 """Test processing arguments. """ |
10 # "ATG" -> c("ATG") | 15 # "ATG" -> c("ATG") |
11 rs = utils.process_args('ATG', ret_mode='charvector') | 16 rs = utils.process_args('ATG', ret_mode='charvector') |
12 self.assertEqual(rs, 'c("ATG")','Return string as a character vector.') | 17 self.assertEqual(rs, 'c("ATG")', 'Return string as a character vector.') |
13 | 18 |
14 # stop codons "TAG,TAA,TGA" -> c("TAG", "TAA", "TGA"). Also | 19 # stop codons "TAG,TAA,TGA" -> c("TAG", "TAA", "TGA"). Also |
15 # replicate names, seqnames. | 20 # replicate names, seqnames. |
16 rs = utils.process_args('TAG,TAA,TGA', ret_mode='charvector') | 21 rs = utils.process_args('TAG,TAA,TGA', ret_mode='charvector') |
17 self.assertEqual( | 22 self.assertEqual( |
54 | 59 |
55 # 'chlamy17.idx, chlamy3.idx' -> ['chlamy17.idx', 'chlamy3.idx'] | 60 # 'chlamy17.idx, chlamy3.idx' -> ['chlamy17.idx', 'chlamy3.idx'] |
56 rs = utils.process_args('chlamy17.idx, chlamy3.idx', ret_mode='list') | 61 rs = utils.process_args('chlamy17.idx, chlamy3.idx', ret_mode='list') |
57 self.assertEqual(rs, ['chlamy17.idx', 'chlamy3.idx'], | 62 self.assertEqual(rs, ['chlamy17.idx', 'chlamy3.idx'], |
58 'Return files as a list.') | 63 'Return files as a list.') |
64 | |
65 | |
66 class TripletTestCase(unittest.TestCase): | |
67 """Test triple periodicity""" | |
68 html_file = None | |
69 output_path = None | |
70 rdata_load = os.path.join(DATA_DIR, 'Prepare riboSeqR input (R data file)') | |
71 rdata_save = None | |
72 include_lengths = '25:30' | |
73 analyze_plot_lengths = '26:30' | |
74 | |
75 def setUp(self): | |
76 self.html_file, self.output_path = tempfile.mkstemp()[1], tempfile.mkdtemp() | |
77 self.rdata_save = os.path.join(self.output_path, 'Periodicity.rda') | |
78 | |
79 def tearDown(self): | |
80 os.remove(self.html_file) | |
81 shutil.rmtree(self.output_path) | |
82 | |
83 def test_triplet_periodicity(self): | |
84 """Given a prepared RDA file, produce triplet periodicity output (R data file and plots). | |
85 | |
86 Note: only checks for the presence of program outputs | |
87 """ | |
88 triplet.find_periodicity( | |
89 rdata_load=self.rdata_load, | |
90 fasta_file=os.path.join(DATA_DIR, 'rsem_chlamy236_deNovo.transcripts.fa'), | |
91 include_lengths=self.include_lengths, analyze_plot_lengths=self.analyze_plot_lengths, | |
92 html_file=self.html_file, output_path=self.output_path, | |
93 rdata_save=self.rdata_save) | |
94 | |
95 for output in ('periodicity.R', 'Periodicity.rda', 'Periodicity-plot.pdf', 'Periodicity-plot.png'): | |
96 self.assertTrue(os.path.exists(os.path.join(self.output_path, output))) | |
97 | |
98 def test_transcript_name(self): | |
99 """Check that the transcript name is the same in the SAM and FASTA file. If not, raise an error.""" | |
100 self.assertRaises( | |
101 triplet.TripletPeriodicityError, triplet.find_periodicity, | |
102 rdata_load=self.rdata_load, | |
103 fasta_file=os.path.join(DATA_DIR, 'rsem_chlamy236_deNovo.transcripts_mod.fa'), | |
104 include_lengths=self.include_lengths, analyze_plot_lengths=self.analyze_plot_lengths, | |
105 html_file=self.html_file, output_path=self.output_path, | |
106 rdata_save=self.rdata_save) | |
107 | |
108 | |
109 class RibosomeProfileTestCase(unittest.TestCase): | |
110 """Test plot ribosome profile.""" | |
111 html_file = None | |
112 output_path = None | |
113 rdata_load = os.path.join(DATA_DIR, 'Metagene analysis (R data file)') | |
114 | |
115 def setUp(self): | |
116 self.html_file, self.output_path = tempfile.mkstemp()[1], tempfile.mkdtemp() | |
117 | |
118 def tearDown(self): | |
119 os.remove(self.html_file) | |
120 shutil.rmtree(self.output_path) | |
121 | |
122 def test_plot_ribosome_profile(self): | |
123 """Given the right transcript name, produce a profile plot. """ | |
124 ribosome_profile.plot_transcript( | |
125 rdata_load=self.rdata_load, transcript_name='CUFF.37930.1', | |
126 transcript_length='27', transcript_cap='200', html_file=self.html_file, | |
127 output_path=self.output_path) | |
128 | |
129 for output in ('ribosome-profile.R', 'Ribosome-profile-plot.pdf', 'Ribosome-profile-plot_1.png', | |
130 'Ribosome-profile-plot_2.png', 'Ribosome-profile-plot_3.png', 'Ribosome-profile-plot_4.png'): | |
131 self.assertTrue(os.path.exists(os.path.join(self.output_path, output))) | |
132 | |
133 def test_invalid_transcript(self): | |
134 """If a transcript is missing, produce an error message.""" | |
135 self.assertRaises( | |
136 ribosome_profile.RibosomeProfileError, ribosome_profile.plot_transcript, | |
137 rdata_load=self.rdata_load, transcript_name='MCUFF.37930.1', | |
138 transcript_length='27', transcript_cap='200', html_file=self.html_file, | |
139 output_path=self.output_path) |