annotate FastQC/rgFastQC.py @ 0:42251cbdeeac draft

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