6 from htsworkflow.util.makebed import make_bed_from_eland_stream, make_bed_from_multi_eland_stream, make_description
9 parser = optparse.OptionParser()
10 parser.add_option('-e', '--eland', dest='inname',
11 help='specify input eland filename')
12 parser.add_option('-b', '--bed', dest='outname',
13 help='specify output befilename')
14 parser.add_option('-n', '--name', dest='name',
15 help='specify the track (short) name.',
17 parser.add_option('-d', '--description', dest='description',
18 help='specify the track description',
20 parser.add_option('--chromosome', dest='prefix',
21 help='Set the chromosome prefix name. defaults to "chr"',
23 parser.add_option("--database", dest='database',
24 help="specify location of fctracker database",
26 parser.add_option("--flowcell", dest='flowcell',
27 help="compute name and description from database using flowcell id",
29 parser.add_option("--lane", dest='lane',
30 help='specify which lane to use when retrieving description from database',
33 multi = optparse.OptionGroup(parser, 'Multi-read ELAND support')
35 multi.add_option('-m', '--multi', action='store_true',
36 help='Enable parsing multi-read eland files',
38 multi.add_option('--reads', type='int',
39 help='limit reporting multi reads to this many reads'
40 '(most usefully --reads=1 will turn a multi-read '
41 'file into a single read file)',
43 parser.add_option_group(multi)
47 def main(command_line=None):
51 if command_line is None:
52 command_line = sys.argv[1:]
54 parser = make_parser()
55 (options, args) = parser.parse_args(command_line)
57 if options.inname is None:
58 parser.error("Need eland input file name")
61 if options.inname == '-':
63 elif os.path.exists(options.inname):
64 instream = open(options.inname, 'r')
66 parser.error('%s was not found' % (options.inname))
69 # figure out name for output file
70 if options.outname is None:
71 # if outname wasn't defined, and we're reading from stdout
72 if instream is sys.stdin:
74 outstream = sys.stdout
76 # if there's a name write to name.bed
77 options.outname = os.path.splitext(options.inname)[0]+'.bed'
78 print >>sys.stderr, "defaulting to outputname", options.outname
79 elif options.outname == '-':
80 outstream = sys.stdout
83 if os.path.exists(options.outname):
84 parser.error("not overwriting %s" % (options.outname))
87 outstream = open(options.outname, 'w')
89 if options.flowcell is not None and options.lane is not None:
90 # get our name/description out of the database
91 name, description = make_description(
92 options.database, options.flowcell, options.lane
96 description = options.description
99 make_bed_from_multi_eland_stream(instream, outstream,
105 make_bed_from_eland_stream(instream, outstream,
110 if __name__ == "__main__":
111 sys.exit(main(sys.argv[1:]))