{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "8e5bb210",
   "metadata": {},
   "source": [
    "# Structural DNA helical parameters from MD trajectory tutorial using BioExcel Building Blocks (biobb)\n",
    "Based on the [**NAFlex**](https://mmb.irbbarcelona.org/NAFlex) server and in particular in its [**Nucleic Acids Analysis**](https://mmb.irbbarcelona.org/NAFlex/help.php?id=tutorialAnalysisNA) section. \n",
    "\n",
    "***\n",
    "This tutorial aims to illustrate the process of **extracting structural and dynamical properties** from a **DNA MD trajectory helical parameters**, step by step, using the **BioExcel Building Blocks library (biobb)**. The particular example used is the **Drew Dickerson Dodecamer** sequence -CGCGAATTCGCG- (PDB code [1BNA](https://www.rcsb.org/structure/1BNA)). The trajectory used is a  500ns-long MD simulation taken from the [BigNASim](https://mmb.irbbarcelona.org/BIGNASim/) database ([NAFlex_DDD_II](https://mmb.irbbarcelona.org/BIGNASim/getStruc.php?idCode=NAFlex_DDD_II) entry).  \n",
    "***\n",
    "\n",
    "## Settings\n",
    "\n",
    "### Biobb modules used\n",
    "\n",
    " - [biobb_dna](https://github.com/bioexcel/biobb_dna): Tools to analyse DNA structures and MD trajectories.\n",
    " \n",
    "### Auxiliar libraries used\n",
    "\n",
    " - [nb_conda_kernels](https://github.com/Anaconda-Platform/nb_conda_kernels): Enables a Jupyter Notebook or JupyterLab application in one conda environment to access kernels for Python, R, and other languages found in other environments.\n",
    " - [ipywidgets](https://github.com/jupyter-widgets/ipywidgets): Interactive HTML widgets for Jupyter notebooks and the IPython kernel.\n",
    " - [matplotlib](https://matplotlib.org/): Comprehensive library for creating static, animated, and interactive visualizations in Python. \n",
    "\n",
    "\n",
    "### Conda Installation and Launch\n",
    "\n",
    "```console\n",
    "git clone https://github.com/bioexcel/biobb_wf_dna_helparms.git\n",
    "cd biobb_wf_dna_helparms\n",
    "conda env create -f conda_env/environment.yml\n",
    "conda activate biobb_dna_helparms_tutorial\n",
    "jupyter-notebook biobb_wf_md_setup/notebooks/biobb_dna_helparms_tutorial.ipynb\n",
    "``` \n",
    "\n",
    "Please execute the following commands before launching the Jupyter Notebook if you experience some issues with some widgets:\n",
    "\n",
    "```console\n",
    "jupyter-nbextension enable --py --user widgetsnbextension\n",
    "``` \n",
    "\n",
    "***\n",
    "## Pipeline steps\n",
    " 1. [Input Parameters](#input)\n",
    " 2. [Running Curves+ and Canal](#curves)\n",
    " 3. [Average Helical Parameters](#averages)\n",
    "     1. [Base Pair Step (Inter Base Pair) Parameters](#avg_bps)\n",
    "     2. [Base Pair (Intra Base Pair) Parameters](#avg_bp)\n",
    "     3. [Axis Parameters](#avg_axis)\n",
    "     4. [Grooves](#avg_grooves)\n",
    "     5. [Backbone Torsions](#avg_backbone)\n",
    " 8. [Time Series Helical Parameters](#timeseries)\n",
    " 8. [Stiffness](#stiffness)\n",
    " 9. [Bimodality](#bimodality)\n",
    " 10. [Correlations](#correlations)\n",
    "     1. [Sequence Correlations: Intra-base pairs](#intrasequencecorrelation)\n",
    "     2. [Sequence Correlations: Inter-base pair steps](#intersequencecorrelation)\n",
    "     3. [Helical Parameter Correlations: Intra-base pairs](#intrahelparcorrelation)\n",
    "     4. [Helical Parameter Correlations: Inter-base pair steps](#interhelparcorrelation)\n",
    "     5. [Neighboring steps Correlations: Intra-base pairs](#intrabasepaircorrelation)\n",
    "     6. [Neighboring steps Correlations: Inter-base pair steps](#interbasepaircorrelation)\n",
    " 11. [Questions & Comments](#questions)\n",
    " \n",
    "***\n",
    "<img src=\"https://bioexcel.eu/wp-content/uploads/2019/04/Bioexcell_logo_1080px_transp.png\" alt=\"Bioexcel2 logo\"\n",
    "\ttitle=\"Bioexcel2 logo\" width=\"400\" />\n",
    "***\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ab4079af",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Auxiliar libraries\n",
    "\n",
    "import os\n",
    "import shutil\n",
    "import glob\n",
    "from pathlib import Path, PurePath\n",
    "import zipfile\n",
    "import matplotlib.image as mpimg\n",
    "import matplotlib.pyplot as plt\n",
    "import pandas as pd\n",
    "from IPython.display import Image\n",
    "import ipywidgets\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4d043012",
   "metadata": {},
   "source": [
    "<a id=\"input\"></a>\n",
    "## Input parameters\n",
    "**Input parameters** needed:\n",
    " - **seq**: Sequence of the DNA structure (e.g. CGCGAATTCGCG)\n",
    " - **seq_comp**: Complementary sequence of the given DNA structure (e.g. CGCGAATTCGCG)\n",
    " \n",
    " - **traj**: Trajectory for a 500ns Drew Dickerson Dodecamer MD simulation (taken from [BigNASim](https://mmb.irbbarcelona.org/BIGNASim/)) \n",
    " - **top**: Associated topology for the MD trajectory "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "610280b4",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Input parameters\n",
    "seq = \"CGCGAATTCGCG\"\n",
    "seq_comp = \"CGCGAATTCGCG\"\n",
    "\n",
    "traj = \"TRAJ/structure.stripped.nc\"\n",
    "top = \"TRAJ/structure.stripped.top\"\n",
    "\n",
    "# Auxiliar lists\n",
    "grooves = ('majd','majw','mind','minw')\n",
    "axis_base_pairs = ('inclin','tip','xdisp','ydisp')\n",
    "base_pair = ('shear','stretch','stagger','buckle','propel','opening')\n",
    "base_pair_step = ('rise','roll','twist','shift','slide','tilt')\n",
    "backbone_torsions = ('alphaC', 'alphaW', 'betaC', 'betaW', 'gammaC', 'gammaW', 'deltaC', 'deltaW', \\\n",
    "'epsilC', 'epsilW', 'zetaC', 'zetaW', 'chiC', 'chiW', 'phaseC', 'phaseW')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a1cae955",
   "metadata": {},
   "source": [
    "<a id=\"curves\"></a>\n",
    "## Running Curves+ and Canal\n",
    "\n",
    "***\n",
    "**Curves+** program and its associated **Canal** tool allow us to extract **helical parameters** from a **DNA MD simulation**.\n",
    "\n",
    "**Curves+** is a **nucleic acid conformational analysis program** which provides both **helical** and **backbone parameters**, including a curvilinear axis and parameters relating the position of the bases to this axis. It additionally provides a full analysis of **groove widths** and **depths**. **Curves+** can also be used to analyse **molecular dynamics trajectories**. With the help of the accompanying program **Canal**, it is possible to produce a variety of graphical output including parameter variations along a given structure and **time series** or **histograms** of parameter variations during dynamics.\n",
    "\n",
    "**Conformational analysis of nucleic acids revisited: Curves+**<br>\n",
    "*R. Lavery, M. Moakher, J. H. Maddocks, D. Petkeviciute, K. Zakrzewska*<br>\n",
    "***Nucleic Acids Research, Volume 37, Issue 17, 1 September 2009, Pages 5917–5929***<br>\n",
    "https://doi.org/10.1093/nar/gkp608\n",
    "\n",
    "\n",
    "**CURVES+ web server for analyzing and visualizing the helical, backbone and groove parameters of nucleic acid structure.**<br>\n",
    "*C. Blanchet, M. Pasi, K. Zakrzewska, R. Lavery*<br>\n",
    "***Nucleic Acids Research, Volume 39, Issue suppl_2, 1 July 2011, Pages W68–W73***<br>\n",
    "https://doi.org/10.1093/nar/gkr316\n",
    "http://curvesplus.bsc.es\n",
    "\n",
    "***\n",
    "**Building Blocks** used:\n",
    "- [curves](https://biobb-dna.readthedocs.io/en/latest/curvesplus.html#module-curvesplus.biobb_curves) from **biobb_dna.curvesplus.biobb_curves**\n",
    "- [canal](https://biobb-dna.readthedocs.io/en/latest/curvesplus.html#module-curvesplus.biobb_canal) from **biobb_dna.curvesplus.biobb_canal**\n",
    "***\n",
    "The extraction of **helical parameters** is then done in **two steps**:\n",
    "\n",
    "- [Step 1: Curves+](#curves1): Reading input **MD trajectory** and analysing **helical parameters**.\n",
    "- [Step 2: Canal](#canal2): Taking **Curves+** output and generating **time series** and/or **histograms** of parameter variations during dynamics.\n",
    "\n",
    "***"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b36fe969",
   "metadata": {},
   "source": [
    "<a id=\"curves1\"></a>\n",
    "### Step 1: Curves+\n",
    "\n",
    "**Curves+** program needs a **trajectory** and its associated **topology**, and a couple of **ranges**, informing about the numeration of the two **DNA strands**: s1range and s2range."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7e1afc1b",
   "metadata": {},
   "outputs": [],
   "source": [
    "from biobb_dna.curvesplus.biobb_curves import biobb_curves\n",
    "\n",
    "curves_out_lis = \"curves.out.lis\"\n",
    "curves_out_cda = \"curves.out.cda\"\n",
    "\n",
    "prop = {\n",
    "    's1range' : '1:12',\n",
    "    's2range' : '24:13'\n",
    "}\n",
    "\n",
    "biobb_curves(\n",
    "    input_struc_path=traj,\n",
    "    input_top_path=top,\n",
    "    output_lis_path=curves_out_lis,\n",
    "    output_cda_path=curves_out_cda,\n",
    "    properties=prop\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "bdcaee41",
   "metadata": {},
   "source": [
    "<a id=\"canal2\"></a>\n",
    "### Step 2: Canal\n",
    "\n",
    "**Canal** program needs the output of the previous **Curves+** execution, and is able to produce **time series** (series property) and **histograms** (histo property) for the **parameter variations** during dynamics."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "291243d0",
   "metadata": {},
   "outputs": [],
   "source": [
    "from biobb_dna.curvesplus.biobb_canal import biobb_canal\n",
    "\n",
    "canal_out = \"canal.out.zip\"\n",
    "\n",
    "prop = {\n",
    "    'series' : True,\n",
    "    'histo' : True\n",
    "}\n",
    "\n",
    "biobb_canal(\n",
    "    input_cda_file=curves_out_cda,\n",
    "    input_lis_file=curves_out_lis,\n",
    "    output_zip_path=canal_out,\n",
    "    properties=prop\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9361e64a",
   "metadata": {},
   "source": [
    "### Extracting Canal results in a temporary folder"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7549008a",
   "metadata": {},
   "outputs": [],
   "source": [
    "canal_dir = \"canal_out\"\n",
    "\n",
    "if Path(canal_dir).exists(): shutil.rmtree(canal_dir) \n",
    "os.mkdir(canal_dir)\n",
    "\n",
    "with zipfile.ZipFile(canal_out, 'r') as zip_ref:\n",
    "    zip_ref.extractall(canal_dir)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "15cc3270",
   "metadata": {},
   "source": [
    "<a id=\"averages\"></a>\n",
    "\n",
    "## Extracting Average Helical Parameters\n",
    "\n",
    "**Average helical parameter** values can be computed from the output of **Curves+/Canal** execution. \n",
    "\n",
    "The **helical parameters** can be divided in 5 main blocks:\n",
    "\n",
    "- [Helical Base Pair Step (Inter-Base Pair) Helical Parameters](#avg_bps)\n",
    "- [Helical Base Pair (Intra-Base Pair) Helical Parameters](#avg_bp)\n",
    "- [Axis Base Pair](#avg_axis)\n",
    "- [Grooves](#avg_grooves)\n",
    "- [Backbone Torsions](#avg_backbone)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "418d815c",
   "metadata": {},
   "source": [
    "<a id=\"avg_bps\"></a>\n",
    "\n",
    "### Helical Base Pair Step (Inter Base Pair) Parameters\n",
    "\n",
    "**Translational (Shift, Slide, Rise)** and **rotational (Tilt, Roll, Twist)** parameters related to a **dinucleotide Inter-Base Pair** (Base Pair Step).\n",
    "\n",
    "- **Shift**: Translation around the X-axis.\n",
    "- **Slide**: Translation around the Y-axis.\n",
    "- **Rise**: Translation around the Z-axis.\n",
    "- **Tilt**: Rotation around the X-axis.\n",
    "- **Roll**: Rotation around the Y-axis.\n",
    "- **Twist**: Rotation around the Z-axis.\n",
    "\n",
    "***\n",
    "<img src=\"https://mmb.irbbarcelona.org/NAFlex/images/helicalParamsBPS.png\" alt=\"Helical Base Pair Step Parameters\"\n",
    "\ttitle=\"Helical Base Pair Step Parameters\" width=\"400\" />\n",
    "***\n",
    "**Building Block** used:\n",
    "- [helparaverages](https://biobb-dna.readthedocs.io/en/latest/dna.html#module-dna.dna_averages) from **biobb_dna.dna.dna_averages** \n",
    "***"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "82b74c1f",
   "metadata": {},
   "source": [
    "#### Extracting a particular Helical Parameter: Rise"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "16898fee",
   "metadata": {},
   "outputs": [],
   "source": [
    "from biobb_dna.dna.dna_averages import dna_averages\n",
    "\n",
    "helpar = 'rise'\n",
    "\n",
    "input_file_path = \"canal_out/canal_output\" + \"_\" + helpar + \".ser\"\n",
    "output_averages_csv_path= helpar+'.averages.csv'\n",
    "output_averages_jpg_path= helpar+'.averages.jpg'\n",
    "\n",
    "prop = {\n",
    "    'helpar_name': helpar,\n",
    "    'sequence': seq\n",
    "}\n",
    "\n",
    "dna_averages(\n",
    "    input_ser_path=input_file_path,\n",
    "    output_csv_path=output_averages_csv_path,\n",
    "    output_jpg_path=output_averages_jpg_path,\n",
    "    properties=prop)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "629acce7",
   "metadata": {},
   "source": [
    "#### Showing the calculated average values for Rise helical parameter"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "41c37557",
   "metadata": {},
   "outputs": [],
   "source": [
    "output_averages_csv_path= helpar+'.averages.csv'\n",
    "df = pd.read_csv(output_averages_csv_path)\n",
    "df"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "49381c46",
   "metadata": {},
   "source": [
    "#### Plotting the average values for Rise helical parameter "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "85491710",
   "metadata": {},
   "outputs": [],
   "source": [
    "Image(filename=output_averages_jpg_path,width = 600)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "cf1333bf",
   "metadata": {},
   "source": [
    "#### Computing average values from all base-pair step parameters"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c262c8e0",
   "metadata": {},
   "outputs": [],
   "source": [
    "from biobb_dna.dna.dna_averages import dna_averages\n",
    "\n",
    "for helpar in base_pair_step:\n",
    "\n",
    "    input_file_path = \"canal_out/canal_output\" + \"_\" + helpar + \".ser\"\n",
    "    output_averages_csv_path= helpar+'.averages.csv'\n",
    "    output_averages_jpg_path= helpar+'.averages.jpg'\n",
    "\n",
    "    prop = {\n",
    "        'helpar_name': helpar,\n",
    "        'sequence': seq\n",
    "    }\n",
    "\n",
    "    dna_averages(\n",
    "        input_ser_path=input_file_path,\n",
    "        output_csv_path=output_averages_csv_path,\n",
    "        output_jpg_path=output_averages_jpg_path,\n",
    "        properties=prop)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f6bb6937",
   "metadata": {},
   "source": [
    "#### Showing the calculated average values for all base-pair step helical parameters"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "18c0cc9b",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "for helpar in base_pair_step:\n",
    "    output_averages_csv_path= helpar+'.averages.csv'\n",
    "    df = pd.read_csv(output_averages_csv_path)\n",
    "    print(\"Helical Parameter: \" + helpar)\n",
    "    print(df)\n",
    "    print(\"---------\\n\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "93893f34",
   "metadata": {},
   "source": [
    "#### Plotting the average values for all base-pair step helical parameters "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4177cae8",
   "metadata": {},
   "outputs": [],
   "source": [
    "images = []\n",
    "for helpar in base_pair_step:\n",
    "    images.append(helpar + '.averages.jpg')\n",
    "\n",
    "f, axarr = plt.subplots(2, 3, figsize=(40, 20))\n",
    "\n",
    "for i, image in enumerate(images):\n",
    "    y = i%3\n",
    "    x = int(i/3)\n",
    "\n",
    "    img = mpimg.imread(image)\n",
    "\n",
    "    axarr[x,y].imshow(img, aspect='auto')\n",
    "    axarr[x,y].axis('off')\n",
    "\n",
    "plt.show()\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "58ecf102",
   "metadata": {},
   "source": [
    "<a id=\"avg_bp\"></a>\n",
    "### Helical Base Pair (Intra Base Pair) Parameters\n",
    "\n",
    "**Translational (Shear, Stretch, Stagger)** and **rotational (Buckle, Propeller, Opening)** parameters related to a **dinucleotide Intra-Base Pair**.\n",
    "\n",
    "- **Shear**: Translation around the X-axis.\n",
    "- **Stretch**: Translation around the Y-axis.\n",
    "- **Stagger**: Translation around the Z-axis.\n",
    "- **Buckle**: Rotation around the X-axis.\n",
    "- **Propeller**: Rotation around the Y-axis.\n",
    "- **Opening**: Rotation around the Z-axis.\n",
    "\n",
    "***\n",
    "<img src=\"https://mmb.irbbarcelona.org/NAFlex/images/helicalParamsBP.png\" alt=\"Helical Base Pair Parameters\"\n",
    "\ttitle=\"Helical Base Pair Parameters\" width=\"400\" />\n",
    "***\n",
    "**Building Block** used:\n",
    "- [helparaverages](https://biobb-dna.readthedocs.io/en/latest/dna.html#module-dna.dna_averages) from **biobb_dna.dna.dna_averages** \n",
    "***"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "de54c637",
   "metadata": {},
   "source": [
    "#### Computing average values from all base-pair parameters"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "240550b2",
   "metadata": {},
   "outputs": [],
   "source": [
    "from biobb_dna.dna.dna_averages import dna_averages\n",
    "\n",
    "for helpar in base_pair:\n",
    "\n",
    "    #input_file_path = canal_out + \"_\" + helpar + \".ser\"\n",
    "    input_file_path = \"canal_out/canal_output\" + \"_\" + helpar + \".ser\"\n",
    "    output_averages_csv_path= helpar+'.averages.csv'\n",
    "    output_averages_jpg_path= helpar+'.averages.jpg'\n",
    "\n",
    "    prop = {\n",
    "        'helpar_name': helpar,\n",
    "        'sequence': seq\n",
    "    }\n",
    "\n",
    "    dna_averages(\n",
    "        input_ser_path=input_file_path,\n",
    "        output_csv_path=output_averages_csv_path,\n",
    "        output_jpg_path=output_averages_jpg_path,\n",
    "        properties=prop)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a8d3e820",
   "metadata": {},
   "source": [
    "#### Showing the calculated average values for all base-pair helical parameters"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "38cd75a3",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "for helpar in base_pair:\n",
    "    output_averages_csv_path= helpar+'.averages.csv'\n",
    "    df = pd.read_csv(output_averages_csv_path)\n",
    "    print(\"Helical Parameter: \" + helpar)\n",
    "    print(df)\n",
    "    print(\"---------\\n\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a2f86462",
   "metadata": {},
   "source": [
    "#### Plotting the average values for all base-pair helical parameters "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "38361c69",
   "metadata": {},
   "outputs": [],
   "source": [
    "images = []\n",
    "for helpar in base_pair:\n",
    "    images.append(helpar + '.averages.jpg')\n",
    "\n",
    "f, axarr = plt.subplots(2, 3, figsize=(40, 20))\n",
    "\n",
    "for i, image in enumerate(images):\n",
    "    y = i%3\n",
    "    x = int(i/3)\n",
    "\n",
    "    img = mpimg.imread(image)\n",
    "\n",
    "    axarr[x,y].imshow(img, aspect='auto')\n",
    "    axarr[x,y].axis('off')\n",
    "\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "13e882d9",
   "metadata": {},
   "source": [
    "<a id=\"avg_axis\"></a>\n",
    "### Axis Base Pair Parameters\n",
    "\n",
    "***\n",
    "**Translational (x/y-displacement)** and **rotational (inclination, tip)** parameters related to a dinucleotide Base Pair.\n",
    "\n",
    "- **X-displacement**: Translation around the X-axis.\n",
    "- **Y-displacement**: Translation around the Y-axis.\n",
    "- **Inclination**: Rotation around the X-axis.\n",
    "- **Tip**: Rotation around the Y-axis.\n",
    "***\n",
    "<img src=\"https://mmb.irbbarcelona.org/NAFlex/images/axis-bp.png\" alt=\"Axis Base Pair Parameters\"\n",
    "\ttitle=\"Axis Base Pair Parameters\" width=\"200\" />\n",
    "***\n",
    "**Building Block** used:\n",
    "- [helparaverages](https://biobb-dna.readthedocs.io/en/latest/dna.html#module-dna.dna_averages) from **biobb_dna.dna.averages** \n",
    "***"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e1744ef2",
   "metadata": {},
   "source": [
    "#### Computing average values from all Axis base-pair parameters"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3f6e0e5e",
   "metadata": {},
   "outputs": [],
   "source": [
    "from biobb_dna.dna.dna_averages import dna_averages\n",
    "\n",
    "for helpar in axis_base_pairs:\n",
    "\n",
    "    #input_file_path = canal_out + \"_\" + helpar + \".ser\"\n",
    "    input_file_path = \"canal_out/canal_output\" + \"_\" + helpar + \".ser\"\n",
    "    output_averages_csv_path= helpar+'.averages.csv'\n",
    "    output_averages_jpg_path= helpar+'.averages.jpg'\n",
    "\n",
    "    prop = {\n",
    "        'helpar_name': helpar,\n",
    "        'sequence': seq,\n",
    "#        'seqpos': [4,3]\n",
    "    }\n",
    "\n",
    "    dna_averages(\n",
    "        input_ser_path=input_file_path,\n",
    "        output_csv_path=output_averages_csv_path,\n",
    "        output_jpg_path=output_averages_jpg_path,\n",
    "        properties=prop)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a546fd79",
   "metadata": {},
   "source": [
    "#### Showing the calculated average values for all Axis base-pair helical parameters"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0c260453",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "for helpar in axis_base_pairs:\n",
    "    output_averages_csv_path= helpar+'.averages.csv'\n",
    "    df = pd.read_csv(output_averages_csv_path)\n",
    "    print(\"Helical Parameter: \" + helpar)\n",
    "    print(df)\n",
    "    print(\"---------\\n\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "31739158",
   "metadata": {},
   "source": [
    "#### Plotting the average values for all Axis base-pair helical parameters "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c61a456b",
   "metadata": {},
   "outputs": [],
   "source": [
    "images = []\n",
    "for helpar in axis_base_pairs:\n",
    "    images.append(helpar + '.averages.jpg')\n",
    "\n",
    "f, axarr = plt.subplots(2, 2, figsize=(30, 20))\n",
    "\n",
    "for i, image in enumerate(images):\n",
    "    y = i%2\n",
    "    x = int(i/2)\n",
    "\n",
    "    img = mpimg.imread(image)\n",
    "\n",
    "    axarr[x,y].imshow(img, aspect='auto')\n",
    "    axarr[x,y].axis('off')\n",
    "\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a94862a3",
   "metadata": {},
   "source": [
    "<a id=\"avg_grooves\"></a>\n",
    "### Grooves\n",
    "\n",
    "***\n",
    "Nucleic Acid Structure's strand backbones appear closer together on one side of the helix than on the other. This creates a **Major groove** (where backbones are far apart) and a **Minor groove** (where backbones are close together). **Depth and width** of these grooves can be mesured giving information about the different conformations that the nucleic acid structure can achieve.\n",
    "\n",
    "- **Major Groove Width**.\n",
    "- **Major Groove Depth**.\n",
    "- **Minor Groove Width**.\n",
    "- **Minor Groove Depth**.\n",
    "\n",
    "***\n",
    "<img src=\"https://mmb.irbbarcelona.org//NAFlex2/images/DnaMajorMinorGroove.gif\" alt=\"Grooves Parameters\"\n",
    "\ttitle=\"Grooves Parameters\" width=\"200\" />\n",
    "***\n",
    "**Building Block** used:\n",
    "- [helparaverages](https://biobb-dna.readthedocs.io/en/latest/dna.html#module-dna.dna_averages) from **biobb_dna.dna.dna_averages**\n",
    "***"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0fdbe831",
   "metadata": {},
   "source": [
    "#### Computing average values from all Grooves parameters"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "476f7468",
   "metadata": {},
   "outputs": [],
   "source": [
    "from biobb_dna.dna.dna_averages import dna_averages\n",
    "\n",
    "for helpar in grooves:\n",
    "\n",
    "    #input_file_path = canal_out + \"_\" + helpar + \".ser\"\n",
    "    input_file_path = \"canal_out/canal_output\" + \"_\" + helpar + \".ser\"\n",
    "    output_averages_csv_path= helpar+'.averages.csv'\n",
    "    output_averages_jpg_path= helpar+'.averages.jpg'\n",
    "\n",
    "    prop = {\n",
    "        'helpar_name': helpar,\n",
    "        'sequence': seq\n",
    "    }\n",
    "\n",
    "    dna_averages(\n",
    "        input_ser_path=input_file_path,\n",
    "        output_csv_path=output_averages_csv_path,\n",
    "        output_jpg_path=output_averages_jpg_path,\n",
    "        properties=prop)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "462a0046",
   "metadata": {},
   "source": [
    "#### Showing the calculated average values for all Grooves parameters"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9062402c",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "for helpar in grooves:\n",
    "    output_averages_csv_path= helpar+'.averages.csv'\n",
    "    df = pd.read_csv(output_averages_csv_path)\n",
    "    print(\"Helical Parameter: \" + helpar)\n",
    "    print(df)\n",
    "    print(\"---------\\n\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "003dffc2",
   "metadata": {},
   "source": [
    "#### Plotting the average values for all Grooves helical parameters "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "05963b52",
   "metadata": {},
   "outputs": [],
   "source": [
    "images = []\n",
    "for helpar in grooves:\n",
    "    images.append(helpar + '.averages.jpg')\n",
    "\n",
    "f, axarr = plt.subplots(2, 2, figsize=(30, 20))\n",
    "\n",
    "for i, image in enumerate(images):\n",
    "    y = i%2\n",
    "    x = int(i/2)\n",
    "\n",
    "    img = mpimg.imread(image)\n",
    "\n",
    "    axarr[x,y].imshow(img, aspect='auto')\n",
    "    axarr[x,y].axis('off')\n",
    "\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "fb9b0671",
   "metadata": {},
   "source": [
    "<a id=\"avg_backbone\"></a>\n",
    "### Backbone Torsions\n",
    "\n",
    "***\n",
    "\n",
    " The three major elements of flexibility in the **backbone** are:\n",
    "\n",
    "- **[Sugar Puckering](#puckering)**:\n",
    "\n",
    "    Sugar Puckering annotation is done by dividing the pseudo-rotational circle in four equivalent sections:<br><br>\n",
    "    - ***North***: 315:45º\n",
    "    - ***East***: 45:135º\n",
    "    - ***South***: 135:225º\n",
    "    - ***West***: 225:315º\n",
    "    \n",
    " These four conformations are those dominating sugar conformational space, in agreement with all available experimental data.\n",
    "\n",
    "\n",
    "- **[Canonical Alpha/Gamma](#alphagamma)**:\n",
    "\n",
    "    Rotations around **α/γ torsions** generate non-canonical local conformations leading to a reduced twist and they have been reported as being important in the formation of several protein-DNA complexes. \n",
    "    \n",
    "    \n",
    "- **[BI/BII Population](#bIbII)**:\n",
    "\n",
    "    The concerted rotation around **ζ/ε torsions** generates two major conformers: **BI and BII**, which are experimentally known to co-exist in a ratio around 80%:20% (BI:BII) in B-DNA.\n",
    "\n",
    "\n",
    "<table><tr style=\"background-color: #FFFFFF\"><td>\n",
    "    <img src=\"https://mmb.irbbarcelona.org/NAFlex/images/Puckering2.png\" alt=\"Sugar Puckering\"\n",
    "\ttitle=\"Sugar Puckering\" width=\"300\" /> \n",
    "</td><td>\n",
    "    <img src=\"https://mmb.irbbarcelona.org/NAFlex/images/AlphaGamma.png\" alt=\"Canonical Alpha/Gamma\"\n",
    "title=\"Canonical Alpha/Gamma\" width=\"300\" />\n",
    "</td><td>\n",
    "    <img src=\"https://mmb.irbbarcelona.org/NAFlex/images/BI-BII.png\" alt=\"BI/BII population\"\n",
    "title=\"BI/BII population\" width=\"300\" />\n",
    "</td></tr>\n",
    "<tr ><td>\n",
    "    <p style=\"text-align: center; font-weight: bold\">Sugar Puckering</p>\n",
    "</td>\n",
    "<td>\n",
    "    <p style=\"text-align: center; font-weight: bold\">Canonical Alpha/Gamma</p>\n",
    "</td>\n",
    "<td>\n",
    "    <p style=\"text-align: center; font-weight: bold\">BI/BII population</p>\n",
    "</td></tr>\n",
    "</table>\n",
    "    \n",
    "***\n",
    "**Building Blocks** used:\n",
    "- [puckering](https://biobb-dna.readthedocs.io/en/latest/backbone.html#module-backbone.puckering) from **biobb_dna.backbone.puckering** \n",
    "- [canonicalag](https://biobb-dna.readthedocs.io/en/latest/backbone.html#module-backbone.canonicalag) from **biobb_dna.backbone.canonicalag**\n",
    "- [bipopulations](https://biobb-dna.readthedocs.io/en/latest/backbone.html#module-backbone.bipopulations) from **biobb_dna.backbone.bipopulations**\n",
    "***"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "46f96dad",
   "metadata": {},
   "source": [
    "<a id=\"puckering\"></a>\n",
    "\n",
    "#### Sugar Puckering"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9dd3df1c",
   "metadata": {},
   "source": [
    "##### Computing average values"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "73222466",
   "metadata": {},
   "outputs": [],
   "source": [
    "from biobb_dna.backbone.puckering import puckering\n",
    "\n",
    "canal_phaseC = \"canal_out/canal_output_phaseC.ser\"\n",
    "canal_phaseW = \"canal_out/canal_output_phaseW.ser\"\n",
    "\n",
    "output_puckering_csv_path = 'puckering.averages.csv'\n",
    "output_puckering_jpg_path = 'puckering.averages.jpg'\n",
    "\n",
    "prop = {\n",
    "    'sequence': seq\n",
    "}\n",
    "\n",
    "puckering(\n",
    "    input_phaseC_path=canal_phaseC,\n",
    "    input_phaseW_path=canal_phaseW,\n",
    "    output_csv_path=output_puckering_csv_path,\n",
    "    output_jpg_path=output_puckering_jpg_path,\n",
    "    properties=prop)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c933e98f",
   "metadata": {},
   "source": [
    "##### Showing the calculated average values"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "bfff4f7f",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "df = pd.read_csv(output_puckering_csv_path)\n",
    "df"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "02ffeec7",
   "metadata": {},
   "source": [
    "##### Plotting the average values "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6883631b",
   "metadata": {},
   "outputs": [],
   "source": [
    "Image(filename=output_puckering_jpg_path,width = 600)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "29e8b473",
   "metadata": {},
   "source": [
    "<a id=\"alphagamma\"></a>\n",
    "#### Canonical Alpha/Gamma"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4f5211b3",
   "metadata": {},
   "source": [
    "##### Computing average values"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "531aea3b",
   "metadata": {},
   "outputs": [],
   "source": [
    "from biobb_dna.backbone.canonicalag import canonicalag\n",
    "\n",
    "canal_alphaC = \"canal_out/canal_output_alphaC.ser\"\n",
    "canal_alphaW = \"canal_out/canal_output_alphaW.ser\"\n",
    "canal_gammaC = \"canal_out/canal_output_gammaC.ser\"\n",
    "canal_gammaW = \"canal_out/canal_output_gammaW.ser\"\n",
    "\n",
    "output_alphagamma_csv_path = 'alphagamma.averages.csv'\n",
    "output_alphagamma_jpg_path = 'alphagamma.averages.jpg'\n",
    "\n",
    "prop = {\n",
    "    'sequence': seq\n",
    "}\n",
    "\n",
    "canonicalag(\n",
    "    input_alphaC_path=canal_alphaC,\n",
    "    input_alphaW_path=canal_alphaW,\n",
    "    input_gammaC_path=canal_gammaC,\n",
    "    input_gammaW_path=canal_gammaW,\n",
    "    output_csv_path=output_alphagamma_csv_path,\n",
    "    output_jpg_path=output_alphagamma_jpg_path,\n",
    "    properties=prop)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "24264a24",
   "metadata": {},
   "source": [
    "##### Showing the calculated average values"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "327d457f",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "df = pd.read_csv(output_alphagamma_csv_path)\n",
    "df"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "773efb9c",
   "metadata": {},
   "source": [
    "##### Plotting the average values "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0f118b89",
   "metadata": {},
   "outputs": [],
   "source": [
    "Image(filename=output_alphagamma_jpg_path,width = 600)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d4b60723",
   "metadata": {},
   "source": [
    "<a id=\"bIbII\"></a>\n",
    "#### BI/BII Population"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1528dbb9",
   "metadata": {},
   "source": [
    "##### Computing average values"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4602101a",
   "metadata": {},
   "outputs": [],
   "source": [
    "from biobb_dna.backbone.bipopulations import bipopulations\n",
    "\n",
    "canal_epsilC = \"canal_out/canal_output_epsilC.ser\"\n",
    "canal_epsilW = \"canal_out/canal_output_epsilW.ser\"\n",
    "canal_zetaC = \"canal_out/canal_output_zetaC.ser\"\n",
    "canal_zetaW = \"canal_out/canal_output_zetaW.ser\"\n",
    "\n",
    "output_bIbII_csv_path = 'bIbII.averages.csv'\n",
    "output_bIbII_jpg_path = 'bIbII.averages.jpg'\n",
    "\n",
    "prop = {\n",
    "    'sequence': seq\n",
    "}\n",
    "\n",
    "bipopulations(\n",
    "    input_epsilC_path=canal_epsilC,\n",
    "    input_epsilW_path=canal_epsilW,\n",
    "    input_zetaC_path=canal_zetaC,\n",
    "    input_zetaW_path=canal_zetaW,\n",
    "    output_csv_path=output_bIbII_csv_path,\n",
    "    output_jpg_path=output_bIbII_jpg_path,\n",
    "    properties=prop)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8c791564",
   "metadata": {},
   "source": [
    "##### Showing the calculated average values"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "559d8cd4",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "df = pd.read_csv(output_bIbII_csv_path)\n",
    "df"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2b861782",
   "metadata": {},
   "source": [
    "##### Plotting the average values "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0d799db8",
   "metadata": {},
   "outputs": [],
   "source": [
    "Image(filename=output_bIbII_jpg_path,width = 600)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d6029d85",
   "metadata": {},
   "source": [
    "<a id=\"timeseries\"></a>\n",
    "## Extracting Time series Helical Parameters\n",
    "\n",
    "**Time series** values for the set of **helical parameters** can be also extracted from the output of **Curves+/Canal** execution on **Molecular Dynamics Trajectories**. The **helical parameters** can be divided in the same 5 main blocks previously introduced:\n",
    "\n",
    "- Helical Base Pair Step (Inter-Base Pair) Helical Parameters\n",
    "- Helical Base Pair (Intra-Base Pair) Helical Parameters\n",
    "- Axis Base Pair\n",
    "- Grooves\n",
    "- Backbone Torsions\n",
    "\n",
    "***\n",
    "**Building Block** used:\n",
    "- [helpartimeseries](https://biobb-dna.readthedocs.io/en/latest/dna.html#module-dna.dna_timeseries) from **biobb_dna.dna.dna_timeseries**\n",
    "***"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "76137e1a",
   "metadata": {},
   "source": [
    "### Extracting a particular Helical Parameter\n",
    "\n",
    "**Time series** values can be extracted from any of the **helical parameters** previously introduced. To illustrate the steps needed, the **base-pair step helical parameter** ***Twist*** has been selected. Please note that computing the **time series** values for a different **helical parameter** just requires modifying the ***helpar*** variable from the next cell.  "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f6b0ba28",
   "metadata": {},
   "outputs": [],
   "source": [
    "from biobb_dna.dna.dna_timeseries import dna_timeseries\n",
    "\n",
    "# Modify the next variable to extract time series values for a different helical parameter\n",
    "# Possible values are: \n",
    "    # Base Pair Step (Inter Base Pair) Helical Parameters: shift, slide, rise, tilt, roll, twist \n",
    "    # Base Pair (Intra Base Pair) Helical Parameters: shear, stretch, stagger, buckle, propeller, opening\n",
    "    # Axis Parameters: inclin, tip, xdisp, ydisp\n",
    "    # Backbone Torsions Parameters: alphaC, alphaW, betaC, betaW, gammaC, gammaW, deltaC, deltaW,\n",
    "    #                                epsilC, epsilW, zetaC, zetaW, chiC, chiW, phaseC, phaseW\n",
    "    # Grooves: mind, minw, majd, majw\n",
    "\n",
    "helpar = \"twist\" # Modify this variable to extract time series values for a different helical parameter\n",
    "\n",
    "input_file_path = \"canal_out/canal_output\" + \"_\" + helpar + \".ser\"\n",
    "output_timeseries_file_path = helpar + '.timeseries.zip'\n",
    "\n",
    "prop = {\n",
    "    'helpar_name': helpar,\n",
    "    'sequence': seq\n",
    "}\n",
    "\n",
    "dna_timeseries(\n",
    "    input_ser_path=input_file_path,\n",
    "    output_zip_path=output_timeseries_file_path,\n",
    "    properties=prop)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e008f927",
   "metadata": {},
   "source": [
    "### Extracting time series results for the selected helical parameter in a temporary folder"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c70f5408",
   "metadata": {},
   "outputs": [],
   "source": [
    "timeseries_dir = \"timeseries\"\n",
    "\n",
    "if Path(timeseries_dir).exists(): shutil.rmtree(timeseries_dir) \n",
    "os.mkdir(timeseries_dir)\n",
    "\n",
    "with zipfile.ZipFile(output_timeseries_file_path, 'r') as zip_ref:\n",
    "    zip_ref.extractall(timeseries_dir)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "da5e3707",
   "metadata": {},
   "source": [
    "### Finding out all the possible nucleotide / base / base-pair / base-pair steps\n",
    "\n",
    "Discover all the possible **nucleotide / base / base-pair / base-pair steps** from the **sequence**. The unit will depend on the helical parameter being studied.  \n",
    "**Select one of them** to study the **time series** values of the **helical parameter** along the **simulation**."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ea3ce065",
   "metadata": {},
   "outputs": [],
   "source": [
    "helpartimesfiles = glob.glob(timeseries_dir + \"/*series*.csv\") \n",
    "\n",
    "helpartimes = []\n",
    "for file in helpartimesfiles:\n",
    "    new_string = file.replace(timeseries_dir + \"/series_\" + helpar + \"_\", \"\")\n",
    "    new_string = new_string.replace(\".csv\" , \"\")\n",
    "    helpartimes.append(new_string)\n",
    "    \n",
    "timesel = ipywidgets.Dropdown(\n",
    "    options=helpartimes,\n",
    "    description='Sel. BPS:',\n",
    "    disabled=False,\n",
    ")\n",
    "display(timesel)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e6cf5626",
   "metadata": {},
   "source": [
    "### Showing the time series values for the selected unit"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3e88edc3",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "file_ser = timeseries_dir + \"/series_\" + helpar + \"_\" + timesel.value + \".csv\"\n",
    "\n",
    "df = pd.read_csv(file_ser)\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "017cc3b3",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "file_hist = timeseries_dir + \"/hist_\" + helpar + \"_\" + timesel.value + \".csv\"\n",
    "\n",
    "df = pd.read_csv(file_hist)\n",
    "df"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4508596a",
   "metadata": {},
   "source": [
    "### Plotting the time series values for the selected base-pair step "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0868ef3c",
   "metadata": {},
   "outputs": [],
   "source": [
    "file_ser = timeseries_dir + \"/series_\" + helpar + \"_\" + timesel.value + \".jpg\"\n",
    "file_hist = timeseries_dir + \"/hist_\" + helpar + \"_\" + timesel.value + \".jpg\"\n",
    "\n",
    "images = []\n",
    "\n",
    "images.append(file_ser)\n",
    "images.append(file_hist)\n",
    "\n",
    "f, axarr = plt.subplots(1, 2, figsize=(50, 15))\n",
    "\n",
    "for i, image in enumerate(images):\n",
    "    img = mpimg.imread(image)\n",
    "\n",
    "    axarr[i].imshow(img, aspect='auto')\n",
    "    axarr[i].axis('off')\n",
    "\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5c915d68",
   "metadata": {},
   "source": [
    "### Computing timeseries for all base-pair step parameters "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e49bdb4e",
   "metadata": {},
   "outputs": [],
   "source": [
    "from biobb_dna.dna.dna_timeseries import dna_timeseries\n",
    "\n",
    "output_timeseries_bps_file_paths = {}\n",
    "for helpar in base_pair_step:\n",
    "\n",
    "    input_file_path = \"canal_out/canal_output\" + \"_\" + helpar + \".ser\"\n",
    "    output_timeseries_bps_file_paths[helpar] = helpar + '.timeseries.zip'\n",
    "\n",
    "    prop = {\n",
    "        'helpar_name': helpar,\n",
    "        'sequence': seq\n",
    "    }\n",
    "\n",
    "    dna_timeseries(\n",
    "        input_ser_path=input_file_path,\n",
    "        output_zip_path=output_timeseries_bps_file_paths[helpar],\n",
    "        properties=prop)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "32b8789c",
   "metadata": {},
   "outputs": [],
   "source": [
    "#if Path(timeseries_dir).exists(): shutil.rmtree(timeseries_dir) \n",
    "#os.mkdir(timeseries_dir)\n",
    "\n",
    "for timeseries_zipfile in output_timeseries_bps_file_paths.values():\n",
    "    with zipfile.ZipFile(timeseries_zipfile, 'r') as zip_ref:\n",
    "        zip_ref.extractall(timeseries_dir)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9381762d",
   "metadata": {},
   "source": [
    "### Computing timeseries for all base-pair parameters "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f938ee32",
   "metadata": {},
   "outputs": [],
   "source": [
    "from biobb_dna.dna.dna_timeseries import dna_timeseries\n",
    "\n",
    "output_timeseries_bp_file_paths = {}\n",
    "for helpar in base_pair:\n",
    "\n",
    "    input_file_path = \"canal_out/canal_output\" + \"_\" + helpar + \".ser\"\n",
    "    output_timeseries_bp_file_paths[helpar] = helpar + '.timeseries.zip'\n",
    "\n",
    "    prop = {\n",
    "        'helpar_name': helpar,\n",
    "        'sequence': seq\n",
    "    }\n",
    "\n",
    "    dna_timeseries(\n",
    "        input_ser_path=input_file_path,\n",
    "        output_zip_path=output_timeseries_bp_file_paths[helpar],\n",
    "        properties=prop)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d4042c85",
   "metadata": {},
   "outputs": [],
   "source": [
    "#if Path(timeseries_dir).exists(): shutil.rmtree(timeseries_dir) \n",
    "#os.mkdir(timeseries_dir)\n",
    "\n",
    "for timeseries_zipfile in output_timeseries_bp_file_paths.values():\n",
    "    with zipfile.ZipFile(timeseries_zipfile, 'r') as zip_ref:\n",
    "        zip_ref.extractall(timeseries_dir)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f4cb2d7b",
   "metadata": {},
   "source": [
    "### Computing timeseries for all axis parameters "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1d4b093b",
   "metadata": {},
   "outputs": [],
   "source": [
    "from biobb_dna.dna.dna_timeseries import dna_timeseries\n",
    "\n",
    "output_timeseries_bp_file_paths = {}\n",
    "for helpar in axis_base_pairs:\n",
    "\n",
    "    input_file_path = \"canal_out/canal_output\" + \"_\" + helpar + \".ser\"\n",
    "    output_timeseries_bp_file_paths[helpar] = helpar + '.timeseries.zip'\n",
    "\n",
    "    prop = {\n",
    "        'helpar_name': helpar,\n",
    "        'sequence': seq\n",
    "    }\n",
    "\n",
    "    dna_timeseries(\n",
    "        input_ser_path=input_file_path,\n",
    "        output_zip_path=output_timeseries_bp_file_paths[helpar],\n",
    "        properties=prop)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a0f21d57",
   "metadata": {},
   "outputs": [],
   "source": [
    "for timeseries_zipfile in output_timeseries_bp_file_paths.values():\n",
    "    with zipfile.ZipFile(timeseries_zipfile, 'r') as zip_ref:\n",
    "        zip_ref.extractall(timeseries_dir)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c6fd096c",
   "metadata": {},
   "source": [
    "### Computing timeseries for all grooves parameters "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a14ae59e",
   "metadata": {},
   "outputs": [],
   "source": [
    "from biobb_dna.dna.dna_timeseries import dna_timeseries\n",
    "\n",
    "output_timeseries_bp_file_paths = {}\n",
    "for helpar in grooves:\n",
    "\n",
    "    input_file_path = \"canal_out/canal_output\" + \"_\" + helpar + \".ser\"\n",
    "    output_timeseries_bp_file_paths[helpar] = helpar + '.timeseries.zip'\n",
    "\n",
    "    prop = {\n",
    "        'helpar_name': helpar,\n",
    "        'sequence': seq\n",
    "    }\n",
    "\n",
    "    dna_timeseries(\n",
    "        input_ser_path=input_file_path,\n",
    "        output_zip_path=output_timeseries_bp_file_paths[helpar],\n",
    "        properties=prop)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a995bb6a",
   "metadata": {},
   "outputs": [],
   "source": [
    "for timeseries_zipfile in output_timeseries_bp_file_paths.values():\n",
    "    with zipfile.ZipFile(timeseries_zipfile, 'r') as zip_ref:\n",
    "        zip_ref.extractall(timeseries_dir)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "dbb07539",
   "metadata": {},
   "source": [
    "### Computing timeseries for all backbone torsions parameters "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "70a3c609",
   "metadata": {},
   "outputs": [],
   "source": [
    "from biobb_dna.dna.dna_timeseries import dna_timeseries\n",
    "\n",
    "output_timeseries_bp_file_paths = {}\n",
    "for helpar in backbone_torsions:\n",
    "\n",
    "    input_file_path = \"canal_out/canal_output\" + \"_\" + helpar + \".ser\"\n",
    "    output_timeseries_bp_file_paths[helpar] = helpar + '.timeseries.zip'\n",
    "\n",
    "    prop = {\n",
    "        'helpar_name': helpar,\n",
    "        'sequence': seq\n",
    "    }\n",
    "\n",
    "    dna_timeseries(\n",
    "        input_ser_path=input_file_path,\n",
    "        output_zip_path=output_timeseries_bp_file_paths[helpar],\n",
    "        properties=prop)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3ed15ea3",
   "metadata": {},
   "outputs": [],
   "source": [
    "for timeseries_zipfile in output_timeseries_bp_file_paths.values():\n",
    "    with zipfile.ZipFile(timeseries_zipfile, 'r') as zip_ref:\n",
    "        zip_ref.extractall(timeseries_dir)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "55c22a3a",
   "metadata": {},
   "source": [
    "<a id=\"stiffness\"></a>\n",
    "## Stiffness\n",
    "\n",
    "**Molecular stiffness** is an **elastic force constant** associated with **helical deformation** at the **base pair step** level and is determined by inversion of the covariance matrix in helical space, which yields **stiffness matrices** whose diagonal elements provide the **stiffness constants** associated with **pure rotational** (twist, roll and tilt) and **translational** (rise, shift and slide) **deformations** within the given step.\n",
    "\n",
    "***\n",
    "<img src=\"https://mmb.irbbarcelona.org/NAFlex2/images/StiffnessMatrix.png\" alt=\"Stiffness Matrix\"\n",
    "\ttitle=\"Stiffness Matrix\" width=\"500\" />\n",
    "***\n",
    "**Building Blocks** used:\n",
    "- [averagestiffness](https://biobb-dna.readthedocs.io/en/latest/stiffness.html#module-stiffness.average_stiffness) from **biobb_dna.stiffness.average_stiffness** \n",
    "- [bpstiffness](https://biobb-dna.readthedocs.io/en/latest/stiffness.html#module-stiffness.basepair_stiffness) from **biobb_dna.stiffness.basepair_stiffness** \n",
    "***\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "acb6fa6d",
   "metadata": {},
   "outputs": [],
   "source": [
    "from biobb_dna.stiffness.average_stiffness import average_stiffness\n",
    "\n",
    "helpar = \"twist\" # Modify this variable to extract time series values for a different helical parameter\n",
    "\n",
    "input_file_path = \"canal_out/canal_output\" + \"_\" + helpar + \".ser\"\n",
    "output_stiffness_csv_path = helpar + '.stiffness.csv'\n",
    "output_stiffness_jpg_path = helpar + '.stiffness.jpg'\n",
    "\n",
    "prop = { \n",
    "    'sequence' : seq\n",
    "}\n",
    "\n",
    "average_stiffness(\n",
    "    input_ser_path=input_file_path,\n",
    "    output_csv_path=output_stiffness_csv_path,\n",
    "    output_jpg_path=output_stiffness_jpg_path,\n",
    "    properties=prop)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "91c12146",
   "metadata": {},
   "outputs": [],
   "source": [
    "df = pd.read_csv(output_stiffness_csv_path)\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "941426c2",
   "metadata": {},
   "outputs": [],
   "source": [
    "Image(filename=output_stiffness_jpg_path,width = 600)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "51bb9616",
   "metadata": {},
   "outputs": [],
   "source": [
    "from biobb_dna.stiffness.basepair_stiffness import basepair_stiffness\n",
    "\n",
    "timeseries_shift = timeseries_dir+\"/series_shift_\" + timesel.value + \".csv\"\n",
    "timeseries_slide = timeseries_dir+\"/series_slide_\" + timesel.value + \".csv\"\n",
    "timeseries_rise = timeseries_dir+\"/series_rise_\" + timesel.value + \".csv\"\n",
    "timeseries_tilt = timeseries_dir+\"/series_tilt_\" + timesel.value + \".csv\"\n",
    "timeseries_roll = timeseries_dir+\"/series_roll_\" + timesel.value + \".csv\"\n",
    "timeseries_twist = timeseries_dir+\"/series_twist_\" + timesel.value + \".csv\"\n",
    "\n",
    "output_stiffness_bps_csv_path = \"stiffness_bps.csv\"\n",
    "output_stiffness_bps_jpg_path = \"stiffness_bps.jpg\"\n",
    "\n",
    "basepair_stiffness(\n",
    "    input_filename_shift=timeseries_shift,\n",
    "    input_filename_slide=timeseries_slide,\n",
    "    input_filename_rise=timeseries_rise,\n",
    "    input_filename_tilt=timeseries_tilt,\n",
    "    input_filename_roll=timeseries_roll,\n",
    "    input_filename_twist=timeseries_twist,\n",
    "    output_csv_path=output_stiffness_bps_csv_path,\n",
    "    output_jpg_path=output_stiffness_bps_jpg_path)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "12395ed2",
   "metadata": {},
   "outputs": [],
   "source": [
    "df = pd.read_csv(output_stiffness_bps_csv_path)\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "98655313",
   "metadata": {},
   "outputs": [],
   "source": [
    "Image(filename=output_stiffness_bps_jpg_path,width = 600)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "04a42832",
   "metadata": {},
   "source": [
    "<a id=\"bimodality\"></a>\n",
    "## Bimodality\n",
    "\n",
    "**Base-pair steps** helical parameters usually follow a normal (Gaussian-like) distribution. However, recent studies observed **bimodal distributions** in some **base-pair steps** for **twist and slide**, highlighting potential caveats on the **harmonic approximation** implicit in **elastic analysis** and mesoscopic models of DNA flexibility.\n",
    "\n",
    "***\n",
    "<img src=\"https://mmb.irbbarcelona.org/BIGNASim/htmlib/help/img/Tut3_GCGA_Twist_plot.png\" alt=\"Twist bimodality\"\n",
    "\ttitle=\"Twist bimodality\" width=\"600\" />\n",
    "***\n",
    "\n",
    "**μABC: a systematic microsecond molecular dynamics study of tetranucleotide sequence effects in B-DNA**\n",
    "*Marco Pasi, John H Maddocks, David Beveridge, Thomas C Bishop, David A Case, Thomas Cheatham 3rd, Pablo D Dans, B Jayaram, Filip Lankas, Charles Laughton, Jonathan Mitchell, Roman Osman, Modesto Orozco, Alberto Pérez, Daiva Petkevičiūtė, Nada Spackova, Jiri Sponer, Krystyna Zakrzewska, Richard Lavery*\n",
    "***Nucleic Acids Research 2014, Volume 42, Issue 19, Pages 12272-12283***<br>\n",
    "https://doi.org/10.1093/nar/gku855\n",
    "\n",
    "**Exploring polymorphisms in B-DNA helical conformations**<br>\n",
    "*Pablo D Dans, Alberto Pérez, Ignacio Faustino, Richard Lavery, Modesto Orozco*<br>\n",
    "***Nucleic Acids Research 2012, Volume 40, Issue 21, Pages 10668-10678***<br>\n",
    "https://doi.org/10.1093/nar/gks884\n",
    "\n",
    "**A systematic molecular dynamics study of nearest-neighbor effects on base pair and base pair step conformations and fluctuations in B-DNA**<br>\n",
    "*Lavery R, Zakrzewska K, Beveridge D, Bishop TC, Case DA, Cheatham T, III, Dixit S, Jayaram B, Lankas F, Laughton C, John H Maddocks, Alexis Michon, Roman Osman, Modesto Orozco, Alberto Perez, Tanya Singh, Nada Spackova, Jiri Sponer*<br>\n",
    "***Nucleic Acids Research 2010, Volume 38, Pages 299–313***<br>\n",
    "https://doi.org/10.1093/nar/gkp834\n",
    "\n",
    "***\n",
    "\n",
    "**Building Block** used:\n",
    "- [helparbimodality](https://biobb-dna.readthedocs.io/en/latest/dna.html#module-dna.dna_bimodality) from **biobb_dna.dna.bimodality** \n",
    "***"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4e1cc3df",
   "metadata": {},
   "outputs": [],
   "source": [
    "from biobb_dna.dna.dna_bimodality import dna_bimodality\n",
    "\n",
    "helpar = \"twist\"\n",
    "input_csv = timeseries_dir+\"/series_\"+helpar+\"_\"+timesel.value+'.csv'\n",
    "#input_csv = \"/Users/hospital/biobb_tutorials/biobb_dna/timeseries\"+\"/series_\"+timesel.value+'.csv' # <-- TO BE REPLACED BY PREVIOUS LINE \n",
    "\n",
    "output_bimodality_csv = helpar+'.bimodality.csv'\n",
    "output_bimodality_jpg = helpar+'.bimodality.jpg'\n",
    "\n",
    "prop = {\n",
    "    'max_iter': 500\n",
    "}\n",
    "dna_bimodality(\n",
    "    input_csv_file=input_csv,\n",
    "    output_csv_path=output_bimodality_csv,\n",
    "    output_jpg_path=output_bimodality_jpg,\n",
    "    properties=prop)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "10af9b6b",
   "metadata": {},
   "outputs": [],
   "source": [
    "file_hist = timeseries_dir + \"/hist_\" + helpar + \"_\" + timesel.value + \".jpg\"\n",
    "file_bi = helpar + \".bimodality.jpg\"\n",
    "\n",
    "images = []\n",
    "\n",
    "images.append(file_hist)\n",
    "images.append(file_bi)\n",
    "\n",
    "f, axarr = plt.subplots(1, 2, figsize=(50, 15))\n",
    "\n",
    "for i, image in enumerate(images):\n",
    "    img = mpimg.imread(image)\n",
    "\n",
    "    axarr[i].imshow(img, aspect='auto')\n",
    "    axarr[i].axis('off')\n",
    "\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3783eff7",
   "metadata": {},
   "source": [
    "<a id=\"correlations\"></a>\n",
    "## Correlations\n",
    "\n",
    "Sequence-dependent **correlation movements** have been identified in DNA conformational analysis at the **base pair** and **base pair-step** level. **Trinucleotides** were found to show moderate to high **correlations** in some **intra base pair helical parameter** (e.g. shear-opening, shear-stretch, stagger-buckle). Similarly, some **tetranucleotides** are showing strong **correlations** in their **inter base pair helical parameters** (e.g. shift-tilt, slide-twist, rise-tilt, shift-slide, and shift-twist in RR steps), with **negative correlations** in the shift-slide and roll-twist cases. **Correlations** are also observed in the combination of **inter- and intra-helical parameters** (e.g. shift-opening, rise-buckle, stagger-tilt). **Correlations** analysis can be also extended to **neighboring steps** (e.g. twist in the central YR step of XYRR tetranucleotides with slide in the adjacent RR step). \n",
    "\n",
    "- [Sequence Correlations: Intra-base pairs](#intrasequencecorrelation)\n",
    "- [Sequence Correlations: Inter-base pair steps](#intersequencecorrelation)\n",
    "- [Helical Parameter Correlations: Intra-base pairs](#intrahelparcorrelation)\n",
    "- [Helical Parameter Correlations: Inter-base pair steps](#interhelparcorrelation)\n",
    "- [Neighboring steps Correlations: Intra-base pairs](#intrabasepaircorrelation)\n",
    "- [Neighboring steps Correlations: Inter-base pair steps](#interbasepaircorrelation)\n",
    "\n",
    "***\n",
    "<img src=\"https://mmb.irbbarcelona.org/NAFlex2/images/rise_correlations.png\" alt=\"Rise correlations\"\n",
    "\ttitle=\"Rise correlations\" width=\"400\" />\n",
    "***\n",
    "\n",
    "**The static and dynamic structural heterogeneities of B-DNA: extending Calladine–Dickerson rules**\n",
    "*Pablo D Dans, Alexandra Balaceanu, Marco Pasi, Alessandro S Patelli, Daiva Petkevičiūtė, Jürgen Walther, Adam Hospital, Genís Bayarri, Richard Lavery, John H Maddocks, Modesto Orozco*\n",
    "***Nucleic Acids Research 2019, Volume 47, Issue 21, Pages 11090-11102***<br>\n",
    "https://doi.org/10.1093/nar/gkz905\n",
    "\n",
    "***\n",
    "\n",
    "**Building Blocks** used:\n",
    "- [intrasequencecorrelation](https://biobb-dna.readthedocs.io/en/latest/intrabp_correlations.html#module-intrabp_correlations.intraseqcorr) from **biobb_dna.intrabp_correlations.intraseqcorr** \n",
    "- [intersequencecorrelation](https://biobb-dna.readthedocs.io/en/latest/interbp_correlations.html#interbp-correlations-interseqcorr-module) from **biobb_dna.interbp_correlations.interseqcorr** \n",
    "- [intrahelparcorrelation](https://biobb-dna.readthedocs.io/en/latest/intrabp_correlations.html#intrabp-correlations-intrahpcorr-module) from **biobb_dna.intrabp_correlations.intrahpcorr** \n",
    "- [interhelparcorrelation](https://biobb-dna.readthedocs.io/en/latest/interbp_correlations.html#interbp-correlations-interhpcorr-module) from **biobb_dna.interbp_correlations.interhpcorr** \n",
    "- [intrabasepaircorrelation](https://biobb-dna.readthedocs.io/en/latest/intrabp_correlations.html#intrabp-correlations-intrabpcorr-module) from **biobb_dna.intrabp_correlations.intrabpcorr** \n",
    "- [interbasepaircorrelation](https://biobb-dna.readthedocs.io/en/latest/interbp_correlations.html#interbp-correlations-interbpcorr-module) from **biobb_dna.interbp_correlations.interbpcorr** \n",
    "\n",
    "***"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "85228ad7",
   "metadata": {},
   "source": [
    "<a id=\"intrasequencecorrelation\"></a>\n",
    "### Sequence Correlations: Intra-base pairs"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d2e0b534",
   "metadata": {},
   "outputs": [],
   "source": [
    "from biobb_dna.intrabp_correlations.intraseqcorr import intraseqcorr\n",
    "\n",
    "input_file_path = \"canal_out/canal_output\" + \"_\" + helpar + \".ser\"\n",
    "output_intrabp_correlation_csv_path = helpar+'.intrabp_correlation.csv'\n",
    "output_intrabp_correlation_jpg_path = helpar+'.intrabp_correlation.jpg'\n",
    "\n",
    "prop={\n",
    "    'sequence' : seq,\n",
    "#    'helpar_name' : 'Rise'\n",
    "}\n",
    "\n",
    "intraseqcorr(\n",
    "    input_ser_path=input_file_path,\n",
    "    output_csv_path=output_intrabp_correlation_csv_path,\n",
    "    output_jpg_path=output_intrabp_correlation_jpg_path,\n",
    "    properties=prop)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c1c9cac8",
   "metadata": {},
   "outputs": [],
   "source": [
    "df = pd.read_csv(output_intrabp_correlation_csv_path)\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "85fe5e93",
   "metadata": {},
   "outputs": [],
   "source": [
    "Image(filename=output_intrabp_correlation_jpg_path,width = 600)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3c4d4cd2",
   "metadata": {},
   "source": [
    "<a id=\"intersequencecorrelation\"></a>\n",
    "### Sequence Correlations: Inter-base pair steps"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "88cfe05c",
   "metadata": {},
   "outputs": [],
   "source": [
    "from biobb_dna.interbp_correlations.interseqcorr import interseqcorr\n",
    "\n",
    "input_file_path = \"canal_out/canal_output\" + \"_\" + helpar + \".ser\"\n",
    "output_interbp_correlation_csv_path = helpar+'.interbp_correlation.csv'\n",
    "output_interbp_correlation_jpg_path = helpar+'.interbp_correlation.jpg'\n",
    "\n",
    "prop={\n",
    "    'sequence' : seq,\n",
    "#    'helpar_name' : 'Rise'\n",
    "}\n",
    "\n",
    "interseqcorr(\n",
    "    input_ser_path=input_file_path,\n",
    "    output_csv_path=output_interbp_correlation_csv_path,\n",
    "    output_jpg_path=output_interbp_correlation_jpg_path,\n",
    "    properties=prop)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4ca31283",
   "metadata": {},
   "outputs": [],
   "source": [
    "df = pd.read_csv(output_interbp_correlation_csv_path)\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3bd2ab34",
   "metadata": {},
   "outputs": [],
   "source": [
    "Image(filename=output_interbp_correlation_jpg_path,width = 600)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "672efce6",
   "metadata": {},
   "source": [
    "<a id=\"intrahelparcorrelation\"></a>\n",
    "### Helical Parameter Correlations: Intra-base pair "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1339ca3d",
   "metadata": {},
   "outputs": [],
   "source": [
    "from biobb_dna.intrabp_correlations.intrahpcorr import intrahpcorr\n",
    "\n",
    "timeseries_shear = timeseries_dir+\"/series_shear_\"+timesel.value[:-1]+\".csv\"\n",
    "timeseries_stretch = timeseries_dir+\"/series_stretch_\"+timesel.value[:-1]+\".csv\"\n",
    "timeseries_stagger = timeseries_dir+\"/series_stagger_\"+timesel.value[:-1]+\".csv\"\n",
    "timeseries_buckle = timeseries_dir+\"/series_buckle_\"+timesel.value[:-1]+\".csv\"\n",
    "timeseries_propel = timeseries_dir+\"/series_propel_\"+timesel.value[:-1]+\".csv\"\n",
    "timeseries_opening = timeseries_dir+\"/series_opening_\"+timesel.value[:-1]+\".csv\"\n",
    "\n",
    "output_helpar_bp_correlation_csv_path = \"helpar_bp_correlation.csv\"\n",
    "output_helpar_bp_correlation_jpg_path = \"helpar_bp_correlation.jpg\"\n",
    "\n",
    "intrahpcorr(\n",
    "    input_filename_shear=timeseries_shear,\n",
    "    input_filename_stretch=timeseries_stretch,\n",
    "    input_filename_stagger=timeseries_stagger,\n",
    "    input_filename_buckle=timeseries_buckle,\n",
    "    input_filename_propel=timeseries_propel,\n",
    "    input_filename_opening=timeseries_opening,\n",
    "    output_csv_path=output_helpar_bp_correlation_csv_path,\n",
    "    output_jpg_path=output_helpar_bp_correlation_jpg_path)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3320d679",
   "metadata": {},
   "outputs": [],
   "source": [
    "df = pd.read_csv(output_helpar_bp_correlation_csv_path)\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8e50eb8f",
   "metadata": {},
   "outputs": [],
   "source": [
    "Image(filename=output_helpar_bp_correlation_jpg_path,width = 600)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4a89bd33",
   "metadata": {},
   "source": [
    "<a id=\"interhelparcorrelation\"></a>\n",
    "### Helical Parameter Correlations: Inter-base pair steps"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "11c7035f",
   "metadata": {},
   "outputs": [],
   "source": [
    "from biobb_dna.interbp_correlations.interhpcorr import interhpcorr\n",
    "\n",
    "timeseries_shift = timeseries_dir+\"/series_shift_\"+timesel.value+\".csv\"\n",
    "timeseries_slide = timeseries_dir+\"/series_slide_\"+timesel.value+\".csv\"\n",
    "timeseries_rise = timeseries_dir+\"/series_rise_\"+timesel.value+\".csv\"\n",
    "timeseries_tilt = timeseries_dir+\"/series_tilt_\"+timesel.value+\".csv\"\n",
    "timeseries_roll = timeseries_dir+\"/series_roll_\"+timesel.value+\".csv\"\n",
    "timeseries_twist = timeseries_dir+\"/series_twist_\"+timesel.value+\".csv\"\n",
    "\n",
    "output_helpar_bps_correlation_csv_path = \"helpar_bps_correlation.csv\"\n",
    "output_helpar_bps_correlation_jpg_path = \"helpar_bps_correlation.jpg\"\n",
    "\n",
    "interhpcorr(\n",
    "    input_filename_shift=timeseries_shift,\n",
    "    input_filename_slide=timeseries_slide,\n",
    "    input_filename_rise=timeseries_rise,\n",
    "    input_filename_tilt=timeseries_tilt,\n",
    "    input_filename_roll=timeseries_roll,\n",
    "    input_filename_twist=timeseries_twist,\n",
    "    output_csv_path=output_helpar_bps_correlation_csv_path,\n",
    "    output_jpg_path=output_helpar_bps_correlation_jpg_path)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9729652d",
   "metadata": {},
   "outputs": [],
   "source": [
    "df = pd.read_csv(output_helpar_bps_correlation_csv_path)\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6ae8e169",
   "metadata": {},
   "outputs": [],
   "source": [
    "Image(filename=output_helpar_bps_correlation_jpg_path,width = 600)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ed5d8377",
   "metadata": {},
   "source": [
    "<a id=\"intrabasepaircorrelation\"></a>\n",
    "### Neighboring steps Correlations: Intra-base pair "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "719b4d76",
   "metadata": {},
   "outputs": [],
   "source": [
    "from biobb_dna.intrabp_correlations.intrabpcorr import intrabpcorr\n",
    "\n",
    "canal_shear = canal_dir+\"/canal_output_shear.ser\"\n",
    "canal_stretch = canal_dir+\"/canal_output_stretch.ser\"\n",
    "canal_stagger = canal_dir+\"/canal_output_stagger.ser\"\n",
    "canal_buckle = canal_dir+\"/canal_output_buckle.ser\"\n",
    "canal_propel = canal_dir+\"/canal_output_propel.ser\"\n",
    "canal_opening = canal_dir+\"/canal_output_opening.ser\"\n",
    "\n",
    "output_bp_correlation_csv_path = \"bp_correlation.csv\"\n",
    "output_bp_correlation_jpg_path = \"bp_correlation.jpg\"\n",
    "\n",
    "prop = {\n",
    "    'sequence' : seq\n",
    "}\n",
    "\n",
    "intrabpcorr(\n",
    "    input_filename_shear=canal_shear,\n",
    "    input_filename_stretch=canal_stretch,\n",
    "    input_filename_stagger=canal_stagger,\n",
    "    input_filename_buckle=canal_buckle,\n",
    "    input_filename_propel=canal_propel,\n",
    "    input_filename_opening=canal_opening,\n",
    "    output_csv_path=output_bp_correlation_csv_path,\n",
    "    output_jpg_path=output_bp_correlation_jpg_path,\n",
    "    properties=prop)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "74759552",
   "metadata": {},
   "outputs": [],
   "source": [
    "df = pd.read_csv(output_bp_correlation_csv_path)\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "62e65d3e",
   "metadata": {},
   "outputs": [],
   "source": [
    "Image(filename=output_bp_correlation_jpg_path,width = 800)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4cd94527",
   "metadata": {},
   "source": [
    "<a id=\"interbasepaircorrelation\"></a>\n",
    "### Neighboring steps Correlations: Inter-base pair steps"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "00a7342c",
   "metadata": {},
   "outputs": [],
   "source": [
    "from biobb_dna.interbp_correlations.interbpcorr import interbpcorr\n",
    "\n",
    "canal_shift = canal_dir+\"/canal_output_shift.ser\"\n",
    "canal_slide = canal_dir+\"/canal_output_slide.ser\"\n",
    "canal_rise = canal_dir+\"/canal_output_rise.ser\"\n",
    "canal_tilt = canal_dir+\"/canal_output_tilt.ser\"\n",
    "canal_roll = canal_dir+\"/canal_output_roll.ser\"\n",
    "canal_twist = canal_dir+\"/canal_output_twist.ser\"\n",
    "\n",
    "output_bps_correlation_csv_path = \"bps_correlation.csv\"\n",
    "output_bps_correlation_jpg_path = \"bps_correlation.jpg\"\n",
    "\n",
    "prop = {\n",
    "    'sequence' : seq\n",
    "}\n",
    "\n",
    "interbpcorr(\n",
    "    input_filename_shift=canal_shift,\n",
    "    input_filename_slide=canal_slide,\n",
    "    input_filename_rise=canal_rise,\n",
    "    input_filename_tilt=canal_tilt,\n",
    "    input_filename_roll=canal_roll,\n",
    "    input_filename_twist=canal_twist,\n",
    "    output_csv_path=output_bps_correlation_csv_path,\n",
    "    output_jpg_path=output_bps_correlation_jpg_path,\n",
    "    properties=prop)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7db5fed3",
   "metadata": {},
   "outputs": [],
   "source": [
    "df = pd.read_csv(output_bps_correlation_csv_path)\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5654dab7",
   "metadata": {},
   "outputs": [],
   "source": [
    "Image(filename=output_bps_correlation_jpg_path,width = 800)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "30305a87",
   "metadata": {},
   "source": [
    "***\n",
    "<a id=\"questions\"></a>\n",
    "\n",
    "## Questions & Comments\n",
    "\n",
    "Questions, issues, suggestions and comments are really welcome!\n",
    "\n",
    "* GitHub issues:\n",
    "    * [https://github.com/bioexcel/biobb](https://github.com/bioexcel/biobb)\n",
    "\n",
    "* BioExcel forum:\n",
    "    * [https://ask.bioexcel.eu/c/BioExcel-Building-Blocks-library](https://ask.bioexcel.eu/c/BioExcel-Building-Blocks-library)\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3.7.12 ('biobb_370')",
   "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.12"
  },
  "vscode": {
   "interpreter": {
    "hash": "69038dd0130c6f11c01ed7ef6249f7ed425247f6d3290b85e32f7bf32f2e5cef"
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
