Implement writing to compressed files for qseq2fastq
[htsworkflow.git] / htsworkflow / pipelines / desplit_fastq.py
index 46a75094a351802b4e3c8e7f02449ebf2d737602..d3db078b0daad29524f8deea9477a796efbdcd9f 100644 (file)
@@ -30,12 +30,7 @@ def main(cmdline=None):
         return 0
 
     if opts.output is not None:
-        if opts.bzip:
-            output = bz2.open(opts.output, 'wt')
-        elif opts.gzip:
-            output = gzip.open(opts.output, 'wt')
-        else:
-            output = open(opts.output, 'w')
+        output = open_output(opts.output, opts)
     else:
         output = sys.stdout
 
@@ -66,6 +61,17 @@ def make_parser():
     return parser
 
 
+def open_output(output, opts):
+    """Open output file with right compression library
+    """
+    if opts.bzip:
+        return bz2.open(output, 'wt')
+    elif opts.gzip:
+        return gzip.open(output, 'wt')
+    else:
+        return open(output, 'w')
+
+
 def file_generator(pattern_list):
     """Given a list of glob patterns return decompressed streams
     """