def main():
    option_parser, opts, args = parse_command_line_parameters(**script_info)

    if len(args) != 0:
        parser.error("Positional argument detected.  make sure all" +
                     ' parameters are identified.' +
                     '\ne.g.: include the \"-m\" in \"-m MINIMUM_LENGTH\"')

    input_dir = opts.input_path
    output_dir = opts.output_path
    example_filepath = opts.example_path

    if not os.path.exists(output_dir):
        os.makedirs(output_dir)

    file_names = os.listdir(input_dir)
    file_names = [fname for fname in file_names if not fname.startswith('.')]

    if example_filepath is None:
        # table row is base_name, seqs_per_sam, iters, ext
        file_name_table = map(parse_rarefaction_fname, file_names)
        # sort on seqs/sam
        sorted_fname_table = sorted(
            file_name_table,
            key=operator.itemgetter(1))
        # now map back to file name
        example_fname = file_names[
            file_name_table.index(sorted_fname_table[0])]
        example_filepath = os.path.join(input_dir, example_fname)
    f = open(example_filepath, 'U')
    all_metrics, all_samples, example_data = parse_matrix(f)
    num_cols = len(all_samples)
    f.close()

    # make the table 1 row at a time
    # we're building a rarefaction by sample mtx from
    # a sample by metric matrix
    # each metric is one output file
    for metric in all_metrics:
        metric_file_data = []
        for fname in file_names:
            # f_ here refers to the input file currently being processed
            # to distinguish from the output file we're building
            f = open(os.path.join(input_dir, fname), 'U')
            f_metrics, f_samples, f_data = parse_matrix(f)
            f.close()
            metric_file_data.append(
                make_output_row(f_metrics, metric, f_samples,
                                f_data, fname, num_cols, all_samples))

        write_output_file(metric_file_data, output_dir, metric, all_samples)
Exemple #2
0
def main():
    option_parser, opts, args = parse_command_line_parameters(**script_info)

    if len(args) != 0:
        parser.error("Positional argument detected.  make sure all" +
                     ' parameters are identified.' +
                     '\ne.g.: include the \"-m\" in \"-m MINIMUM_LENGTH\"')

    input_dir = opts.input_path
    output_dir = opts.output_path
    example_filepath = opts.example_path

    if not os.path.exists(output_dir):
        os.makedirs(output_dir)

    file_names = os.listdir(input_dir)
    file_names = [fname for fname in file_names if not fname.startswith('.')]

    if example_filepath is None:
        # table row is base_name, seqs_per_sam, iters, ext
        file_name_table = map(parse_rarefaction_fname, file_names)
        # sort on seqs/sam
        sorted_fname_table = sorted(
            file_name_table,
            key=operator.itemgetter(1))
        # now map back to file name
        example_fname = file_names[
            file_name_table.index(sorted_fname_table[0])]
        example_filepath = os.path.join(input_dir, example_fname)
    f = open(example_filepath, 'U')
    all_metrics, all_samples, example_data = parse_matrix(f)
    num_cols = len(all_samples)
    f.close()

    # make the table 1 row at a time
    # we're building a rarefaction by sample mtx from
    # a sample by metric matrix
    # each metric is one output file
    for metric in all_metrics:
        metric_file_data = []
        for fname in file_names:
            # f_ here refers to the input file currently being processed
            # to distinguish from the output file we're building
            f = open(os.path.join(input_dir, fname), 'U')
            f_metrics, f_samples, f_data = parse_matrix(f)
            f.close()
            metric_file_data.append(
                make_output_row(f_metrics, metric, f_samples,
                                f_data, fname, num_cols, all_samples))

        write_output_file(metric_file_data, output_dir, metric, all_samples)