{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**NOTE** Please follow the instructions in README file before executing the cells in this Jupyter Notebook."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "import os\n",
    "from Bio.PDB.MMCIFParser import MMCIFParser, MMCIF2Dict"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "RFAM_PATH =  # path to the Rfam covariance model\n",
    "DATA_PATH = \"../test/\"\n",
    "os.environ[\"DATA_PATH\"] = DATA_PATH"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "import nucleoseeker.dataset_creator as dataset_creator\n",
    "import nucleoseeker.dataset_download as dataset_download\n",
    "import nucleoseeker.individual_structure_filter as individual_structure_filter\n",
    "import nucleoseeker.columns as columns\n",
    "import nucleoseeker.structure_comparison_filter as structure_comparison_filter\n",
    "import nucleoseeker.metadata_filter as metadata_filter\n",
    "import nucleoseeker.utils as utils"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Understanding the standalone use of each module"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### How to use the `DatasetDownload` module?"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "This module is used to download data from the RCSB PDB database. It uses API calls to fetch the data. This provides a dataframe containing all the structures with their characteristics for the given criteria.\n",
    "\n",
    "`dstart` and `dend` are used to specify the search results that are captured by the tool. If you want to analyse all available RNA data then `dstart=0` and `dend=10000` or `download_all=True` should be used. At later time, when number of RNA structures exceeds 10000, we would update this limit further.\n",
    "\n",
    "The dataframe fetched can be accessed with the `df` attribute of the class.\n",
    "\n",
    "Here is a simple usage example:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "download = dataset_download.DatasetDownload(\n",
    "    structure_determination_methodology = 'experimental',\n",
    "    rcsb_entity_polymer_type = 'RNA',\n",
    "    dstart = 0,\n",
    "    dend = 100,\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**Accessing the dataframe with `df` attribute**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "rawdf = download.df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>rcsb_id</th>\n",
       "      <th>exptl_method</th>\n",
       "      <th>release_date</th>\n",
       "      <th>polymer_entity_instance_count</th>\n",
       "      <th>polymer_entity_count_RNA</th>\n",
       "      <th>resolution</th>\n",
       "      <th>selected_polymer_entity_types</th>\n",
       "      <th>pdbx_keywords</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>124d</td>\n",
       "      <td>SOLUTION NMR</td>\n",
       "      <td>1993</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Nucleic acid (only)</td>\n",
       "      <td>DNA-RNA HYBRID</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>157d</td>\n",
       "      <td>X-RAY DIFFRACTION</td>\n",
       "      <td>1994</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>1.80</td>\n",
       "      <td>Nucleic acid (only)</td>\n",
       "      <td>RNA</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>165d</td>\n",
       "      <td>X-RAY DIFFRACTION</td>\n",
       "      <td>1994</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>1.55</td>\n",
       "      <td>Nucleic acid (only)</td>\n",
       "      <td>DNA-RNA HYBRID</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>176d</td>\n",
       "      <td>SOLUTION NMR</td>\n",
       "      <td>1994</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Other</td>\n",
       "      <td>PEPTIDE NUCLEIC ACID/RNA</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>17ra</td>\n",
       "      <td>SOLUTION NMR</td>\n",
       "      <td>1999</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Nucleic acid (only)</td>\n",
       "      <td>RNA</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>95</th>\n",
       "      <td>1efo</td>\n",
       "      <td>X-RAY DIFFRACTION</td>\n",
       "      <td>2000</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>2.30</td>\n",
       "      <td>Nucleic acid (only)</td>\n",
       "      <td>DNA-RNA HYBRID</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>96</th>\n",
       "      <td>1efs</td>\n",
       "      <td>SOLUTION NMR</td>\n",
       "      <td>2000</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Nucleic acid (only)</td>\n",
       "      <td>DNA-RNA HYBRID</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>97</th>\n",
       "      <td>1efw</td>\n",
       "      <td>X-RAY DIFFRACTION</td>\n",
       "      <td>2000</td>\n",
       "      <td>4</td>\n",
       "      <td>1</td>\n",
       "      <td>3.00</td>\n",
       "      <td>Protein/NA</td>\n",
       "      <td>LIGASE/RNA</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>98</th>\n",
       "      <td>1eg0</td>\n",
       "      <td>ELECTRON MICROSCOPY</td>\n",
       "      <td>2000</td>\n",
       "      <td>15</td>\n",
       "      <td>4</td>\n",
       "      <td>11.50</td>\n",
       "      <td>Protein/NA</td>\n",
       "      <td>RIBOSOME</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>99</th>\n",
       "      <td>1egk</td>\n",
       "      <td>X-RAY DIFFRACTION</td>\n",
       "      <td>2000</td>\n",
       "      <td>4</td>\n",
       "      <td>1</td>\n",
       "      <td>3.10</td>\n",
       "      <td>Nucleic acid (only)</td>\n",
       "      <td>DNA-RNA HYBRID</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>100 rows × 8 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "   rcsb_id         exptl_method release_date  polymer_entity_instance_count  \\\n",
       "0     124d         SOLUTION NMR         1993                              2   \n",
       "1     157d    X-RAY DIFFRACTION         1994                              2   \n",
       "2     165d    X-RAY DIFFRACTION         1994                              2   \n",
       "3     176d         SOLUTION NMR         1994                              2   \n",
       "4     17ra         SOLUTION NMR         1999                              1   \n",
       "..     ...                  ...          ...                            ...   \n",
       "95    1efo    X-RAY DIFFRACTION         2000                              2   \n",
       "96    1efs         SOLUTION NMR         2000                              2   \n",
       "97    1efw    X-RAY DIFFRACTION         2000                              4   \n",
       "98    1eg0  ELECTRON MICROSCOPY         2000                             15   \n",
       "99    1egk    X-RAY DIFFRACTION         2000                              4   \n",
       "\n",
       "    polymer_entity_count_RNA  resolution selected_polymer_entity_types  \\\n",
       "0                          1         NaN           Nucleic acid (only)   \n",
       "1                          1        1.80           Nucleic acid (only)   \n",
       "2                          1        1.55           Nucleic acid (only)   \n",
       "3                          1         NaN                         Other   \n",
       "4                          1         NaN           Nucleic acid (only)   \n",
       "..                       ...         ...                           ...   \n",
       "95                         1        2.30           Nucleic acid (only)   \n",
       "96                         1         NaN           Nucleic acid (only)   \n",
       "97                         1        3.00                    Protein/NA   \n",
       "98                         4       11.50                    Protein/NA   \n",
       "99                         1        3.10           Nucleic acid (only)   \n",
       "\n",
       "               pdbx_keywords  \n",
       "0             DNA-RNA HYBRID  \n",
       "1                        RNA  \n",
       "2             DNA-RNA HYBRID  \n",
       "3   PEPTIDE NUCLEIC ACID/RNA  \n",
       "4                        RNA  \n",
       "..                       ...  \n",
       "95            DNA-RNA HYBRID  \n",
       "96            DNA-RNA HYBRID  \n",
       "97                LIGASE/RNA  \n",
       "98                  RIBOSOME  \n",
       "99            DNA-RNA HYBRID  \n",
       "\n",
       "[100 rows x 8 columns]"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "rawdf"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### How to use the `MetadataFilter` module?"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "This module allows the application of structure level filters like experimental method, resolution and release year on a dataframe. It requires a dataframe to work, you can use the dataframe we obtained in the *previous step* or provide your own dataframe.\n",
    "\n",
    "Make sure that the dataframe you provide has the same columns as given in `COLUMNS` module.\n",
    "\n",
    "The filters of this module can be applied *individually* if you don't want to apply all of them together.\n",
    "\n",
    "Here is a simple example:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "struct_filter = metadata_filter.MetadataFilter(\n",
    "    exptl_method = ['X-RAY DIFFRACTION'],\n",
    "    resolution = 3.6,\n",
    "    year_range = [1995, 2000],\n",
    "    polymer_entity_instance_count=None,\n",
    "    polymer_entity_count_RNA=None,\n",
    "    selected_polymer_entity_types=None,\n",
    "    pdbx_keywords=None\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**Applying a single filter**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "single_filter_df = struct_filter.apply_resolution_filter(rawdf)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>rcsb_id</th>\n",
       "      <th>exptl_method</th>\n",
       "      <th>release_date</th>\n",
       "      <th>polymer_entity_instance_count</th>\n",
       "      <th>polymer_entity_count_RNA</th>\n",
       "      <th>resolution</th>\n",
       "      <th>selected_polymer_entity_types</th>\n",
       "      <th>pdbx_keywords</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>157d</td>\n",
       "      <td>X-RAY DIFFRACTION</td>\n",
       "      <td>1994</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>1.80</td>\n",
       "      <td>Nucleic acid (only)</td>\n",
       "      <td>RNA</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>165d</td>\n",
       "      <td>X-RAY DIFFRACTION</td>\n",
       "      <td>1994</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>1.55</td>\n",
       "      <td>Nucleic acid (only)</td>\n",
       "      <td>DNA-RNA HYBRID</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1a34</td>\n",
       "      <td>X-RAY DIFFRACTION</td>\n",
       "      <td>1998</td>\n",
       "      <td>3</td>\n",
       "      <td>2</td>\n",
       "      <td>1.81</td>\n",
       "      <td>Protein/NA</td>\n",
       "      <td>Virus/RNA</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1a9n</td>\n",
       "      <td>X-RAY DIFFRACTION</td>\n",
       "      <td>1998</td>\n",
       "      <td>6</td>\n",
       "      <td>1</td>\n",
       "      <td>2.38</td>\n",
       "      <td>Protein/NA</td>\n",
       "      <td>RNA BINDING PROTEIN/RNA</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1aq3</td>\n",
       "      <td>X-RAY DIFFRACTION</td>\n",
       "      <td>1997</td>\n",
       "      <td>5</td>\n",
       "      <td>1</td>\n",
       "      <td>2.80</td>\n",
       "      <td>Protein/NA</td>\n",
       "      <td>Virus/RNA</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>1aq4</td>\n",
       "      <td>X-RAY DIFFRACTION</td>\n",
       "      <td>1997</td>\n",
       "      <td>5</td>\n",
       "      <td>1</td>\n",
       "      <td>3.00</td>\n",
       "      <td>Protein/NA</td>\n",
       "      <td>Virus/RNA</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>1asy</td>\n",
       "      <td>X-RAY DIFFRACTION</td>\n",
       "      <td>1995</td>\n",
       "      <td>4</td>\n",
       "      <td>1</td>\n",
       "      <td>2.90</td>\n",
       "      <td>Protein/NA</td>\n",
       "      <td>COMPLEX (AMINOACYL-TRNA SYNTHASE/TRNA)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>1asz</td>\n",
       "      <td>X-RAY DIFFRACTION</td>\n",
       "      <td>1995</td>\n",
       "      <td>4</td>\n",
       "      <td>1</td>\n",
       "      <td>3.00</td>\n",
       "      <td>Protein/NA</td>\n",
       "      <td>COMPLEX (AMINOACYL-TRNA SYNTHASE/TRNA)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>1av6</td>\n",
       "      <td>X-RAY DIFFRACTION</td>\n",
       "      <td>1998</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>2.80</td>\n",
       "      <td>Protein/NA</td>\n",
       "      <td>TRANSFERASE/RNA</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>1b23</td>\n",
       "      <td>X-RAY DIFFRACTION</td>\n",
       "      <td>1998</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>2.60</td>\n",
       "      <td>Protein/NA</td>\n",
       "      <td>GENE REGULATION/RNA</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>1b2m</td>\n",
       "      <td>X-RAY DIFFRACTION</td>\n",
       "      <td>1999</td>\n",
       "      <td>5</td>\n",
       "      <td>1</td>\n",
       "      <td>2.00</td>\n",
       "      <td>Protein/NA</td>\n",
       "      <td>HYDROLASE/RNA</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>1b7f</td>\n",
       "      <td>X-RAY DIFFRACTION</td>\n",
       "      <td>1999</td>\n",
       "      <td>4</td>\n",
       "      <td>1</td>\n",
       "      <td>2.60</td>\n",
       "      <td>Protein/NA</td>\n",
       "      <td>RNA-BINDING PROTEIN/RNA</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>1bmv</td>\n",
       "      <td>X-RAY DIFFRACTION</td>\n",
       "      <td>1989</td>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "      <td>3.00</td>\n",
       "      <td>Protein/NA</td>\n",
       "      <td>Virus/RNA</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>1br3</td>\n",
       "      <td>X-RAY DIFFRACTION</td>\n",
       "      <td>1999</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>3.00</td>\n",
       "      <td>Nucleic acid (only)</td>\n",
       "      <td>DNA-RNA HYBRID</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>1c0a</td>\n",
       "      <td>X-RAY DIFFRACTION</td>\n",
       "      <td>1999</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>2.40</td>\n",
       "      <td>Protein/NA</td>\n",
       "      <td>LIGASE/RNA</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>1c9s</td>\n",
       "      <td>X-RAY DIFFRACTION</td>\n",
       "      <td>1999</td>\n",
       "      <td>23</td>\n",
       "      <td>1</td>\n",
       "      <td>1.90</td>\n",
       "      <td>Protein/NA</td>\n",
       "      <td>RNA BINDING PROTEIN/RNA</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>1cgm</td>\n",
       "      <td>FIBER DIFFRACTION</td>\n",
       "      <td>1994</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>3.40</td>\n",
       "      <td>Protein/NA</td>\n",
       "      <td>VIRUS</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>1csl</td>\n",
       "      <td>X-RAY DIFFRACTION</td>\n",
       "      <td>2000</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>1.60</td>\n",
       "      <td>Nucleic acid (only)</td>\n",
       "      <td>RNA</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>1cvj</td>\n",
       "      <td>X-RAY DIFFRACTION</td>\n",
       "      <td>1999</td>\n",
       "      <td>16</td>\n",
       "      <td>1</td>\n",
       "      <td>2.60</td>\n",
       "      <td>Protein/NA</td>\n",
       "      <td>GENE REGULATION/RNA</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>1cwp</td>\n",
       "      <td>X-RAY DIFFRACTION</td>\n",
       "      <td>1995</td>\n",
       "      <td>6</td>\n",
       "      <td>2</td>\n",
       "      <td>3.20</td>\n",
       "      <td>Protein/NA</td>\n",
       "      <td>Virus/RNA</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>1d4r</td>\n",
       "      <td>X-RAY DIFFRACTION</td>\n",
       "      <td>1999</td>\n",
       "      <td>3</td>\n",
       "      <td>2</td>\n",
       "      <td>2.00</td>\n",
       "      <td>Nucleic acid (only)</td>\n",
       "      <td>RNA</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>1ddl</td>\n",
       "      <td>X-RAY DIFFRACTION</td>\n",
       "      <td>2000</td>\n",
       "      <td>5</td>\n",
       "      <td>2</td>\n",
       "      <td>2.70</td>\n",
       "      <td>Protein/NA</td>\n",
       "      <td>Virus/RNA</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>1ddy</td>\n",
       "      <td>X-RAY DIFFRACTION</td>\n",
       "      <td>2000</td>\n",
       "      <td>4</td>\n",
       "      <td>1</td>\n",
       "      <td>3.00</td>\n",
       "      <td>Nucleic acid (only)</td>\n",
       "      <td>RNA</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>1dfu</td>\n",
       "      <td>X-RAY DIFFRACTION</td>\n",
       "      <td>1999</td>\n",
       "      <td>3</td>\n",
       "      <td>2</td>\n",
       "      <td>1.80</td>\n",
       "      <td>Protein/NA</td>\n",
       "      <td>RIBOSOME</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>1di2</td>\n",
       "      <td>X-RAY DIFFRACTION</td>\n",
       "      <td>1999</td>\n",
       "      <td>6</td>\n",
       "      <td>1</td>\n",
       "      <td>1.90</td>\n",
       "      <td>Protein/NA</td>\n",
       "      <td>RNA BINDING PROTEIN/RNA</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>1dk1</td>\n",
       "      <td>X-RAY DIFFRACTION</td>\n",
       "      <td>2000</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>2.80</td>\n",
       "      <td>Protein/NA</td>\n",
       "      <td>RIBOSOME</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>1dqf</td>\n",
       "      <td>X-RAY DIFFRACTION</td>\n",
       "      <td>2000</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>2.20</td>\n",
       "      <td>Nucleic acid (only)</td>\n",
       "      <td>RNA</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>1dqh</td>\n",
       "      <td>X-RAY DIFFRACTION</td>\n",
       "      <td>2000</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>1.70</td>\n",
       "      <td>Nucleic acid (only)</td>\n",
       "      <td>RNA</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>1drz</td>\n",
       "      <td>X-RAY DIFFRACTION</td>\n",
       "      <td>1999</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>2.30</td>\n",
       "      <td>Protein/NA</td>\n",
       "      <td>RNA BINDING PROTEIN/RNA</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>1duh</td>\n",
       "      <td>X-RAY DIFFRACTION</td>\n",
       "      <td>2000</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>2.70</td>\n",
       "      <td>Nucleic acid (only)</td>\n",
       "      <td>RNA</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>30</th>\n",
       "      <td>1dul</td>\n",
       "      <td>X-RAY DIFFRACTION</td>\n",
       "      <td>2000</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>1.80</td>\n",
       "      <td>Protein/NA</td>\n",
       "      <td>SIGNALING PROTEIN/RNA</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31</th>\n",
       "      <td>1duq</td>\n",
       "      <td>X-RAY DIFFRACTION</td>\n",
       "      <td>2000</td>\n",
       "      <td>8</td>\n",
       "      <td>2</td>\n",
       "      <td>2.10</td>\n",
       "      <td>Nucleic acid (only)</td>\n",
       "      <td>RNA</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>32</th>\n",
       "      <td>1e7k</td>\n",
       "      <td>X-RAY DIFFRACTION</td>\n",
       "      <td>2001</td>\n",
       "      <td>4</td>\n",
       "      <td>1</td>\n",
       "      <td>2.90</td>\n",
       "      <td>Protein/NA</td>\n",
       "      <td>RNA BINDING PROTEIN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>33</th>\n",
       "      <td>1e8o</td>\n",
       "      <td>X-RAY DIFFRACTION</td>\n",
       "      <td>2000</td>\n",
       "      <td>5</td>\n",
       "      <td>1</td>\n",
       "      <td>3.20</td>\n",
       "      <td>Protein/NA</td>\n",
       "      <td>ALU RIBONUCLEOPROTEIN PARTICLE</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>34</th>\n",
       "      <td>1ec6</td>\n",
       "      <td>X-RAY DIFFRACTION</td>\n",
       "      <td>2000</td>\n",
       "      <td>4</td>\n",
       "      <td>1</td>\n",
       "      <td>2.40</td>\n",
       "      <td>Protein/NA</td>\n",
       "      <td>RNA BINDING PROTEIN/RNA</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>35</th>\n",
       "      <td>1efo</td>\n",
       "      <td>X-RAY DIFFRACTION</td>\n",
       "      <td>2000</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>2.30</td>\n",
       "      <td>Nucleic acid (only)</td>\n",
       "      <td>DNA-RNA HYBRID</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>36</th>\n",
       "      <td>1efw</td>\n",
       "      <td>X-RAY DIFFRACTION</td>\n",
       "      <td>2000</td>\n",
       "      <td>4</td>\n",
       "      <td>1</td>\n",
       "      <td>3.00</td>\n",
       "      <td>Protein/NA</td>\n",
       "      <td>LIGASE/RNA</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>37</th>\n",
       "      <td>1egk</td>\n",
       "      <td>X-RAY DIFFRACTION</td>\n",
       "      <td>2000</td>\n",
       "      <td>4</td>\n",
       "      <td>1</td>\n",
       "      <td>3.10</td>\n",
       "      <td>Nucleic acid (only)</td>\n",
       "      <td>DNA-RNA HYBRID</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   rcsb_id       exptl_method release_date  polymer_entity_instance_count  \\\n",
       "0     157d  X-RAY DIFFRACTION         1994                              2   \n",
       "1     165d  X-RAY DIFFRACTION         1994                              2   \n",
       "2     1a34  X-RAY DIFFRACTION         1998                              3   \n",
       "3     1a9n  X-RAY DIFFRACTION         1998                              6   \n",
       "4     1aq3  X-RAY DIFFRACTION         1997                              5   \n",
       "5     1aq4  X-RAY DIFFRACTION         1997                              5   \n",
       "6     1asy  X-RAY DIFFRACTION         1995                              4   \n",
       "7     1asz  X-RAY DIFFRACTION         1995                              4   \n",
       "8     1av6  X-RAY DIFFRACTION         1998                              2   \n",
       "9     1b23  X-RAY DIFFRACTION         1998                              2   \n",
       "10    1b2m  X-RAY DIFFRACTION         1999                              5   \n",
       "11    1b7f  X-RAY DIFFRACTION         1999                              4   \n",
       "12    1bmv  X-RAY DIFFRACTION         1989                              3   \n",
       "13    1br3  X-RAY DIFFRACTION         1999                              2   \n",
       "14    1c0a  X-RAY DIFFRACTION         1999                              2   \n",
       "15    1c9s  X-RAY DIFFRACTION         1999                             23   \n",
       "16    1cgm  FIBER DIFFRACTION         1994                              2   \n",
       "17    1csl  X-RAY DIFFRACTION         2000                              2   \n",
       "18    1cvj  X-RAY DIFFRACTION         1999                             16   \n",
       "19    1cwp  X-RAY DIFFRACTION         1995                              6   \n",
       "20    1d4r  X-RAY DIFFRACTION         1999                              3   \n",
       "21    1ddl  X-RAY DIFFRACTION         2000                              5   \n",
       "22    1ddy  X-RAY DIFFRACTION         2000                              4   \n",
       "23    1dfu  X-RAY DIFFRACTION         1999                              3   \n",
       "24    1di2  X-RAY DIFFRACTION         1999                              6   \n",
       "25    1dk1  X-RAY DIFFRACTION         2000                              2   \n",
       "26    1dqf  X-RAY DIFFRACTION         2000                              2   \n",
       "27    1dqh  X-RAY DIFFRACTION         2000                              2   \n",
       "28    1drz  X-RAY DIFFRACTION         1999                              2   \n",
       "29    1duh  X-RAY DIFFRACTION         2000                              1   \n",
       "30    1dul  X-RAY DIFFRACTION         2000                              2   \n",
       "31    1duq  X-RAY DIFFRACTION         2000                              8   \n",
       "32    1e7k  X-RAY DIFFRACTION         2001                              4   \n",
       "33    1e8o  X-RAY DIFFRACTION         2000                              5   \n",
       "34    1ec6  X-RAY DIFFRACTION         2000                              4   \n",
       "35    1efo  X-RAY DIFFRACTION         2000                              2   \n",
       "36    1efw  X-RAY DIFFRACTION         2000                              4   \n",
       "37    1egk  X-RAY DIFFRACTION         2000                              4   \n",
       "\n",
       "    polymer_entity_count_RNA  resolution selected_polymer_entity_types  \\\n",
       "0                          1        1.80           Nucleic acid (only)   \n",
       "1                          1        1.55           Nucleic acid (only)   \n",
       "2                          2        1.81                    Protein/NA   \n",
       "3                          1        2.38                    Protein/NA   \n",
       "4                          1        2.80                    Protein/NA   \n",
       "5                          1        3.00                    Protein/NA   \n",
       "6                          1        2.90                    Protein/NA   \n",
       "7                          1        3.00                    Protein/NA   \n",
       "8                          1        2.80                    Protein/NA   \n",
       "9                          1        2.60                    Protein/NA   \n",
       "10                         1        2.00                    Protein/NA   \n",
       "11                         1        2.60                    Protein/NA   \n",
       "12                         1        3.00                    Protein/NA   \n",
       "13                         1        3.00           Nucleic acid (only)   \n",
       "14                         1        2.40                    Protein/NA   \n",
       "15                         1        1.90                    Protein/NA   \n",
       "16                         1        3.40                    Protein/NA   \n",
       "17                         2        1.60           Nucleic acid (only)   \n",
       "18                         1        2.60                    Protein/NA   \n",
       "19                         2        3.20                    Protein/NA   \n",
       "20                         2        2.00           Nucleic acid (only)   \n",
       "21                         2        2.70                    Protein/NA   \n",
       "22                         1        3.00           Nucleic acid (only)   \n",
       "23                         2        1.80                    Protein/NA   \n",
       "24                         1        1.90                    Protein/NA   \n",
       "25                         1        2.80                    Protein/NA   \n",
       "26                         2        2.20           Nucleic acid (only)   \n",
       "27                         2        1.70           Nucleic acid (only)   \n",
       "28                         1        2.30                    Protein/NA   \n",
       "29                         1        2.70           Nucleic acid (only)   \n",
       "30                         1        1.80                    Protein/NA   \n",
       "31                         2        2.10           Nucleic acid (only)   \n",
       "32                         1        2.90                    Protein/NA   \n",
       "33                         1        3.20                    Protein/NA   \n",
       "34                         1        2.40                    Protein/NA   \n",
       "35                         1        2.30           Nucleic acid (only)   \n",
       "36                         1        3.00                    Protein/NA   \n",
       "37                         1        3.10           Nucleic acid (only)   \n",
       "\n",
       "                             pdbx_keywords  \n",
       "0                                      RNA  \n",
       "1                           DNA-RNA HYBRID  \n",
       "2                                Virus/RNA  \n",
       "3                  RNA BINDING PROTEIN/RNA  \n",
       "4                                Virus/RNA  \n",
       "5                                Virus/RNA  \n",
       "6   COMPLEX (AMINOACYL-TRNA SYNTHASE/TRNA)  \n",
       "7   COMPLEX (AMINOACYL-TRNA SYNTHASE/TRNA)  \n",
       "8                          TRANSFERASE/RNA  \n",
       "9                      GENE REGULATION/RNA  \n",
       "10                           HYDROLASE/RNA  \n",
       "11                 RNA-BINDING PROTEIN/RNA  \n",
       "12                               Virus/RNA  \n",
       "13                          DNA-RNA HYBRID  \n",
       "14                              LIGASE/RNA  \n",
       "15                 RNA BINDING PROTEIN/RNA  \n",
       "16                                   VIRUS  \n",
       "17                                     RNA  \n",
       "18                     GENE REGULATION/RNA  \n",
       "19                               Virus/RNA  \n",
       "20                                     RNA  \n",
       "21                               Virus/RNA  \n",
       "22                                     RNA  \n",
       "23                                RIBOSOME  \n",
       "24                 RNA BINDING PROTEIN/RNA  \n",
       "25                                RIBOSOME  \n",
       "26                                     RNA  \n",
       "27                                     RNA  \n",
       "28                 RNA BINDING PROTEIN/RNA  \n",
       "29                                     RNA  \n",
       "30                   SIGNALING PROTEIN/RNA  \n",
       "31                                     RNA  \n",
       "32                     RNA BINDING PROTEIN  \n",
       "33          ALU RIBONUCLEOPROTEIN PARTICLE  \n",
       "34                 RNA BINDING PROTEIN/RNA  \n",
       "35                          DNA-RNA HYBRID  \n",
       "36                              LIGASE/RNA  \n",
       "37                          DNA-RNA HYBRID  "
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "single_filter_df"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**Apply all filters together**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "struct_filter_df = struct_filter.apply_filters(rawdf)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>rcsb_id</th>\n",
       "      <th>exptl_method</th>\n",
       "      <th>release_date</th>\n",
       "      <th>polymer_entity_instance_count</th>\n",
       "      <th>polymer_entity_count_RNA</th>\n",
       "      <th>resolution</th>\n",
       "      <th>selected_polymer_entity_types</th>\n",
       "      <th>pdbx_keywords</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1asy</td>\n",
       "      <td>X-RAY DIFFRACTION</td>\n",
       "      <td>1995</td>\n",
       "      <td>4</td>\n",
       "      <td>1</td>\n",
       "      <td>2.9</td>\n",
       "      <td>Protein/NA</td>\n",
       "      <td>COMPLEX (AMINOACYL-TRNA SYNTHASE/TRNA)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1asz</td>\n",
       "      <td>X-RAY DIFFRACTION</td>\n",
       "      <td>1995</td>\n",
       "      <td>4</td>\n",
       "      <td>1</td>\n",
       "      <td>3.0</td>\n",
       "      <td>Protein/NA</td>\n",
       "      <td>COMPLEX (AMINOACYL-TRNA SYNTHASE/TRNA)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1csl</td>\n",
       "      <td>X-RAY DIFFRACTION</td>\n",
       "      <td>2000</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>1.6</td>\n",
       "      <td>Nucleic acid (only)</td>\n",
       "      <td>RNA</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1cwp</td>\n",
       "      <td>X-RAY DIFFRACTION</td>\n",
       "      <td>1995</td>\n",
       "      <td>6</td>\n",
       "      <td>2</td>\n",
       "      <td>3.2</td>\n",
       "      <td>Protein/NA</td>\n",
       "      <td>Virus/RNA</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1ddl</td>\n",
       "      <td>X-RAY DIFFRACTION</td>\n",
       "      <td>2000</td>\n",
       "      <td>5</td>\n",
       "      <td>2</td>\n",
       "      <td>2.7</td>\n",
       "      <td>Protein/NA</td>\n",
       "      <td>Virus/RNA</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>1ddy</td>\n",
       "      <td>X-RAY DIFFRACTION</td>\n",
       "      <td>2000</td>\n",
       "      <td>4</td>\n",
       "      <td>1</td>\n",
       "      <td>3.0</td>\n",
       "      <td>Nucleic acid (only)</td>\n",
       "      <td>RNA</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>1dk1</td>\n",
       "      <td>X-RAY DIFFRACTION</td>\n",
       "      <td>2000</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>2.8</td>\n",
       "      <td>Protein/NA</td>\n",
       "      <td>RIBOSOME</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>1dqf</td>\n",
       "      <td>X-RAY DIFFRACTION</td>\n",
       "      <td>2000</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>2.2</td>\n",
       "      <td>Nucleic acid (only)</td>\n",
       "      <td>RNA</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>1dqh</td>\n",
       "      <td>X-RAY DIFFRACTION</td>\n",
       "      <td>2000</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>1.7</td>\n",
       "      <td>Nucleic acid (only)</td>\n",
       "      <td>RNA</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>1duh</td>\n",
       "      <td>X-RAY DIFFRACTION</td>\n",
       "      <td>2000</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>2.7</td>\n",
       "      <td>Nucleic acid (only)</td>\n",
       "      <td>RNA</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>1dul</td>\n",
       "      <td>X-RAY DIFFRACTION</td>\n",
       "      <td>2000</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>1.8</td>\n",
       "      <td>Protein/NA</td>\n",
       "      <td>SIGNALING PROTEIN/RNA</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>1duq</td>\n",
       "      <td>X-RAY DIFFRACTION</td>\n",
       "      <td>2000</td>\n",
       "      <td>8</td>\n",
       "      <td>2</td>\n",
       "      <td>2.1</td>\n",
       "      <td>Nucleic acid (only)</td>\n",
       "      <td>RNA</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>1e8o</td>\n",
       "      <td>X-RAY DIFFRACTION</td>\n",
       "      <td>2000</td>\n",
       "      <td>5</td>\n",
       "      <td>1</td>\n",
       "      <td>3.2</td>\n",
       "      <td>Protein/NA</td>\n",
       "      <td>ALU RIBONUCLEOPROTEIN PARTICLE</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>1ec6</td>\n",
       "      <td>X-RAY DIFFRACTION</td>\n",
       "      <td>2000</td>\n",
       "      <td>4</td>\n",
       "      <td>1</td>\n",
       "      <td>2.4</td>\n",
       "      <td>Protein/NA</td>\n",
       "      <td>RNA BINDING PROTEIN/RNA</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>1efo</td>\n",
       "      <td>X-RAY DIFFRACTION</td>\n",
       "      <td>2000</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>2.3</td>\n",
       "      <td>Nucleic acid (only)</td>\n",
       "      <td>DNA-RNA HYBRID</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>1efw</td>\n",
       "      <td>X-RAY DIFFRACTION</td>\n",
       "      <td>2000</td>\n",
       "      <td>4</td>\n",
       "      <td>1</td>\n",
       "      <td>3.0</td>\n",
       "      <td>Protein/NA</td>\n",
       "      <td>LIGASE/RNA</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>1egk</td>\n",
       "      <td>X-RAY DIFFRACTION</td>\n",
       "      <td>2000</td>\n",
       "      <td>4</td>\n",
       "      <td>1</td>\n",
       "      <td>3.1</td>\n",
       "      <td>Nucleic acid (only)</td>\n",
       "      <td>DNA-RNA HYBRID</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   rcsb_id       exptl_method  release_date  polymer_entity_instance_count  \\\n",
       "0     1asy  X-RAY DIFFRACTION          1995                              4   \n",
       "1     1asz  X-RAY DIFFRACTION          1995                              4   \n",
       "2     1csl  X-RAY DIFFRACTION          2000                              2   \n",
       "3     1cwp  X-RAY DIFFRACTION          1995                              6   \n",
       "4     1ddl  X-RAY DIFFRACTION          2000                              5   \n",
       "5     1ddy  X-RAY DIFFRACTION          2000                              4   \n",
       "6     1dk1  X-RAY DIFFRACTION          2000                              2   \n",
       "7     1dqf  X-RAY DIFFRACTION          2000                              2   \n",
       "8     1dqh  X-RAY DIFFRACTION          2000                              2   \n",
       "9     1duh  X-RAY DIFFRACTION          2000                              1   \n",
       "10    1dul  X-RAY DIFFRACTION          2000                              2   \n",
       "11    1duq  X-RAY DIFFRACTION          2000                              8   \n",
       "12    1e8o  X-RAY DIFFRACTION          2000                              5   \n",
       "13    1ec6  X-RAY DIFFRACTION          2000                              4   \n",
       "14    1efo  X-RAY DIFFRACTION          2000                              2   \n",
       "15    1efw  X-RAY DIFFRACTION          2000                              4   \n",
       "16    1egk  X-RAY DIFFRACTION          2000                              4   \n",
       "\n",
       "    polymer_entity_count_RNA  resolution selected_polymer_entity_types  \\\n",
       "0                          1         2.9                    Protein/NA   \n",
       "1                          1         3.0                    Protein/NA   \n",
       "2                          2         1.6           Nucleic acid (only)   \n",
       "3                          2         3.2                    Protein/NA   \n",
       "4                          2         2.7                    Protein/NA   \n",
       "5                          1         3.0           Nucleic acid (only)   \n",
       "6                          1         2.8                    Protein/NA   \n",
       "7                          2         2.2           Nucleic acid (only)   \n",
       "8                          2         1.7           Nucleic acid (only)   \n",
       "9                          1         2.7           Nucleic acid (only)   \n",
       "10                         1         1.8                    Protein/NA   \n",
       "11                         2         2.1           Nucleic acid (only)   \n",
       "12                         1         3.2                    Protein/NA   \n",
       "13                         1         2.4                    Protein/NA   \n",
       "14                         1         2.3           Nucleic acid (only)   \n",
       "15                         1         3.0                    Protein/NA   \n",
       "16                         1         3.1           Nucleic acid (only)   \n",
       "\n",
       "                             pdbx_keywords  \n",
       "0   COMPLEX (AMINOACYL-TRNA SYNTHASE/TRNA)  \n",
       "1   COMPLEX (AMINOACYL-TRNA SYNTHASE/TRNA)  \n",
       "2                                      RNA  \n",
       "3                                Virus/RNA  \n",
       "4                                Virus/RNA  \n",
       "5                                      RNA  \n",
       "6                                 RIBOSOME  \n",
       "7                                      RNA  \n",
       "8                                      RNA  \n",
       "9                                      RNA  \n",
       "10                   SIGNALING PROTEIN/RNA  \n",
       "11                                     RNA  \n",
       "12          ALU RIBONUCLEOPROTEIN PARTICLE  \n",
       "13                 RNA BINDING PROTEIN/RNA  \n",
       "14                          DNA-RNA HYBRID  \n",
       "15                              LIGASE/RNA  \n",
       "16                          DNA-RNA HYBRID  "
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "struct_filter_df"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### How to use the `IndividualStructureFilter` module?"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Like all other modules of this tool, this also works as standalone and at the same time allows analysing PDB files which are not related to this tool.\n",
    "\n",
    "Suppose you have a PDB file and you want to see if it satisfies some criteria then this module can be very handy. You only need to specify the PDB ID, and your criteria, this will download the PDB for you (if `auto_download=True`). It returns a list of tuples containing PDB ID, Chain ID, Sequence which satisfy your criteria.\n",
    "\n",
    "Here you can see its usage:"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**You will get a tuple if criteria is satisfied**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "pdb_fil = individual_structure_filter.IndividualStructureFilter(\n",
    "    pdb_id = '1efw',\n",
    "    polymer_type = 'polyribonucleotide',\n",
    "    sequence_length = 10,\n",
    "    auto_download = True, # turn this to True if mmcif file is not available\n",
    "    pdb_parser=MMCIF2Dict\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "data_list = pdb_fil.check_polymer_type()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[('1efw',\n",
       "  'C',\n",
       "  'GGAGCGGUAGUUCAGUCGGUUAGAAUACCUGCCUGUCACGCAGGGGGUCGCGGGUUCGAGUCCCGUCCGUUCC')]"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data_list"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**Empty list will be returned when criteria is not satisfied**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "pdb_fil = individual_structure_filter.IndividualStructureFilter(\n",
    "    pdb_id = '101m',\n",
    "    polymer_type = 'polyribonucleotide',\n",
    "    sequence_length = 10,\n",
    "    auto_download = True, # turn this to True if mmcif file is not available\n",
    "    pdb_parser=MMCIF2Dict\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [],
   "source": [
    "data_list = pdb_fil.check_polymer_type()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[]"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data_list"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### How to use the `StructureComparisonFilter` module?"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "In this module, we combine the `IndividualStructureFilter` module with an alignment software such as `ClustalOmega` or `Emboss` such that it can process multiple PDB files and also filter them on the basis of sequence identity. \n",
    "\n",
    "For this section you need to have `ClustalOmega` installed otherwise it will fail. (See README)\n",
    "\n",
    "You specify the criteria and the threshold of sequence identity. It calculates pairwise sequence identity between each structure and for structures with an identity percentage above the threshold (say `sequence_identity=50.00`) it chooses the one with higher resolution.\n",
    "\n",
    "We recommend (unless you want to experiment) using `ClustalOmega` for your analysis as it is much efficient than `'Emboss`."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**This can be applied on a single PDB file**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [],
   "source": [
    "poly_fil = structure_comparison_filter.StructureComparisonFilter(\n",
    "    polymer_type = 'polyribonucleotide',\n",
    "    sequence_length = 10,\n",
    "    sequence_identity = 50.00,\n",
    "    auto_download = True,\n",
    "    alignment_tool = 'clustal'\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [],
   "source": [
    "single_pdb_data_list = poly_fil.apply_filters_on_pdb_id('1cgm')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[]"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "single_pdb_data_list"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**It also works on a list of PDB files**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [],
   "source": [
    "multiple_pdbs_data_list = poly_fil.apply_filters_on_list(['1ehz', '1aud'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[('1ehz',\n",
       "  'A',\n",
       "  'GCGGAUUUAGCUCAGUUGGGAGAGCGCCAGACUGAAGAUCUGGAGGUCCUGUGUUCGAUCCACAGAAUUCGCACCA'),\n",
       " ('1aud', 'B', 'GGCAGAGUCCUUCGGGACAUUGCACCUGCC')]"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "multiple_pdbs_data_list"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**Finally, if you provide this a dataframe with other filters applied and a data_list (obtained at *previous step*), this will apply the sequence identity criteria on the dataframe and return the final dataframe**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [],
   "source": [
    "data_list = poly_fil.apply_filters_on_list(struct_filter_df['rcsb_id'].to_list())\n",
    "final_df = poly_fil.apply_filter_on_df(struct_filter_df, data_list)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**Here is the final dataframe with all the filters applied**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>rcsb_id</th>\n",
       "      <th>exptl_method</th>\n",
       "      <th>release_date</th>\n",
       "      <th>polymer_entity_instance_count</th>\n",
       "      <th>polymer_entity_count_RNA</th>\n",
       "      <th>resolution</th>\n",
       "      <th>selected_polymer_entity_types</th>\n",
       "      <th>pdbx_keywords</th>\n",
       "      <th>chain_id</th>\n",
       "      <th>sequence</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1csl</td>\n",
       "      <td>X-RAY DIFFRACTION</td>\n",
       "      <td>2000</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>1.6</td>\n",
       "      <td>Nucleic acid (only)</td>\n",
       "      <td>RNA</td>\n",
       "      <td>A</td>\n",
       "      <td>AACGGGCGCAGAA</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>1dqh</td>\n",
       "      <td>X-RAY DIFFRACTION</td>\n",
       "      <td>2000</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>1.7</td>\n",
       "      <td>Nucleic acid (only)</td>\n",
       "      <td>RNA</td>\n",
       "      <td>B</td>\n",
       "      <td>CAGGGUCGGC</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>1dul</td>\n",
       "      <td>X-RAY DIFFRACTION</td>\n",
       "      <td>2000</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>1.8</td>\n",
       "      <td>Protein/NA</td>\n",
       "      <td>SIGNALING PROTEIN/RNA</td>\n",
       "      <td>B</td>\n",
       "      <td>GGCUCUGUUUACCAGGUCAGGUCCGAAAGGAAGCAGCCAAGGCAGAGCC</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>1efo</td>\n",
       "      <td>X-RAY DIFFRACTION</td>\n",
       "      <td>2000</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>2.3</td>\n",
       "      <td>Nucleic acid (only)</td>\n",
       "      <td>DNA-RNA HYBRID</td>\n",
       "      <td>B</td>\n",
       "      <td>GAAGAGAGAG</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   rcsb_id       exptl_method  release_date  polymer_entity_instance_count  \\\n",
       "2     1csl  X-RAY DIFFRACTION          2000                              2   \n",
       "6     1dqh  X-RAY DIFFRACTION          2000                              2   \n",
       "8     1dul  X-RAY DIFFRACTION          2000                              2   \n",
       "12    1efo  X-RAY DIFFRACTION          2000                              2   \n",
       "\n",
       "    polymer_entity_count_RNA  resolution selected_polymer_entity_types  \\\n",
       "2                          2         1.6           Nucleic acid (only)   \n",
       "6                          2         1.7           Nucleic acid (only)   \n",
       "8                          1         1.8                    Protein/NA   \n",
       "12                         1         2.3           Nucleic acid (only)   \n",
       "\n",
       "            pdbx_keywords chain_id  \\\n",
       "2                     RNA        A   \n",
       "6                     RNA        B   \n",
       "8   SIGNALING PROTEIN/RNA        B   \n",
       "12         DNA-RNA HYBRID        B   \n",
       "\n",
       "                                             sequence  \n",
       "2                                       AACGGGCGCAGAA  \n",
       "6                                          CAGGGUCGGC  \n",
       "8   GGCUCUGUUUACCAGGUCAGGUCCGAAAGGAAGCAGCCAAGGCAGAGCC  \n",
       "12                                         GAAGAGAGAG  "
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "final_df"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**NOTE**: In the module `DatasetCreator`, we combine all the filters and search for the families of these structures using `cmscan` from `Infernal`."
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "ml_env",
   "language": "python",
   "name": "ml_env"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
