annotate picard_wrapper.py @ 133:c127b3314d53 draft

Uploaded
author devteam
date Wed, 26 Feb 2014 02:11:58 -0500
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
133
c127b3314d53 Uploaded
devteam
parents:
diff changeset
1 #!/usr/bin/env python
c127b3314d53 Uploaded
devteam
parents:
diff changeset
2 """
c127b3314d53 Uploaded
devteam
parents:
diff changeset
3 Originally written by Kelly Vincent
c127b3314d53 Uploaded
devteam
parents:
diff changeset
4 pretty output and additional picard wrappers by Ross Lazarus for rgenetics
c127b3314d53 Uploaded
devteam
parents:
diff changeset
5 Runs all available wrapped Picard tools.
c127b3314d53 Uploaded
devteam
parents:
diff changeset
6 usage: picard_wrapper.py [options]
c127b3314d53 Uploaded
devteam
parents:
diff changeset
7 code Ross wrote licensed under the LGPL
c127b3314d53 Uploaded
devteam
parents:
diff changeset
8 see http://www.gnu.org/copyleft/lesser.html
c127b3314d53 Uploaded
devteam
parents:
diff changeset
9 """
c127b3314d53 Uploaded
devteam
parents:
diff changeset
10
c127b3314d53 Uploaded
devteam
parents:
diff changeset
11 import optparse, os, sys, subprocess, tempfile, shutil, time, logging
c127b3314d53 Uploaded
devteam
parents:
diff changeset
12
c127b3314d53 Uploaded
devteam
parents:
diff changeset
13 galhtmlprefix = """<?xml version="1.0" encoding="utf-8" ?>
c127b3314d53 Uploaded
devteam
parents:
diff changeset
14 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
c127b3314d53 Uploaded
devteam
parents:
diff changeset
15 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
c127b3314d53 Uploaded
devteam
parents:
diff changeset
16 <head>
c127b3314d53 Uploaded
devteam
parents:
diff changeset
17 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
c127b3314d53 Uploaded
devteam
parents:
diff changeset
18 <meta name="generator" content="Bluefish 2.2.4" />
c127b3314d53 Uploaded
devteam
parents:
diff changeset
19 <title></title>
c127b3314d53 Uploaded
devteam
parents:
diff changeset
20 <link rel="stylesheet" href="/static/style/base.css" type="text/css" />
c127b3314d53 Uploaded
devteam
parents:
diff changeset
21 </head>
c127b3314d53 Uploaded
devteam
parents:
diff changeset
22 <body>
c127b3314d53 Uploaded
devteam
parents:
diff changeset
23 <div class="document">
c127b3314d53 Uploaded
devteam
parents:
diff changeset
24 """
c127b3314d53 Uploaded
devteam
parents:
diff changeset
25 galhtmlattr = """Galaxy tool %s run at %s</b><br/>"""
c127b3314d53 Uploaded
devteam
parents:
diff changeset
26 galhtmlpostfix = """</div></body></html>\n"""
c127b3314d53 Uploaded
devteam
parents:
diff changeset
27
c127b3314d53 Uploaded
devteam
parents:
diff changeset
28
c127b3314d53 Uploaded
devteam
parents:
diff changeset
29 def stop_err( msg ):
c127b3314d53 Uploaded
devteam
parents:
diff changeset
30 sys.stderr.write( '%s\n' % msg )
c127b3314d53 Uploaded
devteam
parents:
diff changeset
31 sys.exit()
c127b3314d53 Uploaded
devteam
parents:
diff changeset
32
c127b3314d53 Uploaded
devteam
parents:
diff changeset
33
c127b3314d53 Uploaded
devteam
parents:
diff changeset
34 def timenow():
c127b3314d53 Uploaded
devteam
parents:
diff changeset
35 """return current time as a string
c127b3314d53 Uploaded
devteam
parents:
diff changeset
36 """
c127b3314d53 Uploaded
devteam
parents:
diff changeset
37 return time.strftime('%d/%m/%Y %H:%M:%S', time.localtime(time.time()))
c127b3314d53 Uploaded
devteam
parents:
diff changeset
38
c127b3314d53 Uploaded
devteam
parents:
diff changeset
39
c127b3314d53 Uploaded
devteam
parents:
diff changeset
40 class PicardBase():
c127b3314d53 Uploaded
devteam
parents:
diff changeset
41 """
c127b3314d53 Uploaded
devteam
parents:
diff changeset
42 simple base class with some utilities for Picard
c127b3314d53 Uploaded
devteam
parents:
diff changeset
43 adapted and merged with Kelly Vincent's code april 2011 Ross
c127b3314d53 Uploaded
devteam
parents:
diff changeset
44 lots of changes...
c127b3314d53 Uploaded
devteam
parents:
diff changeset
45 """
c127b3314d53 Uploaded
devteam
parents:
diff changeset
46
c127b3314d53 Uploaded
devteam
parents:
diff changeset
47 def __init__(self, opts=None,arg0=None):
c127b3314d53 Uploaded
devteam
parents:
diff changeset
48 """ common stuff needed at init for a picard tool
c127b3314d53 Uploaded
devteam
parents:
diff changeset
49 """
c127b3314d53 Uploaded
devteam
parents:
diff changeset
50 assert opts <> None, 'PicardBase needs opts at init'
c127b3314d53 Uploaded
devteam
parents:
diff changeset
51 self.opts = opts
c127b3314d53 Uploaded
devteam
parents:
diff changeset
52 if self.opts.outdir == None:
c127b3314d53 Uploaded
devteam
parents:
diff changeset
53 self.opts.outdir = os.getcwd() # fixmate has no html file eg so use temp dir
c127b3314d53 Uploaded
devteam
parents:
diff changeset
54 assert self.opts.outdir <> None,'## PicardBase needs a temp directory if no output directory passed in'
c127b3314d53 Uploaded
devteam
parents:
diff changeset
55 self.picname = self.baseName(opts.jar)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
56 if self.picname.startswith('picard'):
c127b3314d53 Uploaded
devteam
parents:
diff changeset
57 self.picname = opts.picard_cmd # special case for some tools like replaceheader?
c127b3314d53 Uploaded
devteam
parents:
diff changeset
58 self.progname = self.baseName(arg0)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
59 self.version = '0.002'
c127b3314d53 Uploaded
devteam
parents:
diff changeset
60 self.delme = [] # list of files to destroy
c127b3314d53 Uploaded
devteam
parents:
diff changeset
61 self.title = opts.title
c127b3314d53 Uploaded
devteam
parents:
diff changeset
62 self.inputfile = opts.input
c127b3314d53 Uploaded
devteam
parents:
diff changeset
63 try:
c127b3314d53 Uploaded
devteam
parents:
diff changeset
64 os.makedirs(opts.outdir)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
65 except:
c127b3314d53 Uploaded
devteam
parents:
diff changeset
66 pass
c127b3314d53 Uploaded
devteam
parents:
diff changeset
67 try:
c127b3314d53 Uploaded
devteam
parents:
diff changeset
68 os.makedirs(opts.tmpdir)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
69 except:
c127b3314d53 Uploaded
devteam
parents:
diff changeset
70 pass
c127b3314d53 Uploaded
devteam
parents:
diff changeset
71 self.log_filename = os.path.join(self.opts.outdir,'%s.log' % self.picname)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
72 self.metricsOut = os.path.join(opts.outdir,'%s.metrics.txt' % self.picname)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
73 self.setLogging(logfname=self.log_filename)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
74
c127b3314d53 Uploaded
devteam
parents:
diff changeset
75 def baseName(self,name=None):
c127b3314d53 Uploaded
devteam
parents:
diff changeset
76 return os.path.splitext(os.path.basename(name))[0]
c127b3314d53 Uploaded
devteam
parents:
diff changeset
77
c127b3314d53 Uploaded
devteam
parents:
diff changeset
78 def setLogging(self,logfname="picard_wrapper.log"):
c127b3314d53 Uploaded
devteam
parents:
diff changeset
79 """setup a logger
c127b3314d53 Uploaded
devteam
parents:
diff changeset
80 """
c127b3314d53 Uploaded
devteam
parents:
diff changeset
81 logging.basicConfig(level=logging.INFO,
c127b3314d53 Uploaded
devteam
parents:
diff changeset
82 filename=logfname,
c127b3314d53 Uploaded
devteam
parents:
diff changeset
83 filemode='a')
c127b3314d53 Uploaded
devteam
parents:
diff changeset
84
c127b3314d53 Uploaded
devteam
parents:
diff changeset
85
c127b3314d53 Uploaded
devteam
parents:
diff changeset
86 def readLarge(self,fname=None):
c127b3314d53 Uploaded
devteam
parents:
diff changeset
87 """ read a potentially huge file.
c127b3314d53 Uploaded
devteam
parents:
diff changeset
88 """
c127b3314d53 Uploaded
devteam
parents:
diff changeset
89 try:
c127b3314d53 Uploaded
devteam
parents:
diff changeset
90 # get stderr, allowing for case where it's very large
c127b3314d53 Uploaded
devteam
parents:
diff changeset
91 tmp = open( fname, 'rb' )
c127b3314d53 Uploaded
devteam
parents:
diff changeset
92 s = ''
c127b3314d53 Uploaded
devteam
parents:
diff changeset
93 buffsize = 1048576
c127b3314d53 Uploaded
devteam
parents:
diff changeset
94 try:
c127b3314d53 Uploaded
devteam
parents:
diff changeset
95 while True:
c127b3314d53 Uploaded
devteam
parents:
diff changeset
96 more = tmp.read( buffsize )
c127b3314d53 Uploaded
devteam
parents:
diff changeset
97 if len(more) > 0:
c127b3314d53 Uploaded
devteam
parents:
diff changeset
98 s += more
c127b3314d53 Uploaded
devteam
parents:
diff changeset
99 else:
c127b3314d53 Uploaded
devteam
parents:
diff changeset
100 break
c127b3314d53 Uploaded
devteam
parents:
diff changeset
101 except OverflowError:
c127b3314d53 Uploaded
devteam
parents:
diff changeset
102 pass
c127b3314d53 Uploaded
devteam
parents:
diff changeset
103 tmp.close()
c127b3314d53 Uploaded
devteam
parents:
diff changeset
104 except Exception, e:
c127b3314d53 Uploaded
devteam
parents:
diff changeset
105 stop_err( 'Read Large Exception : %s' % str( e ) )
c127b3314d53 Uploaded
devteam
parents:
diff changeset
106 return s
c127b3314d53 Uploaded
devteam
parents:
diff changeset
107
c127b3314d53 Uploaded
devteam
parents:
diff changeset
108 def runCL(self,cl=None,output_dir=None):
c127b3314d53 Uploaded
devteam
parents:
diff changeset
109 """ construct and run a command line
c127b3314d53 Uploaded
devteam
parents:
diff changeset
110 we have galaxy's temp path as opt.temp_dir so don't really need isolation
c127b3314d53 Uploaded
devteam
parents:
diff changeset
111 sometimes stdout is needed as the output - ugly hacks to deal with potentially vast artifacts
c127b3314d53 Uploaded
devteam
parents:
diff changeset
112 """
c127b3314d53 Uploaded
devteam
parents:
diff changeset
113 assert cl <> None, 'PicardBase runCL needs a command line as cl'
c127b3314d53 Uploaded
devteam
parents:
diff changeset
114 if output_dir == None:
c127b3314d53 Uploaded
devteam
parents:
diff changeset
115 output_dir = self.opts.outdir
c127b3314d53 Uploaded
devteam
parents:
diff changeset
116 if type(cl) == type([]):
c127b3314d53 Uploaded
devteam
parents:
diff changeset
117 cl = ' '.join(cl)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
118 fd,templog = tempfile.mkstemp(dir=output_dir,suffix='rgtempRun.txt')
c127b3314d53 Uploaded
devteam
parents:
diff changeset
119 tlf = open(templog,'wb')
c127b3314d53 Uploaded
devteam
parents:
diff changeset
120 fd,temperr = tempfile.mkstemp(dir=output_dir,suffix='rgtempErr.txt')
c127b3314d53 Uploaded
devteam
parents:
diff changeset
121 tef = open(temperr,'wb')
c127b3314d53 Uploaded
devteam
parents:
diff changeset
122 process = subprocess.Popen(cl, shell=True, stderr=tef, stdout=tlf, cwd=output_dir)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
123 rval = process.wait()
c127b3314d53 Uploaded
devteam
parents:
diff changeset
124 tlf.close()
c127b3314d53 Uploaded
devteam
parents:
diff changeset
125 tef.close()
c127b3314d53 Uploaded
devteam
parents:
diff changeset
126 stderrs = self.readLarge(temperr)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
127 stdouts = self.readLarge(templog)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
128 if rval > 0:
c127b3314d53 Uploaded
devteam
parents:
diff changeset
129 s = '## executing %s returned status %d and stderr: \n%s\n' % (cl,rval,stderrs)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
130 stdouts = '%s\n%s' % (stdouts,stderrs)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
131 else:
c127b3314d53 Uploaded
devteam
parents:
diff changeset
132 s = '## executing %s returned status %d and nothing on stderr\n' % (cl,rval)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
133 logging.info(s)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
134 os.unlink(templog) # always
c127b3314d53 Uploaded
devteam
parents:
diff changeset
135 os.unlink(temperr) # always
c127b3314d53 Uploaded
devteam
parents:
diff changeset
136 return s, stdouts, rval # sometimes s is an output
c127b3314d53 Uploaded
devteam
parents:
diff changeset
137
c127b3314d53 Uploaded
devteam
parents:
diff changeset
138 def runPic(self, jar, cl):
c127b3314d53 Uploaded
devteam
parents:
diff changeset
139 """
c127b3314d53 Uploaded
devteam
parents:
diff changeset
140 cl should be everything after the jar file name in the command
c127b3314d53 Uploaded
devteam
parents:
diff changeset
141 """
c127b3314d53 Uploaded
devteam
parents:
diff changeset
142 runme = ['java -Xmx%s' % self.opts.maxjheap]
c127b3314d53 Uploaded
devteam
parents:
diff changeset
143 runme.append(" -Djava.io.tmpdir='%s' " % self.opts.tmpdir)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
144 runme.append('-jar %s' % jar)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
145 runme += cl
c127b3314d53 Uploaded
devteam
parents:
diff changeset
146
c127b3314d53 Uploaded
devteam
parents:
diff changeset
147 print runme,self.opts.outdir
c127b3314d53 Uploaded
devteam
parents:
diff changeset
148
c127b3314d53 Uploaded
devteam
parents:
diff changeset
149 s,stdouts,rval = self.runCL(cl=runme, output_dir=self.opts.outdir)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
150 return stdouts,rval
c127b3314d53 Uploaded
devteam
parents:
diff changeset
151
c127b3314d53 Uploaded
devteam
parents:
diff changeset
152 def samToBam(self,infile=None,outdir=None):
c127b3314d53 Uploaded
devteam
parents:
diff changeset
153 """
c127b3314d53 Uploaded
devteam
parents:
diff changeset
154 use samtools view to convert sam to bam
c127b3314d53 Uploaded
devteam
parents:
diff changeset
155 """
c127b3314d53 Uploaded
devteam
parents:
diff changeset
156 fd,tempbam = tempfile.mkstemp(dir=outdir,suffix='rgutilsTemp.bam')
c127b3314d53 Uploaded
devteam
parents:
diff changeset
157 cl = ['samtools view -h -b -S -o ',tempbam,infile]
c127b3314d53 Uploaded
devteam
parents:
diff changeset
158 tlog,stdouts,rval = self.runCL(cl,outdir)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
159 return tlog,tempbam,rval
c127b3314d53 Uploaded
devteam
parents:
diff changeset
160
c127b3314d53 Uploaded
devteam
parents:
diff changeset
161 def sortSam(self, infile=None,outfile=None,outdir=None):
c127b3314d53 Uploaded
devteam
parents:
diff changeset
162 """
c127b3314d53 Uploaded
devteam
parents:
diff changeset
163 """
c127b3314d53 Uploaded
devteam
parents:
diff changeset
164 print '## sortSam got infile=%s,outfile=%s,outdir=%s' % (infile,outfile,outdir)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
165 cl = ['samtools sort',infile,outfile]
c127b3314d53 Uploaded
devteam
parents:
diff changeset
166 tlog,stdouts,rval = self.runCL(cl,outdir)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
167 return tlog
c127b3314d53 Uploaded
devteam
parents:
diff changeset
168
c127b3314d53 Uploaded
devteam
parents:
diff changeset
169 def cleanup(self):
c127b3314d53 Uploaded
devteam
parents:
diff changeset
170 for fname in self.delme:
c127b3314d53 Uploaded
devteam
parents:
diff changeset
171 try:
c127b3314d53 Uploaded
devteam
parents:
diff changeset
172 os.unlink(fname)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
173 except:
c127b3314d53 Uploaded
devteam
parents:
diff changeset
174 pass
c127b3314d53 Uploaded
devteam
parents:
diff changeset
175
c127b3314d53 Uploaded
devteam
parents:
diff changeset
176 def prettyPicout(self,transpose,maxrows):
c127b3314d53 Uploaded
devteam
parents:
diff changeset
177 """organize picard outpouts into a report html page
c127b3314d53 Uploaded
devteam
parents:
diff changeset
178 """
c127b3314d53 Uploaded
devteam
parents:
diff changeset
179 res = []
c127b3314d53 Uploaded
devteam
parents:
diff changeset
180 try:
c127b3314d53 Uploaded
devteam
parents:
diff changeset
181 r = open(self.metricsOut,'r').readlines()
c127b3314d53 Uploaded
devteam
parents:
diff changeset
182 except:
c127b3314d53 Uploaded
devteam
parents:
diff changeset
183 r = []
c127b3314d53 Uploaded
devteam
parents:
diff changeset
184 if len(r) > 0:
c127b3314d53 Uploaded
devteam
parents:
diff changeset
185 res.append('<b>Picard on line resources</b><ul>\n')
c127b3314d53 Uploaded
devteam
parents:
diff changeset
186 res.append('<li><a href="http://picard.sourceforge.net/index.shtml">Click here for Picard Documentation</a></li>\n')
c127b3314d53 Uploaded
devteam
parents:
diff changeset
187 res.append('<li><a href="http://picard.sourceforge.net/picard-metric-definitions.shtml">Click here for Picard Metrics definitions</a></li></ul><hr/>\n')
c127b3314d53 Uploaded
devteam
parents:
diff changeset
188 if transpose:
c127b3314d53 Uploaded
devteam
parents:
diff changeset
189 res.append('<b>Picard output (transposed to make it easier to see)</b><hr/>\n')
c127b3314d53 Uploaded
devteam
parents:
diff changeset
190 else:
c127b3314d53 Uploaded
devteam
parents:
diff changeset
191 res.append('<b>Picard output</b><hr/>\n')
c127b3314d53 Uploaded
devteam
parents:
diff changeset
192 res.append('<table cellpadding="3" >\n')
c127b3314d53 Uploaded
devteam
parents:
diff changeset
193 dat = []
c127b3314d53 Uploaded
devteam
parents:
diff changeset
194 heads = []
c127b3314d53 Uploaded
devteam
parents:
diff changeset
195 lastr = len(r) - 1
c127b3314d53 Uploaded
devteam
parents:
diff changeset
196 # special case for estimate library complexity hist
c127b3314d53 Uploaded
devteam
parents:
diff changeset
197 thist = False
c127b3314d53 Uploaded
devteam
parents:
diff changeset
198 for i,row in enumerate(r):
c127b3314d53 Uploaded
devteam
parents:
diff changeset
199 if row.strip() > '':
c127b3314d53 Uploaded
devteam
parents:
diff changeset
200 srow = row.split('\t')
c127b3314d53 Uploaded
devteam
parents:
diff changeset
201 if row.startswith('#'):
c127b3314d53 Uploaded
devteam
parents:
diff changeset
202 heads.append(row.strip()) # want strings
c127b3314d53 Uploaded
devteam
parents:
diff changeset
203 else:
c127b3314d53 Uploaded
devteam
parents:
diff changeset
204 dat.append(srow) # want lists
c127b3314d53 Uploaded
devteam
parents:
diff changeset
205 if row.startswith('## HISTOGRAM'):
c127b3314d53 Uploaded
devteam
parents:
diff changeset
206 thist = True
c127b3314d53 Uploaded
devteam
parents:
diff changeset
207 if len(heads) > 0:
c127b3314d53 Uploaded
devteam
parents:
diff changeset
208 hres = ['<tr class="d%d"><td colspan="2">%s</td></tr>' % (i % 2,x) for i,x in enumerate(heads)]
c127b3314d53 Uploaded
devteam
parents:
diff changeset
209 res += hres
c127b3314d53 Uploaded
devteam
parents:
diff changeset
210 heads = []
c127b3314d53 Uploaded
devteam
parents:
diff changeset
211 if len(dat) > 0:
c127b3314d53 Uploaded
devteam
parents:
diff changeset
212 if transpose and not thist:
c127b3314d53 Uploaded
devteam
parents:
diff changeset
213 tdat = map(None,*dat) # transpose an arbitrary list of lists
c127b3314d53 Uploaded
devteam
parents:
diff changeset
214 tdat = ['<tr class="d%d"><td>%s</td><td>%s&nbsp;</td></tr>\n' % ((i+len(heads)) % 2,x[0],x[1]) for i,x in enumerate(tdat)]
c127b3314d53 Uploaded
devteam
parents:
diff changeset
215 else:
c127b3314d53 Uploaded
devteam
parents:
diff changeset
216 tdat = ['\t'.join(x).strip() for x in dat] # back to strings :(
c127b3314d53 Uploaded
devteam
parents:
diff changeset
217 tdat = ['<tr class="d%d"><td colspan="2">%s</td></tr>\n' % ((i+len(heads)) % 2,x) for i,x in enumerate(tdat)]
c127b3314d53 Uploaded
devteam
parents:
diff changeset
218 res += tdat
c127b3314d53 Uploaded
devteam
parents:
diff changeset
219 dat = []
c127b3314d53 Uploaded
devteam
parents:
diff changeset
220 res.append('</table>\n')
c127b3314d53 Uploaded
devteam
parents:
diff changeset
221 return res
c127b3314d53 Uploaded
devteam
parents:
diff changeset
222
c127b3314d53 Uploaded
devteam
parents:
diff changeset
223 def fixPicardOutputs(self,transpose,maxloglines):
c127b3314d53 Uploaded
devteam
parents:
diff changeset
224 """
c127b3314d53 Uploaded
devteam
parents:
diff changeset
225 picard produces long hard to read tab header files
c127b3314d53 Uploaded
devteam
parents:
diff changeset
226 make them available but present them transposed for readability
c127b3314d53 Uploaded
devteam
parents:
diff changeset
227 """
c127b3314d53 Uploaded
devteam
parents:
diff changeset
228 logging.shutdown()
c127b3314d53 Uploaded
devteam
parents:
diff changeset
229 self.cleanup() # remove temp files stored in delme
c127b3314d53 Uploaded
devteam
parents:
diff changeset
230 rstyle="""<style type="text/css">
c127b3314d53 Uploaded
devteam
parents:
diff changeset
231 tr.d0 td {background-color: oldlace; color: black;}
c127b3314d53 Uploaded
devteam
parents:
diff changeset
232 tr.d1 td {background-color: aliceblue; color: black;}
c127b3314d53 Uploaded
devteam
parents:
diff changeset
233 </style>"""
c127b3314d53 Uploaded
devteam
parents:
diff changeset
234 res = [rstyle,]
c127b3314d53 Uploaded
devteam
parents:
diff changeset
235 res.append(galhtmlprefix % self.progname)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
236 res.append(galhtmlattr % (self.picname,timenow()))
c127b3314d53 Uploaded
devteam
parents:
diff changeset
237 flist = [x for x in os.listdir(self.opts.outdir) if not x.startswith('.')]
c127b3314d53 Uploaded
devteam
parents:
diff changeset
238 pdflist = [x for x in flist if os.path.splitext(x)[-1].lower() == '.pdf']
c127b3314d53 Uploaded
devteam
parents:
diff changeset
239 if len(pdflist) > 0: # assumes all pdfs come with thumbnail .jpgs
c127b3314d53 Uploaded
devteam
parents:
diff changeset
240 for p in pdflist:
c127b3314d53 Uploaded
devteam
parents:
diff changeset
241 pbase = os.path.splitext(p)[0] # removes .pdf
c127b3314d53 Uploaded
devteam
parents:
diff changeset
242 imghref = '%s.jpg' % pbase
c127b3314d53 Uploaded
devteam
parents:
diff changeset
243 mimghref = '%s-0.jpg' % pbase # multiple pages pdf -> multiple thumbnails without asking!
c127b3314d53 Uploaded
devteam
parents:
diff changeset
244 if mimghref in flist:
c127b3314d53 Uploaded
devteam
parents:
diff changeset
245 imghref=mimghref # only one for thumbnail...it's a multi page pdf
c127b3314d53 Uploaded
devteam
parents:
diff changeset
246 res.append('<table cellpadding="10"><tr><td>\n')
c127b3314d53 Uploaded
devteam
parents:
diff changeset
247 res.append('<a href="%s"><img src="%s" title="Click image preview for a print quality PDF version" hspace="10" align="middle"></a>\n' % (p,imghref))
c127b3314d53 Uploaded
devteam
parents:
diff changeset
248 res.append('</tr></td></table>\n')
c127b3314d53 Uploaded
devteam
parents:
diff changeset
249 if len(flist) > 0:
c127b3314d53 Uploaded
devteam
parents:
diff changeset
250 res.append('<b>The following output files were created (click the filename to view/download a copy):</b><hr/>')
c127b3314d53 Uploaded
devteam
parents:
diff changeset
251 res.append('<table>\n')
c127b3314d53 Uploaded
devteam
parents:
diff changeset
252 for i,f in enumerate(flist):
c127b3314d53 Uploaded
devteam
parents:
diff changeset
253 fn = os.path.split(f)[-1]
c127b3314d53 Uploaded
devteam
parents:
diff changeset
254 res.append('<tr><td><a href="%s">%s</a></td></tr>\n' % (fn,fn))
c127b3314d53 Uploaded
devteam
parents:
diff changeset
255 res.append('</table><p/>\n')
c127b3314d53 Uploaded
devteam
parents:
diff changeset
256 pres = self.prettyPicout(transpose,maxloglines)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
257 if len(pres) > 0:
c127b3314d53 Uploaded
devteam
parents:
diff changeset
258 res += pres
c127b3314d53 Uploaded
devteam
parents:
diff changeset
259 l = open(self.log_filename,'r').readlines()
c127b3314d53 Uploaded
devteam
parents:
diff changeset
260 llen = len(l)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
261 if llen > 0:
c127b3314d53 Uploaded
devteam
parents:
diff changeset
262 res.append('<b>Picard Tool Run Log</b><hr/>\n')
c127b3314d53 Uploaded
devteam
parents:
diff changeset
263 rlog = ['<pre>',]
c127b3314d53 Uploaded
devteam
parents:
diff changeset
264 if llen > maxloglines:
c127b3314d53 Uploaded
devteam
parents:
diff changeset
265 n = min(50,int(maxloglines/2))
c127b3314d53 Uploaded
devteam
parents:
diff changeset
266 rlog += l[:n]
c127b3314d53 Uploaded
devteam
parents:
diff changeset
267 rlog.append('------------ ## %d rows deleted ## --------------\n' % (llen-maxloglines))
c127b3314d53 Uploaded
devteam
parents:
diff changeset
268 rlog += l[-n:]
c127b3314d53 Uploaded
devteam
parents:
diff changeset
269 else:
c127b3314d53 Uploaded
devteam
parents:
diff changeset
270 rlog += l
c127b3314d53 Uploaded
devteam
parents:
diff changeset
271 rlog.append('</pre>')
c127b3314d53 Uploaded
devteam
parents:
diff changeset
272 if llen > maxloglines:
c127b3314d53 Uploaded
devteam
parents:
diff changeset
273 rlog.append('\n<b>## WARNING - %d log lines truncated - <a href="%s">%s</a> contains entire output</b>' % (llen - maxloglines,self.log_filename,self.log_filename))
c127b3314d53 Uploaded
devteam
parents:
diff changeset
274 res += rlog
c127b3314d53 Uploaded
devteam
parents:
diff changeset
275 else:
c127b3314d53 Uploaded
devteam
parents:
diff changeset
276 res.append("### Odd, Picard left no log file %s - must have really barfed badly?\n" % self.log_filename)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
277 res.append('<hr/>The freely available <a href="http://picard.sourceforge.net/command-line-overview.shtml">Picard software</a> \n')
c127b3314d53 Uploaded
devteam
parents:
diff changeset
278 res.append( 'generated all outputs reported here running as a <a href="http://getgalaxy.org">Galaxy</a> tool')
c127b3314d53 Uploaded
devteam
parents:
diff changeset
279 res.append(galhtmlpostfix)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
280 outf = open(self.opts.htmlout,'w')
c127b3314d53 Uploaded
devteam
parents:
diff changeset
281 outf.write(''.join(res))
c127b3314d53 Uploaded
devteam
parents:
diff changeset
282 outf.write('\n')
c127b3314d53 Uploaded
devteam
parents:
diff changeset
283 outf.close()
c127b3314d53 Uploaded
devteam
parents:
diff changeset
284
c127b3314d53 Uploaded
devteam
parents:
diff changeset
285 def makePicInterval(self,inbed=None,outf=None):
c127b3314d53 Uploaded
devteam
parents:
diff changeset
286 """
c127b3314d53 Uploaded
devteam
parents:
diff changeset
287 picard wants bait and target files to have the same header length as the incoming bam/sam
c127b3314d53 Uploaded
devteam
parents:
diff changeset
288 a meaningful (ie accurate) representation will fail because of this - so this hack
c127b3314d53 Uploaded
devteam
parents:
diff changeset
289 it would be far better to be able to supply the original bed untouched
c127b3314d53 Uploaded
devteam
parents:
diff changeset
290 Additional checking added Ross Lazarus Dec 2011 to deal with two 'bug' reports on the list
c127b3314d53 Uploaded
devteam
parents:
diff changeset
291 """
c127b3314d53 Uploaded
devteam
parents:
diff changeset
292 assert inbed <> None
c127b3314d53 Uploaded
devteam
parents:
diff changeset
293 bed = open(inbed,'r').readlines()
c127b3314d53 Uploaded
devteam
parents:
diff changeset
294 sbed = [x.split('\t') for x in bed] # lengths MUST be 5
c127b3314d53 Uploaded
devteam
parents:
diff changeset
295 lens = [len(x) for x in sbed]
c127b3314d53 Uploaded
devteam
parents:
diff changeset
296 strands = [x[3] for x in sbed if not x[3] in ['+','-']]
c127b3314d53 Uploaded
devteam
parents:
diff changeset
297 maxl = max(lens)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
298 minl = min(lens)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
299 e = []
c127b3314d53 Uploaded
devteam
parents:
diff changeset
300 if maxl <> minl:
c127b3314d53 Uploaded
devteam
parents:
diff changeset
301 e.append("## Input error: Inconsistent field count in %s - please read the documentation on bait/target format requirements, fix and try again" % inbed)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
302 if maxl <> 5:
c127b3314d53 Uploaded
devteam
parents:
diff changeset
303 e.append("## Input error: %d fields found in %s, 5 required - please read the warning and documentation on bait/target format requirements, fix and try again" % (maxl,inbed))
c127b3314d53 Uploaded
devteam
parents:
diff changeset
304 if len(strands) > 0:
c127b3314d53 Uploaded
devteam
parents:
diff changeset
305 e.append("## Input error: Fourth column in %s is not the required strand (+ or -) - please read the warning and documentation on bait/target format requirements, fix and try again" % (inbed))
c127b3314d53 Uploaded
devteam
parents:
diff changeset
306 if len(e) > 0: # write to stderr and quit
c127b3314d53 Uploaded
devteam
parents:
diff changeset
307 print >> sys.stderr, '\n'.join(e)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
308 sys.exit(1)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
309 thead = os.path.join(self.opts.outdir,'tempSamHead.txt')
c127b3314d53 Uploaded
devteam
parents:
diff changeset
310 if self.opts.datatype == 'sam':
c127b3314d53 Uploaded
devteam
parents:
diff changeset
311 cl = ['samtools view -H -S',self.opts.input,'>',thead]
c127b3314d53 Uploaded
devteam
parents:
diff changeset
312 else:
c127b3314d53 Uploaded
devteam
parents:
diff changeset
313 cl = ['samtools view -H',self.opts.input,'>',thead]
c127b3314d53 Uploaded
devteam
parents:
diff changeset
314 self.runCL(cl=cl,output_dir=self.opts.outdir)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
315 head = open(thead,'r').readlines()
c127b3314d53 Uploaded
devteam
parents:
diff changeset
316 s = '## got %d rows of header\n' % (len(head))
c127b3314d53 Uploaded
devteam
parents:
diff changeset
317 logging.info(s)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
318 o = open(outf,'w')
c127b3314d53 Uploaded
devteam
parents:
diff changeset
319 o.write(''.join(head))
c127b3314d53 Uploaded
devteam
parents:
diff changeset
320 o.write(''.join(bed))
c127b3314d53 Uploaded
devteam
parents:
diff changeset
321 o.close()
c127b3314d53 Uploaded
devteam
parents:
diff changeset
322 return outf
c127b3314d53 Uploaded
devteam
parents:
diff changeset
323
c127b3314d53 Uploaded
devteam
parents:
diff changeset
324 def cleanSam(self, insam=None, newsam=None, picardErrors=[],outformat=None):
c127b3314d53 Uploaded
devteam
parents:
diff changeset
325 """
c127b3314d53 Uploaded
devteam
parents:
diff changeset
326 interesting problem - if paired, must remove mate pair of errors too or we have a new set of errors after cleaning - missing mate pairs!
c127b3314d53 Uploaded
devteam
parents:
diff changeset
327 Do the work of removing all the error sequences
c127b3314d53 Uploaded
devteam
parents:
diff changeset
328 pysam is cool
c127b3314d53 Uploaded
devteam
parents:
diff changeset
329 infile = pysam.Samfile( "-", "r" )
c127b3314d53 Uploaded
devteam
parents:
diff changeset
330 outfile = pysam.Samfile( "-", "w", template = infile )
c127b3314d53 Uploaded
devteam
parents:
diff changeset
331 for s in infile: outfile.write(s)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
332
c127b3314d53 Uploaded
devteam
parents:
diff changeset
333 errors from ValidateSameFile.jar look like
c127b3314d53 Uploaded
devteam
parents:
diff changeset
334 WARNING: Record 32, Read name SRR006041.1202260, NM tag (nucleotide differences) is missing
c127b3314d53 Uploaded
devteam
parents:
diff changeset
335 ERROR: Record 33, Read name SRR006041.1042721, Empty sequence dictionary.
c127b3314d53 Uploaded
devteam
parents:
diff changeset
336 ERROR: Record 33, Read name SRR006041.1042721, RG ID on SAMRecord not found in header: SRR006041
c127b3314d53 Uploaded
devteam
parents:
diff changeset
337
c127b3314d53 Uploaded
devteam
parents:
diff changeset
338 """
c127b3314d53 Uploaded
devteam
parents:
diff changeset
339 assert os.path.isfile(insam), 'rgPicardValidate cleansam needs an input sam file - cannot find %s' % insam
c127b3314d53 Uploaded
devteam
parents:
diff changeset
340 assert newsam <> None, 'rgPicardValidate cleansam needs an output new sam file path'
c127b3314d53 Uploaded
devteam
parents:
diff changeset
341 removeNames = [x.split(',')[1].replace(' Read name ','') for x in picardErrors if len(x.split(',')) > 2]
c127b3314d53 Uploaded
devteam
parents:
diff changeset
342 remDict = dict(zip(removeNames,range(len(removeNames))))
c127b3314d53 Uploaded
devteam
parents:
diff changeset
343 infile = pysam.Samfile(insam,'rb')
c127b3314d53 Uploaded
devteam
parents:
diff changeset
344 info = 'found %d error sequences in picardErrors, %d unique' % (len(removeNames),len(remDict))
c127b3314d53 Uploaded
devteam
parents:
diff changeset
345 if len(removeNames) > 0:
c127b3314d53 Uploaded
devteam
parents:
diff changeset
346 outfile = pysam.Samfile(newsam,'wb',template=infile) # template must be an open file
c127b3314d53 Uploaded
devteam
parents:
diff changeset
347 i = 0
c127b3314d53 Uploaded
devteam
parents:
diff changeset
348 j = 0
c127b3314d53 Uploaded
devteam
parents:
diff changeset
349 for row in infile:
c127b3314d53 Uploaded
devteam
parents:
diff changeset
350 dropme = remDict.get(row.qname,None) # keep if None
c127b3314d53 Uploaded
devteam
parents:
diff changeset
351 if not dropme:
c127b3314d53 Uploaded
devteam
parents:
diff changeset
352 outfile.write(row)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
353 j += 1
c127b3314d53 Uploaded
devteam
parents:
diff changeset
354 else: # discard
c127b3314d53 Uploaded
devteam
parents:
diff changeset
355 i += 1
c127b3314d53 Uploaded
devteam
parents:
diff changeset
356 info = '%s\n%s' % (info, 'Discarded %d lines writing %d to %s from %s' % (i,j,newsam,insam))
c127b3314d53 Uploaded
devteam
parents:
diff changeset
357 outfile.close()
c127b3314d53 Uploaded
devteam
parents:
diff changeset
358 infile.close()
c127b3314d53 Uploaded
devteam
parents:
diff changeset
359 else: # we really want a nullop or a simple pointer copy
c127b3314d53 Uploaded
devteam
parents:
diff changeset
360 infile.close()
c127b3314d53 Uploaded
devteam
parents:
diff changeset
361 if newsam:
c127b3314d53 Uploaded
devteam
parents:
diff changeset
362 shutil.copy(insam,newsam)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
363 logging.info(info)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
364
c127b3314d53 Uploaded
devteam
parents:
diff changeset
365
c127b3314d53 Uploaded
devteam
parents:
diff changeset
366
c127b3314d53 Uploaded
devteam
parents:
diff changeset
367 def __main__():
c127b3314d53 Uploaded
devteam
parents:
diff changeset
368 doFix = False # tools returning htmlfile don't need this
c127b3314d53 Uploaded
devteam
parents:
diff changeset
369 doTranspose = True # default
c127b3314d53 Uploaded
devteam
parents:
diff changeset
370 maxloglines = 100 # default
c127b3314d53 Uploaded
devteam
parents:
diff changeset
371 #Parse Command Line
c127b3314d53 Uploaded
devteam
parents:
diff changeset
372 op = optparse.OptionParser()
c127b3314d53 Uploaded
devteam
parents:
diff changeset
373 # All tools
c127b3314d53 Uploaded
devteam
parents:
diff changeset
374 op.add_option('-i', '--input', dest='input', help='Input SAM or BAM file' )
c127b3314d53 Uploaded
devteam
parents:
diff changeset
375 op.add_option('-e', '--inputext', default=None)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
376 op.add_option('-o', '--output', default=None)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
377 op.add_option('-n', '--title', default="Pick a Picard Tool")
c127b3314d53 Uploaded
devteam
parents:
diff changeset
378 op.add_option('-t', '--htmlout', default=None)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
379 op.add_option('-d', '--outdir', default=None)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
380 op.add_option('-x', '--maxjheap', default='3000m')
c127b3314d53 Uploaded
devteam
parents:
diff changeset
381 op.add_option('-b', '--bisulphite', default='false')
c127b3314d53 Uploaded
devteam
parents:
diff changeset
382 op.add_option('-s', '--sortorder', default='query')
c127b3314d53 Uploaded
devteam
parents:
diff changeset
383 op.add_option('','--tmpdir', default='/tmp')
c127b3314d53 Uploaded
devteam
parents:
diff changeset
384 op.add_option('-j','--jar',default='')
c127b3314d53 Uploaded
devteam
parents:
diff changeset
385 op.add_option('','--picard-cmd',default=None)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
386 # Many tools
c127b3314d53 Uploaded
devteam
parents:
diff changeset
387 op.add_option( '', '--output-format', dest='output_format', help='Output format' )
c127b3314d53 Uploaded
devteam
parents:
diff changeset
388 op.add_option( '', '--bai-file', dest='bai_file', help='The path to the index file for the input bam file' )
c127b3314d53 Uploaded
devteam
parents:
diff changeset
389 op.add_option( '', '--ref', dest='ref', help='Built-in reference with fasta and dict file', default=None )
c127b3314d53 Uploaded
devteam
parents:
diff changeset
390 # CreateSequenceDictionary
c127b3314d53 Uploaded
devteam
parents:
diff changeset
391 op.add_option( '', '--ref-file', dest='ref_file', help='Fasta to use as reference', default=None )
c127b3314d53 Uploaded
devteam
parents:
diff changeset
392 op.add_option( '', '--species-name', dest='species_name', help='Species name to use in creating dict file from fasta file' )
c127b3314d53 Uploaded
devteam
parents:
diff changeset
393 op.add_option( '', '--build-name', dest='build_name', help='Name of genome assembly to use in creating dict file from fasta file' )
c127b3314d53 Uploaded
devteam
parents:
diff changeset
394 op.add_option( '', '--trunc-names', dest='trunc_names', help='Truncate sequence names at first whitespace from fasta file' )
c127b3314d53 Uploaded
devteam
parents:
diff changeset
395 # MarkDuplicates
c127b3314d53 Uploaded
devteam
parents:
diff changeset
396 op.add_option( '', '--remdups', default='true', help='Remove duplicates from output file' )
c127b3314d53 Uploaded
devteam
parents:
diff changeset
397 op.add_option( '', '--optdupdist', default="100", help='Maximum pixels between two identical sequences in order to consider them optical duplicates.' )
c127b3314d53 Uploaded
devteam
parents:
diff changeset
398 # CollectInsertSizeMetrics
c127b3314d53 Uploaded
devteam
parents:
diff changeset
399 op.add_option('', '--taillimit', default="0")
c127b3314d53 Uploaded
devteam
parents:
diff changeset
400 op.add_option('', '--histwidth', default="0")
c127b3314d53 Uploaded
devteam
parents:
diff changeset
401 op.add_option('', '--minpct', default="0.01")
c127b3314d53 Uploaded
devteam
parents:
diff changeset
402 op.add_option('', '--malevel', default='')
c127b3314d53 Uploaded
devteam
parents:
diff changeset
403 op.add_option('', '--deviations', default="0.0")
c127b3314d53 Uploaded
devteam
parents:
diff changeset
404 # CollectAlignmentSummaryMetrics
c127b3314d53 Uploaded
devteam
parents:
diff changeset
405 op.add_option('', '--maxinsert', default="20")
c127b3314d53 Uploaded
devteam
parents:
diff changeset
406 op.add_option('', '--adaptors', default='')
c127b3314d53 Uploaded
devteam
parents:
diff changeset
407 # FixMateInformation and validate
c127b3314d53 Uploaded
devteam
parents:
diff changeset
408 # CollectGcBiasMetrics
c127b3314d53 Uploaded
devteam
parents:
diff changeset
409 op.add_option('', '--windowsize', default='100')
c127b3314d53 Uploaded
devteam
parents:
diff changeset
410 op.add_option('', '--mingenomefrac', default='0.00001')
c127b3314d53 Uploaded
devteam
parents:
diff changeset
411 # AddOrReplaceReadGroups
c127b3314d53 Uploaded
devteam
parents:
diff changeset
412 op.add_option( '', '--rg-opts', dest='rg_opts', help='Specify extra (optional) arguments with full, otherwise preSet' )
c127b3314d53 Uploaded
devteam
parents:
diff changeset
413 op.add_option( '', '--rg-lb', dest='rg_library', help='Read Group Library' )
c127b3314d53 Uploaded
devteam
parents:
diff changeset
414 op.add_option( '', '--rg-pl', dest='rg_platform', help='Read Group platform (e.g. illumina, solid)' )
c127b3314d53 Uploaded
devteam
parents:
diff changeset
415 op.add_option( '', '--rg-pu', dest='rg_plat_unit', help='Read Group platform unit (eg. run barcode) ' )
c127b3314d53 Uploaded
devteam
parents:
diff changeset
416 op.add_option( '', '--rg-sm', dest='rg_sample', help='Read Group sample name' )
c127b3314d53 Uploaded
devteam
parents:
diff changeset
417 op.add_option( '', '--rg-id', dest='rg_id', help='Read Group ID' )
c127b3314d53 Uploaded
devteam
parents:
diff changeset
418 op.add_option( '', '--rg-cn', dest='rg_seq_center', help='Read Group sequencing center name' )
c127b3314d53 Uploaded
devteam
parents:
diff changeset
419 op.add_option( '', '--rg-ds', dest='rg_desc', help='Read Group description' )
c127b3314d53 Uploaded
devteam
parents:
diff changeset
420 # ReorderSam
c127b3314d53 Uploaded
devteam
parents:
diff changeset
421 op.add_option( '', '--allow-inc-dict-concord', dest='allow_inc_dict_concord', help='Allow incomplete dict concordance' )
c127b3314d53 Uploaded
devteam
parents:
diff changeset
422 op.add_option( '', '--allow-contig-len-discord', dest='allow_contig_len_discord', help='Allow contig length discordance' )
c127b3314d53 Uploaded
devteam
parents:
diff changeset
423 # ReplaceSamHeader
c127b3314d53 Uploaded
devteam
parents:
diff changeset
424 op.add_option( '', '--header-file', dest='header_file', help='sam or bam file from which header will be read' )
c127b3314d53 Uploaded
devteam
parents:
diff changeset
425
c127b3314d53 Uploaded
devteam
parents:
diff changeset
426 op.add_option('','--assumesorted', default='true')
c127b3314d53 Uploaded
devteam
parents:
diff changeset
427 op.add_option('','--readregex', default="[a-zA-Z0-9]+:[0-9]:([0-9]+):([0-9]+):([0-9]+).*")
c127b3314d53 Uploaded
devteam
parents:
diff changeset
428 #estimatelibrarycomplexity
c127b3314d53 Uploaded
devteam
parents:
diff changeset
429 op.add_option('','--minid', default="5")
c127b3314d53 Uploaded
devteam
parents:
diff changeset
430 op.add_option('','--maxdiff', default="0.03")
c127b3314d53 Uploaded
devteam
parents:
diff changeset
431 op.add_option('','--minmeanq', default="20")
c127b3314d53 Uploaded
devteam
parents:
diff changeset
432 #hsmetrics
c127b3314d53 Uploaded
devteam
parents:
diff changeset
433 op.add_option('','--baitbed', default=None)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
434 op.add_option('','--targetbed', default=None)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
435 #validate
c127b3314d53 Uploaded
devteam
parents:
diff changeset
436 op.add_option('','--ignoreflags', action='append', type="string")
c127b3314d53 Uploaded
devteam
parents:
diff changeset
437 op.add_option('','--maxerrors', default=None)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
438 op.add_option('','--datatype', default=None)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
439 op.add_option('','--bamout', default=None)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
440 op.add_option('','--samout', default=None)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
441 #downsample
c127b3314d53 Uploaded
devteam
parents:
diff changeset
442 op.add_option('','--probability', default="1")
c127b3314d53 Uploaded
devteam
parents:
diff changeset
443 op.add_option('','--seed', default="1")
c127b3314d53 Uploaded
devteam
parents:
diff changeset
444 #meanqualitybycycle
c127b3314d53 Uploaded
devteam
parents:
diff changeset
445 op.add_option('','--pfreadsonly', default='false')
c127b3314d53 Uploaded
devteam
parents:
diff changeset
446 op.add_option('','--alignedreadsonly', default='false')
c127b3314d53 Uploaded
devteam
parents:
diff changeset
447 #collectrnaseqmetrics
c127b3314d53 Uploaded
devteam
parents:
diff changeset
448 op.add_option('','--ignoreseq', action='append', type="string")
c127b3314d53 Uploaded
devteam
parents:
diff changeset
449 op.add_option('','--minlength', default=None)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
450 op.add_option('','--refflat', default=None)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
451 op.add_option('','--strandspecificity', default=None)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
452 op.add_option('','--ribosomalintervals', default=None)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
453 op.add_option('','--rrnafragmentpercentage', default=None)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
454
c127b3314d53 Uploaded
devteam
parents:
diff changeset
455 opts, args = op.parse_args()
c127b3314d53 Uploaded
devteam
parents:
diff changeset
456 opts.sortme = opts.assumesorted == 'false'
c127b3314d53 Uploaded
devteam
parents:
diff changeset
457 assert opts.input <> None
c127b3314d53 Uploaded
devteam
parents:
diff changeset
458 # need to add
c127b3314d53 Uploaded
devteam
parents:
diff changeset
459 # instance that does all the work
c127b3314d53 Uploaded
devteam
parents:
diff changeset
460 pic = PicardBase(opts,sys.argv[0])
c127b3314d53 Uploaded
devteam
parents:
diff changeset
461
c127b3314d53 Uploaded
devteam
parents:
diff changeset
462 tmp_dir = opts.outdir
c127b3314d53 Uploaded
devteam
parents:
diff changeset
463 haveTempout = False # we use this where sam output is an option
c127b3314d53 Uploaded
devteam
parents:
diff changeset
464 rval = 0
c127b3314d53 Uploaded
devteam
parents:
diff changeset
465 stdouts = 'Not run yet'
c127b3314d53 Uploaded
devteam
parents:
diff changeset
466 # set ref and dict files to use (create if necessary)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
467 ref_file_name = opts.ref
c127b3314d53 Uploaded
devteam
parents:
diff changeset
468 if opts.ref_file <> None:
c127b3314d53 Uploaded
devteam
parents:
diff changeset
469 csd = 'CreateSequenceDictionary'
c127b3314d53 Uploaded
devteam
parents:
diff changeset
470 realjarpath = os.path.split(opts.jar)[0]
c127b3314d53 Uploaded
devteam
parents:
diff changeset
471 jarpath = os.path.join(realjarpath,'%s.jar' % csd) # for refseq
c127b3314d53 Uploaded
devteam
parents:
diff changeset
472 tmp_ref_fd, tmp_ref_name = tempfile.mkstemp( dir=opts.tmpdir , prefix = pic.picname)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
473 ref_file_name = '%s.fasta' % tmp_ref_name
c127b3314d53 Uploaded
devteam
parents:
diff changeset
474 # build dict
c127b3314d53 Uploaded
devteam
parents:
diff changeset
475 dict_file_name = '%s.dict' % tmp_ref_name
c127b3314d53 Uploaded
devteam
parents:
diff changeset
476 os.symlink( opts.ref_file, ref_file_name )
c127b3314d53 Uploaded
devteam
parents:
diff changeset
477 cl = ['REFERENCE=%s' % ref_file_name]
c127b3314d53 Uploaded
devteam
parents:
diff changeset
478 cl.append('OUTPUT=%s' % dict_file_name)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
479 cl.append('URI=%s' % os.path.basename( opts.ref_file ))
c127b3314d53 Uploaded
devteam
parents:
diff changeset
480 cl.append('TRUNCATE_NAMES_AT_WHITESPACE=%s' % opts.trunc_names)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
481 if opts.species_name:
c127b3314d53 Uploaded
devteam
parents:
diff changeset
482 cl.append('SPECIES=%s' % opts.species_name)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
483 if opts.build_name:
c127b3314d53 Uploaded
devteam
parents:
diff changeset
484 cl.append('GENOME_ASSEMBLY=%s' % opts.build_name)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
485 pic.delme.append(dict_file_name)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
486 pic.delme.append(ref_file_name)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
487 pic.delme.append(tmp_ref_name)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
488 stdouts,rval = pic.runPic(jarpath, cl)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
489 # run relevant command(s)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
490
c127b3314d53 Uploaded
devteam
parents:
diff changeset
491 # define temporary output
c127b3314d53 Uploaded
devteam
parents:
diff changeset
492 # if output is sam, it must have that extension, otherwise bam will be produced
c127b3314d53 Uploaded
devteam
parents:
diff changeset
493 # specify sam or bam file with extension
c127b3314d53 Uploaded
devteam
parents:
diff changeset
494 if opts.output_format == 'sam':
c127b3314d53 Uploaded
devteam
parents:
diff changeset
495 suff = '.sam'
c127b3314d53 Uploaded
devteam
parents:
diff changeset
496 else:
c127b3314d53 Uploaded
devteam
parents:
diff changeset
497 suff = ''
c127b3314d53 Uploaded
devteam
parents:
diff changeset
498 tmp_fd, tempout = tempfile.mkstemp( dir=opts.tmpdir, suffix=suff )
c127b3314d53 Uploaded
devteam
parents:
diff changeset
499
c127b3314d53 Uploaded
devteam
parents:
diff changeset
500 cl = ['VALIDATION_STRINGENCY=LENIENT',]
c127b3314d53 Uploaded
devteam
parents:
diff changeset
501
c127b3314d53 Uploaded
devteam
parents:
diff changeset
502 if pic.picname == 'AddOrReplaceReadGroups':
c127b3314d53 Uploaded
devteam
parents:
diff changeset
503 # sort order to match Galaxy's default
c127b3314d53 Uploaded
devteam
parents:
diff changeset
504 cl.append('SORT_ORDER=coordinate')
c127b3314d53 Uploaded
devteam
parents:
diff changeset
505 # input
c127b3314d53 Uploaded
devteam
parents:
diff changeset
506 cl.append('INPUT=%s' % opts.input)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
507 # outputs
c127b3314d53 Uploaded
devteam
parents:
diff changeset
508 cl.append('OUTPUT=%s' % tempout)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
509 # required read groups
c127b3314d53 Uploaded
devteam
parents:
diff changeset
510 cl.append('RGLB="%s"' % opts.rg_library)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
511 cl.append('RGPL="%s"' % opts.rg_platform)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
512 cl.append('RGPU="%s"' % opts.rg_plat_unit)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
513 cl.append('RGSM="%s"' % opts.rg_sample)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
514 if opts.rg_id:
c127b3314d53 Uploaded
devteam
parents:
diff changeset
515 cl.append('RGID="%s"' % opts.rg_id)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
516 # optional read groups
c127b3314d53 Uploaded
devteam
parents:
diff changeset
517 if opts.rg_seq_center:
c127b3314d53 Uploaded
devteam
parents:
diff changeset
518 cl.append('RGCN="%s"' % opts.rg_seq_center)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
519 if opts.rg_desc:
c127b3314d53 Uploaded
devteam
parents:
diff changeset
520 cl.append('RGDS="%s"' % opts.rg_desc)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
521 stdouts,rval = pic.runPic(opts.jar, cl)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
522 haveTempout = True
c127b3314d53 Uploaded
devteam
parents:
diff changeset
523
c127b3314d53 Uploaded
devteam
parents:
diff changeset
524 elif pic.picname == 'BamIndexStats':
c127b3314d53 Uploaded
devteam
parents:
diff changeset
525 tmp_fd, tmp_name = tempfile.mkstemp( dir=tmp_dir )
c127b3314d53 Uploaded
devteam
parents:
diff changeset
526 tmp_bam_name = '%s.bam' % tmp_name
c127b3314d53 Uploaded
devteam
parents:
diff changeset
527 tmp_bai_name = '%s.bai' % tmp_bam_name
c127b3314d53 Uploaded
devteam
parents:
diff changeset
528 os.symlink( opts.input, tmp_bam_name )
c127b3314d53 Uploaded
devteam
parents:
diff changeset
529 os.symlink( opts.bai_file, tmp_bai_name )
c127b3314d53 Uploaded
devteam
parents:
diff changeset
530 cl.append('INPUT=%s' % ( tmp_bam_name ))
c127b3314d53 Uploaded
devteam
parents:
diff changeset
531 pic.delme.append(tmp_bam_name)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
532 pic.delme.append(tmp_bai_name)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
533 pic.delme.append(tmp_name)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
534 stdouts,rval = pic.runPic( opts.jar, cl )
c127b3314d53 Uploaded
devteam
parents:
diff changeset
535 f = open(pic.metricsOut,'a')
c127b3314d53 Uploaded
devteam
parents:
diff changeset
536 f.write(stdouts) # got this on stdout from runCl
c127b3314d53 Uploaded
devteam
parents:
diff changeset
537 f.write('\n')
c127b3314d53 Uploaded
devteam
parents:
diff changeset
538 f.close()
c127b3314d53 Uploaded
devteam
parents:
diff changeset
539 doTranspose = False # but not transposed
c127b3314d53 Uploaded
devteam
parents:
diff changeset
540
c127b3314d53 Uploaded
devteam
parents:
diff changeset
541 elif pic.picname == 'EstimateLibraryComplexity':
c127b3314d53 Uploaded
devteam
parents:
diff changeset
542 cl.append('I=%s' % opts.input)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
543 cl.append('O=%s' % pic.metricsOut)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
544 if float(opts.minid) > 0:
c127b3314d53 Uploaded
devteam
parents:
diff changeset
545 cl.append('MIN_IDENTICAL_BASES=%s' % opts.minid)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
546 if float(opts.maxdiff) > 0.0:
c127b3314d53 Uploaded
devteam
parents:
diff changeset
547 cl.append('MAX_DIFF_RATE=%s' % opts.maxdiff)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
548 if float(opts.minmeanq) > 0:
c127b3314d53 Uploaded
devteam
parents:
diff changeset
549 cl.append('MIN_MEAN_QUALITY=%s' % opts.minmeanq)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
550 if opts.readregex > '':
c127b3314d53 Uploaded
devteam
parents:
diff changeset
551 cl.append('READ_NAME_REGEX="%s"' % opts.readregex)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
552 if float(opts.optdupdist) > 0:
c127b3314d53 Uploaded
devteam
parents:
diff changeset
553 cl.append('OPTICAL_DUPLICATE_PIXEL_DISTANCE=%s' % opts.optdupdist)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
554 stdouts,rval = pic.runPic(opts.jar, cl)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
555
c127b3314d53 Uploaded
devteam
parents:
diff changeset
556 elif pic.picname == 'CollectAlignmentSummaryMetrics':
c127b3314d53 Uploaded
devteam
parents:
diff changeset
557 # Why do we do this fakefasta thing?
c127b3314d53 Uploaded
devteam
parents:
diff changeset
558 # Because we need NO fai to be available or picard barfs unless it matches the input data.
c127b3314d53 Uploaded
devteam
parents:
diff changeset
559 # why? Dunno Seems to work without complaining if the .bai file is AWOL....
c127b3314d53 Uploaded
devteam
parents:
diff changeset
560 fakefasta = os.path.join(opts.outdir,'%s_fake.fasta' % os.path.basename(ref_file_name))
c127b3314d53 Uploaded
devteam
parents:
diff changeset
561 try:
c127b3314d53 Uploaded
devteam
parents:
diff changeset
562 os.symlink(ref_file_name,fakefasta)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
563 except:
c127b3314d53 Uploaded
devteam
parents:
diff changeset
564 s = '## unable to symlink %s to %s - different devices? Will shutil.copy'
c127b3314d53 Uploaded
devteam
parents:
diff changeset
565 info = s
c127b3314d53 Uploaded
devteam
parents:
diff changeset
566 shutil.copy(ref_file_name,fakefasta)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
567 pic.delme.append(fakefasta)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
568 cl.append('ASSUME_SORTED=true')
c127b3314d53 Uploaded
devteam
parents:
diff changeset
569 adaptlist = opts.adaptors.split(',')
c127b3314d53 Uploaded
devteam
parents:
diff changeset
570 adaptorseqs = ['ADAPTER_SEQUENCE=%s' % x for x in adaptlist]
c127b3314d53 Uploaded
devteam
parents:
diff changeset
571 cl += adaptorseqs
c127b3314d53 Uploaded
devteam
parents:
diff changeset
572 cl.append('IS_BISULFITE_SEQUENCED=%s' % opts.bisulphite)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
573 cl.append('MAX_INSERT_SIZE=%s' % opts.maxinsert)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
574 cl.append('OUTPUT=%s' % pic.metricsOut)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
575 cl.append('R=%s' % fakefasta)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
576 cl.append('TMP_DIR=%s' % opts.tmpdir)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
577 if not opts.assumesorted.lower() == 'true': # we need to sort input
c127b3314d53 Uploaded
devteam
parents:
diff changeset
578 sortedfile = '%s.sorted' % os.path.basename(opts.input)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
579 if opts.datatype == 'sam': # need to work with a bam
c127b3314d53 Uploaded
devteam
parents:
diff changeset
580 tlog,tempbam,trval = pic.samToBam(opts.input,opts.outdir)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
581 pic.delme.append(tempbam)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
582 try:
c127b3314d53 Uploaded
devteam
parents:
diff changeset
583 tlog = pic.sortSam(tempbam,sortedfile,opts.outdir)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
584 except:
c127b3314d53 Uploaded
devteam
parents:
diff changeset
585 print '## exception on sorting sam file %s' % opts.input
c127b3314d53 Uploaded
devteam
parents:
diff changeset
586 else: # is already bam
c127b3314d53 Uploaded
devteam
parents:
diff changeset
587 try:
c127b3314d53 Uploaded
devteam
parents:
diff changeset
588 tlog = pic.sortSam(opts.input,sortedfile,opts.outdir)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
589 except : # bug - [bam_sort_core] not being ignored - TODO fixme
c127b3314d53 Uploaded
devteam
parents:
diff changeset
590 print '## exception %s on sorting bam file %s' % (sys.exc_info()[0],opts.input)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
591 cl.append('INPUT=%s.bam' % os.path.abspath(os.path.join(opts.outdir,sortedfile)))
c127b3314d53 Uploaded
devteam
parents:
diff changeset
592 pic.delme.append(os.path.join(opts.outdir,sortedfile))
c127b3314d53 Uploaded
devteam
parents:
diff changeset
593 else:
c127b3314d53 Uploaded
devteam
parents:
diff changeset
594 cl.append('INPUT=%s' % os.path.abspath(opts.input))
c127b3314d53 Uploaded
devteam
parents:
diff changeset
595 stdouts,rval = pic.runPic(opts.jar, cl)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
596
c127b3314d53 Uploaded
devteam
parents:
diff changeset
597
c127b3314d53 Uploaded
devteam
parents:
diff changeset
598 elif pic.picname == 'CollectGcBiasMetrics':
c127b3314d53 Uploaded
devteam
parents:
diff changeset
599 assert os.path.isfile(ref_file_name),'PicardGC needs a reference sequence - cannot read %s' % ref_file_name
c127b3314d53 Uploaded
devteam
parents:
diff changeset
600 # sigh. Why do we do this fakefasta thing? Because we need NO fai to be available or picard barfs unless it has the same length as the input data.
c127b3314d53 Uploaded
devteam
parents:
diff changeset
601 # why? Dunno
c127b3314d53 Uploaded
devteam
parents:
diff changeset
602 fakefasta = os.path.join(opts.outdir,'%s_fake.fasta' % os.path.basename(ref_file_name))
c127b3314d53 Uploaded
devteam
parents:
diff changeset
603 try:
c127b3314d53 Uploaded
devteam
parents:
diff changeset
604 os.symlink(ref_file_name,fakefasta)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
605 except:
c127b3314d53 Uploaded
devteam
parents:
diff changeset
606 s = '## unable to symlink %s to %s - different devices? May need to replace with shutil.copy'
c127b3314d53 Uploaded
devteam
parents:
diff changeset
607 info = s
c127b3314d53 Uploaded
devteam
parents:
diff changeset
608 shutil.copy(ref_file_name,fakefasta)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
609 pic.delme.append(fakefasta)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
610 x = 'rgPicardGCBiasMetrics'
c127b3314d53 Uploaded
devteam
parents:
diff changeset
611 pdfname = '%s.pdf' % x
c127b3314d53 Uploaded
devteam
parents:
diff changeset
612 jpgname = '%s.jpg' % x
c127b3314d53 Uploaded
devteam
parents:
diff changeset
613 tempout = os.path.join(opts.outdir,'rgPicardGCBiasMetrics.out')
c127b3314d53 Uploaded
devteam
parents:
diff changeset
614 temppdf = os.path.join(opts.outdir,pdfname)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
615 cl.append('R=%s' % fakefasta)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
616 cl.append('WINDOW_SIZE=%s' % opts.windowsize)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
617 cl.append('MINIMUM_GENOME_FRACTION=%s' % opts.mingenomefrac)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
618 cl.append('INPUT=%s' % opts.input)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
619 cl.append('OUTPUT=%s' % tempout)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
620 cl.append('TMP_DIR=%s' % opts.tmpdir)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
621 cl.append('CHART_OUTPUT=%s' % temppdf)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
622 cl.append('SUMMARY_OUTPUT=%s' % pic.metricsOut)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
623 stdouts,rval = pic.runPic(opts.jar, cl)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
624 if os.path.isfile(temppdf):
c127b3314d53 Uploaded
devteam
parents:
diff changeset
625 cl2 = ['convert','-resize x400',temppdf,os.path.join(opts.outdir,jpgname)] # make the jpg for fixPicardOutputs to find
c127b3314d53 Uploaded
devteam
parents:
diff changeset
626 s,stdouts,rval = pic.runCL(cl=cl2,output_dir=opts.outdir)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
627 else:
c127b3314d53 Uploaded
devteam
parents:
diff changeset
628 s='### runGC: Unable to find pdf %s - please check the log for the causal problem\n' % temppdf
c127b3314d53 Uploaded
devteam
parents:
diff changeset
629 lf = open(pic.log_filename,'a')
c127b3314d53 Uploaded
devteam
parents:
diff changeset
630 lf.write(s)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
631 lf.write('\n')
c127b3314d53 Uploaded
devteam
parents:
diff changeset
632 lf.close()
c127b3314d53 Uploaded
devteam
parents:
diff changeset
633
c127b3314d53 Uploaded
devteam
parents:
diff changeset
634 elif pic.picname == 'CollectInsertSizeMetrics':
c127b3314d53 Uploaded
devteam
parents:
diff changeset
635 """ <command interpreter="python">
c127b3314d53 Uploaded
devteam
parents:
diff changeset
636 picard_wrapper.py -i "$input_file" -n "$out_prefix" --tmpdir "${__new_file_path__}" --deviations "$deviations"
c127b3314d53 Uploaded
devteam
parents:
diff changeset
637 --histwidth "$histWidth" --minpct "$minPct" --malevel "$malevel"
c127b3314d53 Uploaded
devteam
parents:
diff changeset
638 -j "${GALAXY_DATA_INDEX_DIR}/shared/jars/picard/CollectInsertSizeMetrics.jar" -d "$html_file.files_path" -t "$html_file"
c127b3314d53 Uploaded
devteam
parents:
diff changeset
639 </command>
c127b3314d53 Uploaded
devteam
parents:
diff changeset
640 """
c127b3314d53 Uploaded
devteam
parents:
diff changeset
641 isPDF = 'InsertSizeHist.pdf'
c127b3314d53 Uploaded
devteam
parents:
diff changeset
642 pdfpath = os.path.join(opts.outdir,isPDF)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
643 histpdf = 'InsertSizeHist.pdf'
c127b3314d53 Uploaded
devteam
parents:
diff changeset
644 cl.append('I=%s' % opts.input)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
645 cl.append('O=%s' % pic.metricsOut)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
646 cl.append('HISTOGRAM_FILE=%s' % histpdf)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
647 #if opts.taillimit <> '0': # this was deprecated although still mentioned in the docs at 1.56
c127b3314d53 Uploaded
devteam
parents:
diff changeset
648 # cl.append('TAIL_LIMIT=%s' % opts.taillimit)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
649 if opts.histwidth <> '0':
c127b3314d53 Uploaded
devteam
parents:
diff changeset
650 cl.append('HISTOGRAM_WIDTH=%s' % opts.histwidth)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
651 if float( opts.minpct) > 0.0:
c127b3314d53 Uploaded
devteam
parents:
diff changeset
652 cl.append('MINIMUM_PCT=%s' % opts.minpct)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
653 if float(opts.deviations) > 0.0:
c127b3314d53 Uploaded
devteam
parents:
diff changeset
654 cl.append('DEVIATIONS=%s' % opts.deviations)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
655 if opts.malevel:
c127b3314d53 Uploaded
devteam
parents:
diff changeset
656 malists = opts.malevel.split(',')
c127b3314d53 Uploaded
devteam
parents:
diff changeset
657 malist = ['METRIC_ACCUMULATION_LEVEL=%s' % x for x in malists]
c127b3314d53 Uploaded
devteam
parents:
diff changeset
658 cl += malist
c127b3314d53 Uploaded
devteam
parents:
diff changeset
659 stdouts,rval = pic.runPic(opts.jar, cl)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
660 if os.path.exists(pdfpath): # automake thumbnail - will be added to html
c127b3314d53 Uploaded
devteam
parents:
diff changeset
661 cl2 = ['mogrify', '-format jpg -resize x400 %s' % pdfpath]
c127b3314d53 Uploaded
devteam
parents:
diff changeset
662 pic.runCL(cl=cl2,output_dir=opts.outdir)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
663 else:
c127b3314d53 Uploaded
devteam
parents:
diff changeset
664 s = 'Unable to find expected pdf file %s<br/>\n' % pdfpath
c127b3314d53 Uploaded
devteam
parents:
diff changeset
665 s += 'This <b>always happens if single ended data was provided</b> to this tool,\n'
c127b3314d53 Uploaded
devteam
parents:
diff changeset
666 s += 'so please double check that your input data really is paired-end NGS data.<br/>\n'
c127b3314d53 Uploaded
devteam
parents:
diff changeset
667 s += 'If your input was paired data this may be a bug worth reporting to the galaxy-bugs list\n<br/>'
c127b3314d53 Uploaded
devteam
parents:
diff changeset
668 logging.info(s)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
669 if len(stdouts) > 0:
c127b3314d53 Uploaded
devteam
parents:
diff changeset
670 logging.info(stdouts)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
671
c127b3314d53 Uploaded
devteam
parents:
diff changeset
672 elif pic.picname == 'MarkDuplicates':
c127b3314d53 Uploaded
devteam
parents:
diff changeset
673 # assume sorted even if header says otherwise
c127b3314d53 Uploaded
devteam
parents:
diff changeset
674 cl.append('ASSUME_SORTED=%s' % (opts.assumesorted))
c127b3314d53 Uploaded
devteam
parents:
diff changeset
675 # input
c127b3314d53 Uploaded
devteam
parents:
diff changeset
676 cl.append('INPUT=%s' % opts.input)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
677 # outputs
c127b3314d53 Uploaded
devteam
parents:
diff changeset
678 cl.append('OUTPUT=%s' % opts.output)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
679 cl.append('METRICS_FILE=%s' % pic.metricsOut )
c127b3314d53 Uploaded
devteam
parents:
diff changeset
680 # remove or mark duplicates
c127b3314d53 Uploaded
devteam
parents:
diff changeset
681 cl.append('REMOVE_DUPLICATES=%s' % opts.remdups)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
682 # the regular expression to be used to parse reads in incoming SAM file
c127b3314d53 Uploaded
devteam
parents:
diff changeset
683 cl.append('READ_NAME_REGEX="%s"' % opts.readregex)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
684 # maximum offset between two duplicate clusters
c127b3314d53 Uploaded
devteam
parents:
diff changeset
685 cl.append('OPTICAL_DUPLICATE_PIXEL_DISTANCE=%s' % opts.optdupdist)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
686 stdouts,rval = pic.runPic(opts.jar, cl)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
687
c127b3314d53 Uploaded
devteam
parents:
diff changeset
688 elif pic.picname == 'FixMateInformation':
c127b3314d53 Uploaded
devteam
parents:
diff changeset
689 cl.append('I=%s' % opts.input)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
690 cl.append('O=%s' % tempout)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
691 cl.append('SORT_ORDER=%s' % opts.sortorder)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
692 stdouts,rval = pic.runPic(opts.jar,cl)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
693 haveTempout = True
c127b3314d53 Uploaded
devteam
parents:
diff changeset
694
c127b3314d53 Uploaded
devteam
parents:
diff changeset
695 elif pic.picname == 'ReorderSam':
c127b3314d53 Uploaded
devteam
parents:
diff changeset
696 # input
c127b3314d53 Uploaded
devteam
parents:
diff changeset
697 cl.append('INPUT=%s' % opts.input)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
698 # output
c127b3314d53 Uploaded
devteam
parents:
diff changeset
699 cl.append('OUTPUT=%s' % tempout)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
700 # reference
c127b3314d53 Uploaded
devteam
parents:
diff changeset
701 cl.append('REFERENCE=%s' % ref_file_name)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
702 # incomplete dict concordance
c127b3314d53 Uploaded
devteam
parents:
diff changeset
703 if opts.allow_inc_dict_concord == 'true':
c127b3314d53 Uploaded
devteam
parents:
diff changeset
704 cl.append('ALLOW_INCOMPLETE_DICT_CONCORDANCE=true')
c127b3314d53 Uploaded
devteam
parents:
diff changeset
705 # contig length discordance
c127b3314d53 Uploaded
devteam
parents:
diff changeset
706 if opts.allow_contig_len_discord == 'true':
c127b3314d53 Uploaded
devteam
parents:
diff changeset
707 cl.append('ALLOW_CONTIG_LENGTH_DISCORDANCE=true')
c127b3314d53 Uploaded
devteam
parents:
diff changeset
708 stdouts,rval = pic.runPic(opts.jar, cl)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
709 haveTempout = True
c127b3314d53 Uploaded
devteam
parents:
diff changeset
710
c127b3314d53 Uploaded
devteam
parents:
diff changeset
711 elif pic.picname == 'ReplaceSamHeader':
c127b3314d53 Uploaded
devteam
parents:
diff changeset
712 cl.append('INPUT=%s' % opts.input)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
713 cl.append('OUTPUT=%s' % tempout)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
714 cl.append('HEADER=%s' % opts.header_file)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
715 stdouts,rval = pic.runPic(opts.jar, cl)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
716 haveTempout = True
c127b3314d53 Uploaded
devteam
parents:
diff changeset
717
c127b3314d53 Uploaded
devteam
parents:
diff changeset
718 elif pic.picname == 'CalculateHsMetrics':
c127b3314d53 Uploaded
devteam
parents:
diff changeset
719 maxloglines = 100
c127b3314d53 Uploaded
devteam
parents:
diff changeset
720 baitfname = os.path.join(opts.outdir,'rgPicardHsMetrics.bait')
c127b3314d53 Uploaded
devteam
parents:
diff changeset
721 targetfname = os.path.join(opts.outdir,'rgPicardHsMetrics.target')
c127b3314d53 Uploaded
devteam
parents:
diff changeset
722 baitf = pic.makePicInterval(opts.baitbed,baitfname)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
723 if opts.targetbed == opts.baitbed: # same file sometimes
c127b3314d53 Uploaded
devteam
parents:
diff changeset
724 targetf = baitf
c127b3314d53 Uploaded
devteam
parents:
diff changeset
725 else:
c127b3314d53 Uploaded
devteam
parents:
diff changeset
726 targetf = pic.makePicInterval(opts.targetbed,targetfname)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
727 cl.append('BAIT_INTERVALS=%s' % baitf)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
728 cl.append('TARGET_INTERVALS=%s' % targetf)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
729 cl.append('INPUT=%s' % os.path.abspath(opts.input))
c127b3314d53 Uploaded
devteam
parents:
diff changeset
730 cl.append('OUTPUT=%s' % pic.metricsOut)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
731 cl.append('TMP_DIR=%s' % opts.tmpdir)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
732 stdouts,rval = pic.runPic(opts.jar,cl)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
733
c127b3314d53 Uploaded
devteam
parents:
diff changeset
734 elif pic.picname == 'ValidateSamFile':
c127b3314d53 Uploaded
devteam
parents:
diff changeset
735 import pysam
c127b3314d53 Uploaded
devteam
parents:
diff changeset
736 doTranspose = False
c127b3314d53 Uploaded
devteam
parents:
diff changeset
737 sortedfile = os.path.join(opts.outdir,'rgValidate.sorted')
c127b3314d53 Uploaded
devteam
parents:
diff changeset
738 stf = open(pic.log_filename,'w')
c127b3314d53 Uploaded
devteam
parents:
diff changeset
739 tlog = None
c127b3314d53 Uploaded
devteam
parents:
diff changeset
740 if opts.datatype == 'sam': # need to work with a bam
c127b3314d53 Uploaded
devteam
parents:
diff changeset
741 tlog,tempbam,rval = pic.samToBam(opts.input,opts.outdir)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
742 try:
c127b3314d53 Uploaded
devteam
parents:
diff changeset
743 tlog = pic.sortSam(tempbam,sortedfile,opts.outdir)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
744 except:
c127b3314d53 Uploaded
devteam
parents:
diff changeset
745 print '## exception on sorting sam file %s' % opts.input
c127b3314d53 Uploaded
devteam
parents:
diff changeset
746 else: # is already bam
c127b3314d53 Uploaded
devteam
parents:
diff changeset
747 try:
c127b3314d53 Uploaded
devteam
parents:
diff changeset
748 tlog = pic.sortSam(opts.input,sortedfile,opts.outdir)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
749 except: # bug - [bam_sort_core] not being ignored - TODO fixme
c127b3314d53 Uploaded
devteam
parents:
diff changeset
750 print '## exception on sorting bam file %s' % opts.input
c127b3314d53 Uploaded
devteam
parents:
diff changeset
751 if tlog:
c127b3314d53 Uploaded
devteam
parents:
diff changeset
752 print '##tlog=',tlog
c127b3314d53 Uploaded
devteam
parents:
diff changeset
753 stf.write(tlog)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
754 stf.write('\n')
c127b3314d53 Uploaded
devteam
parents:
diff changeset
755 sortedfile = '%s.bam' % sortedfile # samtools does that
c127b3314d53 Uploaded
devteam
parents:
diff changeset
756 cl.append('O=%s' % pic.metricsOut)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
757 cl.append('TMP_DIR=%s' % opts.tmpdir)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
758 cl.append('I=%s' % sortedfile)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
759 opts.maxerrors = '99999999'
c127b3314d53 Uploaded
devteam
parents:
diff changeset
760 cl.append('MAX_OUTPUT=%s' % opts.maxerrors)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
761 if opts.ignoreflags[0] <> 'None': # picard error values to ignore
c127b3314d53 Uploaded
devteam
parents:
diff changeset
762 igs = ['IGNORE=%s' % x for x in opts.ignoreflags if x <> 'None']
c127b3314d53 Uploaded
devteam
parents:
diff changeset
763 cl.append(' '.join(igs))
c127b3314d53 Uploaded
devteam
parents:
diff changeset
764 if opts.bisulphite.lower() <> 'false':
c127b3314d53 Uploaded
devteam
parents:
diff changeset
765 cl.append('IS_BISULFITE_SEQUENCED=true')
c127b3314d53 Uploaded
devteam
parents:
diff changeset
766 if opts.ref <> None or opts.ref_file <> None:
c127b3314d53 Uploaded
devteam
parents:
diff changeset
767 cl.append('R=%s' % ref_file_name)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
768 stdouts,rval = pic.runPic(opts.jar,cl)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
769 if opts.datatype == 'sam':
c127b3314d53 Uploaded
devteam
parents:
diff changeset
770 pic.delme.append(tempbam)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
771 newsam = opts.output
c127b3314d53 Uploaded
devteam
parents:
diff changeset
772 outformat = 'bam'
c127b3314d53 Uploaded
devteam
parents:
diff changeset
773 pe = open(pic.metricsOut,'r').readlines()
c127b3314d53 Uploaded
devteam
parents:
diff changeset
774 pic.cleanSam(insam=sortedfile, newsam=newsam, picardErrors=pe,outformat=outformat)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
775 pic.delme.append(sortedfile) # not wanted
c127b3314d53 Uploaded
devteam
parents:
diff changeset
776 stf.close()
c127b3314d53 Uploaded
devteam
parents:
diff changeset
777 pic.cleanup()
c127b3314d53 Uploaded
devteam
parents:
diff changeset
778
c127b3314d53 Uploaded
devteam
parents:
diff changeset
779 ####liubo added CleanSam tool####
c127b3314d53 Uploaded
devteam
parents:
diff changeset
780 elif pic.picname == 'CleanSam':
c127b3314d53 Uploaded
devteam
parents:
diff changeset
781 # input
c127b3314d53 Uploaded
devteam
parents:
diff changeset
782 cl.append('INPUT=%s' % opts.input)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
783 # output
c127b3314d53 Uploaded
devteam
parents:
diff changeset
784 cl.append('OUTPUT=%s' % tempout)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
785 stdouts,rval = pic.runPic(opts.jar, cl)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
786 haveTempout = True
c127b3314d53 Uploaded
devteam
parents:
diff changeset
787
c127b3314d53 Uploaded
devteam
parents:
diff changeset
788 elif pic.picname == 'SortSam':
c127b3314d53 Uploaded
devteam
parents:
diff changeset
789 cl.append('I=%s' % opts.input)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
790 cl.append('O=%s' % tempout)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
791 cl.append('SORT_ORDER=%s' % opts.sortorder)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
792 stdouts,rval = pic.runPic(opts.jar,cl)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
793 haveTempout = True
c127b3314d53 Uploaded
devteam
parents:
diff changeset
794
c127b3314d53 Uploaded
devteam
parents:
diff changeset
795 elif pic.picname == 'BuildBamIndex':
c127b3314d53 Uploaded
devteam
parents:
diff changeset
796 cl.append('I=%s' % opts.input)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
797 cl.append('O=%s' % tempout)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
798 stdouts,rval = pic.runPic(opts.jar,cl)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
799 haveTempout = True
c127b3314d53 Uploaded
devteam
parents:
diff changeset
800
c127b3314d53 Uploaded
devteam
parents:
diff changeset
801 elif pic.picname == 'SamFormatConverter':
c127b3314d53 Uploaded
devteam
parents:
diff changeset
802 cl.append('INPUT=%s' % opts.input)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
803 cl.append('OUTPUT=%s' % tempout)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
804 pic.runPic(opts.jar, cl)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
805 haveTempout = True
c127b3314d53 Uploaded
devteam
parents:
diff changeset
806 elif pic.picname == "DownsampleSam":
c127b3314d53 Uploaded
devteam
parents:
diff changeset
807 cl.append('I=%s' % opts.input)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
808 mystring = opts.output
c127b3314d53 Uploaded
devteam
parents:
diff changeset
809 mystringsam = mystring + ".sam"
c127b3314d53 Uploaded
devteam
parents:
diff changeset
810 cl.append('O=%s' % mystringsam)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
811 if float(opts.probability) > 0:
c127b3314d53 Uploaded
devteam
parents:
diff changeset
812 cl.append('PROBABILITY=%s' % opts.probability)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
813 if float(opts.seed) > 0:
c127b3314d53 Uploaded
devteam
parents:
diff changeset
814 cl.append('RANDOM_SEED=%s' % opts.seed)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
815 stdouts,rval = pic.runPic(opts.jar, cl)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
816 myoutput = mystringsam.replace(".sam", "")
c127b3314d53 Uploaded
devteam
parents:
diff changeset
817 os.rename(mystringsam,myoutput)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
818
c127b3314d53 Uploaded
devteam
parents:
diff changeset
819 elif pic.picname == 'MeanQualityByCycle':
c127b3314d53 Uploaded
devteam
parents:
diff changeset
820 isPDF = 'MeanQualityByCycle.pdf'
c127b3314d53 Uploaded
devteam
parents:
diff changeset
821 pdfpath = os.path.join(opts.outdir,isPDF)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
822 histpdf = isPDF
c127b3314d53 Uploaded
devteam
parents:
diff changeset
823 cl.append('I=%s' % opts.input)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
824 cl.append('O=%s' % pic.metricsOut)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
825 cl.append('CHART_OUTPUT=%s' % histpdf)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
826 cl.append('ASSUME_SORTED=%s' % (opts.assumesorted))
c127b3314d53 Uploaded
devteam
parents:
diff changeset
827 cl.append('ALIGNED_READS_ONLY=%s' % (opts.alignedreadsonly))
c127b3314d53 Uploaded
devteam
parents:
diff changeset
828 cl.append('PF_READS_ONLY=%s' % (opts.pfreadsonly))
c127b3314d53 Uploaded
devteam
parents:
diff changeset
829 stdouts,rval = pic.runPic(opts.jar, cl)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
830 if os.path.exists(pdfpath): # automake thumbnail - will be added to html
c127b3314d53 Uploaded
devteam
parents:
diff changeset
831 cl2 = ['mogrify', '-format jpg -resize x400 %s' % pdfpath]
c127b3314d53 Uploaded
devteam
parents:
diff changeset
832 pic.runCL(cl=cl2,output_dir=opts.outdir)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
833 else:
c127b3314d53 Uploaded
devteam
parents:
diff changeset
834 s = 'Unable to find expected pdf file %s<br/>\n' % pdfpath
c127b3314d53 Uploaded
devteam
parents:
diff changeset
835 logging.info(s)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
836 if len(stdouts) > 0:
c127b3314d53 Uploaded
devteam
parents:
diff changeset
837 logging.info(stdouts)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
838
c127b3314d53 Uploaded
devteam
parents:
diff changeset
839 elif pic.picname == 'CollectRnaSeqMetrics':
c127b3314d53 Uploaded
devteam
parents:
diff changeset
840 isPDF = pic.picname + '.pdf'
c127b3314d53 Uploaded
devteam
parents:
diff changeset
841 pdfpath = os.path.join(opts.outdir,isPDF)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
842 histpdf = isPDF
c127b3314d53 Uploaded
devteam
parents:
diff changeset
843 cl.append('I=%s' % opts.input)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
844 cl.append('O=%s' % pic.metricsOut)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
845 cl.append('CHART_OUTPUT=%s' % histpdf)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
846 cl.append('ASSUME_SORTED=%s' % (opts.assumesorted))
c127b3314d53 Uploaded
devteam
parents:
diff changeset
847 cl.append('MINIMUM_LENGTH=%s' % (opts.minlength))
c127b3314d53 Uploaded
devteam
parents:
diff changeset
848 cl.append('REF_FLAT=%s' % (opts.refflat))
c127b3314d53 Uploaded
devteam
parents:
diff changeset
849 cl.append('STRAND_SPECIFICITY=%s' % (opts.strandspecificity))
c127b3314d53 Uploaded
devteam
parents:
diff changeset
850 cl.append('RIBOSOMAL_INTERVALS=%s' % (opts.ribosomalintervals))
c127b3314d53 Uploaded
devteam
parents:
diff changeset
851 cl.append('RRNA_FRAGMENT_PERCENTAGE=%s' % (opts.rrnafragmentpercentage))
c127b3314d53 Uploaded
devteam
parents:
diff changeset
852 if opts.ignoreseq[0] <> 'None': # picard error values to ignore
c127b3314d53 Uploaded
devteam
parents:
diff changeset
853 igs = ['IGNORE_SEQUENCE=%s' % x for x in opts.ignoreseq if x <> 'None']
c127b3314d53 Uploaded
devteam
parents:
diff changeset
854 cl.append(' '.join(igs))
c127b3314d53 Uploaded
devteam
parents:
diff changeset
855 if opts.malevel:
c127b3314d53 Uploaded
devteam
parents:
diff changeset
856 malists = opts.malevel.split(',')
c127b3314d53 Uploaded
devteam
parents:
diff changeset
857 malist = ['METRIC_ACCUMULATION_LEVEL=%s' % x for x in malists]
c127b3314d53 Uploaded
devteam
parents:
diff changeset
858 cl += malist
c127b3314d53 Uploaded
devteam
parents:
diff changeset
859 stdouts,rval = pic.runPic(opts.jar, cl)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
860 if os.path.exists(pdfpath): # automake thumbnail - will be added to html
c127b3314d53 Uploaded
devteam
parents:
diff changeset
861 cl2 = ['mogrify', '-format jpg -resize x400 %s' % pdfpath]
c127b3314d53 Uploaded
devteam
parents:
diff changeset
862 pic.runCL(cl=cl2,output_dir=opts.outdir)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
863 else:
c127b3314d53 Uploaded
devteam
parents:
diff changeset
864 s = 'Unable to find expected pdf file %s<br/>\n' % pdfpath
c127b3314d53 Uploaded
devteam
parents:
diff changeset
865 logging.info(s)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
866 if len(stdouts) > 0:
c127b3314d53 Uploaded
devteam
parents:
diff changeset
867 logging.info(stdouts)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
868
c127b3314d53 Uploaded
devteam
parents:
diff changeset
869 else:
c127b3314d53 Uploaded
devteam
parents:
diff changeset
870 print >> sys.stderr,'picard.py got an unknown tool name - %s' % pic.picname
c127b3314d53 Uploaded
devteam
parents:
diff changeset
871 sys.exit(1)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
872 if haveTempout:
c127b3314d53 Uploaded
devteam
parents:
diff changeset
873 # Some Picard tools produced a potentially intermediate bam file.
c127b3314d53 Uploaded
devteam
parents:
diff changeset
874 # Either just move to final location or create sam
c127b3314d53 Uploaded
devteam
parents:
diff changeset
875 if os.path.exists(tempout):
c127b3314d53 Uploaded
devteam
parents:
diff changeset
876 shutil.move(tempout, os.path.abspath(opts.output))
c127b3314d53 Uploaded
devteam
parents:
diff changeset
877 if opts.htmlout <> None or doFix: # return a pretty html page
c127b3314d53 Uploaded
devteam
parents:
diff changeset
878 pic.fixPicardOutputs(transpose=doTranspose,maxloglines=maxloglines)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
879 if rval <> 0:
c127b3314d53 Uploaded
devteam
parents:
diff changeset
880 print >> sys.stderr, '## exit code=%d; stdout=%s' % (rval,stdouts)
c127b3314d53 Uploaded
devteam
parents:
diff changeset
881 # signal failure
c127b3314d53 Uploaded
devteam
parents:
diff changeset
882 if __name__=="__main__": __main__()