annotate jemultiplexer.py @ 4:861cbe4eca25 draft default tip

Correct path to java file
author gbcs-embl-heidelberg
date Mon, 26 Jan 2015 08:09:03 -0500
parents 1b79b43626ef
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
1 #!/usr/bin/env python
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
2
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
3 import os, sys, string, shutil, subprocess, tempfile, re
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
4
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
5 def cleanup(tmpdir):
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
6 # cleanup
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
7 try:
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
8 if os.path.exists( tmpdir ):
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
9 shutil.rmtree( tmpdir )
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
10 except Exception, e:
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
11 stop_err( 'Error cleaning. ' + str( e ) )
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
12
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
13 # In the unlikely event of a fire, please use the nearest emergency exit
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
14 def stop_err( msg ):
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
15 sys.stderr.write( '%s\n' % msg )
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
16 sys.exit()
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
17
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
18 def __main__():
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
19 tooldir = os.path.dirname(sys.argv[0])
4
861cbe4eca25 Correct path to java file
gbcs-embl-heidelberg
parents: 2
diff changeset
20 executable = tooldir + "/jemultiplexer_1.0.4_bundle.jar"
2
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
21 if not os.path.exists(executable):
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
22 stop_err( "The file \"%s\" was not found. " % ( executable ) )
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
23 mpxdata = sys.argv[1]
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
24 output1 = sys.argv[2]
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
25 output1id = sys.argv[3]
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
26 barcodes = sys.argv[4]
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
27 barcode_list = sys.argv[5]
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
28 newfilepath = sys.argv[6]
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
29 extension = sys.argv[7]
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
30 barlen = sys.argv[8]
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
31 qualityFormat = sys.argv[9]
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
32 maxMismatches = sys.argv[10]
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
33 minBaseQuality = sys.argv[11]
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
34 minMismatchingDelta = sys.argv[12]
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
35 xTrimLen = sys.argv[13]
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
36 zTrimLen = sys.argv[14]
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
37 clipBarcode = sys.argv[15]
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
38 addBarcodeToHeader = sys.argv[16]
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
39 gzipOutput = sys.argv[17]
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
40 barcodeDiagFile = sys.argv[18]
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
41 rChar = sys.argv[19]
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
42 barcodeReadPos = sys.argv[20]
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
43 barcodeForSampleMatching = sys.argv[21]
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
44 redundantBarcode = sys.argv[22]
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
45 strict = sys.argv[23]
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
46 MpxData2 = sys.argv[24]
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
47
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
48 ## create the tmpdir & co
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
49 tmpdir = newfilepath + "/demultiplex_" + output1id
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
50 oldnames=[]
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
51 stat = tmpdir+"/jemultiplexer_out_stats.txt" #the default output stat file name
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
52 try:
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
53 if not os.path.isdir(tmpdir):
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
54 os.mkdir(tmpdir)
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
55 except Exception, e:
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
56 stop_err( "Error creating directory \"%s\". %s" % ( tmpdir, str( e ) ) )
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
57
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
58 #output file extension
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
59 if gzipOutput == "true":
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
60 outputExtension=".gz"
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
61 else:
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
62 outputExtension=""
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
63
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
64 # Reconstructing the output file names as jemultiplexer writes them
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
65 if MpxData2 != "single":
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
66 oldnames.append('unassigned_1.txt' + outputExtension)
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
67 oldnames.append('unassigned_2.txt' + outputExtension)
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
68 else:
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
69 oldnames.append('unassigned_1.txt' + outputExtension)
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
70 if barcodeDiagFile=="true":
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
71 oldnames.append('barcode_match_report.txt')
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
72 if barcode_list == "none": # If a .bs file was given
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
73 bc = open(barcodes, "r")
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
74 bcw = open( tmpdir + "/barcodes.txt", "w" )
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
75 for line in bc.readlines():
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
76 l = line.split()
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
77 if l[0] != "":
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
78 if MpxData2 != "single":
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
79 oldnames.append(l[0]+'_'+l[1]+'_1.txt' + outputExtension)
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
80 oldnames.append(l[0]+'_'+l[1]+'_2.txt' + outputExtension)
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
81 bcw.write(l[0] + "\t" + l[1] + "\t" + l[0]+'_'+l[1]+'_1.txt' + outputExtension + "\t" + l[0]+'_'+l[1]+'_2.txt' + outputExtension + "\n")
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
82 else:
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
83 oldnames.append(l[0]+'_'+l[1]+'_1.txt' + outputExtension)
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
84 bcw.write(l[0] + "\t" + l[1] + "\t" + l[0]+'_'+l[1]+'_1.txt' + outputExtension + "\n")
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
85 bc.close()
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
86 bcw.close()
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
87 elif barcodes == "none": # If the text area was used
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
88 lines = barcode_list.split("__cr____cn__")
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
89 #bc = csv.writer( open( tmpdir + "/barcodes.txt", "w" ), delimiter = "\t" )
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
90 bc = open( tmpdir + "/barcodes.txt", "w" )
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
91 for l in lines:
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
92 l = l.replace("__tc__", " ").split()
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
93 if len(l) < 2:
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
94 continue
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
95 if l[0] != "":
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
96 if MpxData2 != "single":
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
97 oldnames.append(l[0]+'_'+l[1]+'_1.txt' + outputExtension)
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
98 oldnames.append(l[0]+'_'+l[1]+'_2.txt' + outputExtension)
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
99 bc.write(l[0] + "\t" + l[1] + "\t" + l[0]+'_'+l[1]+'_1.txt' + outputExtension + "\t" + l[0]+'_'+l[1]+'_2.txt' + outputExtension + "\n")
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
100 else:
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
101 oldnames.append(l[0]+'_'+l[1]+'_1.txt' + outputExtension)
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
102 bc.write(l[0] + "\t" + l[1] + "\t" + l[0]+'_'+l[1]+'_1.txt' + outputExtension + "\n")
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
103 bc.close()
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
104
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
105 ## Building the command line
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
106 cmd = "java -Xmx8g -jar " + executable
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
107 cmd+= " F1="
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
108 cmd+= mpxdata
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
109 ## if we have PE data
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
110 if MpxData2 != "single":
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
111 cmd+= " F2="
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
112 cmd+= MpxData2
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
113 cmd+= " BPOS="
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
114 cmd+= barcodeReadPos
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
115 cmd+= " BRED="
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
116 cmd+= redundantBarcode
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
117 cmd+= " BM="
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
118 cmd+= barcodeForSampleMatching
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
119 cmd+= " S="
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
120 cmd+= strict
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
121 cmd+= " BF="
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
122 cmd+= tmpdir + "/barcodes.txt"
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
123 cmd+= " OUTPUT_DIR=\""
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
124 cmd+= tmpdir
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
125 cmd+= "\""
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
126 cmd+= " BCLEN="
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
127 cmd+= barlen
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
128 cmd+= " QUALITY_FORMAT="
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
129 cmd+= qualityFormat
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
130 cmd+= " MAX_MISMATCHES="
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
131 cmd+= maxMismatches
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
132 cmd+= " MIN_BASE_QUALITY="
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
133 cmd+= minBaseQuality
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
134 cmd+= " MMD="
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
135 cmd+= minMismatchingDelta
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
136 cmd+= " XT="
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
137 cmd+= xTrimLen
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
138 cmd+= " ZT="
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
139 cmd+= zTrimLen
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
140 cmd+= " C="
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
141 cmd+= clipBarcode
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
142 cmd+= " ADD="
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
143 cmd+= addBarcodeToHeader
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
144 cmd+= " GZ="
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
145 cmd+= gzipOutput
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
146 if rChar=="2":
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
147 cmd+= " RCHAR="
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
148 cmd+= ":"
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
149 elif rChar=="3":
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
150 cmd+= " RCHAR="
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
151 cmd+= "_"
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
152 elif rChar=="4":
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
153 cmd+= " RCHAR="
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
154 cmd+= "-"
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
155 if barcodeDiagFile=="true":
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
156 cmd+= " BARCODE_DIAG_FILE="
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
157 cmd+= 'barcode_match_report.txt'
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
158
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
159
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
160 # Executing jemultiplexer
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
161 # status = os.system(cmd)
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
162 try:
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
163 tmperr = tempfile.NamedTemporaryFile( dir=tmpdir ).name
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
164 tmpout = tempfile.NamedTemporaryFile( dir=tmpdir ).name
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
165 tmp_stderr = open( tmperr, 'wb' )
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
166 tmp_stdout = open( tmpout, 'wb' )
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
167 proc = subprocess.Popen( args=cmd,
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
168 shell=True,
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
169 cwd=tmpdir,
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
170 stdout=tmp_stdout.fileno(),
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
171 stderr=tmp_stderr.fileno() )
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
172 returncode = proc.wait()
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
173 tmp_stderr.close()
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
174 tmp_stdout.close()
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
175 # get stderr, allowing for case where it's very large
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
176 tmp_stderr = open( tmperr, 'rb' )
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
177 stderr = ''
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
178 buffsize = 1048576
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
179 try:
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
180 while True:
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
181 stderr += tmp_stderr.read( buffsize )
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
182 if not stderr or len( stderr ) % buffsize != 0:
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
183 break
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
184 except OverflowError:
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
185 pass
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
186 tmp_stderr.close()
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
187 if returncode != 0:
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
188 raise Exception, stderr
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
189 except Exception, e:
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
190 #cleanup(tmpdir)
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
191 stop_err( 'Error demultiplexing sequence. ' + str( e ) )
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
192
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
193 # Creating the required paths for multiple outputs
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
194 newnames=[]
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
195 if os.path.isdir(tmpdir):
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
196 for f in oldnames:
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
197 tmpf = tmpdir+"/"+f
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
198 if os.path.isfile(tmpf):
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
199 # check the size
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
200 if os.path.getsize(tmpf) == 0:
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
201 stop_err( 'The output file: ' + f + ' is empty, there may be an error with your barcode file or settings.')
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
202 name = f
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
203 s = "primary_"
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
204 s+= output1id
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
205 s+= "_"
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
206 s+= string.replace(name, "_", "-")
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
207 s+= "_visible_"
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
208 if extension == "fastqillumina":
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
209 if gzipOutput == "true":
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
210 s+="gz"
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
211 else:
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
212 s+= extension
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
213 else:
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
214 if f=="barcode_match_report.txt":
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
215 s+="text"
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
216 else:
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
217 if gzipOutput == "true":
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
218 s+="gz"
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
219 else:
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
220 s+="fastqsanger"
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
221 newnames.append(newfilepath+"/"+s)
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
222 # Adding the appropriate prefixes to the old filenames
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
223 for i in range(len(oldnames)):
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
224 oldnames[i] = tmpdir+"/"+oldnames[i]
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
225
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
226 ### NUMSTAT rewriting ###
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
227 htmlout = open(output1, "w")
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
228 numstat = open(stat, "r")
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
229 htmlout.write("<html><head><title>numStat</title></head><body><!--\n")
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
230 for l in numstat.readlines():
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
231 htmlout.write(l)
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
232 numstat.seek(0)
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
233 htmlout.write("-->\n<h2>Please refresh your history to display the new datasets</h2>\n<h3>numStat</h3><table border=\"1\">\n")
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
234 htmlout.write("<tr><td>%s</td></tr>\n" % (cmd ))
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
235 for l in numstat.readlines():
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
236 l = l.split()
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
237 htmlout.write("<tr><td>%s</td><td>%s</td></tr>\n" % (l[0], l[1]) )
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
238 htmlout.write("</table></body></html>")
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
239 numstat.close()
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
240 htmlout.close()
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
241
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
242 #~ # Moving the first file (the mandatory output file defined in the xml (the txt stats))
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
243 #~ shutil.move(stat,output1)
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
244 #~
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
245 #~ # add a warning to the numStat
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
246 #~ statfh = open(stat,'a')
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
247 #~ statfh.write("\nRefresh you library to see the new DataSets.\n")
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
248 #~ statfh.close()
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
249
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
250 # Moving everything where it will be seen properly by Galaxy
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
251 for i in range(len(oldnames)):
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
252 shutil.move(oldnames[i],newnames[i])
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
253
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
254 # cleanup
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
255 cleanup(tmpdir)
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
256
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
257 # Ta-da!
1b79b43626ef Uploaded
gbcs-embl-heidelberg
parents:
diff changeset
258 if __name__=="__main__": __main__()