annotate rgFastQC.py @ 2:2611a96c30b7 draft

Deleted selected files
author iuc
date Sat, 18 Jan 2014 22:33:36 -0500
parents 39b1c10532a4
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
1 """
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
2 # May 2013 ross added check for bogus gz extension - fastqc gets confused
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
3 # added sanitizer for user supplied name
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
4 # removed shell and make cl a sequence for Popen call
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
5 # ross lazarus August 10 2012 in response to anon insecurity report
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
6 wrapper for fastqc
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
7
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
8 called as
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
9 <command interpreter="python">
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
10 rgFastqc.py -i $input_file -d $html_file.files_path -o $html_file -n "$out_prefix"
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
11 </command>
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
12
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
13
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
14
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
15 Current release seems overly intolerant of sam/bam header strangeness
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
16 Author notified...
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
17
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
18
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
19 """
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
20 import re
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
21 import os
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
22 import sys
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
23 import subprocess
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
24 import optparse
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
25 import shutil
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
26 import tempfile
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
27 import zipfile
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
28 import gzip
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
29
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
30 def pathfind(program):
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
31 """ toolshed path munging isn't so try to work around june 5 2013
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
32 """
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
33 def is_exe(fpath):
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
34 return os.path.isfile(fpath) and os.access(fpath, os.X_OK)
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
35
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
36 fpath, fname = os.path.split(program)
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
37 if fpath:
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
38 if is_exe(program):
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
39 return program
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
40 else:
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
41 for path in os.environ["PATH"].split(os.pathsep):
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
42 path = path.strip('"')
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
43 exe_file = os.path.join(path, program)
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
44 if is_exe(exe_file):
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
45 return exe_file
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
46
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
47 return None
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
48
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
49 class FastQC():
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
50 """wrapper
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
51 """
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
52
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
53
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
54 def __init__(self,opts=None):
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
55 assert opts <> None
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
56 self.opts = opts
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
57 fastqcexe = pathfind(opts.executable)
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
58 assert (fastqcexe != None),'##rgFastQC.py error - cannot find passed fastqc executable %s in path %s' % (opts.executable,os.environ['PATH'])
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
59 self.fastqcexe = fastqcexe
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
60
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
61 def getFileString(self, fpath, outpath):
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
62 """
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
63 format a nice file size string
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
64 """
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
65 size = ''
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
66 fp = os.path.join(outpath, fpath)
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
67 s = fpath
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
68 if os.path.isfile(fp):
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
69 n = float(os.path.getsize(fp))
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
70 if n > 2**20:
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
71 size = ' (%1.1f MB)' % (n/2**20)
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
72 elif n > 2**10:
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
73 size = ' (%1.1f KB)' % (n/2**10)
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
74 elif n > 0:
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
75 size = ' (%d B)' % (int(n))
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
76 s = '%s %s' % (fpath, size)
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
77 return s
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
78
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
79 def run_fastqc(self):
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
80 """
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
81 In batch mode fastqc behaves not very nicely - will write to a new folder in
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
82 the same place as the infile called [infilebasename]_fastqc
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
83 rlazarus@omics:/data/galaxy/test$ ls FC041_1_sequence_fastqc
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
84 duplication_levels.png fastqc_icon.png per_base_n_content.png per_sequence_gc_content.png summary.txt
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
85 error.png fastqc_report.html per_base_quality.png per_sequence_quality.png tick.png
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
86 fastqc_data.txt per_base_gc_content.png per_base_sequence_content.png sequence_length_distribution.png warning.png
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
87
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
88 """
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
89 serr = ''
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
90 dummy,tlog = tempfile.mkstemp(prefix='rgFastQC',suffix=".log",dir=self.opts.outputdir)
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
91 sout = open(tlog, 'w')
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
92 fastq = os.path.basename(self.opts.input)
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
93 cl = [self.fastqcexe,'--outdir=%s' % self.opts.outputdir]
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
94 if self.opts.informat in ['sam','bam']:
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
95 cl.append('--f=%s' % self.opts.informat)
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
96 if self.opts.contaminants <> None :
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
97 cl.append('--contaminants=%s' % self.opts.contaminants)
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
98 # patch suggested by bwlang https://bitbucket.org/galaxy/galaxy-central/pull-request/30
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
99 # use a symlink in a temporary directory so that the FastQC report reflects the history input file name
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
100 # note this exposes a bug in the EBI_SRA download tool which leaves bogus .gz extensions on uncompressed files
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
101 # which fastqc helpfully tries to uncompress again - hilarity ensues.
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
102 # patched may 29 2013 until this is fixed properly
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
103 infname = self.opts.inputfilename
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
104 linf = infname.lower()
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
105 trimext = False
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
106 if ( linf.endswith('.gz') or linf.endswith('.gzip') ):
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
107 f = gzip.open(self.opts.input)
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
108 try:
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
109 testrow = f.readline()
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
110 except:
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
111 trimext = True
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
112 f.close()
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
113 elif linf.endswith('bz2'):
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
114 f = bz2.open(self.opts.input,'rb')
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
115 try:
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
116 f.readline()
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
117 except:
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
118 trimext = True
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
119 f.close()
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
120 elif linf.endswith('.zip'):
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
121 if not zipfile.is_zipfile(self.opts.input):
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
122 trimext = True
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
123 if trimext:
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
124 infname = os.path.splitext(infname)[0]
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
125 fastqinfilename = re.sub(ur'[^a-zA-Z0-9_\-\.]', '_', os.path.basename(infname))
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
126 link_name = os.path.join(self.opts.outputdir, fastqinfilename)
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
127 os.symlink(self.opts.input, link_name)
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
128 cl.append(link_name)
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
129 sout.write('# FastQC cl = %s\n' % ' '.join(cl))
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
130 sout.flush()
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
131 p = subprocess.Popen(cl, shell=False, stderr=sout, stdout=sout, cwd=self.opts.outputdir)
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
132 retval = p.wait()
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
133 sout.close()
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
134 runlog = open(tlog,'r').readlines()
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
135 os.unlink(link_name)
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
136 flist = os.listdir(self.opts.outputdir) # fastqc plays games with its output directory name. eesh
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
137 odpath = None
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
138 for f in flist:
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
139 d = os.path.join(self.opts.outputdir,f)
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
140 if os.path.isdir(d):
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
141 if d.endswith('_fastqc'):
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
142 odpath = d
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
143 hpath = None
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
144 if odpath <> None:
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
145 try:
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
146 hpath = os.path.join(odpath,'fastqc_report.html')
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
147 rep = open(hpath,'r').readlines() # for our new html file but we need to insert our stuff after the <body> tag
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
148 except:
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
149 pass
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
150 if hpath == None:
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
151 serr = '\n'.join(runlog)
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
152 res = ['## odpath=%s: No output found in %s. Output for the run was:<pre>\n' % (odpath,hpath),]
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
153 res += runlog
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
154 res += ['</pre>\n',
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
155 'Please read the above for clues<br/>\n',
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
156 'If you selected a sam/bam format file, it might not have headers or they may not start with @HD?<br/>\n',
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
157 'It is also possible that the log shows that fastqc is not installed?<br/>\n',
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
158 'If that is the case, please tell the relevant Galaxy administrator that it can be snarfed from<br/>\n',
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
159 'http://www.bioinformatics.bbsrc.ac.uk/projects/fastqc/<br/>\n',]
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
160 return res,1,serr
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
161 self.fix_fastqcimages(odpath)
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
162 flist = os.listdir(self.opts.outputdir) # these have now been fixed
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
163 excludefiles = ['tick.png','warning.png','fastqc_icon.png','error.png']
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
164 flist = [x for x in flist if not x in excludefiles]
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
165 for i in range(len(rep)): # need to fix links to Icons and Image subdirectories in lastest fastqc code - ugh
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
166 rep[i] = rep[i].replace('Icons/','')
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
167 rep[i] = rep[i].replace('Images/','')
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
168 html = self.fix_fastqc(rep,flist,runlog)
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
169 return html,retval,serr
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
170
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
171
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
172
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
173 def fix_fastqc(self,rep=[],flist=[],runlog=[]):
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
174 """ add some of our stuff to the html
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
175 """
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
176 bodyindex = len(rep) -1 # hope they don't change this
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
177 footrow = bodyindex - 1
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
178 footer = rep[footrow]
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
179 rep = rep[:footrow] + rep[footrow+1:]
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
180 res = ['<div class="module"><h2>Files created by FastQC</h2><table cellspacing="2" cellpadding="2">\n']
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
181 flist.sort()
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
182 for i,f in enumerate(flist):
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
183 if not(os.path.isdir(f)):
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
184 fn = os.path.split(f)[-1]
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
185 res.append('<tr><td><a href="%s">%s</a></td></tr>\n' % (fn,self.getFileString(fn, self.opts.outputdir)))
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
186 res.append('</table>\n')
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
187 res.append('<a href="http://www.bioinformatics.bbsrc.ac.uk/projects/fastqc/">FastQC documentation and full attribution is here</a><br/><hr/>\n')
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
188 res.append('FastQC was run by Galaxy using the rgenetics rgFastQC wrapper - see http://rgenetics.org for details and licensing\n</div>')
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
189 res.append(footer)
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
190 fixed = rep[:bodyindex] + res + rep[bodyindex:]
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
191 return fixed # with our additions
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
192
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
193
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
194 def fix_fastqcimages(self,odpath):
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
195 """ Galaxy wants everything in the same files_dir
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
196 """
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
197 icpath = os.path.join(odpath,'Icons')
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
198 impath = os.path.join(odpath,'Images')
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
199 for adir in [icpath,impath,odpath]:
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
200 if os.path.exists(adir):
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
201 flist = os.listdir(adir) # get all files created
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
202 for f in flist:
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
203 if not os.path.isdir(os.path.join(adir,f)):
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
204 sauce = os.path.join(adir,f)
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
205 dest = os.path.join(self.opts.outputdir,f)
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
206 shutil.move(sauce,dest)
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
207 os.rmdir(adir)
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
208
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
209
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
210 if __name__ == '__main__':
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
211 op = optparse.OptionParser()
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
212 op.add_option('-i', '--input', default=None)
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
213 op.add_option('-j', '--inputfilename', default=None)
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
214 op.add_option('-o', '--htmloutput', default=None)
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
215 op.add_option('-d', '--outputdir', default="/tmp/shortread")
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
216 op.add_option('-f', '--informat', default='fastq')
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
217 op.add_option('-n', '--namejob', default='rgFastQC')
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
218 op.add_option('-c', '--contaminants', default=None)
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
219 op.add_option('-e', '--executable', default='fastqc')
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
220 opts, args = op.parse_args()
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
221 assert opts.input <> None
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
222 if not os.path.exists(opts.outputdir):
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
223 os.makedirs(opts.outputdir)
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
224 f = FastQC(opts)
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
225 html,retval,serr = f.run_fastqc()
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
226 f = open(opts.htmloutput, 'w')
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
227 f.write(''.join(html))
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
228 f.close()
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
229 if retval <> 0:
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
230 print >> sys.stderr, serr # indicate failure
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
231
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
232
39b1c10532a4 Remove intermediate directory
iuc
parents:
diff changeset
233