def main(): option_parser, opts, args = \ parse_command_line_parameters(suppress_verbose=True, **script_info) input_dir = opts.input_dir parameter_fp = opts.parameter_fp read1_indicator = opts.read1_indicator read2_indicator = opts.read2_indicator match_barcodes = opts.match_barcodes barcode_indicator = opts.barcode_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['join_paired_ends']) 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))] pairs, bc_pairs = get_pairs(all_files, read1_indicator, read2_indicator, match_barcodes, barcode_indicator) commands = create_commands_jpe(pairs, output_dir, params_str, leading_text, trailing_text, include_input_dir_path, remove_filepath_in_name, match_barcodes, bc_pairs) 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)
def test_create_commands_jpe_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'} 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_jpe(pairs, 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 join_paired_ends.py -m OtherMethod -f dir2/f_read2.fastq -r dir2/r_read2.fastq -o output_dir/dir2 | qsub COMMANDxxx', 'Echo join_paired_ends.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_jpe_bcs(self): """ Properly creates commands with matched bcs """ pairs = {'f_read1.fastq':'r_read1.fastq', 'f_read2.fastq':'r_read2.fastq'} base_output_dir = "output_dir/" optional_params = "" leading_text = "" trailing_text = "" include_input_dir_path=False remove_filepath_in_name=False match_barcodes = True bc_pairs = {'f_read1.fastq':'b_read1.fastq', 'f_read2.fastq':'b_read2.fastq'} commands = create_commands_jpe(pairs, base_output_dir, optional_params, leading_text, trailing_text, include_input_dir_path, remove_filepath_in_name, match_barcodes, bc_pairs) actual_commands = [] for n in commands: actual_commands.append(n[0][1]) actual_commands = set(actual_commands) expected_commands = set(['join_paired_ends.py -b b_read1.fastq -f f_read1.fastq -r r_read1.fastq -o output_dir/f_read1 ', 'join_paired_ends.py -b b_read2.fastq -f f_read2.fastq -r r_read2.fastq -o output_dir/f_read2 ']) self.assertEqual(actual_commands, expected_commands)