Fix typo in srf command
[htsworkflow.git] / scripts / makebed
index a4a414b27d57608d89cc5dca4b9b93f629c2fb62..577b86891f098ab5c7cfeb6e2b4139814f1731a5 100755 (executable)
@@ -3,7 +3,8 @@ import optparse
 import sys
 import os
 
-from gaworkflow.util.makebed import make_bed_from_eland_stream, make_bed_from_multi_eland_stream, make_description
+from htsworkflow.util.opener import autoopen
+from htsworkflow.util.makebed import make_bed_from_eland_stream, make_bed_from_multi_eland_stream, make_description
 
 def make_parser():
   parser = optparse.OptionParser()
@@ -45,6 +46,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:]
 
@@ -58,27 +62,30 @@ def main(command_line=None):
   if options.inname == '-':
     instream = sys.stdin
   elif os.path.exists(options.inname):
-    instream = open(options.inname, 'r')
+    instream = autoopen(options.inname, 'r')
   else:
     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