From: Diane Trout Date: Mon, 22 Dec 2008 20:43:32 +0000 (+0000) Subject: clean up the logic for deciding the output filename when using stdin X-Git-Tag: stanford.caltech-merged-database-2009-jan-15~12 X-Git-Url: http://woldlab.caltech.edu/gitweb/?p=htsworkflow.git;a=commitdiff_plain;h=d624ebe5f7269bd0989419758fb190609700564d clean up the logic for deciding the output filename when using stdin as the input --- diff --git a/scripts/makebed b/scripts/makebed index 4878697..64ba518 100755 --- a/scripts/makebed +++ b/scripts/makebed @@ -45,6 +45,9 @@ def make_parser(): return parser def main(command_line=None): + instream = None + outstream = None + if command_line is None: command_line = sys.argv[1:] @@ -63,22 +66,25 @@ def main(command_line=None): parser.error('%s was not found' % (options.inname)) return 1 + # figure out name for output file if options.outname is None: # if outname wasn't defined, and we're reading from stdout if instream is sys.stdin: # write to stdout outstream = sys.stdout else: - # if there's a name write to name.bde + # if there's a name write to name.bed options.outname = os.path.splitext(options.inname)[0]+'.bed' print >>sys.stderr, "defaulting to outputname", options.outname elif options.outname == '-': outstream = sys.stdout - elif os.path.exists(options.outname): - parser.error("not overwriting %s" % (options.outname)) - return 1 - else: - outstream = open(options.outname, 'w') + + if outstream is None: + if os.path.exists(options.outname): + parser.error("not overwriting %s" % (options.outname)) + return 1 + else: + outstream = open(options.outname, 'w') if options.flowcell is not None and options.lane is not None: # get our name/description out of the database