def main(): option_parser, opts, args = parse_command_line_parameters(**script_info) verbose = opts.verbose output_fp = opts.output_fp mapping_files = [open(fp, 'U') for fp in opts.mapping_fps] no_data_value = opts.no_data_value mapping_data = MetadataMap.mergeMappingFiles(mapping_files, no_data_value=no_data_value) with open(output_fp, 'w') as f: f.write(str(mapping_data))
def main(): option_parser, opts, args =\ parse_command_line_parameters(**script_info) if opts.show_indices: for idx_key in sorted(known_indices): idx = known_indices[idx_key] print "%s: %s, %s" % (idx_key, idx['name'], idx['source']) print '\t', 'increased:' print '\n'.join(['\t\t%s' % t for t in idx['increased']]) print '\t', 'decreased:' print '\n'.join(['\t\t%s' % t for t in idx['decreased']]) exit(0) if opts.index is not None and known_indices.get(opts.index) is None: option_parser.error("%s is not a known index. Known indices are: %s" % (opts.index, ','.join(known_indices.keys()))) if opts.index is not None and (opts.increased or opts.decreased): option_parser.error("Cannot specify both an existing and custom index") if opts.index is None and opts.increased is None and \ opts.decreased is None: option_parser.error("Must specify an existing or custom index") if opts.increased and opts.decreased is None: option_parser.error("Must specify decreased taxa") if opts.decreased and opts.increased is None: option_parser.error("Must specify increased taxa") if opts.index is not None: name = opts.name if opts.name is not None else opts.index increased = known_indices[opts.index]['increased'] decreased = known_indices[opts.index]['decreased'] else: name = opts.name if opts.name is not None else 'index' increased = set(opts.increased.split(',')) decreased = set(opts.decreased.split(',')) if opts.input is None: option_parser.error("Input not specified") if opts.output is None: option_parser.error("Output not specified") table = load_table(opts.input) if opts.mapping_file: mapping_file = open(opts.mapping_file, 'U') output_file = TemporaryFile() else: mapping_file = None output_file = open(opts.output, 'w') output_file.write("#SampleID\t%s\n" % name) for id_, value in compute_index(table, increased, decreased, opts.key): output_file.write("%s\t%f\n" % (id_, value)) if opts.mapping_file: output_file.seek(0) mapping_data = MetadataMap.mergeMappingFiles( [output_file, mapping_file], no_data_value=nan) with open(opts.output, 'w') as f: f.write(str(mapping_data)) output_file.close()
def main(): option_parser, opts, args =\ parse_command_line_parameters(**script_info) if opts.show_indices: for idx_key in sorted(known_indices): idx = known_indices[idx_key] print "%s: %s, %s" % (idx_key, idx['name'], idx['source']) print '\t', 'increased:' print '\n'.join(['\t\t%s' % t for t in idx['increased']]) print '\t', 'decreased:' print '\n'.join(['\t\t%s' % t for t in idx['decreased']]) exit(0) if opts.index is not None and known_indices.get(opts.index) is None: option_parser.error("%s is not a known index. Known indices are: %s" % (opts.index, ','.join(known_indices.keys()))) if opts.index is not None and (opts.increased or opts.decreased): option_parser.error("Cannot specify both an existing and custom index") if opts.index is None and opts.increased is None and \ opts.decreased is None: option_parser.error("Must specify an existing or custom index") if opts.increased and opts.decreased is None: option_parser.error("Must specify decreased taxa") if opts.decreased and opts.increased is None: option_parser.error("Must specify increased taxa") if opts.index is not None: name = opts.name if opts.name is not None else opts.index increased = known_indices[opts.index]['increased'] decreased = known_indices[opts.index]['decreased'] else: name = opts.name if opts.name is not None else 'index' increased = set(opts.increased.split(',')) decreased = set(opts.decreased.split(',')) if opts.input is None: option_parser.error("Input not specified") if opts.output is None: option_parser.error("Output not specified") table = load_table(opts.input) if opts.mapping_file: mapping_file = open(opts.mapping_file, 'U') output_fp = TemporaryFile() else: mapping_file = None output_fp = open(opts.output, 'w') output_fp.write("#SampleID\t%s\n" % name) for id_, value in compute_index(table, increased, decreased, opts.key): output_fp.write("%s\t%f\n" % (id_, value)) if opts.mapping_file: output_fp.seek(0) mapping_data = MetadataMap.mergeMappingFiles([output_fp, mapping_file], no_data_value=nan) with open(opts.output, 'w') as fp: fp.write(str(mapping_data)) output_fp.close()