{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Barcode_split 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": 3, "metadata": { "ExecuteTime": { "end_time": "2020-01-09T16:56:53.746078Z", "start_time": "2020-01-09T16:56:53.736022Z" }, "init_cell": true }, "outputs": [], "source": [ "# Run cell with Ctrl + Enter\n", "\n", "# Import main pycoQC module\n", "from pycoQC.Barcode_split import Barcode_split\n", "\n", "# Import helper functions from pycoQC\n", "from pycoQC.common import jhelp, head, ls" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Running Barcode_split" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "ExecuteTime": { "end_time": "2020-01-09T16:56:52.484368Z", "start_time": "2020-01-09T16:56:52.470584Z" }, "init_cell": true }, "outputs": [ { "data": { "text/markdown": [ "**Barcode_split** (summary_file, barcode_file, output_dir, output_unclassified, min_barcode_percent, verbose, quiet)\n", "\n", "Parse Albacore sequencing_summary.txt file and split per barcode By default, data for low frequency barcodes and unclassified reads are not written in the output directory\n", "\n", "---\n", "\n", "* **summary_file** (required) [str]\n", "\n", "Path to a sequencing_summary generated by Albacore 1.0.0 + (read_fast5_basecaller.py) / Guppy 2.1.3+ (guppy_basecaller). One can also pass multiple space separated file paths or a UNIX style regex matching multiple files\n", "\n", "* **barcode_file** (default: \"\") [str]\n", "\n", "Path to the barcode_file generated by Guppy 2.1.3+ (guppy_barcoder) or Deepbinner 0.2.0+. This is not a required file. One can also pass multiple space separated file paths or a UNIX style regex matching multiple files\n", "\n", "* **output_dir** (default: \"\") [str]\n", "\n", "Folder where to output split barcode data\n", "\n", "* **output_unclassified** (default: False) [bool]\n", "\n", "If True unclassified barcodes are also written in a file. By default they are skiped\n", "\n", "* **min_barcode_percent** (default: 0.1) [float]\n", "\n", "Minimal percent of total reads to write barcode reads in file.\n", "\n", "* **verbose** (default: False) [bool]\n", "\n", "Increase verbosity\n", "\n", "* **quiet** (default: False) [bool]\n", "\n", "Reduce verbosity\n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "jhelp(Barcode_split)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Basic usage" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "ExecuteTime": { "end_time": "2020-01-09T16:57:00.123417Z", "start_time": "2020-01-09T16:56:57.339181Z" }, "scrolled": false }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "Import data from sequencing summary file(s) and cleanup\n", "\tRead files and import in a dataframe\n", "Check input data files\n", "Parse data files\n", "Merge data\n", "\tCleanup missing barcodes values\n", "\tCleaning up low frequency barcodes\n", "Split data per barcode\n", "\tProcessing data for Barcode barcode02\n", "\tProcessing data for Barcode barcode07\n", "\tProcessing data for Barcode barcode08\n", "\tProcessing data for Barcode barcode09\n", "\tProcessing data for Barcode barcode10\n", "\tProcessing data for Barcode barcode11\n", "\tProcessing data for Barcode barcode12\n", "\tProcessing data for Barcode unclassified\n", "Barcode Counts\n", " Counts Write\n", "barcode02 2 False\n", "barcode07 1 False\n", "barcode08 30 False\n", "barcode09 9945 True\n", "barcode10 12644 True\n", "barcode11 13594 True\n", "barcode12 9813 True\n", "unclassified 3971 True\n" ] } ], "source": [ "Barcode_split (\n", " summary_file=\"./data/Guppy-2.2.4-basecall-1D-DNA_sequencing_summary+barcode.txt.gz\",\n", " output_unclassified=True,\n", " output_dir=\"./results/\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### With externaly provided barcodes" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "ExecuteTime": { "end_time": "2020-01-09T16:57:00.990564Z", "start_time": "2020-01-09T16:57:00.703388Z" }, "scrolled": false }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "Import data from sequencing summary file(s) and cleanup\n", "\tRead files and import in a dataframe\n", "Check input data files\n", "Parse data files\n", "Merge data\n", "\tCleanup missing barcodes values\n", "\tCleaning up low frequency barcodes\n", "Split data per barcode\n", "\tProcessing data for Barcode 1\n", "\tProcessing data for Barcode 2\n", "\tProcessing data for Barcode 3\n", "\tProcessing data for Barcode 4\n", "\tProcessing data for Barcode 5\n", "\tProcessing data for Barcode 6\n", "\tProcessing data for Barcode 7\n", "\tProcessing data for Barcode 8\n", "\tProcessing data for Barcode unclassified\n", "Barcode Counts\n", " Counts Write\n", "1 534 True\n", "2 206 True\n", "3 562 True\n", "4 579 True\n", "5 590 True\n", "6 655 True\n", "7 271 True\n", "8 378 True\n", "unclassified 224 False\n" ] } ], "source": [ "Barcode_split (\n", " summary_file=\"./data/Guppy-basecall-1D-DNA_sequencing_summary.txt.gz\",\n", " barcode_file=\"./data/Guppy-basecall-1D-DNA_deepbinner_barcoding_summary.txt.gz\",\n", " output_dir=\"./results/\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### If no barcode an error is raised" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "ExecuteTime": { "end_time": "2020-01-09T16:57:06.448474Z", "start_time": "2020-01-09T16:57:06.276306Z" } }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "Import data from sequencing summary file(s) and cleanup\n", "\tRead files and import in a dataframe\n", "Check input data files\n", "Parse data files\n", "Merge data\n" ] }, { "ename": "pycoQCError", "evalue": "No barcode information found in provided file(s)", "output_type": "error", "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mpycoQCError\u001b[0m Traceback (most recent call last)", "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[1;32m 1\u001b[0m Barcode_split (\n\u001b[1;32m 2\u001b[0m \u001b[0msummary_file\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m\"./data/Guppy-basecall-1D-DNA_sequencing_summary.txt.gz\"\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 3\u001b[0;31m output_dir=\"./results/\")\n\u001b[0m", "\u001b[0;32m~/Programming/Packages/pycoQC/pycoQC/Barcode_split.py\u001b[0m in \u001b[0;36mBarcode_split\u001b[0;34m(summary_file, barcode_file, output_dir, output_unclassified, min_barcode_percent, verbose, quiet)\u001b[0m\n\u001b[1;32m 75\u001b[0m \u001b[0mdf\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mdf\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mrename\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mcolumns\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m{\u001b[0m\u001b[0;34m\"barcode_arrangement\"\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\"barcode\"\u001b[0m\u001b[0;34m}\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 76\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0;34m\"barcode\"\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mdf\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 77\u001b[0;31m \u001b[0;32mraise\u001b[0m \u001b[0mpycoQCError\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0;34m\"No barcode information found in provided file(s)\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 78\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 79\u001b[0m \u001b[0;31m# Quick data cleanup\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;31mpycoQCError\u001b[0m: No barcode information found in provided file(s)" ] } ], "source": [ "Barcode_split (\n", " summary_file=\"./data/Guppy-basecall-1D-DNA_sequencing_summary.txt.gz\",\n", " output_dir=\"./results/\")" ] } ], "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 }