#!/usr/bin/python '''' get bed format from the output of extract_bundle_info ''' import sys import os def line_to_list(line): return line.rstrip('\n').split('\t') def get_usage_instruction(option, desc, value=''): return '\t%s\t%s\t%s' % (option, value, desc) def remove_first_line(reader): reader.readline() return reader def get_output_line(l_line): return '\t'.join(l_line) + '\n' def file_to_list(f): out_list = [] with open(f) as reader: for line in reader: out_list.append(line.rstrip('\n')) return out_list def prepare_dir(d): if not os.path.exists(d): os.makedirs(d) def usage(me): print 'Usage:\tpython %s bundle_file bed_file' % me def modify_start_for_bed(s_start): i_start = int(s_start) i_start -= 1 return str(i_start) def main(bundle_file, bed_file): with open(bundle_file) as reader, open(bed_file, 'w') as writer: reader = remove_first_line(reader) for line in reader: l_line = line_to_list(line) name, chr, start, end = l_line[:4] start = modify_start_for_bed(start) out_bed = get_output_line([chr, start, end, name]) writer.write(out_bed) if __name__ == '__main__': me = sys.argv[0] bundle_file = '' bed_file = '' try: bundle_file = sys.argv[1] bed_file = sys.argv[2] except IndexError: usage(me) sys.exit(1) main(bundle_file, bed_file)