comparison rgFastQC.py @ 0:d91b89b552f3 draft default tip

Imported from capsule None
author tmcgowan
date Fri, 12 Sep 2014 11:55:50 -0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:d91b89b552f3
1 """
2 Rewrite of rgFastQC.py for v. 0.11.2 of FastQC
3
4 """
5 import re
6 import os
7 import sys
8 import subprocess
9 import optparse
10 import shutil
11 import tempfile
12 import zipfile
13 import gzip
14 import glob
15
16 class FastQCRunner(object):
17
18 def __init__(self,opts=None):
19 assert opts <> None
20 self.opts = opts
21
22 def prepare_command_line(self):
23 self.fastqinfilename = re.sub(ur'[^a-zA-Z0-9_\-\.]', '_', os.path.basename(self.opts.inputfilename))
24 command_line = [opts.executable, '--outdir %s' % opts.outputdir]
25 if opts.contaminants <> None :
26 command_line.append('--contaminants %s' % opts.contaminants)
27 command_line.append('--quiet %s' % self.fastqinfilename)
28 self.command_line = ' '.join(command_line)
29
30 def copy_working_file_to_dataset(self):
31 result_file = glob.glob('*html')
32 os.system('cp %s %s' % (result_file[0], self.opts.htmloutput))
33
34
35 def run_fastqc(self):
36
37 dummy,tlog = tempfile.mkstemp(prefix='rgFastQC',suffix=".log",dir=self.opts.outputdir)
38 sout = open(tlog, 'w')
39
40 self.prepare_command_line()
41 sout.write(self.command_line)
42 sout.write('\n')
43 sout.write("Creating symlink\n")
44 os.symlink(self.opts.input, self.fastqinfilename)
45 sout.write("check_call\n")
46 subprocess.check_call(self.command_line, shell=True)
47 sout.write("Copying working %s file to %s \n" % (self.fastqinfilename, self.opts.htmloutput))
48 self.copy_working_file_to_dataset()
49 sout.write("Finished")
50 sout.close()
51
52
53 if __name__ == '__main__':
54 op = optparse.OptionParser()
55 op.add_option('-i', '--input', default=None)
56 op.add_option('-j', '--inputfilename', default=None)
57 op.add_option('-o', '--htmloutput', default=None)
58 op.add_option('-d', '--outputdir', default="/tmp/shortread")
59 op.add_option('-f', '--informat', default='fastq')
60 op.add_option('-n', '--namejob', default='rgFastQC')
61 op.add_option('-c', '--contaminants', default=None)
62 op.add_option('-e', '--executable', default='fastqc')
63 opts, args = op.parse_args()
64
65 fastqc_runner = FastQCRunner(opts)
66 fastqc_runner.run_fastqc()