def yield_subset_biom_str(biom_str, new_data, new_axis_md, axis): """Sequentially yield the components of a reduced biom string""" if axis not in ['samples', 'observations']: raise InputError(\ 'yield_subset_biom_str axis parameter must be either "samples" or "observations"') # Still has multiple walks over the file. bad form, but easy right now yield "{" keys = ["id","format","format_url","type",\ "generated_by","date","matrix_type",\ "matrix_element_type"] for key in keys: yield direct_parse_key(biom_str, key) yield "," for entry in [new_data, new_axis_md]: yield entry yield "," if axis == "observations": yield direct_parse_key(biom_str, "columns") else: yield direct_parse_key(biom_str, "rows") yield "}"
def yield_subset_biom_str(biom_str,new_data,new_axis_md,axis): """Sequentially yield the components of a reduced biom string""" if axis not in ['samples','observations']: raise InputError(\ 'yield_subset_biom_str axis parameter must be either "samples" or "observations"') # Still has multiple walks over the file. bad form, but easy right now yield "{" keys = ["id","format","format_url","type",\ "generated_by","date","matrix_type",\ "matrix_element_type"] for key in keys: yield direct_parse_key(biom_str,key) yield "," for entry in [new_data,new_axis_md]: yield entry yield "," if axis == "observations": yield direct_parse_key(biom_str, "columns") else: yield direct_parse_key(biom_str, "rows") yield "}"
def subset_generator(): yield "{" yield direct_parse_key(table_str, "id") yield "," yield direct_parse_key(table_str, "format") yield "," yield direct_parse_key(table_str, "format_url") yield "," yield direct_parse_key(table_str, "type") yield "," yield direct_parse_key(table_str, "generated_by") yield "," yield direct_parse_key(table_str, "date") yield "," yield direct_parse_key(table_str, "matrix_type") yield "," yield direct_parse_key(table_str, "matrix_element_type") yield "," yield new_data yield "," yield new_axis_md yield "," if axis == "observations": yield direct_parse_key(table_str, "columns") else: yield direct_parse_key(table_str, "rows") yield "}"
def subset_generator(): yield "{" yield direct_parse_key(json_table_str, "id") yield "," yield direct_parse_key(json_table_str, "format") yield "," yield direct_parse_key(json_table_str, "format_url") yield "," yield direct_parse_key(json_table_str, "type") yield "," yield direct_parse_key(json_table_str, "generated_by") yield "," yield direct_parse_key(json_table_str, "date") yield "," yield direct_parse_key(json_table_str, "matrix_type") yield "," yield direct_parse_key(json_table_str, "matrix_element_type") yield "," yield new_data yield "," yield new_axis_md yield "," if axis == "observation": yield direct_parse_key(json_table_str, "columns") else: yield direct_parse_key(json_table_str, "rows") yield "}"
parse_command_line_parameters(**script_info) else: parser = OptionParser(option_list=options) opts, args = parser.parse_args() ids = [l.strip() for l in open(opts.ids_fp)] biom_str = open(opts.biom_fp).read() idxs, new_axis_md = get_axis_indices(biom_str, ids, opts.axis) new_data = direct_slice_data(biom_str, idxs, opts.axis) output = open(opts.output_fp,'w') # multiple walks over the file. bad form, but easy right now # ...should add a yield_and_ignore parser or something. output.write('{') output.write(direct_parse_key(biom_str, "id")) output.write(",") output.write(direct_parse_key(biom_str, "format")) output.write(",") output.write(direct_parse_key(biom_str, "format_url")) output.write(",") output.write(direct_parse_key(biom_str, "type")) output.write(",") output.write(direct_parse_key(biom_str, "generated_by")) output.write(",") output.write(direct_parse_key(biom_str, "date")) output.write(",") output.write(direct_parse_key(biom_str, "matrix_type")) output.write(",") output.write(direct_parse_key(biom_str, "matrix_element_type")) output.write(",")