comparison run_seqsero.py @ 7:3d6680af0bec draft

planemo upload commit a4fb57231f274270afbfebd47f67df05babffa4a-dirty
author charles_s_test
date Mon, 27 Nov 2017 16:30:27 -0500
parents 38ad1130d077
children acc5cd06a36a
comparison
equal deleted inserted replaced
6:b6281a377a18 7:3d6680af0bec
7 7
8 # Declare Variables 8 # Declare Variables
9 # paths to files and scripts 9 # paths to files and scripts
10 10
11 fileDir = os.path.dirname(os.path.realpath('__file__')) 11 fileDir = os.path.dirname(os.path.realpath('__file__'))
12 print fileDir 12 print(fileDir)
13 13
14 fq_list1 = [] 14 fq_list1 = []
15 Tool_directory = sys.argv[2] 15 Tool_directory = sys.argv[2]
16 database = Tool_directory + '/universe.sqlite' 16 database = Tool_directory + '/universe.sqlite'
17 seqsero = Tool_directory + 'SeqSero.py' 17 seqsero = Tool_directory + 'SeqSero.py'
29 test_out.write("\t".join(sys.argv)+'\n') 29 test_out.write("\t".join(sys.argv)+'\n')
30 30
31 31
32 32
33 33
34 print Tool_directory + ' path printed ' 34 print(Tool_directory + ' path printed ')
35 35
36 test_out.write(str(len(sys.argv))+"\n") 36 test_out.write(str(len(sys.argv))+"\n")
37 if len(sys.argv) >= 2: 37 if len(sys.argv) >= 2:
38 test_out.write("\t".join(sys.argv)+'\n') 38 test_out.write("\t".join(sys.argv)+'\n')
39 fq_list1 = sys.argv[1] 39 fq_list1 = sys.argv[1]
53 53
54 def list_runs(fastq_files): 54 def list_runs(fastq_files):
55 ''' 55 '''
56 Creates dict with runs as keys and list with filenames as values. 56 Creates dict with runs as keys and list with filenames as values.
57 ''' 57 '''
58 # print "monkey" 58 # print("monkey")
59 run2fastqs = {} 59 run2fastqs = {}
60 for file in fastq_files: 60 for file in fastq_files:
61 run = '' 61 run = ''
62 try: 62 try:
63 fastq = open(file, 'r') 63 fastq = open(file, 'r')
81 if file not in run2fastqs[run]: 81 if file not in run2fastqs[run]:
82 run2fastqs[run].append(new_path_file) 82 run2fastqs[run].append(new_path_file)
83 else: 83 else:
84 run2fastqs[run] = [new_path_file] 84 run2fastqs[run] = [new_path_file]
85 except IOError: 85 except IOError:
86 print "Data not found. It is possible for a deleted file to still be listed "\ 86 print("Data not found. It is possible for a deleted file to still be listed "\
87 "in a Galaxy library. Please confirm that the data still exists on this "\ 87 "in a Galaxy library. Please confirm that the data still exists on this "\
88 "server. You may need to upload it again." 88 "server. You may need to upload it again.")
89 return run2fastqs 89 return run2fastqs
90 90
91 def run_seqsero(run2fastqs): 91 def run_seqsero(run2fastqs):
92 ''' 92 '''
93 Takes files from run2fastqs and runs SeqSero. 93 Takes files from run2fastqs and runs SeqSero.
113 fastqs = '' 113 fastqs = ''
114 lines_used = [] 114 lines_used = []
115 for line in sample: # line is actually the entire seqsero output. 115 for line in sample: # line is actually the entire seqsero output.
116 line = str(line) 116 line = str(line)
117 linel = re.split("\n", line) 117 linel = re.split("\n", line)
118 # print linel 118 # print(linel)
119 #lines_used = [] 119 #lines_used = []
120 for element in linel: # element is a line of seqsero output. 120 for element in linel: # element is a line of seqsero output.
121 element = element.rstrip("\n") 121 element = element.rstrip("\n")
122 test_out.write(element+"\n") 122 test_out.write(element+"\n")
123 elementl = re.split("\t", element) 123 elementl = re.split("\t", element)
142 elif elementl[0] == 'Predicted serotype(s):': 142 elif elementl[0] == 'Predicted serotype(s):':
143 lines_used.append(element) 143 lines_used.append(element)
144 fastq2serotype[fastqs][4] = elementl[1] # add predicted serotype 144 fastq2serotype[fastqs][4] = elementl[1] # add predicted serotype
145 if element not in lines_used and re.search("\w", fastqs) and len(element) > 7: 145 if element not in lines_used and re.search("\w", fastqs) and len(element) > 7:
146 fastq2comment[fastqs].append(element) 146 fastq2comment[fastqs].append(element)
147 #print "\n" 147 #print("\n"
148 return fastq2serotype, fastq2comment 148 return fastq2serotype, fastq2comment
149 149
150 def print_html(fastq2serotype, fastq2comment): 150 def print_html(fastq2serotype, fastq2comment):
151 ''' 151 '''
152 Takes dict and prints to html file. 152 Takes dict and prints to html file.
168 html_out.write('<tr>\n') 168 html_out.write('<tr>\n')
169 for element in header_l: 169 for element in header_l:
170 html_out.write('<td>'+element+'</td>\n') 170 html_out.write('<td>'+element+'</td>\n')
171 html_out.write('</tr>\n') 171 html_out.write('</tr>\n')
172 tab_out.write(header+"\n") 172 tab_out.write(header+"\n")
173 print "\n\n", header 173 print("\n\n", header)
174 for fastq in fastq2serotype: 174 for fastq in fastq2serotype:
175 # print fastq, fastq2serotype[fastq] 175 # print(fastq, fastq2serotype[fastq])
176 line_to_print = fastq+'\t'+"\t".join(fastq2serotype[fastq]) 176 line_to_print = fastq+'\t'+"\t".join(fastq2serotype[fastq])
177 tab_out.write(line_to_print+"\n") 177 tab_out.write(line_to_print+"\n")
178 html_out.write('<tr>\n') 178 html_out.write('<tr>\n')
179 html_out.write('<td>'+fastq+'</td>\n') 179 html_out.write('<td>'+fastq+'</td>\n')
180 for antigen in fastq2serotype[fastq]: 180 for antigen in fastq2serotype[fastq]:
181 html_out.write('<td>'+antigen+'</td>\n') 181 html_out.write('<td>'+antigen+'</td>\n')
182 html_out.write('</tr>\n') 182 html_out.write('</tr>\n')
183 print line_to_print 183 print(line_to_print)
184 html_out.write('</table>\n') 184 html_out.write('</table>\n')
185 print "\n" 185 print("\n")
186 for fastq in fastq2comment: 186 for fastq in fastq2comment:
187 tab_out.write("\n"+fastq+"\n") 187 tab_out.write("\n"+fastq+"\n")
188 html_out.write('<tr>\n') 188 html_out.write('<tr>\n')
189 html_out.write('<p>\n') 189 html_out.write('<p>\n')
190 html_out.write('<td>'+fastq+"<br></td>\n") 190 html_out.write('<td>'+fastq+"<br></td>\n")
191 for line in fastq2comment[fastq]: 191 for line in fastq2comment[fastq]:
192 #if len(line) > 7: 192 #if len(line) > 7:
193 html_out.write('<td>'+line+'</td>\n') 193 html_out.write('<td>'+line+'</td>\n')
194 tab_out.write(line+"\n") 194 tab_out.write(line+"\n")
195 print line 195 print(line)
196 print "\n" 196 print("\n")
197 html_out.write('</p>\n') 197 html_out.write('</p>\n')
198 html_out.write('</tr>\n') 198 html_out.write('</tr>\n')
199 html_out.write('</body>\n') 199 html_out.write('</body>\n')
200 html_out.write('</html>\n') 200 html_out.write('</html>\n')
201 html_out.close() 201 html_out.close()
202 202
203 203
204 def readFile(filename): 204 def readFile(filename):
205 filehandle = open(filename) 205 filehandle = open(filename)
206 print filehandle.read() 206 print(filehandle.read())
207 filehandle.close() 207 filehandle.close()
208 208
209 209
210 run2fastqs = list_runs(fastq_files) 210 run2fastqs = list_runs(fastq_files)
211 outputs = run_seqsero(run2fastqs) 211 outputs = run_seqsero(run2fastqs)