6 from gaworkflow.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):
48 if command_line is None:
49 command_line = sys.argv[1:]
51 parser = make_parser()
52 (options, args) = parser.parse_args(command_line)
54 if options.inname is None:
55 parser.error("Need eland input file name")
58 if options.inname == '-':
60 elif os.path.exists(options.inname):
61 instream = open(options.inname, 'r')
63 parser.error('%s was not found' % (options.inname))
66 if options.outname is None:
67 # if outname wasn't defined, and we're reading from stdout
68 if instream is sys.stdin:
70 outstream = sys.stdout
72 # if there's a name write to name.bde
73 options.outname = os.path.splitext(options.inname)[0]+'.bed'
74 print >>sys.stderr, "defaulting to outputname", options.outname
75 elif options.outname == '-':
76 outstream = sys.stdout
77 elif os.path.exists(options.outname):
78 parser.error("not overwriting %s" % (options.outname))
81 outstream = open(options.outname, 'w')
83 if options.flowcell is not None and options.lane is not None:
84 # get our name/description out of the database
85 name, description = make_description(
86 options.database, options.flowcell, options.lane
90 description = options.description
93 make_bed_from_multi_eland_stream(instream, outstream,
99 make_bed_from_eland_stream(instream, outstream,
104 if __name__ == "__main__":
105 sys.exit(main(sys.argv[1:]))