diff rgFastQC.py @ 0:d91b89b552f3 draft default tip

Imported from capsule None
author tmcgowan
date Fri, 12 Sep 2014 11:55:50 -0400
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/rgFastQC.py	Fri Sep 12 11:55:50 2014 -0400
@@ -0,0 +1,66 @@
+"""
+Rewrite of rgFastQC.py for v. 0.11.2 of FastQC
+
+"""
+import re
+import os
+import sys
+import subprocess
+import optparse
+import shutil
+import tempfile
+import zipfile
+import gzip
+import glob
+
+class FastQCRunner(object):
+    
+    def __init__(self,opts=None):
+        assert opts <> None
+        self.opts = opts
+        
+    def prepare_command_line(self):
+        self.fastqinfilename = re.sub(ur'[^a-zA-Z0-9_\-\.]', '_', os.path.basename(self.opts.inputfilename))
+        command_line = [opts.executable, '--outdir %s' % opts.outputdir]
+        if opts.contaminants <> None :
+            command_line.append('--contaminants %s' % opts.contaminants)
+        command_line.append('--quiet %s' % self.fastqinfilename)
+        self.command_line = ' '.join(command_line)
+        
+    def copy_working_file_to_dataset(self):
+        result_file = glob.glob('*html')
+        os.system('cp %s %s' % (result_file[0], self.opts.htmloutput))
+
+
+    def run_fastqc(self):
+        
+        dummy,tlog = tempfile.mkstemp(prefix='rgFastQC',suffix=".log",dir=self.opts.outputdir)
+        sout = open(tlog, 'w')
+        
+        self.prepare_command_line()
+        sout.write(self.command_line)
+        sout.write('\n')
+        sout.write("Creating symlink\n")
+        os.symlink(self.opts.input, self.fastqinfilename)
+        sout.write("check_call\n")
+        subprocess.check_call(self.command_line, shell=True)        
+        sout.write("Copying working %s file to %s \n" % (self.fastqinfilename, self.opts.htmloutput))
+        self.copy_working_file_to_dataset()
+        sout.write("Finished")
+        sout.close()
+                        
+
+if __name__ == '__main__':
+    op = optparse.OptionParser()
+    op.add_option('-i', '--input', default=None)
+    op.add_option('-j', '--inputfilename', default=None)
+    op.add_option('-o', '--htmloutput', default=None)
+    op.add_option('-d', '--outputdir', default="/tmp/shortread")
+    op.add_option('-f', '--informat', default='fastq')
+    op.add_option('-n', '--namejob', default='rgFastQC')
+    op.add_option('-c', '--contaminants', default=None)
+    op.add_option('-e', '--executable', default='fastqc')
+    opts, args = op.parse_args()
+
+    fastqc_runner = FastQCRunner(opts)
+    fastqc_runner.run_fastqc()
\ No newline at end of file