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 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)
Example #3
0
    def test_get_pairs(self):
        """ Properly returns pairs of matching fastq forward/reverse reads """

        read1_indicator = "_R1_"
        read2_indicator = "_R2_"
        input_forward_reads = ['/home/reads/read1_R1_000.fastq',
            '/home/reads/read1_R2_000.fastq', '/home/not_a_matched_read/_R1_']
        actual_paired_reads, actual_bc_reads =\
            get_pairs(input_forward_reads, read1_indicator, read2_indicator)

        expected_paired_reads =\
            {'/home/reads/read1_R1_000.fastq':'/home/reads/read1_R2_000.fastq'}
        expected_bc_reads = {}

        self.assertEqual(actual_paired_reads, expected_paired_reads)
        self.assertEqual(actual_bc_reads, expected_bc_reads)
Example #4
0
    def test_get_pairs(self):
        """ Properly returns pairs of matching fastq forward/reverse reads """

        read1_indicator = "_R1_"
        read2_indicator = "_R2_"
        input_forward_reads = ['/home/reads/read1_R1_000.fastq',
            '/home/reads/read1_R2_000.fastq', '/home/not_a_matched_read/_R1_']
        actual_paired_reads, actual_bc_reads =\
            get_pairs(input_forward_reads, read1_indicator, read2_indicator)

        expected_paired_reads =\
            {'/home/reads/read1_R1_000.fastq':'/home/reads/read1_R2_000.fastq'}
        expected_bc_reads = {}

        self.assertEqual(actual_paired_reads, expected_paired_reads)
        self.assertEqual(actual_bc_reads, expected_bc_reads)
Example #5
0
    def test_get_pairs_bcs(self):
        """ Properly returns pairs of matching reads plus barcodes """

        read1_indicator = "_R1_"
        read2_indicator = "_R2_"
        input_forward_reads = ['/home/reads/read1_R1_000.fastq',
            '/home/reads/read1_R2_000.fastq', '/home/not_a_matched_read/_R1_',
            '/home/reads/read1_I1_000.fastq']
        actual_paired_reads, actual_bc_reads =\
            get_pairs(input_forward_reads, read1_indicator, read2_indicator,
            match_barcodes = True)

        expected_paired_reads =\
            {'/home/reads/read1_R1_000.fastq':'/home/reads/read1_R2_000.fastq'}
        expected_bc_reads = \
            {'/home/reads/read1_R1_000.fastq':'/home/reads/read1_I1_000.fastq'}

        self.assertEqual(actual_paired_reads, expected_paired_reads)
        self.assertEqual(actual_bc_reads, expected_bc_reads)
Example #6
0
    def test_get_pairs_bcs(self):
        """ Properly returns pairs of matching reads plus barcodes """

        read1_indicator = "_R1_"
        read2_indicator = "_R2_"
        input_forward_reads = ['/home/reads/read1_R1_000.fastq',
            '/home/reads/read1_R2_000.fastq', '/home/not_a_matched_read/_R1_',
            '/home/reads/read1_I1_000.fastq']
        actual_paired_reads, actual_bc_reads =\
            get_pairs(input_forward_reads, read1_indicator, read2_indicator,
            match_barcodes = True)

        expected_paired_reads =\
            {'/home/reads/read1_R1_000.fastq':'/home/reads/read1_R2_000.fastq'}
        expected_bc_reads = \
            {'/home/reads/read1_R1_000.fastq':'/home/reads/read1_I1_000.fastq'}

        self.assertEqual(actual_paired_reads, expected_paired_reads)
        self.assertEqual(actual_bc_reads, expected_bc_reads)