Debian Codegraph @

docs/Fast5_to_seq_summary/API_usage.ipynb

raw
1 {
2 "cells": [
3 {
4 "cell_type": "markdown",
5 "metadata": {},
6 "source": [
7 "# Fast5_to_seq_summary API Usage"
8 ]
9 },
10 {
11 "cell_type": "markdown",
12 "metadata": {},
13 "source": [
14 "## Running Jupyter notebook"
15 ]
16 },
17 {
18 "cell_type": "markdown",
19 "metadata": {},
20 "source": [
21 "If you want to run pycoQC interactively in Jupyter you need to install Jupyter manually. If you installed pycoQC in a virtual environment then install Jupyter in the same virtual environment.\n",
22 "\n",
23 "```bash\n",
24 "pip3 install notebook\n",
25 "```\n",
26 "\n",
27 "Launch the notebook in a shell terminal\n",
28 "\n",
29 "```bash\n",
30 "jupyter notebook\n",
31 "```\n",
32 "\n",
33 "If it does not auto-start, open the following URL in you favorite web browser http://localhost:8888/tree\n",
34 "\n",
35 "From Jupyter homepage you can navigate to the directory you want to work in and create a new Python3 Notebook."
36 ]
37 },
38 {
39 "cell_type": "markdown",
40 "metadata": {},
41 "source": [
42 "## Imports"
43 ]
44 },
45 {
46 "cell_type": "code",
47 "execution_count": 2,
48 "metadata": {
49 "ExecuteTime": {
50 "end_time": "2020-01-09T16:58:36.557409Z",
51 "start_time": "2020-01-09T16:58:36.550687Z"
52 },
53 "init_cell": true
54 },
55 "outputs": [],
56 "source": [
57 "# Run cell with Ctrl + Enter\n",
58 "\n",
59 "# Import main pycoQC module\n",
60 "from pycoQC.Fast5_to_seq_summary import Fast5_to_seq_summary\n",
61 "\n",
62 "# Import helper functions from pycoQC\n",
63 "from pycoQC.common import jhelp, head"
64 ]
65 },
66 {
67 "cell_type": "markdown",
68 "metadata": {},
69 "source": [
70 "## Running Fast5_to_seq_summary"
71 ]
72 },
73 {
74 "cell_type": "code",
75 "execution_count": 3,
76 "metadata": {
77 "ExecuteTime": {
78 "end_time": "2020-01-09T16:58:38.709056Z",
79 "start_time": "2020-01-09T16:58:38.680025Z"
80 }
81 },
82 "outputs": [
83 {
84 "data": {
85 "text/markdown": [
86 "**Fast5_to_seq_summary** (fast5_dir, seq_summary_fn, max_fast5, threads, basecall_id, verbose_level, include_path, fields)\n",
87 "\n",
88 "Create a summary file akin the one generated by Albacore or Guppy from a directory containing multiple fast5 files. The script will attempt to extract all the required fields but will not raise an error if not found.\n",
89 "\n",
90 "---\n",
91 "\n",
92 "* **fast5_dir** (required) [str]\n",
93 "\n",
94 "Directory containing fast5 files. Can contain multiple subdirectories\n",
95 "\n",
96 "* **seq_summary_fn** (required) [str]\n",
97 "\n",
98 "path of the summary sequencing file where to write the data extracted from the fast5 files\n",
99 "\n",
100 "* **max_fast5** (default: 0) [int]\n",
101 "\n",
102 "Maximum number of file to try to parse. 0 to deactivate\n",
103 "\n",
104 "* **threads** (default: 4) [int]\n",
105 "\n",
106 "Total number of threads to use. 1 thread is used for the reader and 1 for the writer. Minimum 3 (default = 4)\n",
107 "\n",
108 "* **basecall_id** (default: 0) [int]\n",
109 "\n",
110 "id of the basecalling group. By default leave to 0, but if you perfome multiple basecalling on the same fast5 files, this can be used to indicate the corresponding group (1, 2 ...)\n",
111 "\n",
112 "* **verbose_level** (default: 0) [int]\n",
113 "\n",
114 "Level of verbosity, from 2 (Chatty) to 0 (Nothing)\n",
115 "\n",
116 "* **include_path** (default: False) [bool]\n",
117 "\n",
118 "If True the absolute path to the corresponding file is added in an extra column\n",
119 "\n",
120 "* **fields** (default: ['read_id', 'run_id', 'channel', 'start_time', 'sequence_length_template', 'mean_qscore_template', 'calibration_strand_genome_template', 'barcode_arrangement']) [list]\n",
121 "\n",
122 "list of field names corresponding to attributes to try to fetch from the fast5 files. List a valid field names: mean_qscore_template, sequence_length_template, called_events, skip_prob, stay_prob, step_prob, strand_score, read_id, start_time, duration, start_mux, read_number, channel, channel_digitisation, channel_offset, channel_range, channel_sampling, run_id, sample_id, device_id, protocol_run, flow_cell, calibration_strand, calibration_strand, calibration_strand, calibration_strand, barcode_arrangement, barcode_full, barcode_score\n",
123 "\n"
124 ],
125 "text/plain": [
126 "<IPython.core.display.Markdown object>"
127 ]
128 },
129 "metadata": {},
130 "output_type": "display_data"
131 }
132 ],
133 "source": [
134 "jhelp(Fast5_to_seq_summary)"
135 ]
136 },
137 {
138 "cell_type": "markdown",
139 "metadata": {},
140 "source": [
141 "### Basic usage"
142 ]
143 },
144 {
145 "cell_type": "markdown",
146 "metadata": {},
147 "source": [
148 "This minimal usage creates a minimal file compatible with pycoQC "
149 ]
150 },
151 {
152 "cell_type": "code",
153 "execution_count": 4,
154 "metadata": {
155 "ExecuteTime": {
156 "end_time": "2020-01-09T16:58:41.784141Z",
157 "start_time": "2020-01-09T16:58:41.556539Z"
158 }
159 },
160 "outputs": [
161 {
162 "name": "stderr",
163 "output_type": "stream",
164 "text": [
165 "Check input data and options\n",
166 "Start processing fast5 files\n",
167 "22 reads [00:00, 391.50 reads/s]\n",
168 "Overall counts \tvalid files: 22\n",
169 "\n",
170 "fields found \tread_id: 22\n",
171 "\trun_id: 22\n",
172 "\tchannel: 22\n",
173 "\tstart_time: 22\n",
174 "\tsequence_length_template: 22\n",
175 "\tmean_qscore_template: 22\n",
176 "\tcalibration_strand_genome_template: 22\n",
177 "\n",
178 "fields not found \tbarcode_arrangement: 22\n",
179 "\n",
180 "Total reads: 22 / Average speed: 161.12 reads/s\n",
181 "\n"
182 ]
183 },
184 {
185 "name": "stdout",
186 "output_type": "stream",
187 "text": [
188 "read_id run_id channel start_time sequence_length_template mean_qscore_template calibration_strand_genome_template \n",
189 "5b7fadd0-c646-4c7b-9800-66ee658a5ca8 40ebe55356ada6c830fa793745ef4c498d896c73 150 37 468 7.608 filtered_out \n",
190 "e6a8e4d0-7b3c-471a-be26-fa7857d12663 40ebe55356ada6c830fa793745ef4c498d896c73 318 15 392 8.304 filtered_out \n",
191 "f8325de9-a77e-4616-a4a8-69ecf32e1688 40ebe55356ada6c830fa793745ef4c498d896c73 354 16 568 8.206 filtered_out \n",
192 "2c32553e-62c6-4c7a-bf05-249771364f04 40ebe55356ada6c830fa793745ef4c498d896c73 237 11 1151 8.544 filtered_out \n",
193 "3e81c32a-f2ee-4719-a88d-e0affe93d26f 40ebe55356ada6c830fa793745ef4c498d896c73 348 24 1137 8.124 filtered_out \n",
194 "6af04302-04c8-4d8d-8e87-aa69178b3f24 40ebe55356ada6c830fa793745ef4c498d896c73 36 26 832 8.234 filtered_out \n",
195 "3784283c-47cc-48ac-8d7b-7efd32123b56 40ebe55356ada6c830fa793745ef4c498d896c73 243 20 893 8.54 filtered_out \n",
196 "68804104-71dc-465c-b82d-3a99a4689701 40ebe55356ada6c830fa793745ef4c498d896c73 38 20 1010 8.325 filtered_out \n",
197 "37dfa1d5-5d84-486c-bf47-9eb6438f5645 40ebe55356ada6c830fa793745ef4c498d896c73 410 30 555 8.219 filtered_out \n",
198 "\n"
199 ]
200 }
201 ],
202 "source": [
203 "Fast5_to_seq_summary (\n",
204 " fast5_dir=\"./data/\",\n",
205 " seq_summary_fn=\"./results/summary_sequencing.tsv\",\n",
206 " verbose_level=1)\n",
207 "\n",
208 "head (\"./results/summary_sequencing.tsv\")"
209 ]
210 },
211 {
212 "cell_type": "markdown",
213 "metadata": {},
214 "source": [
215 "### Multi-threading support"
216 ]
217 },
218 {
219 "cell_type": "code",
220 "execution_count": 5,
221 "metadata": {
222 "ExecuteTime": {
223 "end_time": "2020-01-09T16:58:44.400049Z",
224 "start_time": "2020-01-09T16:58:44.185159Z"
225 }
226 },
227 "outputs": [
228 {
229 "name": "stderr",
230 "output_type": "stream",
231 "text": [
232 "Check input data and options\n",
233 "Start processing fast5 files\n",
234 "22 reads [00:00, 13120.25 reads/s]\n",
235 "Overall counts \tvalid files: 22\n",
236 "\n",
237 "fields found \tread_id: 22\n",
238 "\trun_id: 22\n",
239 "\tchannel: 22\n",
240 "\tstart_time: 22\n",
241 "\tsequence_length_template: 22\n",
242 "\tmean_qscore_template: 22\n",
243 "\tcalibration_strand_genome_template: 22\n",
244 "\n",
245 "fields not found \tbarcode_arrangement: 22\n",
246 "\n",
247 "Total reads: 22 / Average speed: 385.38 reads/s\n",
248 "\n"
249 ]
250 },
251 {
252 "name": "stdout",
253 "output_type": "stream",
254 "text": [
255 "read_id run_id channel start_time sequence_length_template mean_qscore_template calibration_strand_genome_template \n",
256 "2c32553e-62c6-4c7a-bf05-249771364f04 40ebe55356ada6c830fa793745ef4c498d896c73 237 11 1151 8.544 filtered_out \n",
257 "5b7fadd0-c646-4c7b-9800-66ee658a5ca8 40ebe55356ada6c830fa793745ef4c498d896c73 150 37 468 7.608 filtered_out \n",
258 "f8325de9-a77e-4616-a4a8-69ecf32e1688 40ebe55356ada6c830fa793745ef4c498d896c73 354 16 568 8.206 filtered_out \n",
259 "151757ea-53de-44b1-b86e-f823511af02a 40ebe55356ada6c830fa793745ef4c498d896c73 191 13 568 8.23 filtered_out \n",
260 "97205d42-93ac-4c99-af78-e553f7d1ff83 40ebe55356ada6c830fa793745ef4c498d896c73 343 26 1584 8.987 filtered_out \n",
261 "37dfa1d5-5d84-486c-bf47-9eb6438f5645 40ebe55356ada6c830fa793745ef4c498d896c73 410 30 555 8.219 filtered_out \n",
262 "bcb20156-a5fe-4daa-aad9-b62c286e468d 40ebe55356ada6c830fa793745ef4c498d896c73 192 21 306 7.337 filtered_out \n",
263 "e6a8e4d0-7b3c-471a-be26-fa7857d12663 40ebe55356ada6c830fa793745ef4c498d896c73 318 15 392 8.304 filtered_out \n",
264 "6af04302-04c8-4d8d-8e87-aa69178b3f24 40ebe55356ada6c830fa793745ef4c498d896c73 36 26 832 8.234 filtered_out \n",
265 "\n"
266 ]
267 }
268 ],
269 "source": [
270 "Fast5_to_seq_summary (\n",
271 " fast5_dir=\"./data/\",\n",
272 " seq_summary_fn=\"./results/summary_sequencing.tsv\",\n",
273 " verbose_level=1,\n",
274 " threads=10)\n",
275 "\n",
276 "head (\"./results/summary_sequencing.tsv\")"
277 ]
278 },
279 {
280 "cell_type": "markdown",
281 "metadata": {},
282 "source": [
283 "### Customize fields of the summary file"
284 ]
285 },
286 {
287 "cell_type": "code",
288 "execution_count": 6,
289 "metadata": {
290 "ExecuteTime": {
291 "end_time": "2020-01-09T16:58:48.104345Z",
292 "start_time": "2020-01-09T16:58:47.935066Z"
293 }
294 },
295 "outputs": [
296 {
297 "name": "stderr",
298 "output_type": "stream",
299 "text": [
300 "Check input data and options\n",
301 "Start processing fast5 files\n",
302 "22 reads [00:00, 20876.63 reads/s]\n",
303 "Overall counts \tvalid files: 22\n",
304 "\n",
305 "fields found \tmean_qscore_template: 22\n",
306 "\tcalled_events: 22\n",
307 "\tduration: 22\n",
308 "\tstrand_score: 22\n",
309 "\n",
310 "fields not found \n",
311 "Total reads: 22 / Average speed: 386.96 reads/s\n",
312 "\n"
313 ]
314 },
315 {
316 "name": "stdout",
317 "output_type": "stream",
318 "text": [
319 "mean_qscore_template called_events duration strand_score \n",
320 "8.544 3740 56107 -0.0003 \n",
321 "7.608 1615 24233 -0.0007 \n",
322 "8.234 1827 27409 -0.0011 \n",
323 "8.206 1649 24747 -0.0009 \n",
324 "8.124 2978 44675 -0.0005 \n",
325 "8.304 1547 23218 -0.0008 \n",
326 "8.325 3846 57697 -0.0004 \n",
327 "8.219 2080 31208 -0.0011 \n",
328 "8.23 2778 51387 -0.0007 \n",
329 "\n"
330 ]
331 }
332 ],
333 "source": [
334 "Fast5_to_seq_summary (\n",
335 " fast5_dir=\"./data/\",\n",
336 " seq_summary_fn=\"./results/custom_summary_sequencing.tsv\",\n",
337 " threads=6,\n",
338 " verbose_level=1,\n",
339 " fields=[\"mean_qscore_template\", \"called_events\", \"duration\", \"strand_score\"])\n",
340 "\n",
341 "head (\"./results/custom_summary_sequencing.tsv\")"
342 ]
343 },
344 {
345 "cell_type": "markdown",
346 "metadata": {},
347 "source": [
348 "### Add file path"
349 ]
350 },
351 {
352 "cell_type": "code",
353 "execution_count": 7,
354 "metadata": {
355 "ExecuteTime": {
356 "end_time": "2020-01-09T16:58:50.259501Z",
357 "start_time": "2020-01-09T16:58:50.101543Z"
358 },
359 "scrolled": false
360 },
361 "outputs": [
362 {
363 "name": "stderr",
364 "output_type": "stream",
365 "text": [
366 "Check input data and options\n",
367 "Start processing fast5 files\n",
368 "22 reads [00:00, 15978.30 reads/s]\n",
369 "Overall counts \tvalid files: 22\n",
370 "\n",
371 "fields found \tread_id: 22\n",
372 "\trun_id: 22\n",
373 "\tchannel: 22\n",
374 "\tstart_time: 22\n",
375 "\tsequence_length_template: 22\n",
376 "\tmean_qscore_template: 22\n",
377 "\tcalibration_strand_genome_template: 22\n",
378 "\n",
379 "fields not found \tbarcode_arrangement: 22\n",
380 "\n",
381 "Total reads: 22 / Average speed: 366.98 reads/s\n",
382 "\n"
383 ]
384 },
385 {
386 "name": "stdout",
387 "output_type": "stream",
388 "text": [
389 "read_id run_id channel start_time sequence_length_template mean_qscore_template calibration_strand_genome_template path \n",
390 "5b7fadd0-c646-4c7b-9800-66ee658a5ca8 40ebe55356ada6c830fa793745ef4c498d896c73 150 37 468 7.608 filtered_out /home/aleg/Programming/Packages/pycoQC/docs/Fast5_to_seq_summary/data/20180625_FAH77625_MN23126_sequencing_run_S1_57529_read_10_ch_150_strand.fast5 \n",
391 "2c32553e-62c6-4c7a-bf05-249771364f04 40ebe55356ada6c830fa793745ef4c498d896c73 237 11 1151 8.544 filtered_out /home/aleg/Programming/Packages/pycoQC/docs/Fast5_to_seq_summary/data/20180625_FAH77625_MN23126_sequencing_run_S1_57529_read_10_ch_237_strand.fast5 \n",
392 "e6a8e4d0-7b3c-471a-be26-fa7857d12663 40ebe55356ada6c830fa793745ef4c498d896c73 318 15 392 8.304 filtered_out /home/aleg/Programming/Packages/pycoQC/docs/Fast5_to_seq_summary/data/20180625_FAH77625_MN23126_sequencing_run_S1_57529_read_10_ch_318_strand.fast5 \n",
393 "6af04302-04c8-4d8d-8e87-aa69178b3f24 40ebe55356ada6c830fa793745ef4c498d896c73 36 26 832 8.234 filtered_out /home/aleg/Programming/Packages/pycoQC/docs/Fast5_to_seq_summary/data/20180625_FAH77625_MN23126_sequencing_run_S1_57529_read_10_ch_36_strand.fast5 \n",
394 "3e81c32a-f2ee-4719-a88d-e0affe93d26f 40ebe55356ada6c830fa793745ef4c498d896c73 348 24 1137 8.124 filtered_out /home/aleg/Programming/Packages/pycoQC/docs/Fast5_to_seq_summary/data/20180625_FAH77625_MN23126_sequencing_run_S1_57529_read_10_ch_348_strand.fast5 \n",
395 "37dfa1d5-5d84-486c-bf47-9eb6438f5645 40ebe55356ada6c830fa793745ef4c498d896c73 410 30 555 8.219 filtered_out /home/aleg/Programming/Packages/pycoQC/docs/Fast5_to_seq_summary/data/20180625_FAH77625_MN23126_sequencing_run_S1_57529_read_10_ch_410_strand.fast5 \n",
396 "08642be5-5cf7-4c4c-8c45-e4d569b9a482 40ebe55356ada6c830fa793745ef4c498d896c73 121 28 450 7.805 filtered_out /home/aleg/Programming/Packages/pycoQC/docs/Fast5_to_seq_summary/data/20180625_FAH77625_MN23126_sequencing_run_S1_57529_read_10_ch_121_strand.fast5 \n",
397 "151757ea-53de-44b1-b86e-f823511af02a 40ebe55356ada6c830fa793745ef4c498d896c73 191 13 568 8.23 filtered_out /home/aleg/Programming/Packages/pycoQC/docs/Fast5_to_seq_summary/data/20180625_FAH77625_MN23126_sequencing_run_S1_57529_read_10_ch_191_strand.fast5 \n",
398 "4e21bf07-e2df-42d8-b347-59ef2c0618ea 40ebe55356ada6c830fa793745ef4c498d896c73 290 31 1160 8.741 filtered_out /home/aleg/Programming/Packages/pycoQC/docs/Fast5_to_seq_summary/data/20180625_FAH77625_MN23126_sequencing_run_S1_57529_read_10_ch_290_strand.fast5 \n",
399 "\n"
400 ]
401 }
402 ],
403 "source": [
404 "Fast5_to_seq_summary (\n",
405 " fast5_dir=\"./data/\",\n",
406 " seq_summary_fn=\"./results/fn_summary_sequencing.tsv\",\n",
407 " threads=6,\n",
408 " verbose_level=1,\n",
409 " include_path=True)\n",
410 "\n",
411 "head (\"./results/fn_summary_sequencing.tsv\")"
412 ]
413 }
414 ],
415 "metadata": {
416 "celltoolbar": "Initialization Cell",
417 "hide_input": false,
418 "kernelspec": {
419 "display_name": "pycoQC",
420 "language": "python",
421 "name": "pycoqc"
422 },
423 "language_info": {
424 "codemirror_mode": {
425 "name": "ipython",
426 "version": 3
427 },
428 "file_extension": ".py",
429 "mimetype": "text/x-python",
430 "name": "python",
431 "nbconvert_exporter": "python",
432 "pygments_lexer": "ipython3",
433 "version": "3.6.6"
434 },
435 "widgets": {
436 "state": {},
437 "version": "1.1.1"
438 }
439 },
440 "nbformat": 4,
441 "nbformat_minor": 1
442 }