[4c33d4]: / exseek / templates / summarize_cutadapt_pe.ipynb

Download this file

107 lines (106 with data), 2.9 kB

{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "%pylab inline"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import pandas as pd\n",
    "from IPython.display import display\n",
    "\n",
    "def gradient_func(val):\n",
    "    return '<span style=\"background: linear-gradient(90deg, #d65f5f {0}%, transparent 0%)\">{0:.3f}</span>'.format(val)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "summary = pd.read_table('cutadapt.txt', sep='\\t', index_col=0)\n",
    "summary_reads = summary.loc[:, ['total_read_pairs', 'read1_with_adapters', 'read2_with_adapters', 'read_pairs_too_short', 'read_pairs_kept']]\n",
    "display(summary_reads.style.set_caption('Read pairs summary'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "percent_reads = 100.0*summary_reads.div(summary_reads['total_read_pairs'], axis=0)\n",
    "percent_reads.drop(columns=['total_read_pairs'], inplace=True)\n",
    "display(percent_reads.style.format(gradient_func).set_caption('Read pairs percentage'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "summary_bp = summary.loc[:, ['total_bp', 'total_bp_read1', 'total_bp_read2',\n",
    "                             'bp_quality_trimmed', 'bp_quality_trimmed_read1', 'bp_quality_trimmed_read2',\n",
    "                             'bp_kept', 'bp_kept_read1', 'bp_kept_read2']]\n",
    "display(summary_bp.style.set_caption('Base pairs summary'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "percent_bp = 100.0*summary_bp.div(summary_bp['total_bp'], axis=0)\n",
    "percent_bp.drop(columns=['total_bp'], inplace=True)\n",
    "display(percent_bp.style.format(gradient_func).set_caption('Base pairs percentage'))"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "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.7.6"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}