Mercurial > repos > charles_s_test > seqsero2
comparison run_seqsero.py @ 9:acc5cd06a36a draft
planemo upload commit a4fb57231f274270afbfebd47f67df05babffa4a-dirty
author | charles_s_test |
---|---|
date | Tue, 28 Nov 2017 21:16:36 -0500 |
parents | 3d6680af0bec |
children | 53efef402c51 |
comparison
equal
deleted
inserted
replaced
8:b04931a9fe71 | 9:acc5cd06a36a |
---|---|
105 return outputs | 105 return outputs |
106 | 106 |
107 def get_serotypes(outputs): | 107 def get_serotypes(outputs): |
108 ''' | 108 ''' |
109 ''' | 109 ''' |
110 fastq2comment = {} | 110 fastq2comment = {} |
111 fastq2serotype = {} | 111 fastq2serotype = {} |
112 | |
112 for sample in outputs: | 113 for sample in outputs: |
113 fastqs = '' | 114 fastqs = '' |
114 lines_used = [] | 115 lines_used = [] |
115 for line in sample: # line is actually the entire seqsero output. | 116 for line in sample: # line is actually the entire seqsero output. |
116 line = str(line) | 117 line = str(line) |
117 linel = re.split("\n", line) | 118 linel = re.split("\n", line) |
118 # print(linel) | 119 # print(linel) |
119 #lines_used = [] | 120 #lines_used = [] |
120 for element in linel: # element is a line of seqsero output. | 121 for element in linel: # element is a line of seqsero output. |
121 element = element.rstrip("\n") | 122 element = element.rstrip("\n") |
122 test_out.write(element+"\n") | 123 test_out.write(element+"\n") |
123 elementl = re.split("\t", element) | 124 elementl = re.split("\t", element) |
124 if elementl[0] == 'Input files:': | 125 if elementl[0] == 'Input files:': |
125 fastqs = elementl[1] | 126 fastqs = elementl[1] |
126 lines_used.append(element) | 127 lines_used.append(element) |
127 if elementl[1] not in fastq2serotype.keys(): | 128 if elementl[1] not in fastq2serotype.keys(): |
128 fastq2serotype[fastqs] = ['']*5 | 129 fastq2serotype[fastqs] = ['']*5 |
129 fastq2comment[fastqs] = [] | 130 fastq2comment[fastqs] = [] |
130 elif elementl[0] == 'O antigen prediction:': | 131 elif elementl[0] == 'O antigen prediction:': |
131 lines_used.append(element) | 132 lines_used.append(element) |
132 fastq2serotype[fastqs][0] = elementl[1] # add predicted profile | 133 fastq2serotype[fastqs][0] = elementl[1] # add predicted profile |
133 elif elementl[0] == 'H1 antigen prediction(fliC):': | 134 elif elementl[0] == 'H1 antigen prediction(fliC):': |
134 lines_used.append(element) | 135 lines_used.append(element) |
135 fastq2serotype[fastqs][1] = elementl[1] # add predicted profile | 136 fastq2serotype[fastqs][1] = elementl[1] # add predicted profile |
136 elif elementl[0] == 'H2 antigen prediction(fljB):': | 137 elif elementl[0] == 'H2 antigen prediction(fljB):': |
137 lines_used.append(element) | 138 lines_used.append(element) |
138 fastq2serotype[fastqs][2] = elementl[1] # add predicted profile | 139 fastq2serotype[fastqs][2] = elementl[1] # add predicted profile |
139 elif elementl[0] == 'Predicted antigenic profile:': | 140 elif elementl[0] == 'Predicted antigenic profile:': |
140 lines_used.append(element) | 141 lines_used.append(element) |
141 fastq2serotype[fastqs][3] = elementl[1] # add predicted profile | 142 fastq2serotype[fastqs][3] = elementl[1] # add predicted profile |
142 elif elementl[0] == 'Predicted serotype(s):': | 143 elif elementl[0] == 'Predicted serotype(s):': |
143 lines_used.append(element) | 144 lines_used.append(element) |
144 fastq2serotype[fastqs][4] = elementl[1] # add predicted serotype | 145 fastq2serotype[fastqs][4] = elementl[1] # add predicted serotype |
145 if element not in lines_used and re.search("\w", fastqs) and len(element) > 7: | 146 if element not in lines_used and re.search("\w", fastqs) and len(element) > 7: |
146 fastq2comment[fastqs].append(element) | 147 fastq2comment[fastqs].append(element) |
147 #print("\n" | 148 #print("\n" |
148 return fastq2serotype, fastq2comment | 149 return fastq2serotype, fastq2comment |
149 | 150 |
150 def print_html(fastq2serotype, fastq2comment): | 151 def print_html(fastq2serotype, fastq2comment): |
151 ''' | 152 ''' |
152 Takes dict and prints to html file. | 153 Takes dict and prints to html file. |
153 ''' | 154 ''' |
154 tab_out = open('Seqsero_result.txt', 'w'); | 155 tab_out = open('Seqsero_result.txt', 'w'); |
155 html_out = open('Seqsero_result.html', 'w') | 156 html_out = open('Seqsero_result.html', 'w') |
156 html_out.write('<!DOCTYPE html>\n') | 157 html_out.write('<!DOCTYPE html>\n') |
157 html_out.write('<html>\n') | 158 html_out.write('<html>\n') |
158 html_out.write('<head>\n') | 159 html_out.write('<head>\n') |
159 html_out.write('<title>SeqSero Results</title>\n') | 160 html_out.write('<title>SeqSero Results</title>\n') |
180 for antigen in fastq2serotype[fastq]: | 181 for antigen in fastq2serotype[fastq]: |
181 html_out.write('<td>'+antigen+'</td>\n') | 182 html_out.write('<td>'+antigen+'</td>\n') |
182 html_out.write('</tr>\n') | 183 html_out.write('</tr>\n') |
183 print(line_to_print) | 184 print(line_to_print) |
184 html_out.write('</table>\n') | 185 html_out.write('</table>\n') |
185 print("\n") | 186 print("\n") |
186 for fastq in fastq2comment: | 187 for fastq in fastq2comment: |
187 tab_out.write("\n"+fastq+"\n") | 188 tab_out.write("\n"+fastq+"\n") |
188 html_out.write('<tr>\n') | 189 html_out.write('<tr>\n') |
189 html_out.write('<p>\n') | 190 html_out.write('<p>\n') |
190 html_out.write('<td>'+fastq+"<br></td>\n") | 191 html_out.write('<td>'+fastq+"<br></td>\n") |
191 for line in fastq2comment[fastq]: | 192 for line in fastq2comment[fastq]: |
192 #if len(line) > 7: | 193 #if len(line) > 7: |
193 html_out.write('<td>'+line+'</td>\n') | 194 html_out.write('<td>'+line+'</td>\n') |
194 tab_out.write(line+"\n") | 195 tab_out.write(line+"\n") |
195 print(line) | 196 print(line) |
196 print("\n") | 197 print("\n") |
197 html_out.write('</p>\n') | 198 html_out.write('</p>\n') |
198 html_out.write('</tr>\n') | 199 html_out.write('</tr>\n') |
199 html_out.write('</body>\n') | 200 html_out.write('</body>\n') |
200 html_out.write('</html>\n') | 201 html_out.write('</html>\n') |
201 html_out.close() | 202 html_out.close() |
202 | 203 |