Mercurial > repos > fubar > fastqc_320
annotate FastQC/rgFastQC.py @ 13:c3ac02711af2 draft default tip
Uploaded
author | fubar |
---|---|
date | Mon, 03 Jun 2013 23:59:16 -0400 |
parents | 91cb2603b56c |
children |
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 import zipfile |
42251cbdeeac
Initial commit of test for FastQC with installation of the java stuff
fubar
parents:
diff
changeset
|
28 import gzip |
42251cbdeeac
Initial commit of test for FastQC with installation of the java stuff
fubar
parents:
diff
changeset
|
29 |
42251cbdeeac
Initial commit of test for FastQC with installation of the java stuff
fubar
parents:
diff
changeset
|
30 class FastQC(): |
42251cbdeeac
Initial commit of test for FastQC with installation of the java stuff
fubar
parents:
diff
changeset
|
31 """wrapper |
42251cbdeeac
Initial commit of test for FastQC with installation of the java stuff
fubar
parents:
diff
changeset
|
32 """ |
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 def __init__(self,opts=None): |
42251cbdeeac
Initial commit of test for FastQC with installation of the java stuff
fubar
parents:
diff
changeset
|
36 assert opts <> None |
42251cbdeeac
Initial commit of test for FastQC with installation of the java stuff
fubar
parents:
diff
changeset
|
37 self.opts = opts |
42251cbdeeac
Initial commit of test for FastQC with installation of the java stuff
fubar
parents:
diff
changeset
|
38 |
1
91cb2603b56c
Added getFileSize from rgutils to remove bogus dependency
fubar
parents:
0
diff
changeset
|
39 def getFileString(fpath, outpath): |
91cb2603b56c
Added getFileSize from rgutils to remove bogus dependency
fubar
parents:
0
diff
changeset
|
40 """ |
91cb2603b56c
Added getFileSize from rgutils to remove bogus dependency
fubar
parents:
0
diff
changeset
|
41 format a nice file size string |
91cb2603b56c
Added getFileSize from rgutils to remove bogus dependency
fubar
parents:
0
diff
changeset
|
42 """ |
91cb2603b56c
Added getFileSize from rgutils to remove bogus dependency
fubar
parents:
0
diff
changeset
|
43 size = '' |
91cb2603b56c
Added getFileSize from rgutils to remove bogus dependency
fubar
parents:
0
diff
changeset
|
44 fp = os.path.join(outpath, fpath) |
91cb2603b56c
Added getFileSize from rgutils to remove bogus dependency
fubar
parents:
0
diff
changeset
|
45 s = fpath |
91cb2603b56c
Added getFileSize from rgutils to remove bogus dependency
fubar
parents:
0
diff
changeset
|
46 if os.path.isfile(fp): |
91cb2603b56c
Added getFileSize from rgutils to remove bogus dependency
fubar
parents:
0
diff
changeset
|
47 n = float(os.path.getsize(fp)) |
91cb2603b56c
Added getFileSize from rgutils to remove bogus dependency
fubar
parents:
0
diff
changeset
|
48 if n > 2**20: |
91cb2603b56c
Added getFileSize from rgutils to remove bogus dependency
fubar
parents:
0
diff
changeset
|
49 size = ' (%1.1f MB)' % (n/2**20) |
91cb2603b56c
Added getFileSize from rgutils to remove bogus dependency
fubar
parents:
0
diff
changeset
|
50 elif n > 2**10: |
91cb2603b56c
Added getFileSize from rgutils to remove bogus dependency
fubar
parents:
0
diff
changeset
|
51 size = ' (%1.1f KB)' % (n/2**10) |
91cb2603b56c
Added getFileSize from rgutils to remove bogus dependency
fubar
parents:
0
diff
changeset
|
52 elif n > 0: |
91cb2603b56c
Added getFileSize from rgutils to remove bogus dependency
fubar
parents:
0
diff
changeset
|
53 size = ' (%d B)' % (int(n)) |
91cb2603b56c
Added getFileSize from rgutils to remove bogus dependency
fubar
parents:
0
diff
changeset
|
54 s = '%s %s' % (fpath, size) |
91cb2603b56c
Added getFileSize from rgutils to remove bogus dependency
fubar
parents:
0
diff
changeset
|
55 return s |
91cb2603b56c
Added getFileSize from rgutils to remove bogus dependency
fubar
parents:
0
diff
changeset
|
56 |
0
42251cbdeeac
Initial commit of test for FastQC with installation of the java stuff
fubar
parents:
diff
changeset
|
57 def run_fastqc(self): |
42251cbdeeac
Initial commit of test for FastQC with installation of the java stuff
fubar
parents:
diff
changeset
|
58 """ |
42251cbdeeac
Initial commit of test for FastQC with installation of the java stuff
fubar
parents:
diff
changeset
|
59 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
|
60 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
|
61 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
|
62 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
|
63 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
|
64 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
|
65 |
42251cbdeeac
Initial commit of test for FastQC with installation of the java stuff
fubar
parents:
diff
changeset
|
66 """ |
42251cbdeeac
Initial commit of test for FastQC with installation of the java stuff
fubar
parents:
diff
changeset
|
67 serr = '' |
42251cbdeeac
Initial commit of test for FastQC with installation of the java stuff
fubar
parents:
diff
changeset
|
68 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
|
69 sout = open(tlog, 'w') |
42251cbdeeac
Initial commit of test for FastQC with installation of the java stuff
fubar
parents:
diff
changeset
|
70 fastq = os.path.basename(self.opts.input) |
42251cbdeeac
Initial commit of test for FastQC with installation of the java stuff
fubar
parents:
diff
changeset
|
71 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
|
72 if self.opts.informat in ['sam','bam']: |
42251cbdeeac
Initial commit of test for FastQC with installation of the java stuff
fubar
parents:
diff
changeset
|
73 cl.append('--f=%s' % self.opts.informat) |
42251cbdeeac
Initial commit of test for FastQC with installation of the java stuff
fubar
parents:
diff
changeset
|
74 if self.opts.contaminants <> None : |
42251cbdeeac
Initial commit of test for FastQC with installation of the java stuff
fubar
parents:
diff
changeset
|
75 cl.append('--contaminants=%s' % self.opts.contaminants) |
42251cbdeeac
Initial commit of test for FastQC with installation of the java stuff
fubar
parents:
diff
changeset
|
76 # 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
|
77 # 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
|
78 # 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
|
79 # 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
|
80 # 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
|
81 infname = self.opts.inputfilename |
42251cbdeeac
Initial commit of test for FastQC with installation of the java stuff
fubar
parents:
diff
changeset
|
82 linf = infname.lower() |
42251cbdeeac
Initial commit of test for FastQC with installation of the java stuff
fubar
parents:
diff
changeset
|
83 trimext = False |
42251cbdeeac
Initial commit of test for FastQC with installation of the java stuff
fubar
parents:
diff
changeset
|
84 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
|
85 f = gzip.open(self.opts.input) |
42251cbdeeac
Initial commit of test for FastQC with installation of the java stuff
fubar
parents:
diff
changeset
|
86 try: |
42251cbdeeac
Initial commit of test for FastQC with installation of the java stuff
fubar
parents:
diff
changeset
|
87 testrow = f.readline() |
42251cbdeeac
Initial commit of test for FastQC with installation of the java stuff
fubar
parents:
diff
changeset
|
88 except: |
42251cbdeeac
Initial commit of test for FastQC with installation of the java stuff
fubar
parents:
diff
changeset
|
89 trimext = True |
42251cbdeeac
Initial commit of test for FastQC with installation of the java stuff
fubar
parents:
diff
changeset
|
90 f.close() |
42251cbdeeac
Initial commit of test for FastQC with installation of the java stuff
fubar
parents:
diff
changeset
|
91 elif linf.endswith('bz2'): |
42251cbdeeac
Initial commit of test for FastQC with installation of the java stuff
fubar
parents:
diff
changeset
|
92 f = bz2.open(self.opts.input,'rb') |
42251cbdeeac
Initial commit of test for FastQC with installation of the java stuff
fubar
parents:
diff
changeset
|
93 try: |
42251cbdeeac
Initial commit of test for FastQC with installation of the java stuff
fubar
parents:
diff
changeset
|
94 f.readline() |
42251cbdeeac
Initial commit of test for FastQC with installation of the java stuff
fubar
parents:
diff
changeset
|
95 except: |
42251cbdeeac
Initial commit of test for FastQC with installation of the java stuff
fubar
parents:
diff
changeset
|
96 trimext = True |
42251cbdeeac
Initial commit of test for FastQC with installation of the java stuff
fubar
parents:
diff
changeset
|
97 f.close() |
42251cbdeeac
Initial commit of test for FastQC with installation of the java stuff
fubar
parents:
diff
changeset
|
98 elif linf.endswith('.zip'): |
42251cbdeeac
Initial commit of test for FastQC with installation of the java stuff
fubar
parents:
diff
changeset
|
99 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
|
100 trimext = True |
42251cbdeeac
Initial commit of test for FastQC with installation of the java stuff
fubar
parents:
diff
changeset
|
101 if trimext: |
42251cbdeeac
Initial commit of test for FastQC with installation of the java stuff
fubar
parents:
diff
changeset
|
102 infname = os.path.splitext(infname)[0] |
42251cbdeeac
Initial commit of test for FastQC with installation of the java stuff
fubar
parents:
diff
changeset
|
103 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
|
104 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
|
105 os.symlink(self.opts.input, link_name) |
42251cbdeeac
Initial commit of test for FastQC with installation of the java stuff
fubar
parents:
diff
changeset
|
106 cl.append(link_name) |
42251cbdeeac
Initial commit of test for FastQC with installation of the java stuff
fubar
parents:
diff
changeset
|
107 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
|
108 sout.flush() |
42251cbdeeac
Initial commit of test for FastQC with installation of the java stuff
fubar
parents:
diff
changeset
|
109 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
|
110 retval = p.wait() |
42251cbdeeac
Initial commit of test for FastQC with installation of the java stuff
fubar
parents:
diff
changeset
|
111 sout.close() |
42251cbdeeac
Initial commit of test for FastQC with installation of the java stuff
fubar
parents:
diff
changeset
|
112 runlog = open(tlog,'r').readlines() |
42251cbdeeac
Initial commit of test for FastQC with installation of the java stuff
fubar
parents:
diff
changeset
|
113 os.unlink(link_name) |
42251cbdeeac
Initial commit of test for FastQC with installation of the java stuff
fubar
parents:
diff
changeset
|
114 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
|
115 odpath = None |
42251cbdeeac
Initial commit of test for FastQC with installation of the java stuff
fubar
parents:
diff
changeset
|
116 for f in flist: |
42251cbdeeac
Initial commit of test for FastQC with installation of the java stuff
fubar
parents:
diff
changeset
|
117 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
|
118 if os.path.isdir(d): |
42251cbdeeac
Initial commit of test for FastQC with installation of the java stuff
fubar
parents:
diff
changeset
|
119 if d.endswith('_fastqc'): |
42251cbdeeac
Initial commit of test for FastQC with installation of the java stuff
fubar
parents:
diff
changeset
|
120 odpath = d |
42251cbdeeac
Initial commit of test for FastQC with installation of the java stuff
fubar
parents:
diff
changeset
|
121 hpath = None |
42251cbdeeac
Initial commit of test for FastQC with installation of the java stuff
fubar
parents:
diff
changeset
|
122 if odpath <> None: |
42251cbdeeac
Initial commit of test for FastQC with installation of the java stuff
fubar
parents:
diff
changeset
|
123 try: |
42251cbdeeac
Initial commit of test for FastQC with installation of the java stuff
fubar
parents:
diff
changeset
|
124 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
|
125 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
|
126 except: |
42251cbdeeac
Initial commit of test for FastQC with installation of the java stuff
fubar
parents:
diff
changeset
|
127 pass |
42251cbdeeac
Initial commit of test for FastQC with installation of the java stuff
fubar
parents:
diff
changeset
|
128 if hpath == None: |
42251cbdeeac
Initial commit of test for FastQC with installation of the java stuff
fubar
parents:
diff
changeset
|
129 serr = '\n'.join(runlog) |
42251cbdeeac
Initial commit of test for FastQC with installation of the java stuff
fubar
parents:
diff
changeset
|
130 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
|
131 res += runlog |
42251cbdeeac
Initial commit of test for FastQC with installation of the java stuff
fubar
parents:
diff
changeset
|
132 res += ['</pre>\n', |
42251cbdeeac
Initial commit of test for FastQC with installation of the java stuff
fubar
parents:
diff
changeset
|
133 '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
|
134 '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
|
135 '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
|
136 '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
|
137 '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
|
138 return res,1,serr |
42251cbdeeac
Initial commit of test for FastQC with installation of the java stuff
fubar
parents:
diff
changeset
|
139 self.fix_fastqcimages(odpath) |
42251cbdeeac
Initial commit of test for FastQC with installation of the java stuff
fubar
parents:
diff
changeset
|
140 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
|
141 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
|
142 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
|
143 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
|
144 rep[i] = rep[i].replace('Icons/','') |
42251cbdeeac
Initial commit of test for FastQC with installation of the java stuff
fubar
parents:
diff
changeset
|
145 rep[i] = rep[i].replace('Images/','') |
42251cbdeeac
Initial commit of test for FastQC with installation of the java stuff
fubar
parents:
diff
changeset
|
146 html = self.fix_fastqc(rep,flist,runlog) |
42251cbdeeac
Initial commit of test for FastQC with installation of the java stuff
fubar
parents:
diff
changeset
|
147 return html,retval,serr |
42251cbdeeac
Initial commit of test for FastQC with installation of the java stuff
fubar
parents:
diff
changeset
|
148 |
42251cbdeeac
Initial commit of test for FastQC with installation of the java stuff
fubar
parents:
diff
changeset
|
149 |
42251cbdeeac
Initial commit of test for FastQC with installation of the java stuff
fubar
parents:
diff
changeset
|
150 |
42251cbdeeac
Initial commit of test for FastQC with installation of the java stuff
fubar
parents:
diff
changeset
|
151 def fix_fastqc(self,rep=[],flist=[],runlog=[]): |
42251cbdeeac
Initial commit of test for FastQC with installation of the java stuff
fubar
parents:
diff
changeset
|
152 """ 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
|
153 """ |
42251cbdeeac
Initial commit of test for FastQC with installation of the java stuff
fubar
parents:
diff
changeset
|
154 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
|
155 footrow = bodyindex - 1 |
42251cbdeeac
Initial commit of test for FastQC with installation of the java stuff
fubar
parents:
diff
changeset
|
156 footer = rep[footrow] |
42251cbdeeac
Initial commit of test for FastQC with installation of the java stuff
fubar
parents:
diff
changeset
|
157 rep = rep[:footrow] + rep[footrow+1:] |
42251cbdeeac
Initial commit of test for FastQC with installation of the java stuff
fubar
parents:
diff
changeset
|
158 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
|
159 flist.sort() |
42251cbdeeac
Initial commit of test for FastQC with installation of the java stuff
fubar
parents:
diff
changeset
|
160 for i,f in enumerate(flist): |
42251cbdeeac
Initial commit of test for FastQC with installation of the java stuff
fubar
parents:
diff
changeset
|
161 if not(os.path.isdir(f)): |
42251cbdeeac
Initial commit of test for FastQC with installation of the java stuff
fubar
parents:
diff
changeset
|
162 fn = os.path.split(f)[-1] |
42251cbdeeac
Initial commit of test for FastQC with installation of the java stuff
fubar
parents:
diff
changeset
|
163 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
|
164 res.append('</table>\n') |
42251cbdeeac
Initial commit of test for FastQC with installation of the java stuff
fubar
parents:
diff
changeset
|
165 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
|
166 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
|
167 res.append(footer) |
42251cbdeeac
Initial commit of test for FastQC with installation of the java stuff
fubar
parents:
diff
changeset
|
168 fixed = rep[:bodyindex] + res + rep[bodyindex:] |
42251cbdeeac
Initial commit of test for FastQC with installation of the java stuff
fubar
parents:
diff
changeset
|
169 return fixed # with our additions |
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 def fix_fastqcimages(self,odpath): |
42251cbdeeac
Initial commit of test for FastQC with installation of the java stuff
fubar
parents:
diff
changeset
|
173 """ 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
|
174 """ |
42251cbdeeac
Initial commit of test for FastQC with installation of the java stuff
fubar
parents:
diff
changeset
|
175 icpath = os.path.join(odpath,'Icons') |
42251cbdeeac
Initial commit of test for FastQC with installation of the java stuff
fubar
parents:
diff
changeset
|
176 impath = os.path.join(odpath,'Images') |
42251cbdeeac
Initial commit of test for FastQC with installation of the java stuff
fubar
parents:
diff
changeset
|
177 for adir in [icpath,impath,odpath]: |
42251cbdeeac
Initial commit of test for FastQC with installation of the java stuff
fubar
parents:
diff
changeset
|
178 if os.path.exists(adir): |
42251cbdeeac
Initial commit of test for FastQC with installation of the java stuff
fubar
parents:
diff
changeset
|
179 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
|
180 for f in flist: |
42251cbdeeac
Initial commit of test for FastQC with installation of the java stuff
fubar
parents:
diff
changeset
|
181 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
|
182 sauce = os.path.join(adir,f) |
42251cbdeeac
Initial commit of test for FastQC with installation of the java stuff
fubar
parents:
diff
changeset
|
183 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
|
184 shutil.move(sauce,dest) |
42251cbdeeac
Initial commit of test for FastQC with installation of the java stuff
fubar
parents:
diff
changeset
|
185 os.rmdir(adir) |
42251cbdeeac
Initial commit of test for FastQC with installation of the java stuff
fubar
parents:
diff
changeset
|
186 |
42251cbdeeac
Initial commit of test for FastQC with installation of the java stuff
fubar
parents:
diff
changeset
|
187 |
42251cbdeeac
Initial commit of test for FastQC with installation of the java stuff
fubar
parents:
diff
changeset
|
188 |
42251cbdeeac
Initial commit of test for FastQC with installation of the java stuff
fubar
parents:
diff
changeset
|
189 if __name__ == '__main__': |
42251cbdeeac
Initial commit of test for FastQC with installation of the java stuff
fubar
parents:
diff
changeset
|
190 op = optparse.OptionParser() |
42251cbdeeac
Initial commit of test for FastQC with installation of the java stuff
fubar
parents:
diff
changeset
|
191 op.add_option('-i', '--input', default=None) |
42251cbdeeac
Initial commit of test for FastQC with installation of the java stuff
fubar
parents:
diff
changeset
|
192 op.add_option('-j', '--inputfilename', default=None) |
42251cbdeeac
Initial commit of test for FastQC with installation of the java stuff
fubar
parents:
diff
changeset
|
193 op.add_option('-o', '--htmloutput', default=None) |
42251cbdeeac
Initial commit of test for FastQC with installation of the java stuff
fubar
parents:
diff
changeset
|
194 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
|
195 op.add_option('-f', '--informat', default='fastq') |
42251cbdeeac
Initial commit of test for FastQC with installation of the java stuff
fubar
parents:
diff
changeset
|
196 op.add_option('-n', '--namejob', default='rgFastQC') |
42251cbdeeac
Initial commit of test for FastQC with installation of the java stuff
fubar
parents:
diff
changeset
|
197 op.add_option('-c', '--contaminants', default=None) |
42251cbdeeac
Initial commit of test for FastQC with installation of the java stuff
fubar
parents:
diff
changeset
|
198 op.add_option('-e', '--executable', default='fastqc') |
42251cbdeeac
Initial commit of test for FastQC with installation of the java stuff
fubar
parents:
diff
changeset
|
199 opts, args = op.parse_args() |
42251cbdeeac
Initial commit of test for FastQC with installation of the java stuff
fubar
parents:
diff
changeset
|
200 assert opts.input <> None |
42251cbdeeac
Initial commit of test for FastQC with installation of the java stuff
fubar
parents:
diff
changeset
|
201 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
|
202 if not os.path.exists(opts.outputdir): |
42251cbdeeac
Initial commit of test for FastQC with installation of the java stuff
fubar
parents:
diff
changeset
|
203 os.makedirs(opts.outputdir) |
42251cbdeeac
Initial commit of test for FastQC with installation of the java stuff
fubar
parents:
diff
changeset
|
204 f = FastQC(opts) |
42251cbdeeac
Initial commit of test for FastQC with installation of the java stuff
fubar
parents:
diff
changeset
|
205 html,retval,serr = f.run_fastqc() |
42251cbdeeac
Initial commit of test for FastQC with installation of the java stuff
fubar
parents:
diff
changeset
|
206 f = open(opts.htmloutput, 'w') |
42251cbdeeac
Initial commit of test for FastQC with installation of the java stuff
fubar
parents:
diff
changeset
|
207 f.write(''.join(html)) |
42251cbdeeac
Initial commit of test for FastQC with installation of the java stuff
fubar
parents:
diff
changeset
|
208 f.close() |
42251cbdeeac
Initial commit of test for FastQC with installation of the java stuff
fubar
parents:
diff
changeset
|
209 if retval <> 0: |
42251cbdeeac
Initial commit of test for FastQC with installation of the java stuff
fubar
parents:
diff
changeset
|
210 print >> sys.stderr, serr # indicate failure |
42251cbdeeac
Initial commit of test for FastQC with installation of the java stuff
fubar
parents:
diff
changeset
|
211 |
42251cbdeeac
Initial commit of test for FastQC with installation of the java stuff
fubar
parents:
diff
changeset
|
212 |
42251cbdeeac
Initial commit of test for FastQC with installation of the java stuff
fubar
parents:
diff
changeset
|
213 |