{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Fast5_to_seq_summary API Usage" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Running Jupyter notebook" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "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", "\n", "```bash\n", "pip3 install notebook\n", "```\n", "\n", "Launch the notebook in a shell terminal\n", "\n", "```bash\n", "jupyter notebook\n", "```\n", "\n", "If it does not auto-start, open the following URL in you favorite web browser http://localhost:8888/tree\n", "\n", "From Jupyter homepage you can navigate to the directory you want to work in and create a new Python3 Notebook." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Imports" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "ExecuteTime": { "end_time": "2020-01-09T16:58:36.557409Z", "start_time": "2020-01-09T16:58:36.550687Z" }, "init_cell": true }, "outputs": [], "source": [ "# Run cell with Ctrl + Enter\n", "\n", "# Import main pycoQC module\n", "from pycoQC.Fast5_to_seq_summary import Fast5_to_seq_summary\n", "\n", "# Import helper functions from pycoQC\n", "from pycoQC.common import jhelp, head" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Running Fast5_to_seq_summary" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "ExecuteTime": { "end_time": "2020-01-09T16:58:38.709056Z", "start_time": "2020-01-09T16:58:38.680025Z" } }, "outputs": [ { "data": { "text/markdown": [ "**Fast5_to_seq_summary** (fast5_dir, seq_summary_fn, max_fast5, threads, basecall_id, verbose_level, include_path, fields)\n", "\n", "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", "\n", "---\n", "\n", "* **fast5_dir** (required) [str]\n", "\n", "Directory containing fast5 files. Can contain multiple subdirectories\n", "\n", "* **seq_summary_fn** (required) [str]\n", "\n", "path of the summary sequencing file where to write the data extracted from the fast5 files\n", "\n", "* **max_fast5** (default: 0) [int]\n", "\n", "Maximum number of file to try to parse. 0 to deactivate\n", "\n", "* **threads** (default: 4) [int]\n", "\n", "Total number of threads to use. 1 thread is used for the reader and 1 for the writer. Minimum 3 (default = 4)\n", "\n", "* **basecall_id** (default: 0) [int]\n", "\n", "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", "\n", "* **verbose_level** (default: 0) [int]\n", "\n", "Level of verbosity, from 2 (Chatty) to 0 (Nothing)\n", "\n", "* **include_path** (default: False) [bool]\n", "\n", "If True the absolute path to the corresponding file is added in an extra column\n", "\n", "* **fields** (default: ['read_id', 'run_id', 'channel', 'start_time', 'sequence_length_template', 'mean_qscore_template', 'calibration_strand_genome_template', 'barcode_arrangement']) [list]\n", "\n", "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", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "jhelp(Fast5_to_seq_summary)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Basic usage" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This minimal usage creates a minimal file compatible with pycoQC " ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "ExecuteTime": { "end_time": "2020-01-09T16:58:41.784141Z", "start_time": "2020-01-09T16:58:41.556539Z" } }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "Check input data and options\n", "Start processing fast5 files\n", "22 reads [00:00, 391.50 reads/s]\n", "Overall counts \tvalid files: 22\n", "\n", "fields found \tread_id: 22\n", "\trun_id: 22\n", "\tchannel: 22\n", "\tstart_time: 22\n", "\tsequence_length_template: 22\n", "\tmean_qscore_template: 22\n", "\tcalibration_strand_genome_template: 22\n", "\n", "fields not found \tbarcode_arrangement: 22\n", "\n", "Total reads: 22 / Average speed: 161.12 reads/s\n", "\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "read_id run_id channel start_time sequence_length_template mean_qscore_template calibration_strand_genome_template \n", "5b7fadd0-c646-4c7b-9800-66ee658a5ca8 40ebe55356ada6c830fa793745ef4c498d896c73 150 37 468 7.608 filtered_out \n", "e6a8e4d0-7b3c-471a-be26-fa7857d12663 40ebe55356ada6c830fa793745ef4c498d896c73 318 15 392 8.304 filtered_out \n", "f8325de9-a77e-4616-a4a8-69ecf32e1688 40ebe55356ada6c830fa793745ef4c498d896c73 354 16 568 8.206 filtered_out \n", "2c32553e-62c6-4c7a-bf05-249771364f04 40ebe55356ada6c830fa793745ef4c498d896c73 237 11 1151 8.544 filtered_out \n", "3e81c32a-f2ee-4719-a88d-e0affe93d26f 40ebe55356ada6c830fa793745ef4c498d896c73 348 24 1137 8.124 filtered_out \n", "6af04302-04c8-4d8d-8e87-aa69178b3f24 40ebe55356ada6c830fa793745ef4c498d896c73 36 26 832 8.234 filtered_out \n", "3784283c-47cc-48ac-8d7b-7efd32123b56 40ebe55356ada6c830fa793745ef4c498d896c73 243 20 893 8.54 filtered_out \n", "68804104-71dc-465c-b82d-3a99a4689701 40ebe55356ada6c830fa793745ef4c498d896c73 38 20 1010 8.325 filtered_out \n", "37dfa1d5-5d84-486c-bf47-9eb6438f5645 40ebe55356ada6c830fa793745ef4c498d896c73 410 30 555 8.219 filtered_out \n", "\n" ] } ], "source": [ "Fast5_to_seq_summary (\n", " fast5_dir=\"./data/\",\n", " seq_summary_fn=\"./results/summary_sequencing.tsv\",\n", " verbose_level=1)\n", "\n", "head (\"./results/summary_sequencing.tsv\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Multi-threading support" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "ExecuteTime": { "end_time": "2020-01-09T16:58:44.400049Z", "start_time": "2020-01-09T16:58:44.185159Z" } }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "Check input data and options\n", "Start processing fast5 files\n", "22 reads [00:00, 13120.25 reads/s]\n", "Overall counts \tvalid files: 22\n", "\n", "fields found \tread_id: 22\n", "\trun_id: 22\n", "\tchannel: 22\n", "\tstart_time: 22\n", "\tsequence_length_template: 22\n", "\tmean_qscore_template: 22\n", "\tcalibration_strand_genome_template: 22\n", "\n", "fields not found \tbarcode_arrangement: 22\n", "\n", "Total reads: 22 / Average speed: 385.38 reads/s\n", "\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "read_id run_id channel start_time sequence_length_template mean_qscore_template calibration_strand_genome_template \n", "2c32553e-62c6-4c7a-bf05-249771364f04 40ebe55356ada6c830fa793745ef4c498d896c73 237 11 1151 8.544 filtered_out \n", "5b7fadd0-c646-4c7b-9800-66ee658a5ca8 40ebe55356ada6c830fa793745ef4c498d896c73 150 37 468 7.608 filtered_out \n", "f8325de9-a77e-4616-a4a8-69ecf32e1688 40ebe55356ada6c830fa793745ef4c498d896c73 354 16 568 8.206 filtered_out \n", "151757ea-53de-44b1-b86e-f823511af02a 40ebe55356ada6c830fa793745ef4c498d896c73 191 13 568 8.23 filtered_out \n", "97205d42-93ac-4c99-af78-e553f7d1ff83 40ebe55356ada6c830fa793745ef4c498d896c73 343 26 1584 8.987 filtered_out \n", "37dfa1d5-5d84-486c-bf47-9eb6438f5645 40ebe55356ada6c830fa793745ef4c498d896c73 410 30 555 8.219 filtered_out \n", "bcb20156-a5fe-4daa-aad9-b62c286e468d 40ebe55356ada6c830fa793745ef4c498d896c73 192 21 306 7.337 filtered_out \n", "e6a8e4d0-7b3c-471a-be26-fa7857d12663 40ebe55356ada6c830fa793745ef4c498d896c73 318 15 392 8.304 filtered_out \n", "6af04302-04c8-4d8d-8e87-aa69178b3f24 40ebe55356ada6c830fa793745ef4c498d896c73 36 26 832 8.234 filtered_out \n", "\n" ] } ], "source": [ "Fast5_to_seq_summary (\n", " fast5_dir=\"./data/\",\n", " seq_summary_fn=\"./results/summary_sequencing.tsv\",\n", " verbose_level=1,\n", " threads=10)\n", "\n", "head (\"./results/summary_sequencing.tsv\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Customize fields of the summary file" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "ExecuteTime": { "end_time": "2020-01-09T16:58:48.104345Z", "start_time": "2020-01-09T16:58:47.935066Z" } }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "Check input data and options\n", "Start processing fast5 files\n", "22 reads [00:00, 20876.63 reads/s]\n", "Overall counts \tvalid files: 22\n", "\n", "fields found \tmean_qscore_template: 22\n", "\tcalled_events: 22\n", "\tduration: 22\n", "\tstrand_score: 22\n", "\n", "fields not found \n", "Total reads: 22 / Average speed: 386.96 reads/s\n", "\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "mean_qscore_template called_events duration strand_score \n", "8.544 3740 56107 -0.0003 \n", "7.608 1615 24233 -0.0007 \n", "8.234 1827 27409 -0.0011 \n", "8.206 1649 24747 -0.0009 \n", "8.124 2978 44675 -0.0005 \n", "8.304 1547 23218 -0.0008 \n", "8.325 3846 57697 -0.0004 \n", "8.219 2080 31208 -0.0011 \n", "8.23 2778 51387 -0.0007 \n", "\n" ] } ], "source": [ "Fast5_to_seq_summary (\n", " fast5_dir=\"./data/\",\n", " seq_summary_fn=\"./results/custom_summary_sequencing.tsv\",\n", " threads=6,\n", " verbose_level=1,\n", " fields=[\"mean_qscore_template\", \"called_events\", \"duration\", \"strand_score\"])\n", "\n", "head (\"./results/custom_summary_sequencing.tsv\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Add file path" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "ExecuteTime": { "end_time": "2020-01-09T16:58:50.259501Z", "start_time": "2020-01-09T16:58:50.101543Z" }, "scrolled": false }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "Check input data and options\n", "Start processing fast5 files\n", "22 reads [00:00, 15978.30 reads/s]\n", "Overall counts \tvalid files: 22\n", "\n", "fields found \tread_id: 22\n", "\trun_id: 22\n", "\tchannel: 22\n", "\tstart_time: 22\n", "\tsequence_length_template: 22\n", "\tmean_qscore_template: 22\n", "\tcalibration_strand_genome_template: 22\n", "\n", "fields not found \tbarcode_arrangement: 22\n", "\n", "Total reads: 22 / Average speed: 366.98 reads/s\n", "\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "read_id run_id channel start_time sequence_length_template mean_qscore_template calibration_strand_genome_template path \n", "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", "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", "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", "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", "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", "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", "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", "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", "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", "\n" ] } ], "source": [ "Fast5_to_seq_summary (\n", " fast5_dir=\"./data/\",\n", " seq_summary_fn=\"./results/fn_summary_sequencing.tsv\",\n", " threads=6,\n", " verbose_level=1,\n", " include_path=True)\n", "\n", "head (\"./results/fn_summary_sequencing.tsv\")" ] } ], "metadata": { "celltoolbar": "Initialization Cell", "hide_input": false, "kernelspec": { "display_name": "pycoQC", "language": "python", "name": "pycoqc" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.6.6" }, "widgets": { "state": {}, "version": "1.1.1" } }, "nbformat": 4, "nbformat_minor": 1 }