Add option to compress fastq file
authorDiane Trout <diane@ghic.org>
Tue, 18 Feb 2014 23:34:14 +0000 (15:34 -0800)
committerDiane Trout <diane@caltech.edu>
Tue, 18 Feb 2014 23:36:17 +0000 (15:36 -0800)
htsworkflow/pipelines/desplit_fastq.py

index 2ad853c1fe2053f91ffaf19268264b159798e520..83a995588079f34088e5b07ac7d098bfb08b3072 100644 (file)
@@ -1,7 +1,8 @@
 #!/usr/bin/env python
 """Write fastq data from multiple compressed files into a single file
 """
-
+import bz2
+import gzip
 from glob import glob
 import os
 from optparse import OptionParser
@@ -29,7 +30,12 @@ def main(cmdline=None):
         return 0
 
     if opts.output is not None:
-        output = open(opts.output, 'w')
+        if opts.bzip:
+            output = bz2.BZ2File(opts.output,'w')
+        elif opts.gzip:
+            output = gzip.GzipFile(opts.output, 'w')
+        else:
+            output = open(opts.output, 'w')
     else:
         output = sys.stdout
 
@@ -51,6 +57,10 @@ def make_parser():
     parser.add_option('-s', '--slice',
                       help="specify python slice, e.g. 0:75, 0:-1",
                       default=None)
+    parser.add_option('--gzip', default=False, action='store_true',
+                      help='gzip output')
+    parser.add_option('--bzip', default=False, action='store_true',
+                      help='bzip output')
     parser.add_option("--version", default=False, action="store_true",
                       help="report software version")
     return parser