Mercurial > repos > fubar > fastqc
comparison FastQC/rgFastQC.py @ 3:7e6db50c9d47 draft
Uploaded
| author | fubar |
|---|---|
| date | Tue, 04 Jun 2013 22:42:51 -0400 |
| parents | 68b330b860ee |
| children |
comparison
equal
deleted
inserted
replaced
| 2:40b80f54e1a7 | 3:7e6db50c9d47 |
|---|---|
| 25 import shutil | 25 import shutil |
| 26 import tempfile | 26 import tempfile |
| 27 import zipfile | 27 import zipfile |
| 28 import gzip | 28 import gzip |
| 29 | 29 |
| 30 def pathfind(program): | |
| 31 """ toolshed path munging isn't so try to work around june 5 2013 | |
| 32 """ | |
| 33 def is_exe(fpath): | |
| 34 return os.path.isfile(fpath) and os.access(fpath, os.X_OK) | |
| 35 | |
| 36 fpath, fname = os.path.split(program) | |
| 37 if fpath: | |
| 38 if is_exe(program): | |
| 39 return program | |
| 40 else: | |
| 41 for path in os.environ["PATH"].split(os.pathsep): | |
| 42 path = path.strip('"') | |
| 43 exe_file = os.path.join(path, program) | |
| 44 if is_exe(exe_file): | |
| 45 return exe_file | |
| 46 | |
| 47 return None | |
| 48 | |
| 30 class FastQC(): | 49 class FastQC(): |
| 31 """wrapper | 50 """wrapper |
| 32 """ | 51 """ |
| 33 | 52 |
| 34 | 53 |
| 35 def __init__(self,opts=None): | 54 def __init__(self,opts=None): |
| 36 assert opts <> None | 55 assert opts <> None |
| 37 self.opts = opts | 56 self.opts = opts |
| 57 fastqcexe = pathfind(opts.executable) | |
| 58 assert (fastqcexe != None),'##rgFastQC.py error - cannot find passed fastqc executable %s in path %s' % (opts.executable,os.environ['PATH']) | |
| 59 self.fastqcexe = fastqcexe | |
| 38 | 60 |
| 39 def getFileString(self, fpath, outpath): | 61 def getFileString(self, fpath, outpath): |
| 40 """ | 62 """ |
| 41 format a nice file size string | 63 format a nice file size string |
| 42 """ | 64 """ |
| 66 """ | 88 """ |
| 67 serr = '' | 89 serr = '' |
| 68 dummy,tlog = tempfile.mkstemp(prefix='rgFastQC',suffix=".log",dir=self.opts.outputdir) | 90 dummy,tlog = tempfile.mkstemp(prefix='rgFastQC',suffix=".log",dir=self.opts.outputdir) |
| 69 sout = open(tlog, 'w') | 91 sout = open(tlog, 'w') |
| 70 fastq = os.path.basename(self.opts.input) | 92 fastq = os.path.basename(self.opts.input) |
| 71 cl = [self.opts.executable,'--outdir=%s' % self.opts.outputdir] | 93 cl = [self.fastqcexe,'--outdir=%s' % self.opts.outputdir] |
| 72 if self.opts.informat in ['sam','bam']: | 94 if self.opts.informat in ['sam','bam']: |
| 73 cl.append('--f=%s' % self.opts.informat) | 95 cl.append('--f=%s' % self.opts.informat) |
| 74 if self.opts.contaminants <> None : | 96 if self.opts.contaminants <> None : |
| 75 cl.append('--contaminants=%s' % self.opts.contaminants) | 97 cl.append('--contaminants=%s' % self.opts.contaminants) |
| 76 # patch suggested by bwlang https://bitbucket.org/galaxy/galaxy-central/pull-request/30 | 98 # patch suggested by bwlang https://bitbucket.org/galaxy/galaxy-central/pull-request/30 |
| 182 sauce = os.path.join(adir,f) | 204 sauce = os.path.join(adir,f) |
| 183 dest = os.path.join(self.opts.outputdir,f) | 205 dest = os.path.join(self.opts.outputdir,f) |
| 184 shutil.move(sauce,dest) | 206 shutil.move(sauce,dest) |
| 185 os.rmdir(adir) | 207 os.rmdir(adir) |
| 186 | 208 |
| 187 | |
| 188 | 209 |
| 189 if __name__ == '__main__': | 210 if __name__ == '__main__': |
| 190 op = optparse.OptionParser() | 211 op = optparse.OptionParser() |
| 191 op.add_option('-i', '--input', default=None) | 212 op.add_option('-i', '--input', default=None) |
| 192 op.add_option('-j', '--inputfilename', default=None) | 213 op.add_option('-j', '--inputfilename', default=None) |
| 196 op.add_option('-n', '--namejob', default='rgFastQC') | 217 op.add_option('-n', '--namejob', default='rgFastQC') |
| 197 op.add_option('-c', '--contaminants', default=None) | 218 op.add_option('-c', '--contaminants', default=None) |
| 198 op.add_option('-e', '--executable', default='fastqc') | 219 op.add_option('-e', '--executable', default='fastqc') |
| 199 opts, args = op.parse_args() | 220 opts, args = op.parse_args() |
| 200 assert opts.input <> None | 221 assert opts.input <> None |
| 201 assert os.path.isfile(opts.executable),'##rgFastQC.py error - cannot find executable %s' % opts.executable | |
| 202 if not os.path.exists(opts.outputdir): | 222 if not os.path.exists(opts.outputdir): |
| 203 os.makedirs(opts.outputdir) | 223 os.makedirs(opts.outputdir) |
| 204 f = FastQC(opts) | 224 f = FastQC(opts) |
| 205 html,retval,serr = f.run_fastqc() | 225 html,retval,serr = f.run_fastqc() |
| 206 f = open(opts.htmloutput, 'w') | 226 f = open(opts.htmloutput, 'w') |
