@@ -163,8 +163,8 @@ def test_get_preprocess_fasta_cmd_sff_no_run_prefix(self):
163
163
raw_data , prep_template , params )
164
164
165
165
get_raw_path = partial (join , self .db_dir , 'raw_data' )
166
- seqs_fp = [get_raw_path ('preprocess_test1 .sff' ),
167
- get_raw_path ('preprocess_test2 .sff' )]
166
+ seqs_fp = [get_raw_path ('1_preprocess_test1 .sff' ),
167
+ get_raw_path ('1_preprocess_test2 .sff' )]
168
168
169
169
exp_cmd_1 = ' ' .join (["process_sff.py" ,
170
170
"-i %s" % seqs_fp [0 ],
@@ -173,10 +173,12 @@ def test_get_preprocess_fasta_cmd_sff_no_run_prefix(self):
173
173
"-i %s" % seqs_fp [1 ],
174
174
"-o %s" % obs_output_dir ])
175
175
176
- fasta_files = ',' .join ([join (obs_output_dir , "preprocess_test1.fna" ),
177
- join (obs_output_dir , "preprocess_test2.fna" )])
178
- qual_files = ',' .join ([join (obs_output_dir , "preprocess_test1.qual" ),
179
- join (obs_output_dir , "preprocess_test2.qual" )])
176
+ fasta_files = ',' .join ([
177
+ join (obs_output_dir , "1_preprocess_test1.fna" ),
178
+ join (obs_output_dir , "1_preprocess_test2.fna" )])
179
+ qual_files = ',' .join ([
180
+ join (obs_output_dir , "1_preprocess_test1.qual" ),
181
+ join (obs_output_dir , "1_preprocess_test2.qual" )])
180
182
exp_cmd_3a = ' ' .join (["split_libraries.py" ,
181
183
"-f %s" % fasta_files ])
182
184
@@ -208,8 +210,8 @@ def test_get_preprocess_fasta_cmd_sff_run_prefix(self):
208
210
# Need to alter the run_prefix of one sample so we can test the
209
211
# multiple values
210
212
conn_handler = SQLConnectionHandler ()
211
- sql = ("UPDATE qiita.prep_1 SET run_prefix='test ' WHERE "
212
- "sample_id ='1.SKM9.640192'" )
213
+ sql = ("UPDATE qiita.prep_1 SET run_prefix='test1 ' WHERE "
214
+ "sample_id = '1.SKM9.640192'" )
213
215
conn_handler .execute (sql )
214
216
215
217
raw_data = RawData (3 )
@@ -223,19 +225,113 @@ def test_get_preprocess_fasta_cmd_sff_run_prefix(self):
223
225
# assumming that test_get_preprocess_fasta_cmd_sff_no_run_prefix is
224
226
# working we only need to test for the commands being ran and
225
227
# that n is valid
226
- self .assertTrue (len (obs_cmds ) == 8 )
228
+ self .assertEqual (len (obs_cmds ), 8 )
227
229
self .assertTrue (obs_cmds [0 ].startswith ('process_sff.py' ))
228
230
self .assertTrue (obs_cmds [1 ].startswith ('process_sff.py' ))
229
231
self .assertTrue (obs_cmds [2 ].startswith ('split_libraries.py' ))
230
- self .assertTrue ('-n 1' in obs_cmds [2 ])
232
+ self .assertIn ('-n 1' , obs_cmds [2 ])
231
233
self .assertTrue (obs_cmds [3 ].startswith ('split_libraries.py' ))
232
- self .assertTrue ('-n 800000' in obs_cmds [3 ])
234
+ self .assertIn ('-n 800000' , obs_cmds [3 ])
233
235
self .assertTrue (obs_cmds [4 ].startswith ('cat' ))
234
- self .assertTrue ('split_library_log.txt' in obs_cmds [4 ])
236
+ self .assertIn ('split_library_log.txt' , obs_cmds [4 ])
235
237
self .assertTrue (obs_cmds [5 ].startswith ('cat' ))
236
- self .assertTrue ('seqs.fna' in obs_cmds [5 ])
238
+ self .assertTrue ('seqs.fna' , obs_cmds [5 ])
237
239
self .assertTrue (obs_cmds [6 ].startswith ('cat' ))
238
- self .assertTrue ('seqs_filtered.qual' in obs_cmds [6 ])
240
+ self .assertIn ('seqs_filtered.qual' , obs_cmds [6 ])
241
+
242
+ def test_get_preprocess_fasta_cmd_sff_run_prefix_match (self ):
243
+ # Test that the run prefixes in the prep_template and the file names
244
+ # actually match and raise an error if not
245
+ conn_handler = SQLConnectionHandler ()
246
+ sql = ("""
247
+ INSERT INTO qiita.filepath (filepath_id, filepath,
248
+ filepath_type_id, checksum, checksum_algorithm_id,
249
+ data_directory_id) VALUES (19, '1_new.sff', 17, 852952723, 1,
250
+ 5);
251
+ INSERT INTO qiita.raw_filepath (raw_data_id , filepath_id) VALUES
252
+ (3, 19);
253
+ UPDATE qiita.prep_1 SET run_prefix='preprocess_test';
254
+ UPDATE qiita.prep_1 SET run_prefix='new' WHERE
255
+ sample_id = '1.SKB8.640193';
256
+ """ )
257
+ conn_handler .execute (sql )
258
+
259
+ raw_data = RawData (3 )
260
+ params = Preprocessed454Params (1 )
261
+ prep_template = PrepTemplate (1 )
262
+
263
+ obs_cmd , obs_output_dir = _get_preprocess_fasta_cmd (
264
+ raw_data , prep_template , params )
265
+
266
+ obs_cmds = obs_cmd .split ('; ' )
267
+ # assumming that test_get_preprocess_fasta_cmd_sff_no_run_prefix is
268
+ # working we only need to test for the commands being ran and
269
+ # that n is valid
270
+ self .assertEqual (len (obs_cmds ), 9 )
271
+ self .assertTrue (obs_cmds [0 ].startswith ('process_sff.py' ))
272
+ self .assertTrue (obs_cmds [1 ].startswith ('process_sff.py' ))
273
+ self .assertTrue (obs_cmds [2 ].startswith ('process_sff.py' ))
274
+ self .assertTrue (obs_cmds [3 ].startswith ('split_libraries.py' ))
275
+ self .assertIn ('-n 1' , obs_cmds [3 ])
276
+ self .assertTrue (obs_cmds [4 ].startswith ('split_libraries.py' ))
277
+ self .assertIn ('-n 800000' , obs_cmds [4 ])
278
+ self .assertTrue (obs_cmds [5 ].startswith ('cat' ))
279
+ self .assertIn ('split_library_log.txt' , obs_cmds [5 ])
280
+ self .assertTrue (obs_cmds [6 ].startswith ('cat' ))
281
+ self .assertIn ('seqs.fna' , obs_cmds [6 ])
282
+ self .assertEqual (len (obs_cmds [6 ].split (' ' )), 5 )
283
+ self .assertTrue (obs_cmds [7 ].startswith ('cat' ))
284
+ self .assertIn ('seqs_filtered.qual' , obs_cmds [7 ])
285
+ self .assertEqual (len (obs_cmds [7 ].split (' ' )), 5 )
286
+
287
+ def test_get_preprocess_fasta_cmd_sff_run_prefix_match_error_1 (self ):
288
+ # Test that the run prefixes in the prep_template and the file names
289
+ # actually match and raise an error if not
290
+ conn_handler = SQLConnectionHandler ()
291
+ sql = ("""
292
+ INSERT INTO qiita.filepath (filepath_id, filepath,
293
+ filepath_type_id, checksum, checksum_algorithm_id,
294
+ data_directory_id) VALUES (19, '1_new.sff', 17, 852952723, 1,
295
+ 5);
296
+ INSERT INTO qiita.raw_filepath (raw_data_id , filepath_id) VALUES
297
+ (3, 19);
298
+ INSERT INTO qiita.filepath (filepath_id, filepath,
299
+ filepath_type_id, checksum, checksum_algorithm_id,
300
+ data_directory_id) VALUES (20, '1_error.sff', 17, 852952723,
301
+ 1, 5);
302
+ INSERT INTO qiita.raw_filepath (raw_data_id , filepath_id) VALUES
303
+ (3, 20);
304
+ UPDATE qiita.prep_1 SET run_prefix='preprocess_test';
305
+ UPDATE qiita.prep_1 SET run_prefix='new' WHERE
306
+ sample_id = '1.SKB8.640193';
307
+ """ )
308
+ conn_handler .execute (sql )
309
+
310
+ raw_data = RawData (3 )
311
+ params = Preprocessed454Params (1 )
312
+ prep_template = PrepTemplate (1 )
313
+
314
+ with self .assertRaises (ValueError ):
315
+ _get_preprocess_fasta_cmd (raw_data , prep_template , params )
316
+
317
+ def test_get_preprocess_fasta_cmd_sff_run_prefix_match_error_2 (self ):
318
+ # Should raise error
319
+ conn_handler = SQLConnectionHandler ()
320
+ sql = ("""
321
+ UPDATE qiita.prep_1 SET run_prefix='test1';
322
+ UPDATE qiita.prep_1 SET run_prefix='test2' WHERE
323
+ sample_id = '1.SKB2.640194';
324
+ UPDATE qiita.prep_1 SET run_prefix='error' WHERE
325
+ sample_id = '1.SKB8.640193';
326
+ """ )
327
+ conn_handler .execute (sql )
328
+
329
+ raw_data = RawData (3 )
330
+ params = Preprocessed454Params (1 )
331
+ prep_template = PrepTemplate (1 )
332
+
333
+ with self .assertRaises (ValueError ):
334
+ _get_preprocess_fasta_cmd (raw_data , prep_template , params )
239
335
240
336
def test_insert_preprocessed_data (self ):
241
337
study = Study (1 )
0 commit comments