def test_create_commands_eb_added_options(self): """ Properly creates commands with all optional parameters """ pairs = {'dir1/f_read1.fastq':'dir1/r_read1.fastq', 'dir2/f_read2.fastq':'dir2/r_read2.fastq'} ispaired = True base_output_dir = "output_dir/" optional_params = "-m OtherMethod" leading_text = "Echo" trailing_text = "| qsub COMMANDxxx" include_input_dir_path=True remove_filepath_in_name=True commands = create_commands_eb(pairs, ispaired, base_output_dir, optional_params, leading_text, trailing_text, include_input_dir_path, remove_filepath_in_name) actual_commands = [] for n in commands: actual_commands.append(n[0][1]) actual_commands = set(actual_commands) expected_commands = set(['Echo extract_barcodes.py -m OtherMethod -f dir2/f_read2.fastq -r dir2/r_read2.fastq -o output_dir/dir2 | qsub COMMANDxxx', 'Echo extract_barcodes.py -m OtherMethod -f dir1/f_read1.fastq -r dir1/r_read1.fastq -o output_dir/dir1 | qsub COMMANDxxx']) self.assertEqual(actual_commands, expected_commands)
def test_create_commands_eb_unpaired(self): """ Properly creates commands """ pairs = ['read1.fastq','read2.fastq'] ispaired = False base_output_dir = "output_dir/" optional_params = "" leading_text = "" trailing_text = "" include_input_dir_path=False remove_filepath_in_name=False commands = create_commands_eb(pairs, ispaired, base_output_dir, optional_params, leading_text, trailing_text, include_input_dir_path, remove_filepath_in_name) actual_commands = [] for n in commands: actual_commands.append(n[0][1]) actual_commands = set(actual_commands) expected_commands = set(['extract_barcodes.py -f read1.fastq -o output_dir/read1 ', 'extract_barcodes.py -f read2.fastq -o output_dir/read2 ']) self.assertEqual(actual_commands, expected_commands)
def main(): option_parser, opts, args = \ parse_command_line_parameters(suppress_verbose=True, **script_info) input_dir = opts.input_dir paired_data = opts.paired_data parameter_fp = opts.parameter_fp read1_indicator = opts.read1_indicator read2_indicator = opts.read2_indicator leading_text = opts.leading_text trailing_text = opts.trailing_text include_input_dir_path = opts.include_input_dir_path output_dir = abspath(opts.output_dir) remove_filepath_in_name = opts.remove_filepath_in_name print_only = opts.print_only if remove_filepath_in_name and not include_input_dir_path: option_parser.error("If --remove_filepath_in_name is enabled, " "--include_input_dir_path must also be enabled.") if opts.parameter_fp: with open(opts.parameter_fp, 'U') as parameter_f: params_dict = parse_qiime_parameters(parameter_f) params_str = get_params_str(params_dict['extract_barcodes']) else: params_dict = {} params_str = "" create_dir(output_dir) all_files = [] extensions = ['.fastq.gz', '.fastq', '.fq.gz', '.fq'] for root, dir, fps in walk(input_dir): for fp in fps: for extension in extensions: if fp.endswith(extension): all_files += [abspath(join(root, fp))] if paired_data: all_files, bc_pairs = get_pairs(all_files, read1_indicator, read2_indicator) commands = create_commands_eb(all_files, paired_data, output_dir, params_str, leading_text, trailing_text, include_input_dir_path, remove_filepath_in_name) qiime_config = load_qiime_config() if print_only: command_handler = print_commands else: command_handler = call_commands_serially logger = WorkflowLogger(generate_log_fp(output_dir), params=params_dict, qiime_config=qiime_config) # Call the command handler on the list of commands command_handler(commands, status_update_callback = no_status_updates, logger=logger, close_logger_on_success=True)