def main(): option_parser, opts, args =\ parse_command_line_parameters(**script_info) otu_table_data = parse_biom_table(open(opts.input_otu_table, 'U')) sort_field = opts.sort_field mapping_fp = opts.mapping_fp sorted_sample_ids_fp = opts.sorted_sample_ids_fp if sort_field and mapping_fp: mapping_data = parse_mapping_file(open(mapping_fp, 'U')) result = sort_otu_table_by_mapping_field(otu_table_data, mapping_data, sort_field) elif sorted_sample_ids_fp: sorted_sample_ids = sample_ids_from_f(open(sorted_sample_ids_fp, 'U')) result = sort_otu_table(otu_table_data, sorted_sample_ids) else: result = sort_otu_table( otu_table_data, natsort_case_insensitive(otu_table_data.SampleIds)) # format and write the otu table result_str = format_biom_table(result) of = open(opts.output_fp, 'w') of.write(result_str) of.close()
def main(): option_parser, opts, args =\ parse_command_line_parameters(**script_info) otu_table_data = parse_biom_table(open(opts.input_otu_table,'U')) sort_field = opts.sort_field mapping_fp = opts.mapping_fp sorted_sample_ids_fp = opts.sorted_sample_ids_fp if sort_field and mapping_fp: mapping_data = parse_mapping_file(open(mapping_fp,'U')) result = sort_otu_table_by_mapping_field(otu_table_data, mapping_data, sort_field) elif sorted_sample_ids_fp: sorted_sample_ids = sample_ids_from_f(open(sorted_sample_ids_fp,'U')) result = sort_otu_table(otu_table_data, sorted_sample_ids) else: result = sort_otu_table(otu_table_data, natsort_case_insensitive(otu_table_data.SampleIds)) # format and write the otu table result_str = format_biom_table(result) of = open(opts.output_fp,'w') of.write(result_str) of.close()
def test_sort_otu_table(self): """ sort_otu_table fns as expected """ actual = sort_otu_table(parse_biom_table_str(self.otu_table1), ['NA','Key','Fing']) expected = parse_biom_table_str(self.age_sorted_otu_table1) self.assertEqual(actual, expected)
def main(): option_parser, opts, args =\ parse_command_line_parameters(**script_info) otu_table_data = parse_otu_table(open(opts.input_otu_table,'U')) sort_field = opts.sort_field mapping_fp = opts.mapping_fp sorted_sample_ids_fp = opts.sorted_sample_ids_fp if sort_field and mapping_fp: mapping_data = parse_mapping_file(open(mapping_fp,'U')) result = sort_otu_table_by_mapping_field(otu_table_data, mapping_data, sort_field) elif sorted_sample_ids_fp: sorted_sample_ids = sample_ids_from_f(open(sorted_sample_ids_fp,'U')) result = sort_otu_table(otu_table_data, sorted_sample_ids) else: parser.error("must provide either --sort_field and --mapping_fp OR --sorted_sample_ids_fp") # format and write the otu table result_str = format_otu_table(result[0],result[1],result[2],result[3]) of = open(opts.output_fp,'w') of.write(result_str) of.close()
def main(): option_parser, opts, args = parse_command_line_parameters(**script_info) otu_table_data = load_table(opts.input_otu_table) sort_field = opts.sort_field mapping_fp = opts.mapping_fp sorted_sample_ids_fp = opts.sorted_sample_ids_fp if sort_field and mapping_fp: mapping_data = parse_mapping_file(open(mapping_fp, 'U')) result = sort_otu_table_by_mapping_field(otu_table_data, mapping_data, sort_field) elif sorted_sample_ids_fp: sorted_sample_ids = sample_ids_from_f(open(sorted_sample_ids_fp, 'U')) result = sort_otu_table(otu_table_data, sorted_sample_ids) else: result = sort_otu_table(otu_table_data, natsort_case_insensitive(otu_table_data.ids())) write_biom_table(result, opts.output_fp)
def test_sort_otu_table(self): """ sort_otu_table fns as expected """ actual = sort_otu_table(parse_otu_table(self.otu_table1), ['NA','Key','Fing']) expected = parse_otu_table(self.age_sorted_otu_table1) # sample ids match expected self.assertEqual(actual[0],expected[0]) # otu ids match expected self.assertEqual(actual[1],expected[1]) # otu data match expected self.assertEqual(actual[2],expected[2]) # taxa match expected self.assertEqual(actual[3],expected[3])