{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# OBSERVABLES"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "from pygor3 import *\n",
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "modelpath :  /home/olivares/.local/share/igor/models\n",
      "modelpath :  /home/olivares/.local/share/igor/models\n",
      "Parms filename:  /home/olivares/.local/share/igor/models/human/tcr_beta/models/model_parms.txt\n",
      "Marginals filename:  /home/olivares/.local/share/igor/models/human/tcr_beta/models/model_marginals.txt\n",
      "modelpath :  /home/olivares/.local/share/igor/models\n"
     ]
    }
   ],
   "source": [
    "mdl = IgorModel.load_default(\"human\", \"tcr_beta\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "igor_fln_generated_realizations_werr:  delete_me/ttmmpp_output/best_scenarios_counts.csv\n"
     ]
    },
    {
     "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>scenario_rank</th>\n",
       "      <th>scenario_proba_cond_seq</th>\n",
       "      <th>v_choice</th>\n",
       "      <th>j_choice</th>\n",
       "      <th>d_gene</th>\n",
       "      <th>v_3_del</th>\n",
       "      <th>d_5_del</th>\n",
       "      <th>j_5_del</th>\n",
       "      <th>d_3_del</th>\n",
       "      <th>vd_ins</th>\n",
       "      <th>vd_dinucl</th>\n",
       "      <th>dj_ins</th>\n",
       "      <th>dj_dinucl</th>\n",
       "      <th>Mismatches</th>\n",
       "      <th>norm_scenario_proba_cond_seq</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>seq_index</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>998</th>\n",
       "      <td>1</td>\n",
       "      <td>0.783497</td>\n",
       "      <td>77</td>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "      <td>9</td>\n",
       "      <td>6</td>\n",
       "      <td>19</td>\n",
       "      <td>9</td>\n",
       "      <td>4</td>\n",
       "      <td>[1, 1, 2, 3]</td>\n",
       "      <td>7</td>\n",
       "      <td>[2, 2, 2, 2, 0, 2, 0]</td>\n",
       "      <td>[]</td>\n",
       "      <td>0.000801</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>998</th>\n",
       "      <td>2</td>\n",
       "      <td>0.076884</td>\n",
       "      <td>77</td>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "      <td>9</td>\n",
       "      <td>6</td>\n",
       "      <td>19</td>\n",
       "      <td>10</td>\n",
       "      <td>4</td>\n",
       "      <td>[1, 1, 2, 3]</td>\n",
       "      <td>8</td>\n",
       "      <td>[2, 2, 2, 2, 0, 2, 0, 2]</td>\n",
       "      <td>[]</td>\n",
       "      <td>0.000079</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>998</th>\n",
       "      <td>3</td>\n",
       "      <td>0.043634</td>\n",
       "      <td>77</td>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "      <td>9</td>\n",
       "      <td>7</td>\n",
       "      <td>19</td>\n",
       "      <td>9</td>\n",
       "      <td>5</td>\n",
       "      <td>[1, 1, 2, 3, 2]</td>\n",
       "      <td>7</td>\n",
       "      <td>[2, 2, 2, 2, 0, 2, 0]</td>\n",
       "      <td>[]</td>\n",
       "      <td>0.000045</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>998</th>\n",
       "      <td>4</td>\n",
       "      <td>0.023517</td>\n",
       "      <td>77</td>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "      <td>10</td>\n",
       "      <td>6</td>\n",
       "      <td>19</td>\n",
       "      <td>9</td>\n",
       "      <td>5</td>\n",
       "      <td>[1, 1, 1, 2, 3]</td>\n",
       "      <td>7</td>\n",
       "      <td>[2, 2, 2, 2, 0, 2, 0]</td>\n",
       "      <td>[]</td>\n",
       "      <td>0.000024</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>998</th>\n",
       "      <td>5</td>\n",
       "      <td>0.021809</td>\n",
       "      <td>77</td>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "      <td>9</td>\n",
       "      <td>8</td>\n",
       "      <td>19</td>\n",
       "      <td>9</td>\n",
       "      <td>6</td>\n",
       "      <td>[1, 1, 2, 3, 2, 0]</td>\n",
       "      <td>7</td>\n",
       "      <td>[2, 2, 2, 2, 0, 2, 0]</td>\n",
       "      <td>[]</td>\n",
       "      <td>0.000022</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "           scenario_rank  scenario_proba_cond_seq  v_choice  j_choice  d_gene  \\\n",
       "seq_index                                                                       \n",
       "998                    1                 0.783497        77         4       0   \n",
       "998                    2                 0.076884        77         4       0   \n",
       "998                    3                 0.043634        77         4       0   \n",
       "998                    4                 0.023517        77         4       0   \n",
       "998                    5                 0.021809        77         4       0   \n",
       "\n",
       "           v_3_del  d_5_del  j_5_del  d_3_del  vd_ins           vd_dinucl  \\\n",
       "seq_index                                                                   \n",
       "998              9        6       19        9       4        [1, 1, 2, 3]   \n",
       "998              9        6       19       10       4        [1, 1, 2, 3]   \n",
       "998              9        7       19        9       5     [1, 1, 2, 3, 2]   \n",
       "998             10        6       19        9       5     [1, 1, 1, 2, 3]   \n",
       "998              9        8       19        9       6  [1, 1, 2, 3, 2, 0]   \n",
       "\n",
       "           dj_ins                 dj_dinucl Mismatches  \\\n",
       "seq_index                                                \n",
       "998             7     [2, 2, 2, 2, 0, 2, 0]         []   \n",
       "998             8  [2, 2, 2, 2, 0, 2, 0, 2]         []   \n",
       "998             7     [2, 2, 2, 2, 0, 2, 0]         []   \n",
       "998             7     [2, 2, 2, 2, 0, 2, 0]         []   \n",
       "998             7     [2, 2, 2, 2, 0, 2, 0]         []   \n",
       "\n",
       "           norm_scenario_proba_cond_seq  \n",
       "seq_index                                \n",
       "998                            0.000801  \n",
       "998                            0.000079  \n",
       "998                            0.000045  \n",
       "998                            0.000024  \n",
       "998                            0.000022  "
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "fln_scenarios = \"delete_me/ttmmpp_output/best_scenarios_counts.csv\"\n",
    "df_scenarios = mdl.get_dataframe_scenarios(fln_scenarios)\n",
    "df_scenarios.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## CDR3 as an observable"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "def observable_get_CDR3(ps_scenario):\n",
    "    \"\"\"\n",
    "    Return the numbers of amino acids in vd insertions\n",
    "    \"\"\"\n",
    "    try:\n",
    "        v_choice = mdl.realization(ps_scenario, 'v_choice')\n",
    "        j_choice = mdl.realization(ps_scenario, 'j_choice')\n",
    "        d_gene = mdl.realization(ps_scenario, 'd_gene')\n",
    "\n",
    "        v_3_del = mdl.realization(ps_scenario, 'v_3_del')\n",
    "        d_5_del = mdl.realization(ps_scenario, 'd_5_del')\n",
    "        d_3_del = mdl.realization(ps_scenario, 'd_3_del')\n",
    "        j_5_del = mdl.realization(ps_scenario, 'j_5_del')\n",
    "\n",
    "        # vd_ins = mdl.realization(ps_scenario, 'vd_ins')\n",
    "        vd_dinucl = mdl.realization(ps_scenario, 'vd_dinucl')\n",
    "\n",
    "        # dj_ins = mdl.realization(ps_scenario, 'dj_ins')\n",
    "        dj_dinucl = mdl.realization(ps_scenario, 'dj_dinucl')\n",
    "\n",
    "        v_anchor = mdl.V_anchor(v_choice.id)\n",
    "        j_anchor = mdl.J_anchor(j_choice.id)\n",
    "\n",
    "        # TODO: mdl.get_CDR3_seq(ps_scenario)\n",
    "        ##### V_Gene\n",
    "        v_gene_len = len(v_choice.value)\n",
    "        # mdl.get_CDR3_seq(ps_scenario)\n",
    "        v_ini = 0\n",
    "        v_end = v_gene_len\n",
    "        str_v_3_palidrome = \"\"\n",
    "        if v_3_del.value < 0:\n",
    "            str_v_3_palidrome = dna_complementary((v_choice.value[v_3_del.value:])[::-1])\n",
    "        else:\n",
    "            v_end = v_end - v_3_del.value\n",
    "\n",
    "        str_V_segment = v_choice.value[v_ini:v_end] + str_v_3_palidrome\n",
    "\n",
    "        ##### D_gene\n",
    "        d_gene_len = len(d_gene.value)\n",
    "        d_ini = 0\n",
    "        d_end = d_gene_len\n",
    "        str_d_5_palidrome = \"\"\n",
    "        if d_5_del.value < 0:\n",
    "            int_ini = 0\n",
    "            str_d_5_palidrome = dna_complementary((d_gene.value[:-d_5_del.value])[::-1])\n",
    "        else:\n",
    "            d_ini = d_5_del.value\n",
    "\n",
    "        str_d_3_palidrome = \"\"\n",
    "        if d_3_del.value < 0:\n",
    "            str_d_3_palidrome = dna_complementary((d_gene.value[d_3_del.value:])[::-1])\n",
    "        else:\n",
    "            d_end = d_end - d_3_del.value\n",
    "\n",
    "        str_D_segment = str_d_5_palidrome + d_gene.value[d_ini:d_end] + str_d_3_palidrome\n",
    "\n",
    "        ##### J_gene\n",
    "        j_gene_len = len(j_choice.value)\n",
    "        j_ini = 0\n",
    "        j_end = j_gene_len\n",
    "        str_j_5_palindrome = \"\"\n",
    "        if j_5_del.value < 0:\n",
    "            j_ini = 0\n",
    "            str_j_5_palindrome = dna_complementary((j_choice.value[:-j_5_del.value])[::-1])\n",
    "        else:\n",
    "            j_ini = j_5_del.value\n",
    "\n",
    "        str_J_segment = str_j_5_palindrome + j_choice.value[j_ini:j_end]\n",
    "\n",
    "        str_VD_segment = \"\".join(vd_dinucl.value)\n",
    "        str_DJ_segment = \"\".join(dj_dinucl.value[::-1])\n",
    "\n",
    "        if (v_anchor > v_end) or (j_anchor < j_ini):\n",
    "            return np.NaN\n",
    "        else:\n",
    "            str_sequence = str_V_segment[v_anchor:] + str_VD_segment + str_D_segment + str_DJ_segment + str_J_segment[:j_anchor]\n",
    "            # return dna_translate(str_sequence)\n",
    "            if len(str_sequence) % 3 == 0:\n",
    "                return dna_translate(str_sequence)\n",
    "            else:\n",
    "                return 'NoProductive'\n",
    "    except Exception as e:\n",
    "        # print(e) # FIXME: A 0 is returned as Exception\n",
    "        return None # FIXME: what to do in these cases, this will change the normalization.\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### get_observable_from_scenarios_dataframe"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "CPU times: user 8.52 s, sys: 0 ns, total: 8.52 s\n",
      "Wall time: 8.5 s\n"
     ]
    },
    {
     "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>scenario_rank</th>\n",
       "      <th>scenario_proba_cond_seq</th>\n",
       "      <th>v_choice</th>\n",
       "      <th>j_choice</th>\n",
       "      <th>d_gene</th>\n",
       "      <th>v_3_del</th>\n",
       "      <th>d_5_del</th>\n",
       "      <th>j_5_del</th>\n",
       "      <th>d_3_del</th>\n",
       "      <th>vd_ins</th>\n",
       "      <th>vd_dinucl</th>\n",
       "      <th>dj_ins</th>\n",
       "      <th>dj_dinucl</th>\n",
       "      <th>Mismatches</th>\n",
       "      <th>norm_scenario_proba_cond_seq</th>\n",
       "      <th>CDR3</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>seq_index</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>998</th>\n",
       "      <td>1</td>\n",
       "      <td>0.783497</td>\n",
       "      <td>77</td>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "      <td>9</td>\n",
       "      <td>6</td>\n",
       "      <td>19</td>\n",
       "      <td>9</td>\n",
       "      <td>4</td>\n",
       "      <td>[1, 1, 2, 3]</td>\n",
       "      <td>7</td>\n",
       "      <td>[2, 2, 2, 2, 0, 2, 0]</td>\n",
       "      <td>[]</td>\n",
       "      <td>0.000801</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>998</th>\n",
       "      <td>2</td>\n",
       "      <td>0.076884</td>\n",
       "      <td>77</td>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "      <td>9</td>\n",
       "      <td>6</td>\n",
       "      <td>19</td>\n",
       "      <td>10</td>\n",
       "      <td>4</td>\n",
       "      <td>[1, 1, 2, 3]</td>\n",
       "      <td>8</td>\n",
       "      <td>[2, 2, 2, 2, 0, 2, 0, 2]</td>\n",
       "      <td>[]</td>\n",
       "      <td>0.000079</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>998</th>\n",
       "      <td>3</td>\n",
       "      <td>0.043634</td>\n",
       "      <td>77</td>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "      <td>9</td>\n",
       "      <td>7</td>\n",
       "      <td>19</td>\n",
       "      <td>9</td>\n",
       "      <td>5</td>\n",
       "      <td>[1, 1, 2, 3, 2]</td>\n",
       "      <td>7</td>\n",
       "      <td>[2, 2, 2, 2, 0, 2, 0]</td>\n",
       "      <td>[]</td>\n",
       "      <td>0.000045</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>998</th>\n",
       "      <td>4</td>\n",
       "      <td>0.023517</td>\n",
       "      <td>77</td>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "      <td>10</td>\n",
       "      <td>6</td>\n",
       "      <td>19</td>\n",
       "      <td>9</td>\n",
       "      <td>5</td>\n",
       "      <td>[1, 1, 1, 2, 3]</td>\n",
       "      <td>7</td>\n",
       "      <td>[2, 2, 2, 2, 0, 2, 0]</td>\n",
       "      <td>[]</td>\n",
       "      <td>0.000024</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>998</th>\n",
       "      <td>5</td>\n",
       "      <td>0.021809</td>\n",
       "      <td>77</td>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "      <td>9</td>\n",
       "      <td>8</td>\n",
       "      <td>19</td>\n",
       "      <td>9</td>\n",
       "      <td>6</td>\n",
       "      <td>[1, 1, 2, 3, 2, 0]</td>\n",
       "      <td>7</td>\n",
       "      <td>[2, 2, 2, 2, 0, 2, 0]</td>\n",
       "      <td>[]</td>\n",
       "      <td>0.000022</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "           scenario_rank  scenario_proba_cond_seq  v_choice  j_choice  d_gene  \\\n",
       "seq_index                                                                       \n",
       "998                    1                 0.783497        77         4       0   \n",
       "998                    2                 0.076884        77         4       0   \n",
       "998                    3                 0.043634        77         4       0   \n",
       "998                    4                 0.023517        77         4       0   \n",
       "998                    5                 0.021809        77         4       0   \n",
       "\n",
       "           v_3_del  d_5_del  j_5_del  d_3_del  vd_ins           vd_dinucl  \\\n",
       "seq_index                                                                   \n",
       "998              9        6       19        9       4        [1, 1, 2, 3]   \n",
       "998              9        6       19       10       4        [1, 1, 2, 3]   \n",
       "998              9        7       19        9       5     [1, 1, 2, 3, 2]   \n",
       "998             10        6       19        9       5     [1, 1, 1, 2, 3]   \n",
       "998              9        8       19        9       6  [1, 1, 2, 3, 2, 0]   \n",
       "\n",
       "           dj_ins                 dj_dinucl Mismatches  \\\n",
       "seq_index                                                \n",
       "998             7     [2, 2, 2, 2, 0, 2, 0]         []   \n",
       "998             8  [2, 2, 2, 2, 0, 2, 0, 2]         []   \n",
       "998             7     [2, 2, 2, 2, 0, 2, 0]         []   \n",
       "998             7     [2, 2, 2, 2, 0, 2, 0]         []   \n",
       "998             7     [2, 2, 2, 2, 0, 2, 0]         []   \n",
       "\n",
       "           norm_scenario_proba_cond_seq  CDR3  \n",
       "seq_index                                      \n",
       "998                            0.000801  None  \n",
       "998                            0.000079  None  \n",
       "998                            0.000045  None  \n",
       "998                            0.000024  None  \n",
       "998                            0.000022  None  "
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "%%time\n",
    "df_scenarios['CDR3'] = mdl.get_observable_from_df_scenarios(observable_get_CDR3, df_scenarios)\n",
    "df_scenarios.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "seq_index\n",
       "998          NoProductive\n",
       "998          NoProductive\n",
       "998          NoProductive\n",
       "998          NoProductive\n",
       "998          NoProductive\n",
       "              ...        \n",
       "703    CASSQGIAGPRGPTS*LS\n",
       "703          NoProductive\n",
       "703    CASSQGIAGPRGPTS*LS\n",
       "703    CASSQGIAGPRGPTS*LS\n",
       "703    CASSQGIAGPRGPTS*LS\n",
       "Name: CDR3, Length: 10000, dtype: object"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_scenarios['CDR3']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "ename": "KeyError",
     "evalue": "'CDR3'",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mKeyError\u001b[0m                                  Traceback (most recent call last)",
      "\u001b[0;32m<ipython-input-4-219654bdf522>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mda_P\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mmdl\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mget_P_from_scenarios_cols\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdf_scenarios\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0;34m'v_choice'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m'CDR3'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m      2\u001b[0m \u001b[0mda_P\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mmean\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m~/GitHub/statbiophys/pygor3/pygor3/IgorIO.py\u001b[0m in \u001b[0;36mget_P_from_scenarios_cols\u001b[0;34m(self, df_scenarios, colname_list)\u001b[0m\n\u001b[1;32m   4640\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m   4641\u001b[0m     \u001b[0;32mdef\u001b[0m \u001b[0mget_P_from_scenarios_cols\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdf_scenarios\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcolname_list\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 4642\u001b[0;31m         groupby_colname = df_scenarios.groupby(colname_list)['norm_scenario_proba_cond_seq'].apply(\n\u001b[0m\u001b[1;32m   4643\u001b[0m             lambda x: x.sum())\n\u001b[1;32m   4644\u001b[0m         \u001b[0mda\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mgroupby_colname\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mto_xarray\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m~/anaconda3/envs/pygor3-dev/lib/python3.7/site-packages/pandas/core/frame.py\u001b[0m in \u001b[0;36mgroupby\u001b[0;34m(self, by, axis, level, as_index, sort, group_keys, squeeze, observed, dropna)\u001b[0m\n\u001b[1;32m   6722\u001b[0m             \u001b[0msqueeze\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0msqueeze\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m   6723\u001b[0m             \u001b[0mobserved\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mobserved\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 6724\u001b[0;31m             \u001b[0mdropna\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mdropna\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m   6725\u001b[0m         )\n\u001b[1;32m   6726\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m~/anaconda3/envs/pygor3-dev/lib/python3.7/site-packages/pandas/core/groupby/groupby.py\u001b[0m in \u001b[0;36m__init__\u001b[0;34m(self, obj, keys, axis, level, grouper, exclusions, selection, as_index, sort, group_keys, squeeze, observed, mutated, dropna)\u001b[0m\n\u001b[1;32m    566\u001b[0m                 \u001b[0mobserved\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mobserved\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    567\u001b[0m                 \u001b[0mmutated\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mmutated\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 568\u001b[0;31m                 \u001b[0mdropna\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdropna\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    569\u001b[0m             )\n\u001b[1;32m    570\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m~/anaconda3/envs/pygor3-dev/lib/python3.7/site-packages/pandas/core/groupby/grouper.py\u001b[0m in \u001b[0;36mget_grouper\u001b[0;34m(obj, key, axis, level, sort, observed, mutated, validate, dropna)\u001b[0m\n\u001b[1;32m    814\u001b[0m                 \u001b[0min_axis\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mname\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mlevel\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mgpr\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;32mFalse\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mgpr\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    815\u001b[0m             \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 816\u001b[0;31m                 \u001b[0;32mraise\u001b[0m \u001b[0mKeyError\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mgpr\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    817\u001b[0m         \u001b[0;32melif\u001b[0m \u001b[0misinstance\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mgpr\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mGrouper\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mand\u001b[0m \u001b[0mgpr\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mkey\u001b[0m \u001b[0;32mis\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    818\u001b[0m             \u001b[0;31m# Add key to exclusions\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;31mKeyError\u001b[0m: 'CDR3'"
     ]
    }
   ],
   "source": [
    "da_P = mdl.get_P_from_scenarios_cols(df_scenarios, ['v_choice', 'CDR3'])\n",
    "da_P.mean()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div><svg style=\"position: absolute; width: 0; height: 0; overflow: hidden\">\n",
       "<defs>\n",
       "<symbol id=\"icon-database\" viewBox=\"0 0 32 32\">\n",
       "<path d=\"M16 0c-8.837 0-16 2.239-16 5v4c0 2.761 7.163 5 16 5s16-2.239 16-5v-4c0-2.761-7.163-5-16-5z\"></path>\n",
       "<path d=\"M16 17c-8.837 0-16-2.239-16-5v6c0 2.761 7.163 5 16 5s16-2.239 16-5v-6c0 2.761-7.163 5-16 5z\"></path>\n",
       "<path d=\"M16 26c-8.837 0-16-2.239-16-5v6c0 2.761 7.163 5 16 5s16-2.239 16-5v-6c0 2.761-7.163 5-16 5z\"></path>\n",
       "</symbol>\n",
       "<symbol id=\"icon-file-text2\" viewBox=\"0 0 32 32\">\n",
       "<path d=\"M28.681 7.159c-0.694-0.947-1.662-2.053-2.724-3.116s-2.169-2.030-3.116-2.724c-1.612-1.182-2.393-1.319-2.841-1.319h-15.5c-1.378 0-2.5 1.121-2.5 2.5v27c0 1.378 1.122 2.5 2.5 2.5h23c1.378 0 2.5-1.122 2.5-2.5v-19.5c0-0.448-0.137-1.23-1.319-2.841zM24.543 5.457c0.959 0.959 1.712 1.825 2.268 2.543h-4.811v-4.811c0.718 0.556 1.584 1.309 2.543 2.268zM28 29.5c0 0.271-0.229 0.5-0.5 0.5h-23c-0.271 0-0.5-0.229-0.5-0.5v-27c0-0.271 0.229-0.5 0.5-0.5 0 0 15.499-0 15.5 0v7c0 0.552 0.448 1 1 1h7v19.5z\"></path>\n",
       "<path d=\"M23 26h-14c-0.552 0-1-0.448-1-1s0.448-1 1-1h14c0.552 0 1 0.448 1 1s-0.448 1-1 1z\"></path>\n",
       "<path d=\"M23 22h-14c-0.552 0-1-0.448-1-1s0.448-1 1-1h14c0.552 0 1 0.448 1 1s-0.448 1-1 1z\"></path>\n",
       "<path d=\"M23 18h-14c-0.552 0-1-0.448-1-1s0.448-1 1-1h14c0.552 0 1 0.448 1 1s-0.448 1-1 1z\"></path>\n",
       "</symbol>\n",
       "</defs>\n",
       "</svg>\n",
       "<style>/* CSS stylesheet for displaying xarray objects in jupyterlab.\n",
       " *\n",
       " */\n",
       "\n",
       ":root {\n",
       "  --xr-font-color0: var(--jp-content-font-color0, rgba(0, 0, 0, 1));\n",
       "  --xr-font-color2: var(--jp-content-font-color2, rgba(0, 0, 0, 0.54));\n",
       "  --xr-font-color3: var(--jp-content-font-color3, rgba(0, 0, 0, 0.38));\n",
       "  --xr-border-color: var(--jp-border-color2, #e0e0e0);\n",
       "  --xr-disabled-color: var(--jp-layout-color3, #bdbdbd);\n",
       "  --xr-background-color: var(--jp-layout-color0, white);\n",
       "  --xr-background-color-row-even: var(--jp-layout-color1, white);\n",
       "  --xr-background-color-row-odd: var(--jp-layout-color2, #eeeeee);\n",
       "}\n",
       "\n",
       "html[theme=dark],\n",
       "body.vscode-dark {\n",
       "  --xr-font-color0: rgba(255, 255, 255, 1);\n",
       "  --xr-font-color2: rgba(255, 255, 255, 0.54);\n",
       "  --xr-font-color3: rgba(255, 255, 255, 0.38);\n",
       "  --xr-border-color: #1F1F1F;\n",
       "  --xr-disabled-color: #515151;\n",
       "  --xr-background-color: #111111;\n",
       "  --xr-background-color-row-even: #111111;\n",
       "  --xr-background-color-row-odd: #313131;\n",
       "}\n",
       "\n",
       ".xr-wrap {\n",
       "  display: block;\n",
       "  min-width: 300px;\n",
       "  max-width: 700px;\n",
       "}\n",
       "\n",
       ".xr-text-repr-fallback {\n",
       "  /* fallback to plain text repr when CSS is not injected (untrusted notebook) */\n",
       "  display: none;\n",
       "}\n",
       "\n",
       ".xr-header {\n",
       "  padding-top: 6px;\n",
       "  padding-bottom: 6px;\n",
       "  margin-bottom: 4px;\n",
       "  border-bottom: solid 1px var(--xr-border-color);\n",
       "}\n",
       "\n",
       ".xr-header > div,\n",
       ".xr-header > ul {\n",
       "  display: inline;\n",
       "  margin-top: 0;\n",
       "  margin-bottom: 0;\n",
       "}\n",
       "\n",
       ".xr-obj-type,\n",
       ".xr-array-name {\n",
       "  margin-left: 2px;\n",
       "  margin-right: 10px;\n",
       "}\n",
       "\n",
       ".xr-obj-type {\n",
       "  color: var(--xr-font-color2);\n",
       "}\n",
       "\n",
       ".xr-sections {\n",
       "  padding-left: 0 !important;\n",
       "  display: grid;\n",
       "  grid-template-columns: 150px auto auto 1fr 20px 20px;\n",
       "}\n",
       "\n",
       ".xr-section-item {\n",
       "  display: contents;\n",
       "}\n",
       "\n",
       ".xr-section-item input {\n",
       "  display: none;\n",
       "}\n",
       "\n",
       ".xr-section-item input + label {\n",
       "  color: var(--xr-disabled-color);\n",
       "}\n",
       "\n",
       ".xr-section-item input:enabled + label {\n",
       "  cursor: pointer;\n",
       "  color: var(--xr-font-color2);\n",
       "}\n",
       "\n",
       ".xr-section-item input:enabled + label:hover {\n",
       "  color: var(--xr-font-color0);\n",
       "}\n",
       "\n",
       ".xr-section-summary {\n",
       "  grid-column: 1;\n",
       "  color: var(--xr-font-color2);\n",
       "  font-weight: 500;\n",
       "}\n",
       "\n",
       ".xr-section-summary > span {\n",
       "  display: inline-block;\n",
       "  padding-left: 0.5em;\n",
       "}\n",
       "\n",
       ".xr-section-summary-in:disabled + label {\n",
       "  color: var(--xr-font-color2);\n",
       "}\n",
       "\n",
       ".xr-section-summary-in + label:before {\n",
       "  display: inline-block;\n",
       "  content: '►';\n",
       "  font-size: 11px;\n",
       "  width: 15px;\n",
       "  text-align: center;\n",
       "}\n",
       "\n",
       ".xr-section-summary-in:disabled + label:before {\n",
       "  color: var(--xr-disabled-color);\n",
       "}\n",
       "\n",
       ".xr-section-summary-in:checked + label:before {\n",
       "  content: '▼';\n",
       "}\n",
       "\n",
       ".xr-section-summary-in:checked + label > span {\n",
       "  display: none;\n",
       "}\n",
       "\n",
       ".xr-section-summary,\n",
       ".xr-section-inline-details {\n",
       "  padding-top: 4px;\n",
       "  padding-bottom: 4px;\n",
       "}\n",
       "\n",
       ".xr-section-inline-details {\n",
       "  grid-column: 2 / -1;\n",
       "}\n",
       "\n",
       ".xr-section-details {\n",
       "  display: none;\n",
       "  grid-column: 1 / -1;\n",
       "  margin-bottom: 5px;\n",
       "}\n",
       "\n",
       ".xr-section-summary-in:checked ~ .xr-section-details {\n",
       "  display: contents;\n",
       "}\n",
       "\n",
       ".xr-array-wrap {\n",
       "  grid-column: 1 / -1;\n",
       "  display: grid;\n",
       "  grid-template-columns: 20px auto;\n",
       "}\n",
       "\n",
       ".xr-array-wrap > label {\n",
       "  grid-column: 1;\n",
       "  vertical-align: top;\n",
       "}\n",
       "\n",
       ".xr-preview {\n",
       "  color: var(--xr-font-color3);\n",
       "}\n",
       "\n",
       ".xr-array-preview,\n",
       ".xr-array-data {\n",
       "  padding: 0 5px !important;\n",
       "  grid-column: 2;\n",
       "}\n",
       "\n",
       ".xr-array-data,\n",
       ".xr-array-in:checked ~ .xr-array-preview {\n",
       "  display: none;\n",
       "}\n",
       "\n",
       ".xr-array-in:checked ~ .xr-array-data,\n",
       ".xr-array-preview {\n",
       "  display: inline-block;\n",
       "}\n",
       "\n",
       ".xr-dim-list {\n",
       "  display: inline-block !important;\n",
       "  list-style: none;\n",
       "  padding: 0 !important;\n",
       "  margin: 0;\n",
       "}\n",
       "\n",
       ".xr-dim-list li {\n",
       "  display: inline-block;\n",
       "  padding: 0;\n",
       "  margin: 0;\n",
       "}\n",
       "\n",
       ".xr-dim-list:before {\n",
       "  content: '(';\n",
       "}\n",
       "\n",
       ".xr-dim-list:after {\n",
       "  content: ')';\n",
       "}\n",
       "\n",
       ".xr-dim-list li:not(:last-child):after {\n",
       "  content: ',';\n",
       "  padding-right: 5px;\n",
       "}\n",
       "\n",
       ".xr-has-index {\n",
       "  font-weight: bold;\n",
       "}\n",
       "\n",
       ".xr-var-list,\n",
       ".xr-var-item {\n",
       "  display: contents;\n",
       "}\n",
       "\n",
       ".xr-var-item > div,\n",
       ".xr-var-item label,\n",
       ".xr-var-item > .xr-var-name span {\n",
       "  background-color: var(--xr-background-color-row-even);\n",
       "  margin-bottom: 0;\n",
       "}\n",
       "\n",
       ".xr-var-item > .xr-var-name:hover span {\n",
       "  padding-right: 5px;\n",
       "}\n",
       "\n",
       ".xr-var-list > li:nth-child(odd) > div,\n",
       ".xr-var-list > li:nth-child(odd) > label,\n",
       ".xr-var-list > li:nth-child(odd) > .xr-var-name span {\n",
       "  background-color: var(--xr-background-color-row-odd);\n",
       "}\n",
       "\n",
       ".xr-var-name {\n",
       "  grid-column: 1;\n",
       "}\n",
       "\n",
       ".xr-var-dims {\n",
       "  grid-column: 2;\n",
       "}\n",
       "\n",
       ".xr-var-dtype {\n",
       "  grid-column: 3;\n",
       "  text-align: right;\n",
       "  color: var(--xr-font-color2);\n",
       "}\n",
       "\n",
       ".xr-var-preview {\n",
       "  grid-column: 4;\n",
       "}\n",
       "\n",
       ".xr-var-name,\n",
       ".xr-var-dims,\n",
       ".xr-var-dtype,\n",
       ".xr-preview,\n",
       ".xr-attrs dt {\n",
       "  white-space: nowrap;\n",
       "  overflow: hidden;\n",
       "  text-overflow: ellipsis;\n",
       "  padding-right: 10px;\n",
       "}\n",
       "\n",
       ".xr-var-name:hover,\n",
       ".xr-var-dims:hover,\n",
       ".xr-var-dtype:hover,\n",
       ".xr-attrs dt:hover {\n",
       "  overflow: visible;\n",
       "  width: auto;\n",
       "  z-index: 1;\n",
       "}\n",
       "\n",
       ".xr-var-attrs,\n",
       ".xr-var-data {\n",
       "  display: none;\n",
       "  background-color: var(--xr-background-color) !important;\n",
       "  padding-bottom: 5px !important;\n",
       "}\n",
       "\n",
       ".xr-var-attrs-in:checked ~ .xr-var-attrs,\n",
       ".xr-var-data-in:checked ~ .xr-var-data {\n",
       "  display: block;\n",
       "}\n",
       "\n",
       ".xr-var-data > table {\n",
       "  float: right;\n",
       "}\n",
       "\n",
       ".xr-var-name span,\n",
       ".xr-var-data,\n",
       ".xr-attrs {\n",
       "  padding-left: 25px !important;\n",
       "}\n",
       "\n",
       ".xr-attrs,\n",
       ".xr-var-attrs,\n",
       ".xr-var-data {\n",
       "  grid-column: 1 / -1;\n",
       "}\n",
       "\n",
       "dl.xr-attrs {\n",
       "  padding: 0;\n",
       "  margin: 0;\n",
       "  display: grid;\n",
       "  grid-template-columns: 125px auto;\n",
       "}\n",
       "\n",
       ".xr-attrs dt,\n",
       ".xr-attrs dd {\n",
       "  padding: 0;\n",
       "  margin: 0;\n",
       "  float: left;\n",
       "  padding-right: 10px;\n",
       "  width: auto;\n",
       "}\n",
       "\n",
       ".xr-attrs dt {\n",
       "  font-weight: normal;\n",
       "  grid-column: 1;\n",
       "}\n",
       "\n",
       ".xr-attrs dt:hover span {\n",
       "  display: inline-block;\n",
       "  background: var(--xr-background-color);\n",
       "  padding-right: 10px;\n",
       "}\n",
       "\n",
       ".xr-attrs dd {\n",
       "  grid-column: 2;\n",
       "  white-space: pre-wrap;\n",
       "  word-break: break-all;\n",
       "}\n",
       "\n",
       ".xr-icon-database,\n",
       ".xr-icon-file-text2 {\n",
       "  display: inline-block;\n",
       "  vertical-align: middle;\n",
       "  width: 1em;\n",
       "  height: 1.5em !important;\n",
       "  stroke-width: 0;\n",
       "  stroke: currentColor;\n",
       "  fill: currentColor;\n",
       "}\n",
       "</style><pre class='xr-text-repr-fallback'>&lt;xarray.DataArray &#x27;norm_scenario_proba_cond_seq&#x27; ()&gt;\n",
       "array(0.997)</pre><div class='xr-wrap' hidden><div class='xr-header'><div class='xr-obj-type'>xarray.DataArray</div><div class='xr-array-name'>'norm_scenario_proba_cond_seq'</div></div><ul class='xr-sections'><li class='xr-section-item'><div class='xr-array-wrap'><input id='section-bc23db7e-2e03-4121-847e-eea6bb837229' class='xr-array-in' type='checkbox' checked><label for='section-bc23db7e-2e03-4121-847e-eea6bb837229' title='Show/hide data repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-array-preview xr-preview'><span>0.997</span></div><div class='xr-array-data'><pre>array(0.997)</pre></div></div></li><li class='xr-section-item'><input id='section-f2a2df6e-6d9f-4e0b-b4e6-7069f7622bc5' class='xr-section-summary-in' type='checkbox' disabled ><label for='section-f2a2df6e-6d9f-4e0b-b4e6-7069f7622bc5' class='xr-section-summary'  title='Expand/collapse section'>Coordinates: <span>(0)</span></label><div class='xr-section-inline-details'></div><div class='xr-section-details'><ul class='xr-var-list'></ul></div></li><li class='xr-section-item'><input id='section-1027cb42-63bf-474c-a6fd-d4ab64dc4d3b' class='xr-section-summary-in' type='checkbox' disabled ><label for='section-1027cb42-63bf-474c-a6fd-d4ab64dc4d3b' class='xr-section-summary'  title='Expand/collapse section'>Attributes: <span>(0)</span></label><div class='xr-section-inline-details'></div><div class='xr-section-details'><dl class='xr-attrs'></dl></div></li></ul></div></div>"
      ],
      "text/plain": [
       "<xarray.DataArray 'norm_scenario_proba_cond_seq' ()>\n",
       "array(0.997)"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "da_P.sum()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div><svg style=\"position: absolute; width: 0; height: 0; overflow: hidden\">\n",
       "<defs>\n",
       "<symbol id=\"icon-database\" viewBox=\"0 0 32 32\">\n",
       "<path d=\"M16 0c-8.837 0-16 2.239-16 5v4c0 2.761 7.163 5 16 5s16-2.239 16-5v-4c0-2.761-7.163-5-16-5z\"></path>\n",
       "<path d=\"M16 17c-8.837 0-16-2.239-16-5v6c0 2.761 7.163 5 16 5s16-2.239 16-5v-6c0 2.761-7.163 5-16 5z\"></path>\n",
       "<path d=\"M16 26c-8.837 0-16-2.239-16-5v6c0 2.761 7.163 5 16 5s16-2.239 16-5v-6c0 2.761-7.163 5-16 5z\"></path>\n",
       "</symbol>\n",
       "<symbol id=\"icon-file-text2\" viewBox=\"0 0 32 32\">\n",
       "<path d=\"M28.681 7.159c-0.694-0.947-1.662-2.053-2.724-3.116s-2.169-2.030-3.116-2.724c-1.612-1.182-2.393-1.319-2.841-1.319h-15.5c-1.378 0-2.5 1.121-2.5 2.5v27c0 1.378 1.122 2.5 2.5 2.5h23c1.378 0 2.5-1.122 2.5-2.5v-19.5c0-0.448-0.137-1.23-1.319-2.841zM24.543 5.457c0.959 0.959 1.712 1.825 2.268 2.543h-4.811v-4.811c0.718 0.556 1.584 1.309 2.543 2.268zM28 29.5c0 0.271-0.229 0.5-0.5 0.5h-23c-0.271 0-0.5-0.229-0.5-0.5v-27c0-0.271 0.229-0.5 0.5-0.5 0 0 15.499-0 15.5 0v7c0 0.552 0.448 1 1 1h7v19.5z\"></path>\n",
       "<path d=\"M23 26h-14c-0.552 0-1-0.448-1-1s0.448-1 1-1h14c0.552 0 1 0.448 1 1s-0.448 1-1 1z\"></path>\n",
       "<path d=\"M23 22h-14c-0.552 0-1-0.448-1-1s0.448-1 1-1h14c0.552 0 1 0.448 1 1s-0.448 1-1 1z\"></path>\n",
       "<path d=\"M23 18h-14c-0.552 0-1-0.448-1-1s0.448-1 1-1h14c0.552 0 1 0.448 1 1s-0.448 1-1 1z\"></path>\n",
       "</symbol>\n",
       "</defs>\n",
       "</svg>\n",
       "<style>/* CSS stylesheet for displaying xarray objects in jupyterlab.\n",
       " *\n",
       " */\n",
       "\n",
       ":root {\n",
       "  --xr-font-color0: var(--jp-content-font-color0, rgba(0, 0, 0, 1));\n",
       "  --xr-font-color2: var(--jp-content-font-color2, rgba(0, 0, 0, 0.54));\n",
       "  --xr-font-color3: var(--jp-content-font-color3, rgba(0, 0, 0, 0.38));\n",
       "  --xr-border-color: var(--jp-border-color2, #e0e0e0);\n",
       "  --xr-disabled-color: var(--jp-layout-color3, #bdbdbd);\n",
       "  --xr-background-color: var(--jp-layout-color0, white);\n",
       "  --xr-background-color-row-even: var(--jp-layout-color1, white);\n",
       "  --xr-background-color-row-odd: var(--jp-layout-color2, #eeeeee);\n",
       "}\n",
       "\n",
       "html[theme=dark],\n",
       "body.vscode-dark {\n",
       "  --xr-font-color0: rgba(255, 255, 255, 1);\n",
       "  --xr-font-color2: rgba(255, 255, 255, 0.54);\n",
       "  --xr-font-color3: rgba(255, 255, 255, 0.38);\n",
       "  --xr-border-color: #1F1F1F;\n",
       "  --xr-disabled-color: #515151;\n",
       "  --xr-background-color: #111111;\n",
       "  --xr-background-color-row-even: #111111;\n",
       "  --xr-background-color-row-odd: #313131;\n",
       "}\n",
       "\n",
       ".xr-wrap {\n",
       "  display: block;\n",
       "  min-width: 300px;\n",
       "  max-width: 700px;\n",
       "}\n",
       "\n",
       ".xr-text-repr-fallback {\n",
       "  /* fallback to plain text repr when CSS is not injected (untrusted notebook) */\n",
       "  display: none;\n",
       "}\n",
       "\n",
       ".xr-header {\n",
       "  padding-top: 6px;\n",
       "  padding-bottom: 6px;\n",
       "  margin-bottom: 4px;\n",
       "  border-bottom: solid 1px var(--xr-border-color);\n",
       "}\n",
       "\n",
       ".xr-header > div,\n",
       ".xr-header > ul {\n",
       "  display: inline;\n",
       "  margin-top: 0;\n",
       "  margin-bottom: 0;\n",
       "}\n",
       "\n",
       ".xr-obj-type,\n",
       ".xr-array-name {\n",
       "  margin-left: 2px;\n",
       "  margin-right: 10px;\n",
       "}\n",
       "\n",
       ".xr-obj-type {\n",
       "  color: var(--xr-font-color2);\n",
       "}\n",
       "\n",
       ".xr-sections {\n",
       "  padding-left: 0 !important;\n",
       "  display: grid;\n",
       "  grid-template-columns: 150px auto auto 1fr 20px 20px;\n",
       "}\n",
       "\n",
       ".xr-section-item {\n",
       "  display: contents;\n",
       "}\n",
       "\n",
       ".xr-section-item input {\n",
       "  display: none;\n",
       "}\n",
       "\n",
       ".xr-section-item input + label {\n",
       "  color: var(--xr-disabled-color);\n",
       "}\n",
       "\n",
       ".xr-section-item input:enabled + label {\n",
       "  cursor: pointer;\n",
       "  color: var(--xr-font-color2);\n",
       "}\n",
       "\n",
       ".xr-section-item input:enabled + label:hover {\n",
       "  color: var(--xr-font-color0);\n",
       "}\n",
       "\n",
       ".xr-section-summary {\n",
       "  grid-column: 1;\n",
       "  color: var(--xr-font-color2);\n",
       "  font-weight: 500;\n",
       "}\n",
       "\n",
       ".xr-section-summary > span {\n",
       "  display: inline-block;\n",
       "  padding-left: 0.5em;\n",
       "}\n",
       "\n",
       ".xr-section-summary-in:disabled + label {\n",
       "  color: var(--xr-font-color2);\n",
       "}\n",
       "\n",
       ".xr-section-summary-in + label:before {\n",
       "  display: inline-block;\n",
       "  content: '►';\n",
       "  font-size: 11px;\n",
       "  width: 15px;\n",
       "  text-align: center;\n",
       "}\n",
       "\n",
       ".xr-section-summary-in:disabled + label:before {\n",
       "  color: var(--xr-disabled-color);\n",
       "}\n",
       "\n",
       ".xr-section-summary-in:checked + label:before {\n",
       "  content: '▼';\n",
       "}\n",
       "\n",
       ".xr-section-summary-in:checked + label > span {\n",
       "  display: none;\n",
       "}\n",
       "\n",
       ".xr-section-summary,\n",
       ".xr-section-inline-details {\n",
       "  padding-top: 4px;\n",
       "  padding-bottom: 4px;\n",
       "}\n",
       "\n",
       ".xr-section-inline-details {\n",
       "  grid-column: 2 / -1;\n",
       "}\n",
       "\n",
       ".xr-section-details {\n",
       "  display: none;\n",
       "  grid-column: 1 / -1;\n",
       "  margin-bottom: 5px;\n",
       "}\n",
       "\n",
       ".xr-section-summary-in:checked ~ .xr-section-details {\n",
       "  display: contents;\n",
       "}\n",
       "\n",
       ".xr-array-wrap {\n",
       "  grid-column: 1 / -1;\n",
       "  display: grid;\n",
       "  grid-template-columns: 20px auto;\n",
       "}\n",
       "\n",
       ".xr-array-wrap > label {\n",
       "  grid-column: 1;\n",
       "  vertical-align: top;\n",
       "}\n",
       "\n",
       ".xr-preview {\n",
       "  color: var(--xr-font-color3);\n",
       "}\n",
       "\n",
       ".xr-array-preview,\n",
       ".xr-array-data {\n",
       "  padding: 0 5px !important;\n",
       "  grid-column: 2;\n",
       "}\n",
       "\n",
       ".xr-array-data,\n",
       ".xr-array-in:checked ~ .xr-array-preview {\n",
       "  display: none;\n",
       "}\n",
       "\n",
       ".xr-array-in:checked ~ .xr-array-data,\n",
       ".xr-array-preview {\n",
       "  display: inline-block;\n",
       "}\n",
       "\n",
       ".xr-dim-list {\n",
       "  display: inline-block !important;\n",
       "  list-style: none;\n",
       "  padding: 0 !important;\n",
       "  margin: 0;\n",
       "}\n",
       "\n",
       ".xr-dim-list li {\n",
       "  display: inline-block;\n",
       "  padding: 0;\n",
       "  margin: 0;\n",
       "}\n",
       "\n",
       ".xr-dim-list:before {\n",
       "  content: '(';\n",
       "}\n",
       "\n",
       ".xr-dim-list:after {\n",
       "  content: ')';\n",
       "}\n",
       "\n",
       ".xr-dim-list li:not(:last-child):after {\n",
       "  content: ',';\n",
       "  padding-right: 5px;\n",
       "}\n",
       "\n",
       ".xr-has-index {\n",
       "  font-weight: bold;\n",
       "}\n",
       "\n",
       ".xr-var-list,\n",
       ".xr-var-item {\n",
       "  display: contents;\n",
       "}\n",
       "\n",
       ".xr-var-item > div,\n",
       ".xr-var-item label,\n",
       ".xr-var-item > .xr-var-name span {\n",
       "  background-color: var(--xr-background-color-row-even);\n",
       "  margin-bottom: 0;\n",
       "}\n",
       "\n",
       ".xr-var-item > .xr-var-name:hover span {\n",
       "  padding-right: 5px;\n",
       "}\n",
       "\n",
       ".xr-var-list > li:nth-child(odd) > div,\n",
       ".xr-var-list > li:nth-child(odd) > label,\n",
       ".xr-var-list > li:nth-child(odd) > .xr-var-name span {\n",
       "  background-color: var(--xr-background-color-row-odd);\n",
       "}\n",
       "\n",
       ".xr-var-name {\n",
       "  grid-column: 1;\n",
       "}\n",
       "\n",
       ".xr-var-dims {\n",
       "  grid-column: 2;\n",
       "}\n",
       "\n",
       ".xr-var-dtype {\n",
       "  grid-column: 3;\n",
       "  text-align: right;\n",
       "  color: var(--xr-font-color2);\n",
       "}\n",
       "\n",
       ".xr-var-preview {\n",
       "  grid-column: 4;\n",
       "}\n",
       "\n",
       ".xr-var-name,\n",
       ".xr-var-dims,\n",
       ".xr-var-dtype,\n",
       ".xr-preview,\n",
       ".xr-attrs dt {\n",
       "  white-space: nowrap;\n",
       "  overflow: hidden;\n",
       "  text-overflow: ellipsis;\n",
       "  padding-right: 10px;\n",
       "}\n",
       "\n",
       ".xr-var-name:hover,\n",
       ".xr-var-dims:hover,\n",
       ".xr-var-dtype:hover,\n",
       ".xr-attrs dt:hover {\n",
       "  overflow: visible;\n",
       "  width: auto;\n",
       "  z-index: 1;\n",
       "}\n",
       "\n",
       ".xr-var-attrs,\n",
       ".xr-var-data {\n",
       "  display: none;\n",
       "  background-color: var(--xr-background-color) !important;\n",
       "  padding-bottom: 5px !important;\n",
       "}\n",
       "\n",
       ".xr-var-attrs-in:checked ~ .xr-var-attrs,\n",
       ".xr-var-data-in:checked ~ .xr-var-data {\n",
       "  display: block;\n",
       "}\n",
       "\n",
       ".xr-var-data > table {\n",
       "  float: right;\n",
       "}\n",
       "\n",
       ".xr-var-name span,\n",
       ".xr-var-data,\n",
       ".xr-attrs {\n",
       "  padding-left: 25px !important;\n",
       "}\n",
       "\n",
       ".xr-attrs,\n",
       ".xr-var-attrs,\n",
       ".xr-var-data {\n",
       "  grid-column: 1 / -1;\n",
       "}\n",
       "\n",
       "dl.xr-attrs {\n",
       "  padding: 0;\n",
       "  margin: 0;\n",
       "  display: grid;\n",
       "  grid-template-columns: 125px auto;\n",
       "}\n",
       "\n",
       ".xr-attrs dt,\n",
       ".xr-attrs dd {\n",
       "  padding: 0;\n",
       "  margin: 0;\n",
       "  float: left;\n",
       "  padding-right: 10px;\n",
       "  width: auto;\n",
       "}\n",
       "\n",
       ".xr-attrs dt {\n",
       "  font-weight: normal;\n",
       "  grid-column: 1;\n",
       "}\n",
       "\n",
       ".xr-attrs dt:hover span {\n",
       "  display: inline-block;\n",
       "  background: var(--xr-background-color);\n",
       "  padding-right: 10px;\n",
       "}\n",
       "\n",
       ".xr-attrs dd {\n",
       "  grid-column: 2;\n",
       "  white-space: pre-wrap;\n",
       "  word-break: break-all;\n",
       "}\n",
       "\n",
       ".xr-icon-database,\n",
       ".xr-icon-file-text2 {\n",
       "  display: inline-block;\n",
       "  vertical-align: middle;\n",
       "  width: 1em;\n",
       "  height: 1.5em !important;\n",
       "  stroke-width: 0;\n",
       "  stroke: currentColor;\n",
       "  fill: currentColor;\n",
       "}\n",
       "</style><pre class='xr-text-repr-fallback'>&lt;xarray.DataArray &#x27;norm_scenario_proba_cond_seq&#x27; ()&gt;\n",
       "array(0.00071446)\n",
       "Coordinates:\n",
       "    v_choice  int64 40\n",
       "    CDR3      &lt;U11 &#x27;CASRDRGAVFW&#x27;</pre><div class='xr-wrap' hidden><div class='xr-header'><div class='xr-obj-type'>xarray.DataArray</div><div class='xr-array-name'>'norm_scenario_proba_cond_seq'</div></div><ul class='xr-sections'><li class='xr-section-item'><div class='xr-array-wrap'><input id='section-db014616-134a-4803-bd52-2aa419c0bdd8' class='xr-array-in' type='checkbox' checked><label for='section-db014616-134a-4803-bd52-2aa419c0bdd8' title='Show/hide data repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-array-preview xr-preview'><span>0.0007145</span></div><div class='xr-array-data'><pre>array(0.00071446)</pre></div></div></li><li class='xr-section-item'><input id='section-7d81d599-c1b2-4b58-8df3-26b84a0f0815' class='xr-section-summary-in' type='checkbox'  checked><label for='section-7d81d599-c1b2-4b58-8df3-26b84a0f0815' class='xr-section-summary' >Coordinates: <span>(2)</span></label><div class='xr-section-inline-details'></div><div class='xr-section-details'><ul class='xr-var-list'><li class='xr-var-item'><div class='xr-var-name'><span>v_choice</span></div><div class='xr-var-dims'>()</div><div class='xr-var-dtype'>int64</div><div class='xr-var-preview xr-preview'>40</div><input id='attrs-9c596da7-9ad2-472d-9490-ed49ccadd6c6' class='xr-var-attrs-in' type='checkbox' disabled><label for='attrs-9c596da7-9ad2-472d-9490-ed49ccadd6c6' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-40811a08-b3d8-4d22-b614-72e8cce66352' class='xr-var-data-in' type='checkbox'><label for='data-40811a08-b3d8-4d22-b614-72e8cce66352' title='Show/Hide data repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-var-attrs'><dl class='xr-attrs'></dl></div><div class='xr-var-data'><pre>array(40)</pre></div></li><li class='xr-var-item'><div class='xr-var-name'><span>CDR3</span></div><div class='xr-var-dims'>()</div><div class='xr-var-dtype'>&lt;U11</div><div class='xr-var-preview xr-preview'>&#x27;CASRDRGAVFW&#x27;</div><input id='attrs-4cbf570c-3fea-4cc5-9590-8fb2d521c450' class='xr-var-attrs-in' type='checkbox' disabled><label for='attrs-4cbf570c-3fea-4cc5-9590-8fb2d521c450' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-6f8d07d2-583b-413b-89c7-f4fa165149c4' class='xr-var-data-in' type='checkbox'><label for='data-6f8d07d2-583b-413b-89c7-f4fa165149c4' title='Show/Hide data repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-var-attrs'><dl class='xr-attrs'></dl></div><div class='xr-var-data'><pre>array(&#x27;CASRDRGAVFW&#x27;, dtype=&#x27;&lt;U11&#x27;)</pre></div></li></ul></div></li><li class='xr-section-item'><input id='section-79a7b325-764f-407b-b566-c81334187a28' class='xr-section-summary-in' type='checkbox' disabled ><label for='section-79a7b325-764f-407b-b566-c81334187a28' class='xr-section-summary'  title='Expand/collapse section'>Attributes: <span>(0)</span></label><div class='xr-section-inline-details'></div><div class='xr-section-details'><dl class='xr-attrs'></dl></div></li></ul></div></div>"
      ],
      "text/plain": [
       "<xarray.DataArray 'norm_scenario_proba_cond_seq' ()>\n",
       "array(0.00071446)\n",
       "Coordinates:\n",
       "    v_choice  int64 40\n",
       "    CDR3      <U11 'CASRDRGAVFW'"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "da_P.sel({'v_choice':40, 'CDR3': 'CASRDRGAVFW'})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div><svg style=\"position: absolute; width: 0; height: 0; overflow: hidden\">\n",
       "<defs>\n",
       "<symbol id=\"icon-database\" viewBox=\"0 0 32 32\">\n",
       "<path d=\"M16 0c-8.837 0-16 2.239-16 5v4c0 2.761 7.163 5 16 5s16-2.239 16-5v-4c0-2.761-7.163-5-16-5z\"></path>\n",
       "<path d=\"M16 17c-8.837 0-16-2.239-16-5v6c0 2.761 7.163 5 16 5s16-2.239 16-5v-6c0 2.761-7.163 5-16 5z\"></path>\n",
       "<path d=\"M16 26c-8.837 0-16-2.239-16-5v6c0 2.761 7.163 5 16 5s16-2.239 16-5v-6c0 2.761-7.163 5-16 5z\"></path>\n",
       "</symbol>\n",
       "<symbol id=\"icon-file-text2\" viewBox=\"0 0 32 32\">\n",
       "<path d=\"M28.681 7.159c-0.694-0.947-1.662-2.053-2.724-3.116s-2.169-2.030-3.116-2.724c-1.612-1.182-2.393-1.319-2.841-1.319h-15.5c-1.378 0-2.5 1.121-2.5 2.5v27c0 1.378 1.122 2.5 2.5 2.5h23c1.378 0 2.5-1.122 2.5-2.5v-19.5c0-0.448-0.137-1.23-1.319-2.841zM24.543 5.457c0.959 0.959 1.712 1.825 2.268 2.543h-4.811v-4.811c0.718 0.556 1.584 1.309 2.543 2.268zM28 29.5c0 0.271-0.229 0.5-0.5 0.5h-23c-0.271 0-0.5-0.229-0.5-0.5v-27c0-0.271 0.229-0.5 0.5-0.5 0 0 15.499-0 15.5 0v7c0 0.552 0.448 1 1 1h7v19.5z\"></path>\n",
       "<path d=\"M23 26h-14c-0.552 0-1-0.448-1-1s0.448-1 1-1h14c0.552 0 1 0.448 1 1s-0.448 1-1 1z\"></path>\n",
       "<path d=\"M23 22h-14c-0.552 0-1-0.448-1-1s0.448-1 1-1h14c0.552 0 1 0.448 1 1s-0.448 1-1 1z\"></path>\n",
       "<path d=\"M23 18h-14c-0.552 0-1-0.448-1-1s0.448-1 1-1h14c0.552 0 1 0.448 1 1s-0.448 1-1 1z\"></path>\n",
       "</symbol>\n",
       "</defs>\n",
       "</svg>\n",
       "<style>/* CSS stylesheet for displaying xarray objects in jupyterlab.\n",
       " *\n",
       " */\n",
       "\n",
       ":root {\n",
       "  --xr-font-color0: var(--jp-content-font-color0, rgba(0, 0, 0, 1));\n",
       "  --xr-font-color2: var(--jp-content-font-color2, rgba(0, 0, 0, 0.54));\n",
       "  --xr-font-color3: var(--jp-content-font-color3, rgba(0, 0, 0, 0.38));\n",
       "  --xr-border-color: var(--jp-border-color2, #e0e0e0);\n",
       "  --xr-disabled-color: var(--jp-layout-color3, #bdbdbd);\n",
       "  --xr-background-color: var(--jp-layout-color0, white);\n",
       "  --xr-background-color-row-even: var(--jp-layout-color1, white);\n",
       "  --xr-background-color-row-odd: var(--jp-layout-color2, #eeeeee);\n",
       "}\n",
       "\n",
       "html[theme=dark],\n",
       "body.vscode-dark {\n",
       "  --xr-font-color0: rgba(255, 255, 255, 1);\n",
       "  --xr-font-color2: rgba(255, 255, 255, 0.54);\n",
       "  --xr-font-color3: rgba(255, 255, 255, 0.38);\n",
       "  --xr-border-color: #1F1F1F;\n",
       "  --xr-disabled-color: #515151;\n",
       "  --xr-background-color: #111111;\n",
       "  --xr-background-color-row-even: #111111;\n",
       "  --xr-background-color-row-odd: #313131;\n",
       "}\n",
       "\n",
       ".xr-wrap {\n",
       "  display: block;\n",
       "  min-width: 300px;\n",
       "  max-width: 700px;\n",
       "}\n",
       "\n",
       ".xr-text-repr-fallback {\n",
       "  /* fallback to plain text repr when CSS is not injected (untrusted notebook) */\n",
       "  display: none;\n",
       "}\n",
       "\n",
       ".xr-header {\n",
       "  padding-top: 6px;\n",
       "  padding-bottom: 6px;\n",
       "  margin-bottom: 4px;\n",
       "  border-bottom: solid 1px var(--xr-border-color);\n",
       "}\n",
       "\n",
       ".xr-header > div,\n",
       ".xr-header > ul {\n",
       "  display: inline;\n",
       "  margin-top: 0;\n",
       "  margin-bottom: 0;\n",
       "}\n",
       "\n",
       ".xr-obj-type,\n",
       ".xr-array-name {\n",
       "  margin-left: 2px;\n",
       "  margin-right: 10px;\n",
       "}\n",
       "\n",
       ".xr-obj-type {\n",
       "  color: var(--xr-font-color2);\n",
       "}\n",
       "\n",
       ".xr-sections {\n",
       "  padding-left: 0 !important;\n",
       "  display: grid;\n",
       "  grid-template-columns: 150px auto auto 1fr 20px 20px;\n",
       "}\n",
       "\n",
       ".xr-section-item {\n",
       "  display: contents;\n",
       "}\n",
       "\n",
       ".xr-section-item input {\n",
       "  display: none;\n",
       "}\n",
       "\n",
       ".xr-section-item input + label {\n",
       "  color: var(--xr-disabled-color);\n",
       "}\n",
       "\n",
       ".xr-section-item input:enabled + label {\n",
       "  cursor: pointer;\n",
       "  color: var(--xr-font-color2);\n",
       "}\n",
       "\n",
       ".xr-section-item input:enabled + label:hover {\n",
       "  color: var(--xr-font-color0);\n",
       "}\n",
       "\n",
       ".xr-section-summary {\n",
       "  grid-column: 1;\n",
       "  color: var(--xr-font-color2);\n",
       "  font-weight: 500;\n",
       "}\n",
       "\n",
       ".xr-section-summary > span {\n",
       "  display: inline-block;\n",
       "  padding-left: 0.5em;\n",
       "}\n",
       "\n",
       ".xr-section-summary-in:disabled + label {\n",
       "  color: var(--xr-font-color2);\n",
       "}\n",
       "\n",
       ".xr-section-summary-in + label:before {\n",
       "  display: inline-block;\n",
       "  content: '►';\n",
       "  font-size: 11px;\n",
       "  width: 15px;\n",
       "  text-align: center;\n",
       "}\n",
       "\n",
       ".xr-section-summary-in:disabled + label:before {\n",
       "  color: var(--xr-disabled-color);\n",
       "}\n",
       "\n",
       ".xr-section-summary-in:checked + label:before {\n",
       "  content: '▼';\n",
       "}\n",
       "\n",
       ".xr-section-summary-in:checked + label > span {\n",
       "  display: none;\n",
       "}\n",
       "\n",
       ".xr-section-summary,\n",
       ".xr-section-inline-details {\n",
       "  padding-top: 4px;\n",
       "  padding-bottom: 4px;\n",
       "}\n",
       "\n",
       ".xr-section-inline-details {\n",
       "  grid-column: 2 / -1;\n",
       "}\n",
       "\n",
       ".xr-section-details {\n",
       "  display: none;\n",
       "  grid-column: 1 / -1;\n",
       "  margin-bottom: 5px;\n",
       "}\n",
       "\n",
       ".xr-section-summary-in:checked ~ .xr-section-details {\n",
       "  display: contents;\n",
       "}\n",
       "\n",
       ".xr-array-wrap {\n",
       "  grid-column: 1 / -1;\n",
       "  display: grid;\n",
       "  grid-template-columns: 20px auto;\n",
       "}\n",
       "\n",
       ".xr-array-wrap > label {\n",
       "  grid-column: 1;\n",
       "  vertical-align: top;\n",
       "}\n",
       "\n",
       ".xr-preview {\n",
       "  color: var(--xr-font-color3);\n",
       "}\n",
       "\n",
       ".xr-array-preview,\n",
       ".xr-array-data {\n",
       "  padding: 0 5px !important;\n",
       "  grid-column: 2;\n",
       "}\n",
       "\n",
       ".xr-array-data,\n",
       ".xr-array-in:checked ~ .xr-array-preview {\n",
       "  display: none;\n",
       "}\n",
       "\n",
       ".xr-array-in:checked ~ .xr-array-data,\n",
       ".xr-array-preview {\n",
       "  display: inline-block;\n",
       "}\n",
       "\n",
       ".xr-dim-list {\n",
       "  display: inline-block !important;\n",
       "  list-style: none;\n",
       "  padding: 0 !important;\n",
       "  margin: 0;\n",
       "}\n",
       "\n",
       ".xr-dim-list li {\n",
       "  display: inline-block;\n",
       "  padding: 0;\n",
       "  margin: 0;\n",
       "}\n",
       "\n",
       ".xr-dim-list:before {\n",
       "  content: '(';\n",
       "}\n",
       "\n",
       ".xr-dim-list:after {\n",
       "  content: ')';\n",
       "}\n",
       "\n",
       ".xr-dim-list li:not(:last-child):after {\n",
       "  content: ',';\n",
       "  padding-right: 5px;\n",
       "}\n",
       "\n",
       ".xr-has-index {\n",
       "  font-weight: bold;\n",
       "}\n",
       "\n",
       ".xr-var-list,\n",
       ".xr-var-item {\n",
       "  display: contents;\n",
       "}\n",
       "\n",
       ".xr-var-item > div,\n",
       ".xr-var-item label,\n",
       ".xr-var-item > .xr-var-name span {\n",
       "  background-color: var(--xr-background-color-row-even);\n",
       "  margin-bottom: 0;\n",
       "}\n",
       "\n",
       ".xr-var-item > .xr-var-name:hover span {\n",
       "  padding-right: 5px;\n",
       "}\n",
       "\n",
       ".xr-var-list > li:nth-child(odd) > div,\n",
       ".xr-var-list > li:nth-child(odd) > label,\n",
       ".xr-var-list > li:nth-child(odd) > .xr-var-name span {\n",
       "  background-color: var(--xr-background-color-row-odd);\n",
       "}\n",
       "\n",
       ".xr-var-name {\n",
       "  grid-column: 1;\n",
       "}\n",
       "\n",
       ".xr-var-dims {\n",
       "  grid-column: 2;\n",
       "}\n",
       "\n",
       ".xr-var-dtype {\n",
       "  grid-column: 3;\n",
       "  text-align: right;\n",
       "  color: var(--xr-font-color2);\n",
       "}\n",
       "\n",
       ".xr-var-preview {\n",
       "  grid-column: 4;\n",
       "}\n",
       "\n",
       ".xr-var-name,\n",
       ".xr-var-dims,\n",
       ".xr-var-dtype,\n",
       ".xr-preview,\n",
       ".xr-attrs dt {\n",
       "  white-space: nowrap;\n",
       "  overflow: hidden;\n",
       "  text-overflow: ellipsis;\n",
       "  padding-right: 10px;\n",
       "}\n",
       "\n",
       ".xr-var-name:hover,\n",
       ".xr-var-dims:hover,\n",
       ".xr-var-dtype:hover,\n",
       ".xr-attrs dt:hover {\n",
       "  overflow: visible;\n",
       "  width: auto;\n",
       "  z-index: 1;\n",
       "}\n",
       "\n",
       ".xr-var-attrs,\n",
       ".xr-var-data {\n",
       "  display: none;\n",
       "  background-color: var(--xr-background-color) !important;\n",
       "  padding-bottom: 5px !important;\n",
       "}\n",
       "\n",
       ".xr-var-attrs-in:checked ~ .xr-var-attrs,\n",
       ".xr-var-data-in:checked ~ .xr-var-data {\n",
       "  display: block;\n",
       "}\n",
       "\n",
       ".xr-var-data > table {\n",
       "  float: right;\n",
       "}\n",
       "\n",
       ".xr-var-name span,\n",
       ".xr-var-data,\n",
       ".xr-attrs {\n",
       "  padding-left: 25px !important;\n",
       "}\n",
       "\n",
       ".xr-attrs,\n",
       ".xr-var-attrs,\n",
       ".xr-var-data {\n",
       "  grid-column: 1 / -1;\n",
       "}\n",
       "\n",
       "dl.xr-attrs {\n",
       "  padding: 0;\n",
       "  margin: 0;\n",
       "  display: grid;\n",
       "  grid-template-columns: 125px auto;\n",
       "}\n",
       "\n",
       ".xr-attrs dt,\n",
       ".xr-attrs dd {\n",
       "  padding: 0;\n",
       "  margin: 0;\n",
       "  float: left;\n",
       "  padding-right: 10px;\n",
       "  width: auto;\n",
       "}\n",
       "\n",
       ".xr-attrs dt {\n",
       "  font-weight: normal;\n",
       "  grid-column: 1;\n",
       "}\n",
       "\n",
       ".xr-attrs dt:hover span {\n",
       "  display: inline-block;\n",
       "  background: var(--xr-background-color);\n",
       "  padding-right: 10px;\n",
       "}\n",
       "\n",
       ".xr-attrs dd {\n",
       "  grid-column: 2;\n",
       "  white-space: pre-wrap;\n",
       "  word-break: break-all;\n",
       "}\n",
       "\n",
       ".xr-icon-database,\n",
       ".xr-icon-file-text2 {\n",
       "  display: inline-block;\n",
       "  vertical-align: middle;\n",
       "  width: 1em;\n",
       "  height: 1.5em !important;\n",
       "  stroke-width: 0;\n",
       "  stroke: currentColor;\n",
       "  fill: currentColor;\n",
       "}\n",
       "</style><pre class='xr-text-repr-fallback'>&lt;xarray.DataArray &#x27;norm_scenario_proba_cond_seq&#x27; (CDR3: 737)&gt;\n",
       "array([2.10871258e-04, 1.06907257e-04, 9.55472497e-05, 3.91025721e-05,\n",
       "       8.89871842e-04, 2.22909579e-05, 6.09749693e-04, 5.54054093e-05,\n",
       "       9.14677052e-04, 2.23230292e-04, 9.78506279e-04, 8.22960606e-04,\n",
       "       9.03969818e-04, 1.54448512e-04, 1.18388232e-05, 1.31500675e-04,\n",
       "       8.32939598e-05, 2.37699016e-05, 6.38606184e-04, 8.33707254e-04,\n",
       "       1.50292923e-04, 6.64391812e-04, 1.42471008e-05, 3.35267198e-04,\n",
       "       1.00000000e-03, 1.00000000e-03, 9.39886951e-04, 3.12125089e-04,\n",
       "       1.03673134e-04, 9.67609144e-05, 1.49478719e-04, 2.73049682e-04,\n",
       "       1.36462444e-04, 5.06234809e-05, 8.39266251e-04, 1.71292629e-05,\n",
       "       6.56874975e-05, 7.43080789e-04, 9.46457348e-04, 1.22023857e-04,\n",
       "       3.02091141e-05, 8.03745567e-04, 1.55673795e-04, 6.21671048e-04,\n",
       "       9.24611426e-04, 9.04549092e-04, 7.35960961e-04, 1.93450694e-05,\n",
       "       1.74043188e-04, 8.68109499e-05, 2.59395492e-04, 7.84799552e-04,\n",
       "       8.57903826e-04, 6.16969180e-05, 8.31436114e-04, 6.74039495e-04,\n",
       "       7.86102683e-05, 9.52476818e-04, 6.30824734e-05, 2.87145587e-05,\n",
       "       9.12770152e-04, 1.19815579e-04, 8.25124125e-04, 2.18862212e-04,\n",
       "       1.00000000e-03, 3.45825009e-05, 8.35443098e-04, 2.05482388e-04,\n",
       "       8.32356507e-05, 7.81960904e-04, 9.05602720e-04, 5.48837714e-05,\n",
       "       2.07558165e-04, 3.62878735e-04, 1.44393543e-04, 8.49762106e-04,\n",
       "       3.95975663e-05, 1.53082086e-04, 5.40217813e-04, 1.00000000e-03,\n",
       "...\n",
       "       4.54346764e-05, 8.37541605e-04, 1.37023751e-04, 9.50588421e-04,\n",
       "       9.63374230e-04, 9.37827649e-04, 5.05595759e-05, 1.00000000e-03,\n",
       "       1.03274902e-04, 1.00000000e-03, 4.60282604e-05, 1.00000000e-03,\n",
       "       5.84314593e-05, 9.03177742e-04, 2.54081848e-04, 4.30344846e-05,\n",
       "       4.15048257e-05, 8.26204987e-05, 3.09170545e-04, 4.46334578e-05,\n",
       "       9.12390214e-04, 8.21726317e-04, 9.78950684e-04, 7.88778246e-05,\n",
       "       1.00000000e-03, 2.07620085e-04, 1.43617457e-05, 4.40827186e-04,\n",
       "       8.15381574e-04, 1.36736141e-04, 7.59579626e-04, 9.63825272e-04,\n",
       "       7.70389574e-05, 1.00000000e-03, 1.00000000e-03, 9.59706894e-04,\n",
       "       5.93322228e-05, 7.28820208e-04, 2.10452125e-04, 9.03108613e-04,\n",
       "       2.71668779e-04, 1.00000000e-03, 6.02243131e-05, 9.77637119e-04,\n",
       "       9.80394692e-05, 3.91646108e-04, 1.46166436e-05, 1.99396506e-04,\n",
       "       2.36737769e-04, 7.89869079e-04, 1.64775362e-04, 2.05338159e-04,\n",
       "       9.71326695e-05, 1.85190465e-05, 9.49665838e-04, 2.63136686e-05,\n",
       "       1.00000000e-03, 1.39014597e-04, 7.09158505e-05, 8.98550082e-05,\n",
       "       1.00000000e-03, 3.85417178e-05, 6.50207864e-04, 7.48508872e-04,\n",
       "       3.84602160e-05, 8.05334469e-04, 1.42996910e-05, 4.14589287e-04,\n",
       "       1.57012919e-04, 9.24472859e-04, 6.16238983e-04, 3.93178346e-05,\n",
       "       9.25018108e-04, 1.66823300e-04, 5.93516292e-04, 9.12304394e-04,\n",
       "       6.66447640e-01])\n",
       "Coordinates:\n",
       "  * CDR3     (CDR3) object &#x27;CACIVTRRDKNCFLAV&#x27; &#x27;CADRRQGEH*SFL&#x27; ... &#x27;NoProductive&#x27;</pre><div class='xr-wrap' hidden><div class='xr-header'><div class='xr-obj-type'>xarray.DataArray</div><div class='xr-array-name'>'norm_scenario_proba_cond_seq'</div><ul class='xr-dim-list'><li><span class='xr-has-index'>CDR3</span>: 737</li></ul></div><ul class='xr-sections'><li class='xr-section-item'><div class='xr-array-wrap'><input id='section-f31385d8-ecda-4719-aede-42909a163f5c' class='xr-array-in' type='checkbox' checked><label for='section-f31385d8-ecda-4719-aede-42909a163f5c' title='Show/hide data repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-array-preview xr-preview'><span>0.0002109 0.0001069 9.555e-05 3.91e-05 ... 0.0005935 0.0009123 0.6664</span></div><div class='xr-array-data'><pre>array([2.10871258e-04, 1.06907257e-04, 9.55472497e-05, 3.91025721e-05,\n",
       "       8.89871842e-04, 2.22909579e-05, 6.09749693e-04, 5.54054093e-05,\n",
       "       9.14677052e-04, 2.23230292e-04, 9.78506279e-04, 8.22960606e-04,\n",
       "       9.03969818e-04, 1.54448512e-04, 1.18388232e-05, 1.31500675e-04,\n",
       "       8.32939598e-05, 2.37699016e-05, 6.38606184e-04, 8.33707254e-04,\n",
       "       1.50292923e-04, 6.64391812e-04, 1.42471008e-05, 3.35267198e-04,\n",
       "       1.00000000e-03, 1.00000000e-03, 9.39886951e-04, 3.12125089e-04,\n",
       "       1.03673134e-04, 9.67609144e-05, 1.49478719e-04, 2.73049682e-04,\n",
       "       1.36462444e-04, 5.06234809e-05, 8.39266251e-04, 1.71292629e-05,\n",
       "       6.56874975e-05, 7.43080789e-04, 9.46457348e-04, 1.22023857e-04,\n",
       "       3.02091141e-05, 8.03745567e-04, 1.55673795e-04, 6.21671048e-04,\n",
       "       9.24611426e-04, 9.04549092e-04, 7.35960961e-04, 1.93450694e-05,\n",
       "       1.74043188e-04, 8.68109499e-05, 2.59395492e-04, 7.84799552e-04,\n",
       "       8.57903826e-04, 6.16969180e-05, 8.31436114e-04, 6.74039495e-04,\n",
       "       7.86102683e-05, 9.52476818e-04, 6.30824734e-05, 2.87145587e-05,\n",
       "       9.12770152e-04, 1.19815579e-04, 8.25124125e-04, 2.18862212e-04,\n",
       "       1.00000000e-03, 3.45825009e-05, 8.35443098e-04, 2.05482388e-04,\n",
       "       8.32356507e-05, 7.81960904e-04, 9.05602720e-04, 5.48837714e-05,\n",
       "       2.07558165e-04, 3.62878735e-04, 1.44393543e-04, 8.49762106e-04,\n",
       "       3.95975663e-05, 1.53082086e-04, 5.40217813e-04, 1.00000000e-03,\n",
       "...\n",
       "       4.54346764e-05, 8.37541605e-04, 1.37023751e-04, 9.50588421e-04,\n",
       "       9.63374230e-04, 9.37827649e-04, 5.05595759e-05, 1.00000000e-03,\n",
       "       1.03274902e-04, 1.00000000e-03, 4.60282604e-05, 1.00000000e-03,\n",
       "       5.84314593e-05, 9.03177742e-04, 2.54081848e-04, 4.30344846e-05,\n",
       "       4.15048257e-05, 8.26204987e-05, 3.09170545e-04, 4.46334578e-05,\n",
       "       9.12390214e-04, 8.21726317e-04, 9.78950684e-04, 7.88778246e-05,\n",
       "       1.00000000e-03, 2.07620085e-04, 1.43617457e-05, 4.40827186e-04,\n",
       "       8.15381574e-04, 1.36736141e-04, 7.59579626e-04, 9.63825272e-04,\n",
       "       7.70389574e-05, 1.00000000e-03, 1.00000000e-03, 9.59706894e-04,\n",
       "       5.93322228e-05, 7.28820208e-04, 2.10452125e-04, 9.03108613e-04,\n",
       "       2.71668779e-04, 1.00000000e-03, 6.02243131e-05, 9.77637119e-04,\n",
       "       9.80394692e-05, 3.91646108e-04, 1.46166436e-05, 1.99396506e-04,\n",
       "       2.36737769e-04, 7.89869079e-04, 1.64775362e-04, 2.05338159e-04,\n",
       "       9.71326695e-05, 1.85190465e-05, 9.49665838e-04, 2.63136686e-05,\n",
       "       1.00000000e-03, 1.39014597e-04, 7.09158505e-05, 8.98550082e-05,\n",
       "       1.00000000e-03, 3.85417178e-05, 6.50207864e-04, 7.48508872e-04,\n",
       "       3.84602160e-05, 8.05334469e-04, 1.42996910e-05, 4.14589287e-04,\n",
       "       1.57012919e-04, 9.24472859e-04, 6.16238983e-04, 3.93178346e-05,\n",
       "       9.25018108e-04, 1.66823300e-04, 5.93516292e-04, 9.12304394e-04,\n",
       "       6.66447640e-01])</pre></div></div></li><li class='xr-section-item'><input id='section-7e80fee0-47a0-468d-9d22-985d5fa9edf5' class='xr-section-summary-in' type='checkbox'  checked><label for='section-7e80fee0-47a0-468d-9d22-985d5fa9edf5' class='xr-section-summary' >Coordinates: <span>(1)</span></label><div class='xr-section-inline-details'></div><div class='xr-section-details'><ul class='xr-var-list'><li class='xr-var-item'><div class='xr-var-name'><span class='xr-has-index'>CDR3</span></div><div class='xr-var-dims'>(CDR3)</div><div class='xr-var-dtype'>object</div><div class='xr-var-preview xr-preview'>&#x27;CACIVTRRDKNCFLAV&#x27; ... &#x27;NoProduc...</div><input id='attrs-54291e08-89cb-4c87-9db4-ae52e8e8b82c' class='xr-var-attrs-in' type='checkbox' disabled><label for='attrs-54291e08-89cb-4c87-9db4-ae52e8e8b82c' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-ee741d4f-fb1b-45de-a9db-b4989ed6465d' class='xr-var-data-in' type='checkbox'><label for='data-ee741d4f-fb1b-45de-a9db-b4989ed6465d' title='Show/Hide data repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-var-attrs'><dl class='xr-attrs'></dl></div><div class='xr-var-data'><pre>array([&#x27;CACIVTRRDKNCFLAV&#x27;, &#x27;CADRRQGEH*SFL&#x27;, &#x27;CAIAQIRSI&#x27;, ..., &#x27;CSVRRGLAAQIRSI&#x27;,\n",
       "       &#x27;CSVVRDMGTLKLS&#x27;, &#x27;NoProductive&#x27;], dtype=object)</pre></div></li></ul></div></li><li class='xr-section-item'><input id='section-78671e7d-a6d1-4743-b526-052f5ae00dbc' class='xr-section-summary-in' type='checkbox' disabled ><label for='section-78671e7d-a6d1-4743-b526-052f5ae00dbc' class='xr-section-summary'  title='Expand/collapse section'>Attributes: <span>(0)</span></label><div class='xr-section-inline-details'></div><div class='xr-section-details'><dl class='xr-attrs'></dl></div></li></ul></div></div>"
      ],
      "text/plain": [
       "<xarray.DataArray 'norm_scenario_proba_cond_seq' (CDR3: 737)>\n",
       "array([2.10871258e-04, 1.06907257e-04, 9.55472497e-05, 3.91025721e-05,\n",
       "       8.89871842e-04, 2.22909579e-05, 6.09749693e-04, 5.54054093e-05,\n",
       "       9.14677052e-04, 2.23230292e-04, 9.78506279e-04, 8.22960606e-04,\n",
       "       9.03969818e-04, 1.54448512e-04, 1.18388232e-05, 1.31500675e-04,\n",
       "       8.32939598e-05, 2.37699016e-05, 6.38606184e-04, 8.33707254e-04,\n",
       "       1.50292923e-04, 6.64391812e-04, 1.42471008e-05, 3.35267198e-04,\n",
       "       1.00000000e-03, 1.00000000e-03, 9.39886951e-04, 3.12125089e-04,\n",
       "       1.03673134e-04, 9.67609144e-05, 1.49478719e-04, 2.73049682e-04,\n",
       "       1.36462444e-04, 5.06234809e-05, 8.39266251e-04, 1.71292629e-05,\n",
       "       6.56874975e-05, 7.43080789e-04, 9.46457348e-04, 1.22023857e-04,\n",
       "       3.02091141e-05, 8.03745567e-04, 1.55673795e-04, 6.21671048e-04,\n",
       "       9.24611426e-04, 9.04549092e-04, 7.35960961e-04, 1.93450694e-05,\n",
       "       1.74043188e-04, 8.68109499e-05, 2.59395492e-04, 7.84799552e-04,\n",
       "       8.57903826e-04, 6.16969180e-05, 8.31436114e-04, 6.74039495e-04,\n",
       "       7.86102683e-05, 9.52476818e-04, 6.30824734e-05, 2.87145587e-05,\n",
       "       9.12770152e-04, 1.19815579e-04, 8.25124125e-04, 2.18862212e-04,\n",
       "       1.00000000e-03, 3.45825009e-05, 8.35443098e-04, 2.05482388e-04,\n",
       "       8.32356507e-05, 7.81960904e-04, 9.05602720e-04, 5.48837714e-05,\n",
       "       2.07558165e-04, 3.62878735e-04, 1.44393543e-04, 8.49762106e-04,\n",
       "       3.95975663e-05, 1.53082086e-04, 5.40217813e-04, 1.00000000e-03,\n",
       "...\n",
       "       4.54346764e-05, 8.37541605e-04, 1.37023751e-04, 9.50588421e-04,\n",
       "       9.63374230e-04, 9.37827649e-04, 5.05595759e-05, 1.00000000e-03,\n",
       "       1.03274902e-04, 1.00000000e-03, 4.60282604e-05, 1.00000000e-03,\n",
       "       5.84314593e-05, 9.03177742e-04, 2.54081848e-04, 4.30344846e-05,\n",
       "       4.15048257e-05, 8.26204987e-05, 3.09170545e-04, 4.46334578e-05,\n",
       "       9.12390214e-04, 8.21726317e-04, 9.78950684e-04, 7.88778246e-05,\n",
       "       1.00000000e-03, 2.07620085e-04, 1.43617457e-05, 4.40827186e-04,\n",
       "       8.15381574e-04, 1.36736141e-04, 7.59579626e-04, 9.63825272e-04,\n",
       "       7.70389574e-05, 1.00000000e-03, 1.00000000e-03, 9.59706894e-04,\n",
       "       5.93322228e-05, 7.28820208e-04, 2.10452125e-04, 9.03108613e-04,\n",
       "       2.71668779e-04, 1.00000000e-03, 6.02243131e-05, 9.77637119e-04,\n",
       "       9.80394692e-05, 3.91646108e-04, 1.46166436e-05, 1.99396506e-04,\n",
       "       2.36737769e-04, 7.89869079e-04, 1.64775362e-04, 2.05338159e-04,\n",
       "       9.71326695e-05, 1.85190465e-05, 9.49665838e-04, 2.63136686e-05,\n",
       "       1.00000000e-03, 1.39014597e-04, 7.09158505e-05, 8.98550082e-05,\n",
       "       1.00000000e-03, 3.85417178e-05, 6.50207864e-04, 7.48508872e-04,\n",
       "       3.84602160e-05, 8.05334469e-04, 1.42996910e-05, 4.14589287e-04,\n",
       "       1.57012919e-04, 9.24472859e-04, 6.16238983e-04, 3.93178346e-05,\n",
       "       9.25018108e-04, 1.66823300e-04, 5.93516292e-04, 9.12304394e-04,\n",
       "       6.66447640e-01])\n",
       "Coordinates:\n",
       "  * CDR3     (CDR3) object 'CACIVTRRDKNCFLAV' 'CADRRQGEH*SFL' ... 'NoProductive'"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "da_P_CDR3 = mdl.get_P_from_scenarios_cols(df_scenarios, ['CDR3'])\n",
    "da_P_CDR3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<AxesSubplot:xlabel='CDR3'>"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 372008 characters]\n",
      "text/plain": [
       "<Figure size 2160x720 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "import matplotlib.pyplot as plt\n",
    "fig, ax = plt.subplots(figsize=(30,10))\n",
    "ax.set_yscale('log')\n",
    "df_P_CDR3 = da_P_CDR3.to_pandas()\n",
    "# zeros_p\n",
    "df_P_CDR3.plot.bar(ax=ax)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "### DEFAULT CDR3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "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>scenario_rank</th>\n",
       "      <th>scenario_proba_cond_seq</th>\n",
       "      <th>v_choice</th>\n",
       "      <th>j_choice</th>\n",
       "      <th>d_gene</th>\n",
       "      <th>v_3_del</th>\n",
       "      <th>d_5_del</th>\n",
       "      <th>j_5_del</th>\n",
       "      <th>d_3_del</th>\n",
       "      <th>vd_ins</th>\n",
       "      <th>vd_dinucl</th>\n",
       "      <th>dj_ins</th>\n",
       "      <th>dj_dinucl</th>\n",
       "      <th>Mismatches</th>\n",
       "      <th>norm_scenario_proba_cond_seq</th>\n",
       "      <th>CDR3</th>\n",
       "      <th>CDR3_py</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>seq_index</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>998</th>\n",
       "      <td>1</td>\n",
       "      <td>0.783497</td>\n",
       "      <td>77</td>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "      <td>9</td>\n",
       "      <td>6</td>\n",
       "      <td>19</td>\n",
       "      <td>9</td>\n",
       "      <td>4</td>\n",
       "      <td>[1, 1, 2, 3]</td>\n",
       "      <td>7</td>\n",
       "      <td>[2, 2, 2, 2, 0, 2, 0]</td>\n",
       "      <td>[]</td>\n",
       "      <td>0.000801</td>\n",
       "      <td>NoProductive</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>998</th>\n",
       "      <td>2</td>\n",
       "      <td>0.076884</td>\n",
       "      <td>77</td>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "      <td>9</td>\n",
       "      <td>6</td>\n",
       "      <td>19</td>\n",
       "      <td>10</td>\n",
       "      <td>4</td>\n",
       "      <td>[1, 1, 2, 3]</td>\n",
       "      <td>8</td>\n",
       "      <td>[2, 2, 2, 2, 0, 2, 0, 2]</td>\n",
       "      <td>[]</td>\n",
       "      <td>0.000079</td>\n",
       "      <td>NoProductive</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>998</th>\n",
       "      <td>3</td>\n",
       "      <td>0.043634</td>\n",
       "      <td>77</td>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "      <td>9</td>\n",
       "      <td>7</td>\n",
       "      <td>19</td>\n",
       "      <td>9</td>\n",
       "      <td>5</td>\n",
       "      <td>[1, 1, 2, 3, 2]</td>\n",
       "      <td>7</td>\n",
       "      <td>[2, 2, 2, 2, 0, 2, 0]</td>\n",
       "      <td>[]</td>\n",
       "      <td>0.000045</td>\n",
       "      <td>NoProductive</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>998</th>\n",
       "      <td>4</td>\n",
       "      <td>0.023517</td>\n",
       "      <td>77</td>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "      <td>10</td>\n",
       "      <td>6</td>\n",
       "      <td>19</td>\n",
       "      <td>9</td>\n",
       "      <td>5</td>\n",
       "      <td>[1, 1, 1, 2, 3]</td>\n",
       "      <td>7</td>\n",
       "      <td>[2, 2, 2, 2, 0, 2, 0]</td>\n",
       "      <td>[]</td>\n",
       "      <td>0.000024</td>\n",
       "      <td>NoProductive</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>998</th>\n",
       "      <td>5</td>\n",
       "      <td>0.021809</td>\n",
       "      <td>77</td>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "      <td>9</td>\n",
       "      <td>8</td>\n",
       "      <td>19</td>\n",
       "      <td>9</td>\n",
       "      <td>6</td>\n",
       "      <td>[1, 1, 2, 3, 2, 0]</td>\n",
       "      <td>7</td>\n",
       "      <td>[2, 2, 2, 2, 0, 2, 0]</td>\n",
       "      <td>[]</td>\n",
       "      <td>0.000022</td>\n",
       "      <td>NoProductive</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "           scenario_rank  scenario_proba_cond_seq  v_choice  j_choice  d_gene  \\\n",
       "seq_index                                                                       \n",
       "998                    1                 0.783497        77         4       0   \n",
       "998                    2                 0.076884        77         4       0   \n",
       "998                    3                 0.043634        77         4       0   \n",
       "998                    4                 0.023517        77         4       0   \n",
       "998                    5                 0.021809        77         4       0   \n",
       "\n",
       "           v_3_del  d_5_del  j_5_del  d_3_del  vd_ins           vd_dinucl  \\\n",
       "seq_index                                                                   \n",
       "998              9        6       19        9       4        [1, 1, 2, 3]   \n",
       "998              9        6       19       10       4        [1, 1, 2, 3]   \n",
       "998              9        7       19        9       5     [1, 1, 2, 3, 2]   \n",
       "998             10        6       19        9       5     [1, 1, 1, 2, 3]   \n",
       "998              9        8       19        9       6  [1, 1, 2, 3, 2, 0]   \n",
       "\n",
       "           dj_ins                 dj_dinucl Mismatches  \\\n",
       "seq_index                                                \n",
       "998             7     [2, 2, 2, 2, 0, 2, 0]         []   \n",
       "998             8  [2, 2, 2, 2, 0, 2, 0, 2]         []   \n",
       "998             7     [2, 2, 2, 2, 0, 2, 0]         []   \n",
       "998             7     [2, 2, 2, 2, 0, 2, 0]         []   \n",
       "998             7     [2, 2, 2, 2, 0, 2, 0]         []   \n",
       "\n",
       "           norm_scenario_proba_cond_seq          CDR3 CDR3_py  \n",
       "seq_index                                                      \n",
       "998                            0.000801  NoProductive     NaN  \n",
       "998                            0.000079  NoProductive     NaN  \n",
       "998                            0.000045  NoProductive     NaN  \n",
       "998                            0.000024  NoProductive     NaN  \n",
       "998                            0.000022  NoProductive     NaN  "
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_scenarios['CDR3_py'] = mdl.get_VDJ_CDR3_from_df_scenario(df_scenarios)\n",
    "df_scenarios.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### other example"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [],
   "source": [
    "from Bio.SeqUtils.ProtParam import ProteinAnalysis\n",
    "hydro_aa_list = ['M', 'L', 'I', 'V']\n",
    "def observable_n_hydro(ps_scenario):\n",
    "    seq_aa_CDR3 = observable_get_CDR3(ps_scenario)\n",
    "    if (seq_aa_CDR3 is None) or (seq_aa_CDR3 is np.NaN):\n",
    "        return np.NaN\n",
    "    else:\n",
    "        analyzed_seq = ProteinAnalysis(str(seq_aa_CDR3))\n",
    "        aa_counts_dict = analyzed_seq.count_amino_acids()    \n",
    "        aa_counts = 0\n",
    "        for aa in hydro_aa_list:\n",
    "            aa_counts = aa_counts + aa_counts_dict[aa]\n",
    "        return aa_counts"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "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>scenario_rank</th>\n",
       "      <th>scenario_proba_cond_seq</th>\n",
       "      <th>v_choice</th>\n",
       "      <th>j_choice</th>\n",
       "      <th>d_gene</th>\n",
       "      <th>v_3_del</th>\n",
       "      <th>d_5_del</th>\n",
       "      <th>j_5_del</th>\n",
       "      <th>d_3_del</th>\n",
       "      <th>vd_ins</th>\n",
       "      <th>vd_dinucl</th>\n",
       "      <th>dj_ins</th>\n",
       "      <th>dj_dinucl</th>\n",
       "      <th>Mismatches</th>\n",
       "      <th>norm_scenario_proba_cond_seq</th>\n",
       "      <th>CDR3</th>\n",
       "      <th>CDR3_py</th>\n",
       "      <th>n_hydro</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>seq_index</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>998</th>\n",
       "      <td>1</td>\n",
       "      <td>0.783497</td>\n",
       "      <td>77</td>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "      <td>9</td>\n",
       "      <td>6</td>\n",
       "      <td>19</td>\n",
       "      <td>9</td>\n",
       "      <td>4</td>\n",
       "      <td>[1, 1, 2, 3]</td>\n",
       "      <td>7</td>\n",
       "      <td>[2, 2, 2, 2, 0, 2, 0]</td>\n",
       "      <td>[]</td>\n",
       "      <td>0.000801</td>\n",
       "      <td>NoProductive</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>998</th>\n",
       "      <td>2</td>\n",
       "      <td>0.076884</td>\n",
       "      <td>77</td>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "      <td>9</td>\n",
       "      <td>6</td>\n",
       "      <td>19</td>\n",
       "      <td>10</td>\n",
       "      <td>4</td>\n",
       "      <td>[1, 1, 2, 3]</td>\n",
       "      <td>8</td>\n",
       "      <td>[2, 2, 2, 2, 0, 2, 0, 2]</td>\n",
       "      <td>[]</td>\n",
       "      <td>0.000079</td>\n",
       "      <td>NoProductive</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>998</th>\n",
       "      <td>3</td>\n",
       "      <td>0.043634</td>\n",
       "      <td>77</td>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "      <td>9</td>\n",
       "      <td>7</td>\n",
       "      <td>19</td>\n",
       "      <td>9</td>\n",
       "      <td>5</td>\n",
       "      <td>[1, 1, 2, 3, 2]</td>\n",
       "      <td>7</td>\n",
       "      <td>[2, 2, 2, 2, 0, 2, 0]</td>\n",
       "      <td>[]</td>\n",
       "      <td>0.000045</td>\n",
       "      <td>NoProductive</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>998</th>\n",
       "      <td>4</td>\n",
       "      <td>0.023517</td>\n",
       "      <td>77</td>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "      <td>10</td>\n",
       "      <td>6</td>\n",
       "      <td>19</td>\n",
       "      <td>9</td>\n",
       "      <td>5</td>\n",
       "      <td>[1, 1, 1, 2, 3]</td>\n",
       "      <td>7</td>\n",
       "      <td>[2, 2, 2, 2, 0, 2, 0]</td>\n",
       "      <td>[]</td>\n",
       "      <td>0.000024</td>\n",
       "      <td>NoProductive</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>998</th>\n",
       "      <td>5</td>\n",
       "      <td>0.021809</td>\n",
       "      <td>77</td>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "      <td>9</td>\n",
       "      <td>8</td>\n",
       "      <td>19</td>\n",
       "      <td>9</td>\n",
       "      <td>6</td>\n",
       "      <td>[1, 1, 2, 3, 2, 0]</td>\n",
       "      <td>7</td>\n",
       "      <td>[2, 2, 2, 2, 0, 2, 0]</td>\n",
       "      <td>[]</td>\n",
       "      <td>0.000022</td>\n",
       "      <td>NoProductive</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "           scenario_rank  scenario_proba_cond_seq  v_choice  j_choice  d_gene  \\\n",
       "seq_index                                                                       \n",
       "998                    1                 0.783497        77         4       0   \n",
       "998                    2                 0.076884        77         4       0   \n",
       "998                    3                 0.043634        77         4       0   \n",
       "998                    4                 0.023517        77         4       0   \n",
       "998                    5                 0.021809        77         4       0   \n",
       "\n",
       "           v_3_del  d_5_del  j_5_del  d_3_del  vd_ins           vd_dinucl  \\\n",
       "seq_index                                                                   \n",
       "998              9        6       19        9       4        [1, 1, 2, 3]   \n",
       "998              9        6       19       10       4        [1, 1, 2, 3]   \n",
       "998              9        7       19        9       5     [1, 1, 2, 3, 2]   \n",
       "998             10        6       19        9       5     [1, 1, 1, 2, 3]   \n",
       "998              9        8       19        9       6  [1, 1, 2, 3, 2, 0]   \n",
       "\n",
       "           dj_ins                 dj_dinucl Mismatches  \\\n",
       "seq_index                                                \n",
       "998             7     [2, 2, 2, 2, 0, 2, 0]         []   \n",
       "998             8  [2, 2, 2, 2, 0, 2, 0, 2]         []   \n",
       "998             7     [2, 2, 2, 2, 0, 2, 0]         []   \n",
       "998             7     [2, 2, 2, 2, 0, 2, 0]         []   \n",
       "998             7     [2, 2, 2, 2, 0, 2, 0]         []   \n",
       "\n",
       "           norm_scenario_proba_cond_seq          CDR3 CDR3_py  n_hydro  \n",
       "seq_index                                                               \n",
       "998                            0.000801  NoProductive     NaN      0.0  \n",
       "998                            0.000079  NoProductive     NaN      0.0  \n",
       "998                            0.000045  NoProductive     NaN      0.0  \n",
       "998                            0.000024  NoProductive     NaN      0.0  \n",
       "998                            0.000022  NoProductive     NaN      0.0  "
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "%%time\n",
    "df_scenarios['n_hydro'] = mdl.get_observable_from_scenarios_dataframe(observable_n_hydro, df_scenarios)\n",
    "df_scenarios.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div><svg style=\"position: absolute; width: 0; height: 0; overflow: hidden\">\n",
       "<defs>\n",
       "<symbol id=\"icon-database\" viewBox=\"0 0 32 32\">\n",
       "<path d=\"M16 0c-8.837 0-16 2.239-16 5v4c0 2.761 7.163 5 16 5s16-2.239 16-5v-4c0-2.761-7.163-5-16-5z\"></path>\n",
       "<path d=\"M16 17c-8.837 0-16-2.239-16-5v6c0 2.761 7.163 5 16 5s16-2.239 16-5v-6c0 2.761-7.163 5-16 5z\"></path>\n",
       "<path d=\"M16 26c-8.837 0-16-2.239-16-5v6c0 2.761 7.163 5 16 5s16-2.239 16-5v-6c0 2.761-7.163 5-16 5z\"></path>\n",
       "</symbol>\n",
       "<symbol id=\"icon-file-text2\" viewBox=\"0 0 32 32\">\n",
       "<path d=\"M28.681 7.159c-0.694-0.947-1.662-2.053-2.724-3.116s-2.169-2.030-3.116-2.724c-1.612-1.182-2.393-1.319-2.841-1.319h-15.5c-1.378 0-2.5 1.121-2.5 2.5v27c0 1.378 1.122 2.5 2.5 2.5h23c1.378 0 2.5-1.122 2.5-2.5v-19.5c0-0.448-0.137-1.23-1.319-2.841zM24.543 5.457c0.959 0.959 1.712 1.825 2.268 2.543h-4.811v-4.811c0.718 0.556 1.584 1.309 2.543 2.268zM28 29.5c0 0.271-0.229 0.5-0.5 0.5h-23c-0.271 0-0.5-0.229-0.5-0.5v-27c0-0.271 0.229-0.5 0.5-0.5 0 0 15.499-0 15.5 0v7c0 0.552 0.448 1 1 1h7v19.5z\"></path>\n",
       "<path d=\"M23 26h-14c-0.552 0-1-0.448-1-1s0.448-1 1-1h14c0.552 0 1 0.448 1 1s-0.448 1-1 1z\"></path>\n",
       "<path d=\"M23 22h-14c-0.552 0-1-0.448-1-1s0.448-1 1-1h14c0.552 0 1 0.448 1 1s-0.448 1-1 1z\"></path>\n",
       "<path d=\"M23 18h-14c-0.552 0-1-0.448-1-1s0.448-1 1-1h14c0.552 0 1 0.448 1 1s-0.448 1-1 1z\"></path>\n",
       "</symbol>\n",
       "</defs>\n",
       "</svg>\n",
       "<style>/* CSS stylesheet for displaying xarray objects in jupyterlab.\n",
       " *\n",
       " */\n",
       "\n",
       ":root {\n",
       "  --xr-font-color0: var(--jp-content-font-color0, rgba(0, 0, 0, 1));\n",
       "  --xr-font-color2: var(--jp-content-font-color2, rgba(0, 0, 0, 0.54));\n",
       "  --xr-font-color3: var(--jp-content-font-color3, rgba(0, 0, 0, 0.38));\n",
       "  --xr-border-color: var(--jp-border-color2, #e0e0e0);\n",
       "  --xr-disabled-color: var(--jp-layout-color3, #bdbdbd);\n",
       "  --xr-background-color: var(--jp-layout-color0, white);\n",
       "  --xr-background-color-row-even: var(--jp-layout-color1, white);\n",
       "  --xr-background-color-row-odd: var(--jp-layout-color2, #eeeeee);\n",
       "}\n",
       "\n",
       "html[theme=dark],\n",
       "body.vscode-dark {\n",
       "  --xr-font-color0: rgba(255, 255, 255, 1);\n",
       "  --xr-font-color2: rgba(255, 255, 255, 0.54);\n",
       "  --xr-font-color3: rgba(255, 255, 255, 0.38);\n",
       "  --xr-border-color: #1F1F1F;\n",
       "  --xr-disabled-color: #515151;\n",
       "  --xr-background-color: #111111;\n",
       "  --xr-background-color-row-even: #111111;\n",
       "  --xr-background-color-row-odd: #313131;\n",
       "}\n",
       "\n",
       ".xr-wrap {\n",
       "  display: block;\n",
       "  min-width: 300px;\n",
       "  max-width: 700px;\n",
       "}\n",
       "\n",
       ".xr-text-repr-fallback {\n",
       "  /* fallback to plain text repr when CSS is not injected (untrusted notebook) */\n",
       "  display: none;\n",
       "}\n",
       "\n",
       ".xr-header {\n",
       "  padding-top: 6px;\n",
       "  padding-bottom: 6px;\n",
       "  margin-bottom: 4px;\n",
       "  border-bottom: solid 1px var(--xr-border-color);\n",
       "}\n",
       "\n",
       ".xr-header > div,\n",
       ".xr-header > ul {\n",
       "  display: inline;\n",
       "  margin-top: 0;\n",
       "  margin-bottom: 0;\n",
       "}\n",
       "\n",
       ".xr-obj-type,\n",
       ".xr-array-name {\n",
       "  margin-left: 2px;\n",
       "  margin-right: 10px;\n",
       "}\n",
       "\n",
       ".xr-obj-type {\n",
       "  color: var(--xr-font-color2);\n",
       "}\n",
       "\n",
       ".xr-sections {\n",
       "  padding-left: 0 !important;\n",
       "  display: grid;\n",
       "  grid-template-columns: 150px auto auto 1fr 20px 20px;\n",
       "}\n",
       "\n",
       ".xr-section-item {\n",
       "  display: contents;\n",
       "}\n",
       "\n",
       ".xr-section-item input {\n",
       "  display: none;\n",
       "}\n",
       "\n",
       ".xr-section-item input + label {\n",
       "  color: var(--xr-disabled-color);\n",
       "}\n",
       "\n",
       ".xr-section-item input:enabled + label {\n",
       "  cursor: pointer;\n",
       "  color: var(--xr-font-color2);\n",
       "}\n",
       "\n",
       ".xr-section-item input:enabled + label:hover {\n",
       "  color: var(--xr-font-color0);\n",
       "}\n",
       "\n",
       ".xr-section-summary {\n",
       "  grid-column: 1;\n",
       "  color: var(--xr-font-color2);\n",
       "  font-weight: 500;\n",
       "}\n",
       "\n",
       ".xr-section-summary > span {\n",
       "  display: inline-block;\n",
       "  padding-left: 0.5em;\n",
       "}\n",
       "\n",
       ".xr-section-summary-in:disabled + label {\n",
       "  color: var(--xr-font-color2);\n",
       "}\n",
       "\n",
       ".xr-section-summary-in + label:before {\n",
       "  display: inline-block;\n",
       "  content: '►';\n",
       "  font-size: 11px;\n",
       "  width: 15px;\n",
       "  text-align: center;\n",
       "}\n",
       "\n",
       ".xr-section-summary-in:disabled + label:before {\n",
       "  color: var(--xr-disabled-color);\n",
       "}\n",
       "\n",
       ".xr-section-summary-in:checked + label:before {\n",
       "  content: '▼';\n",
       "}\n",
       "\n",
       ".xr-section-summary-in:checked + label > span {\n",
       "  display: none;\n",
       "}\n",
       "\n",
       ".xr-section-summary,\n",
       ".xr-section-inline-details {\n",
       "  padding-top: 4px;\n",
       "  padding-bottom: 4px;\n",
       "}\n",
       "\n",
       ".xr-section-inline-details {\n",
       "  grid-column: 2 / -1;\n",
       "}\n",
       "\n",
       ".xr-section-details {\n",
       "  display: none;\n",
       "  grid-column: 1 / -1;\n",
       "  margin-bottom: 5px;\n",
       "}\n",
       "\n",
       ".xr-section-summary-in:checked ~ .xr-section-details {\n",
       "  display: contents;\n",
       "}\n",
       "\n",
       ".xr-array-wrap {\n",
       "  grid-column: 1 / -1;\n",
       "  display: grid;\n",
       "  grid-template-columns: 20px auto;\n",
       "}\n",
       "\n",
       ".xr-array-wrap > label {\n",
       "  grid-column: 1;\n",
       "  vertical-align: top;\n",
       "}\n",
       "\n",
       ".xr-preview {\n",
       "  color: var(--xr-font-color3);\n",
       "}\n",
       "\n",
       ".xr-array-preview,\n",
       ".xr-array-data {\n",
       "  padding: 0 5px !important;\n",
       "  grid-column: 2;\n",
       "}\n",
       "\n",
       ".xr-array-data,\n",
       ".xr-array-in:checked ~ .xr-array-preview {\n",
       "  display: none;\n",
       "}\n",
       "\n",
       ".xr-array-in:checked ~ .xr-array-data,\n",
       ".xr-array-preview {\n",
       "  display: inline-block;\n",
       "}\n",
       "\n",
       ".xr-dim-list {\n",
       "  display: inline-block !important;\n",
       "  list-style: none;\n",
       "  padding: 0 !important;\n",
       "  margin: 0;\n",
       "}\n",
       "\n",
       ".xr-dim-list li {\n",
       "  display: inline-block;\n",
       "  padding: 0;\n",
       "  margin: 0;\n",
       "}\n",
       "\n",
       ".xr-dim-list:before {\n",
       "  content: '(';\n",
       "}\n",
       "\n",
       ".xr-dim-list:after {\n",
       "  content: ')';\n",
       "}\n",
       "\n",
       ".xr-dim-list li:not(:last-child):after {\n",
       "  content: ',';\n",
       "  padding-right: 5px;\n",
       "}\n",
       "\n",
       ".xr-has-index {\n",
       "  font-weight: bold;\n",
       "}\n",
       "\n",
       ".xr-var-list,\n",
       ".xr-var-item {\n",
       "  display: contents;\n",
       "}\n",
       "\n",
       ".xr-var-item > div,\n",
       ".xr-var-item label,\n",
       ".xr-var-item > .xr-var-name span {\n",
       "  background-color: var(--xr-background-color-row-even);\n",
       "  margin-bottom: 0;\n",
       "}\n",
       "\n",
       ".xr-var-item > .xr-var-name:hover span {\n",
       "  padding-right: 5px;\n",
       "}\n",
       "\n",
       ".xr-var-list > li:nth-child(odd) > div,\n",
       ".xr-var-list > li:nth-child(odd) > label,\n",
       ".xr-var-list > li:nth-child(odd) > .xr-var-name span {\n",
       "  background-color: var(--xr-background-color-row-odd);\n",
       "}\n",
       "\n",
       ".xr-var-name {\n",
       "  grid-column: 1;\n",
       "}\n",
       "\n",
       ".xr-var-dims {\n",
       "  grid-column: 2;\n",
       "}\n",
       "\n",
       ".xr-var-dtype {\n",
       "  grid-column: 3;\n",
       "  text-align: right;\n",
       "  color: var(--xr-font-color2);\n",
       "}\n",
       "\n",
       ".xr-var-preview {\n",
       "  grid-column: 4;\n",
       "}\n",
       "\n",
       ".xr-var-name,\n",
       ".xr-var-dims,\n",
       ".xr-var-dtype,\n",
       ".xr-preview,\n",
       ".xr-attrs dt {\n",
       "  white-space: nowrap;\n",
       "  overflow: hidden;\n",
       "  text-overflow: ellipsis;\n",
       "  padding-right: 10px;\n",
       "}\n",
       "\n",
       ".xr-var-name:hover,\n",
       ".xr-var-dims:hover,\n",
       ".xr-var-dtype:hover,\n",
       ".xr-attrs dt:hover {\n",
       "  overflow: visible;\n",
       "  width: auto;\n",
       "  z-index: 1;\n",
       "}\n",
       "\n",
       ".xr-var-attrs,\n",
       ".xr-var-data {\n",
       "  display: none;\n",
       "  background-color: var(--xr-background-color) !important;\n",
       "  padding-bottom: 5px !important;\n",
       "}\n",
       "\n",
       ".xr-var-attrs-in:checked ~ .xr-var-attrs,\n",
       ".xr-var-data-in:checked ~ .xr-var-data {\n",
       "  display: block;\n",
       "}\n",
       "\n",
       ".xr-var-data > table {\n",
       "  float: right;\n",
       "}\n",
       "\n",
       ".xr-var-name span,\n",
       ".xr-var-data,\n",
       ".xr-attrs {\n",
       "  padding-left: 25px !important;\n",
       "}\n",
       "\n",
       ".xr-attrs,\n",
       ".xr-var-attrs,\n",
       ".xr-var-data {\n",
       "  grid-column: 1 / -1;\n",
       "}\n",
       "\n",
       "dl.xr-attrs {\n",
       "  padding: 0;\n",
       "  margin: 0;\n",
       "  display: grid;\n",
       "  grid-template-columns: 125px auto;\n",
       "}\n",
       "\n",
       ".xr-attrs dt,\n",
       ".xr-attrs dd {\n",
       "  padding: 0;\n",
       "  margin: 0;\n",
       "  float: left;\n",
       "  padding-right: 10px;\n",
       "  width: auto;\n",
       "}\n",
       "\n",
       ".xr-attrs dt {\n",
       "  font-weight: normal;\n",
       "  grid-column: 1;\n",
       "}\n",
       "\n",
       ".xr-attrs dt:hover span {\n",
       "  display: inline-block;\n",
       "  background: var(--xr-background-color);\n",
       "  padding-right: 10px;\n",
       "}\n",
       "\n",
       ".xr-attrs dd {\n",
       "  grid-column: 2;\n",
       "  white-space: pre-wrap;\n",
       "  word-break: break-all;\n",
       "}\n",
       "\n",
       ".xr-icon-database,\n",
       ".xr-icon-file-text2 {\n",
       "  display: inline-block;\n",
       "  vertical-align: middle;\n",
       "  width: 1em;\n",
       "  height: 1.5em !important;\n",
       "  stroke-width: 0;\n",
       "  stroke: currentColor;\n",
       "  fill: currentColor;\n",
       "}\n",
       "</style><pre class='xr-text-repr-fallback'>&lt;xarray.DataArray &#x27;norm_scenario_proba_cond_seq&#x27; (n_hydro: 7)&gt;\n",
       "array([0.70461721, 0.07812675, 0.09171433, 0.07252926, 0.03611753,\n",
       "       0.00983321, 0.00406171])\n",
       "Coordinates:\n",
       "  * n_hydro  (n_hydro) float64 0.0 1.0 2.0 3.0 4.0 5.0 6.0</pre><div class='xr-wrap' hidden><div class='xr-header'><div class='xr-obj-type'>xarray.DataArray</div><div class='xr-array-name'>'norm_scenario_proba_cond_seq'</div><ul class='xr-dim-list'><li><span class='xr-has-index'>n_hydro</span>: 7</li></ul></div><ul class='xr-sections'><li class='xr-section-item'><div class='xr-array-wrap'><input id='section-8bbfacc1-ba69-40a7-a416-99d93c0992c7' class='xr-array-in' type='checkbox' checked><label for='section-8bbfacc1-ba69-40a7-a416-99d93c0992c7' title='Show/hide data repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-array-preview xr-preview'><span>0.7046 0.07813 0.09171 0.07253 0.03612 0.009833 0.004062</span></div><div class='xr-array-data'><pre>array([0.70461721, 0.07812675, 0.09171433, 0.07252926, 0.03611753,\n",
       "       0.00983321, 0.00406171])</pre></div></div></li><li class='xr-section-item'><input id='section-67314dea-f690-48a8-aa9c-c34311b95370' class='xr-section-summary-in' type='checkbox'  checked><label for='section-67314dea-f690-48a8-aa9c-c34311b95370' class='xr-section-summary' >Coordinates: <span>(1)</span></label><div class='xr-section-inline-details'></div><div class='xr-section-details'><ul class='xr-var-list'><li class='xr-var-item'><div class='xr-var-name'><span class='xr-has-index'>n_hydro</span></div><div class='xr-var-dims'>(n_hydro)</div><div class='xr-var-dtype'>float64</div><div class='xr-var-preview xr-preview'>0.0 1.0 2.0 3.0 4.0 5.0 6.0</div><input id='attrs-ac2cf3f8-8301-468a-9f75-28658d236f8e' class='xr-var-attrs-in' type='checkbox' disabled><label for='attrs-ac2cf3f8-8301-468a-9f75-28658d236f8e' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-c1c8d298-3b17-4903-9b7e-1ad7aa06f214' class='xr-var-data-in' type='checkbox'><label for='data-c1c8d298-3b17-4903-9b7e-1ad7aa06f214' title='Show/Hide data repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-var-attrs'><dl class='xr-attrs'></dl></div><div class='xr-var-data'><pre>array([0., 1., 2., 3., 4., 5., 6.])</pre></div></li></ul></div></li><li class='xr-section-item'><input id='section-e44327b6-4dbe-4216-a2bf-3bac4d45791f' class='xr-section-summary-in' type='checkbox' disabled ><label for='section-e44327b6-4dbe-4216-a2bf-3bac4d45791f' class='xr-section-summary'  title='Expand/collapse section'>Attributes: <span>(0)</span></label><div class='xr-section-inline-details'></div><div class='xr-section-details'><dl class='xr-attrs'></dl></div></li></ul></div></div>"
      ],
      "text/plain": [
       "<xarray.DataArray 'norm_scenario_proba_cond_seq' (n_hydro: 7)>\n",
       "array([0.70461721, 0.07812675, 0.09171433, 0.07252926, 0.03611753,\n",
       "       0.00983321, 0.00406171])\n",
       "Coordinates:\n",
       "  * n_hydro  (n_hydro) float64 0.0 1.0 2.0 3.0 4.0 5.0 6.0"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "da_n_hydro = mdl.get_P_from_scenarios_cols(df_scenarios, ['n_hydro'])\n",
    "da_n_hydro"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[<matplotlib.lines.Line2D at 0x7f9a91fd0750>]"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 14064 characters]\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "da_n_hydro.plot()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div><svg style=\"position: absolute; width: 0; height: 0; overflow: hidden\">\n",
       "<defs>\n",
       "<symbol id=\"icon-database\" viewBox=\"0 0 32 32\">\n",
       "<path d=\"M16 0c-8.837 0-16 2.239-16 5v4c0 2.761 7.163 5 16 5s16-2.239 16-5v-4c0-2.761-7.163-5-16-5z\"></path>\n",
       "<path d=\"M16 17c-8.837 0-16-2.239-16-5v6c0 2.761 7.163 5 16 5s16-2.239 16-5v-6c0 2.761-7.163 5-16 5z\"></path>\n",
       "<path d=\"M16 26c-8.837 0-16-2.239-16-5v6c0 2.761 7.163 5 16 5s16-2.239 16-5v-6c0 2.761-7.163 5-16 5z\"></path>\n",
       "</symbol>\n",
       "<symbol id=\"icon-file-text2\" viewBox=\"0 0 32 32\">\n",
       "<path d=\"M28.681 7.159c-0.694-0.947-1.662-2.053-2.724-3.116s-2.169-2.030-3.116-2.724c-1.612-1.182-2.393-1.319-2.841-1.319h-15.5c-1.378 0-2.5 1.121-2.5 2.5v27c0 1.378 1.122 2.5 2.5 2.5h23c1.378 0 2.5-1.122 2.5-2.5v-19.5c0-0.448-0.137-1.23-1.319-2.841zM24.543 5.457c0.959 0.959 1.712 1.825 2.268 2.543h-4.811v-4.811c0.718 0.556 1.584 1.309 2.543 2.268zM28 29.5c0 0.271-0.229 0.5-0.5 0.5h-23c-0.271 0-0.5-0.229-0.5-0.5v-27c0-0.271 0.229-0.5 0.5-0.5 0 0 15.499-0 15.5 0v7c0 0.552 0.448 1 1 1h7v19.5z\"></path>\n",
       "<path d=\"M23 26h-14c-0.552 0-1-0.448-1-1s0.448-1 1-1h14c0.552 0 1 0.448 1 1s-0.448 1-1 1z\"></path>\n",
       "<path d=\"M23 22h-14c-0.552 0-1-0.448-1-1s0.448-1 1-1h14c0.552 0 1 0.448 1 1s-0.448 1-1 1z\"></path>\n",
       "<path d=\"M23 18h-14c-0.552 0-1-0.448-1-1s0.448-1 1-1h14c0.552 0 1 0.448 1 1s-0.448 1-1 1z\"></path>\n",
       "</symbol>\n",
       "</defs>\n",
       "</svg>\n",
       "<style>/* CSS stylesheet for displaying xarray objects in jupyterlab.\n",
       " *\n",
       " */\n",
       "\n",
       ":root {\n",
       "  --xr-font-color0: var(--jp-content-font-color0, rgba(0, 0, 0, 1));\n",
       "  --xr-font-color2: var(--jp-content-font-color2, rgba(0, 0, 0, 0.54));\n",
       "  --xr-font-color3: var(--jp-content-font-color3, rgba(0, 0, 0, 0.38));\n",
       "  --xr-border-color: var(--jp-border-color2, #e0e0e0);\n",
       "  --xr-disabled-color: var(--jp-layout-color3, #bdbdbd);\n",
       "  --xr-background-color: var(--jp-layout-color0, white);\n",
       "  --xr-background-color-row-even: var(--jp-layout-color1, white);\n",
       "  --xr-background-color-row-odd: var(--jp-layout-color2, #eeeeee);\n",
       "}\n",
       "\n",
       "html[theme=dark],\n",
       "body.vscode-dark {\n",
       "  --xr-font-color0: rgba(255, 255, 255, 1);\n",
       "  --xr-font-color2: rgba(255, 255, 255, 0.54);\n",
       "  --xr-font-color3: rgba(255, 255, 255, 0.38);\n",
       "  --xr-border-color: #1F1F1F;\n",
       "  --xr-disabled-color: #515151;\n",
       "  --xr-background-color: #111111;\n",
       "  --xr-background-color-row-even: #111111;\n",
       "  --xr-background-color-row-odd: #313131;\n",
       "}\n",
       "\n",
       ".xr-wrap {\n",
       "  display: block;\n",
       "  min-width: 300px;\n",
       "  max-width: 700px;\n",
       "}\n",
       "\n",
       ".xr-text-repr-fallback {\n",
       "  /* fallback to plain text repr when CSS is not injected (untrusted notebook) */\n",
       "  display: none;\n",
       "}\n",
       "\n",
       ".xr-header {\n",
       "  padding-top: 6px;\n",
       "  padding-bottom: 6px;\n",
       "  margin-bottom: 4px;\n",
       "  border-bottom: solid 1px var(--xr-border-color);\n",
       "}\n",
       "\n",
       ".xr-header > div,\n",
       ".xr-header > ul {\n",
       "  display: inline;\n",
       "  margin-top: 0;\n",
       "  margin-bottom: 0;\n",
       "}\n",
       "\n",
       ".xr-obj-type,\n",
       ".xr-array-name {\n",
       "  margin-left: 2px;\n",
       "  margin-right: 10px;\n",
       "}\n",
       "\n",
       ".xr-obj-type {\n",
       "  color: var(--xr-font-color2);\n",
       "}\n",
       "\n",
       ".xr-sections {\n",
       "  padding-left: 0 !important;\n",
       "  display: grid;\n",
       "  grid-template-columns: 150px auto auto 1fr 20px 20px;\n",
       "}\n",
       "\n",
       ".xr-section-item {\n",
       "  display: contents;\n",
       "}\n",
       "\n",
       ".xr-section-item input {\n",
       "  display: none;\n",
       "}\n",
       "\n",
       ".xr-section-item input + label {\n",
       "  color: var(--xr-disabled-color);\n",
       "}\n",
       "\n",
       ".xr-section-item input:enabled + label {\n",
       "  cursor: pointer;\n",
       "  color: var(--xr-font-color2);\n",
       "}\n",
       "\n",
       ".xr-section-item input:enabled + label:hover {\n",
       "  color: var(--xr-font-color0);\n",
       "}\n",
       "\n",
       ".xr-section-summary {\n",
       "  grid-column: 1;\n",
       "  color: var(--xr-font-color2);\n",
       "  font-weight: 500;\n",
       "}\n",
       "\n",
       ".xr-section-summary > span {\n",
       "  display: inline-block;\n",
       "  padding-left: 0.5em;\n",
       "}\n",
       "\n",
       ".xr-section-summary-in:disabled + label {\n",
       "  color: var(--xr-font-color2);\n",
       "}\n",
       "\n",
       ".xr-section-summary-in + label:before {\n",
       "  display: inline-block;\n",
       "  content: '►';\n",
       "  font-size: 11px;\n",
       "  width: 15px;\n",
       "  text-align: center;\n",
       "}\n",
       "\n",
       ".xr-section-summary-in:disabled + label:before {\n",
       "  color: var(--xr-disabled-color);\n",
       "}\n",
       "\n",
       ".xr-section-summary-in:checked + label:before {\n",
       "  content: '▼';\n",
       "}\n",
       "\n",
       ".xr-section-summary-in:checked + label > span {\n",
       "  display: none;\n",
       "}\n",
       "\n",
       ".xr-section-summary,\n",
       ".xr-section-inline-details {\n",
       "  padding-top: 4px;\n",
       "  padding-bottom: 4px;\n",
       "}\n",
       "\n",
       ".xr-section-inline-details {\n",
       "  grid-column: 2 / -1;\n",
       "}\n",
       "\n",
       ".xr-section-details {\n",
       "  display: none;\n",
       "  grid-column: 1 / -1;\n",
       "  margin-bottom: 5px;\n",
       "}\n",
       "\n",
       ".xr-section-summary-in:checked ~ .xr-section-details {\n",
       "  display: contents;\n",
       "}\n",
       "\n",
       ".xr-array-wrap {\n",
       "  grid-column: 1 / -1;\n",
       "  display: grid;\n",
       "  grid-template-columns: 20px auto;\n",
       "}\n",
       "\n",
       ".xr-array-wrap > label {\n",
       "  grid-column: 1;\n",
       "  vertical-align: top;\n",
       "}\n",
       "\n",
       ".xr-preview {\n",
       "  color: var(--xr-font-color3);\n",
       "}\n",
       "\n",
       ".xr-array-preview,\n",
       ".xr-array-data {\n",
       "  padding: 0 5px !important;\n",
       "  grid-column: 2;\n",
       "}\n",
       "\n",
       ".xr-array-data,\n",
       ".xr-array-in:checked ~ .xr-array-preview {\n",
       "  display: none;\n",
       "}\n",
       "\n",
       ".xr-array-in:checked ~ .xr-array-data,\n",
       ".xr-array-preview {\n",
       "  display: inline-block;\n",
       "}\n",
       "\n",
       ".xr-dim-list {\n",
       "  display: inline-block !important;\n",
       "  list-style: none;\n",
       "  padding: 0 !important;\n",
       "  margin: 0;\n",
       "}\n",
       "\n",
       ".xr-dim-list li {\n",
       "  display: inline-block;\n",
       "  padding: 0;\n",
       "  margin: 0;\n",
       "}\n",
       "\n",
       ".xr-dim-list:before {\n",
       "  content: '(';\n",
       "}\n",
       "\n",
       ".xr-dim-list:after {\n",
       "  content: ')';\n",
       "}\n",
       "\n",
       ".xr-dim-list li:not(:last-child):after {\n",
       "  content: ',';\n",
       "  padding-right: 5px;\n",
       "}\n",
       "\n",
       ".xr-has-index {\n",
       "  font-weight: bold;\n",
       "}\n",
       "\n",
       ".xr-var-list,\n",
       ".xr-var-item {\n",
       "  display: contents;\n",
       "}\n",
       "\n",
       ".xr-var-item > div,\n",
       ".xr-var-item label,\n",
       ".xr-var-item > .xr-var-name span {\n",
       "  background-color: var(--xr-background-color-row-even);\n",
       "  margin-bottom: 0;\n",
       "}\n",
       "\n",
       ".xr-var-item > .xr-var-name:hover span {\n",
       "  padding-right: 5px;\n",
       "}\n",
       "\n",
       ".xr-var-list > li:nth-child(odd) > div,\n",
       ".xr-var-list > li:nth-child(odd) > label,\n",
       ".xr-var-list > li:nth-child(odd) > .xr-var-name span {\n",
       "  background-color: var(--xr-background-color-row-odd);\n",
       "}\n",
       "\n",
       ".xr-var-name {\n",
       "  grid-column: 1;\n",
       "}\n",
       "\n",
       ".xr-var-dims {\n",
       "  grid-column: 2;\n",
       "}\n",
       "\n",
       ".xr-var-dtype {\n",
       "  grid-column: 3;\n",
       "  text-align: right;\n",
       "  color: var(--xr-font-color2);\n",
       "}\n",
       "\n",
       ".xr-var-preview {\n",
       "  grid-column: 4;\n",
       "}\n",
       "\n",
       ".xr-var-name,\n",
       ".xr-var-dims,\n",
       ".xr-var-dtype,\n",
       ".xr-preview,\n",
       ".xr-attrs dt {\n",
       "  white-space: nowrap;\n",
       "  overflow: hidden;\n",
       "  text-overflow: ellipsis;\n",
       "  padding-right: 10px;\n",
       "}\n",
       "\n",
       ".xr-var-name:hover,\n",
       ".xr-var-dims:hover,\n",
       ".xr-var-dtype:hover,\n",
       ".xr-attrs dt:hover {\n",
       "  overflow: visible;\n",
       "  width: auto;\n",
       "  z-index: 1;\n",
       "}\n",
       "\n",
       ".xr-var-attrs,\n",
       ".xr-var-data {\n",
       "  display: none;\n",
       "  background-color: var(--xr-background-color) !important;\n",
       "  padding-bottom: 5px !important;\n",
       "}\n",
       "\n",
       ".xr-var-attrs-in:checked ~ .xr-var-attrs,\n",
       ".xr-var-data-in:checked ~ .xr-var-data {\n",
       "  display: block;\n",
       "}\n",
       "\n",
       ".xr-var-data > table {\n",
       "  float: right;\n",
       "}\n",
       "\n",
       ".xr-var-name span,\n",
       ".xr-var-data,\n",
       ".xr-attrs {\n",
       "  padding-left: 25px !important;\n",
       "}\n",
       "\n",
       ".xr-attrs,\n",
       ".xr-var-attrs,\n",
       ".xr-var-data {\n",
       "  grid-column: 1 / -1;\n",
       "}\n",
       "\n",
       "dl.xr-attrs {\n",
       "  padding: 0;\n",
       "  margin: 0;\n",
       "  display: grid;\n",
       "  grid-template-columns: 125px auto;\n",
       "}\n",
       "\n",
       ".xr-attrs dt,\n",
       ".xr-attrs dd {\n",
       "  padding: 0;\n",
       "  margin: 0;\n",
       "  float: left;\n",
       "  padding-right: 10px;\n",
       "  width: auto;\n",
       "}\n",
       "\n",
       ".xr-attrs dt {\n",
       "  font-weight: normal;\n",
       "  grid-column: 1;\n",
       "}\n",
       "\n",
       ".xr-attrs dt:hover span {\n",
       "  display: inline-block;\n",
       "  background: var(--xr-background-color);\n",
       "  padding-right: 10px;\n",
       "}\n",
       "\n",
       ".xr-attrs dd {\n",
       "  grid-column: 2;\n",
       "  white-space: pre-wrap;\n",
       "  word-break: break-all;\n",
       "}\n",
       "\n",
       ".xr-icon-database,\n",
       ".xr-icon-file-text2 {\n",
       "  display: inline-block;\n",
       "  vertical-align: middle;\n",
       "  width: 1em;\n",
       "  height: 1.5em !important;\n",
       "  stroke-width: 0;\n",
       "  stroke: currentColor;\n",
       "  fill: currentColor;\n",
       "}\n",
       "</style><pre class='xr-text-repr-fallback'>&lt;xarray.DataArray &#x27;norm_scenario_proba_cond_seq&#x27; ()&gt;\n",
       "array(0.997)</pre><div class='xr-wrap' hidden><div class='xr-header'><div class='xr-obj-type'>xarray.DataArray</div><div class='xr-array-name'>'norm_scenario_proba_cond_seq'</div></div><ul class='xr-sections'><li class='xr-section-item'><div class='xr-array-wrap'><input id='section-39e24153-1f2f-4546-a9b3-9ace6a206d92' class='xr-array-in' type='checkbox' checked><label for='section-39e24153-1f2f-4546-a9b3-9ace6a206d92' title='Show/hide data repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-array-preview xr-preview'><span>0.997</span></div><div class='xr-array-data'><pre>array(0.997)</pre></div></div></li><li class='xr-section-item'><input id='section-23fe4da7-edf4-464b-996e-a3962013a689' class='xr-section-summary-in' type='checkbox' disabled ><label for='section-23fe4da7-edf4-464b-996e-a3962013a689' class='xr-section-summary'  title='Expand/collapse section'>Coordinates: <span>(0)</span></label><div class='xr-section-inline-details'></div><div class='xr-section-details'><ul class='xr-var-list'></ul></div></li><li class='xr-section-item'><input id='section-a54dd2cd-5561-46de-9051-ae860e5bdb4d' class='xr-section-summary-in' type='checkbox' disabled ><label for='section-a54dd2cd-5561-46de-9051-ae860e5bdb4d' class='xr-section-summary'  title='Expand/collapse section'>Attributes: <span>(0)</span></label><div class='xr-section-inline-details'></div><div class='xr-section-details'><dl class='xr-attrs'></dl></div></li></ul></div></div>"
      ],
      "text/plain": [
       "<xarray.DataArray 'norm_scenario_proba_cond_seq' ()>\n",
       "array(0.997)"
      ]
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "da_n_hydro.sum()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.collections.QuadMesh at 0x7f9a9270ddd0>"
      ]
     },
     "execution_count": 52,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 17368 characters]\n",
      "text/plain": [
       "<Figure size 720x720 with 2 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "da_gene_n_hydro = mdl.get_P_from_scenarios_cols(df_scenarios, ['j_choice', 'n_hydro'])\n",
    "fig, ax = plt.subplots(figsize=(10,10))\n",
    "da_gene_n_hydro.plot(ax=ax, cmap='gnuplot2_r')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[<matplotlib.lines.Line2D at 0x7f9a9cabedd0>]"
      ]
     },
     "execution_count": 53,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 15908 characters]\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "da_gene_n_hydro.sel({'j_choice': 4}).plot()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.collections.QuadMesh at 0x7f9a91bc9150>"
      ]
     },
     "execution_count": 60,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 55692 characters]\n",
      "text/plain": [
       "<Figure size 1440x1440 with 8 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "da_2genes_n_hydro = mdl.get_P_from_scenarios_cols(df_scenarios, ['j_choice', 'd_gene', 'n_hydro'])\n",
    "fig, ax = plt.subplots(2,2, figsize=(20,20))\n",
    "da_2genes_n_hydro.sel({'d_gene': 0 }).plot(ax=ax[0][0], cmap='gnuplot2_r')\n",
    "da_2genes_n_hydro.sel({'d_gene': 1 }).plot(ax=ax[0][1], cmap='gnuplot2_r')\n",
    "da_2genes_n_hydro.sel({'d_gene': 2 }).plot(ax=ax[1][0], cmap='gnuplot2_r')\n",
    "da_2genes_n_hydro.sum(dim='d_gene').plot(ax=ax[1][1], cmap='gnuplot2_r')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "def observable_correlation(ps_scenario):\n",
    "    vd_ins = mdl.realization(ps_scenario, 'vd_ins')\n",
    "    dj_ins = mdl.realization(ps_scenario, 'dj_ins')\n",
    "    return vd_ins.value*dj_ins.value"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "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>scenario_rank</th>\n",
       "      <th>scenario_proba_cond_seq</th>\n",
       "      <th>v_choice</th>\n",
       "      <th>j_choice</th>\n",
       "      <th>d_gene</th>\n",
       "      <th>v_3_del</th>\n",
       "      <th>d_5_del</th>\n",
       "      <th>j_5_del</th>\n",
       "      <th>d_3_del</th>\n",
       "      <th>vd_ins</th>\n",
       "      <th>vd_dinucl</th>\n",
       "      <th>dj_ins</th>\n",
       "      <th>dj_dinucl</th>\n",
       "      <th>Mismatches</th>\n",
       "      <th>norm_scenario_proba_cond_seq</th>\n",
       "      <th>CDR3</th>\n",
       "      <th>ins_corr</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>seq_index</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>998</th>\n",
       "      <td>1</td>\n",
       "      <td>0.783497</td>\n",
       "      <td>77</td>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "      <td>9</td>\n",
       "      <td>6</td>\n",
       "      <td>19</td>\n",
       "      <td>9</td>\n",
       "      <td>4</td>\n",
       "      <td>[1, 1, 2, 3]</td>\n",
       "      <td>7</td>\n",
       "      <td>[2, 2, 2, 2, 0, 2, 0]</td>\n",
       "      <td>[]</td>\n",
       "      <td>0.000801</td>\n",
       "      <td>NoProductive</td>\n",
       "      <td>28</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>998</th>\n",
       "      <td>2</td>\n",
       "      <td>0.076884</td>\n",
       "      <td>77</td>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "      <td>9</td>\n",
       "      <td>6</td>\n",
       "      <td>19</td>\n",
       "      <td>10</td>\n",
       "      <td>4</td>\n",
       "      <td>[1, 1, 2, 3]</td>\n",
       "      <td>8</td>\n",
       "      <td>[2, 2, 2, 2, 0, 2, 0, 2]</td>\n",
       "      <td>[]</td>\n",
       "      <td>0.000079</td>\n",
       "      <td>NoProductive</td>\n",
       "      <td>32</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>998</th>\n",
       "      <td>3</td>\n",
       "      <td>0.043634</td>\n",
       "      <td>77</td>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "      <td>9</td>\n",
       "      <td>7</td>\n",
       "      <td>19</td>\n",
       "      <td>9</td>\n",
       "      <td>5</td>\n",
       "      <td>[1, 1, 2, 3, 2]</td>\n",
       "      <td>7</td>\n",
       "      <td>[2, 2, 2, 2, 0, 2, 0]</td>\n",
       "      <td>[]</td>\n",
       "      <td>0.000045</td>\n",
       "      <td>NoProductive</td>\n",
       "      <td>35</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>998</th>\n",
       "      <td>4</td>\n",
       "      <td>0.023517</td>\n",
       "      <td>77</td>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "      <td>10</td>\n",
       "      <td>6</td>\n",
       "      <td>19</td>\n",
       "      <td>9</td>\n",
       "      <td>5</td>\n",
       "      <td>[1, 1, 1, 2, 3]</td>\n",
       "      <td>7</td>\n",
       "      <td>[2, 2, 2, 2, 0, 2, 0]</td>\n",
       "      <td>[]</td>\n",
       "      <td>0.000024</td>\n",
       "      <td>NoProductive</td>\n",
       "      <td>35</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>998</th>\n",
       "      <td>5</td>\n",
       "      <td>0.021809</td>\n",
       "      <td>77</td>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "      <td>9</td>\n",
       "      <td>8</td>\n",
       "      <td>19</td>\n",
       "      <td>9</td>\n",
       "      <td>6</td>\n",
       "      <td>[1, 1, 2, 3, 2, 0]</td>\n",
       "      <td>7</td>\n",
       "      <td>[2, 2, 2, 2, 0, 2, 0]</td>\n",
       "      <td>[]</td>\n",
       "      <td>0.000022</td>\n",
       "      <td>NoProductive</td>\n",
       "      <td>42</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "           scenario_rank  scenario_proba_cond_seq  v_choice  j_choice  d_gene  \\\n",
       "seq_index                                                                       \n",
       "998                    1                 0.783497        77         4       0   \n",
       "998                    2                 0.076884        77         4       0   \n",
       "998                    3                 0.043634        77         4       0   \n",
       "998                    4                 0.023517        77         4       0   \n",
       "998                    5                 0.021809        77         4       0   \n",
       "\n",
       "           v_3_del  d_5_del  j_5_del  d_3_del  vd_ins           vd_dinucl  \\\n",
       "seq_index                                                                   \n",
       "998              9        6       19        9       4        [1, 1, 2, 3]   \n",
       "998              9        6       19       10       4        [1, 1, 2, 3]   \n",
       "998              9        7       19        9       5     [1, 1, 2, 3, 2]   \n",
       "998             10        6       19        9       5     [1, 1, 1, 2, 3]   \n",
       "998              9        8       19        9       6  [1, 1, 2, 3, 2, 0]   \n",
       "\n",
       "           dj_ins                 dj_dinucl Mismatches  \\\n",
       "seq_index                                                \n",
       "998             7     [2, 2, 2, 2, 0, 2, 0]         []   \n",
       "998             8  [2, 2, 2, 2, 0, 2, 0, 2]         []   \n",
       "998             7     [2, 2, 2, 2, 0, 2, 0]         []   \n",
       "998             7     [2, 2, 2, 2, 0, 2, 0]         []   \n",
       "998             7     [2, 2, 2, 2, 0, 2, 0]         []   \n",
       "\n",
       "           norm_scenario_proba_cond_seq          CDR3  ins_corr  \n",
       "seq_index                                                        \n",
       "998                            0.000801  NoProductive        28  \n",
       "998                            0.000079  NoProductive        32  \n",
       "998                            0.000045  NoProductive        35  \n",
       "998                            0.000024  NoProductive        35  \n",
       "998                            0.000022  NoProductive        42  "
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_scenarios['ins_corr'] = mdl.get_observable_from_scenarios_dataframe(observable_correlation, df_scenarios)\n",
    "df_scenarios.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.collections.QuadMesh at 0x7ff1b4210d10>"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 17276 characters]\n",
      "text/plain": [
       "<Figure size 432x288 with 2 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "da = mdl.get_P_from_scenarios_cols(df_scenarios, ['v_choice', 'dj_ins','ins_corr'])\n",
    "da.sum('ins_corr').plot(cmap='gnuplot2_r')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "ins_corr\n",
       "0      0.126748\n",
       "1      0.003528\n",
       "2      0.015140\n",
       "3      0.016946\n",
       "4      0.032758\n",
       "         ...   \n",
       "224    0.000097\n",
       "228    0.000206\n",
       "231    0.000062\n",
       "234    0.000157\n",
       "238    0.000126\n",
       "Name: norm_scenario_proba_cond_seq, Length: 133, dtype: float64"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "aaa = df_scenarios.groupby('ins_corr')['norm_scenario_proba_cond_seq'].sum()\n",
    "aaa"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "pandas.core.series.Series"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type(aaa)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "25.985685213409095"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(df_scenarios['ins_corr']*df_scenarios['norm_scenario_proba_cond_seq']).sum()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "25.985685213409095"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "average = (mdl.get_observable_from_scenarios_dataframe(observable_correlation, df_scenarios)*df_scenarios['norm_scenario_proba_cond_seq'] ).sum()\n",
    "average"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 176,
   "metadata": {},
   "outputs": [],
   "source": [
    "v_choice = mdl.realization(df_scenarios, 'v_choice')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "seq_index\n",
       "998    77\n",
       "998    77\n",
       "998    77\n",
       "998    77\n",
       "998    77\n",
       "       ..\n",
       "703    45\n",
       "703    45\n",
       "703    45\n",
       "703    45\n",
       "703    45\n",
       "Name: v_choice, Length: 10000, dtype: int64"
      ]
     },
     "execution_count": 57,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "v_choice.id"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array(['GGTGCTGGAGTCTCCCAGTCCCCAAGGTACAAAGTCGCAAAGAGGGGACGGGATGTAGCTCTCAGGTGTGATTCAATTTCGGGTCATGTAACCCTTTATTGGTACCGACAGACCCTGGGGCAGGGCTCAGAGGTTCTGACTTACTCCCAGAGTGATGCTCAACGAGACAAATCAGGGCGGCCCAGTGGTCGGTTCTCTGCAGAGAGGCCTGAGAGATCCGTCTCCACTCTGAAGATCCAGCGCACAGAGCAGGGGGACTCAGCTGTGTATCTCTGTGCCAGCAGCTTAGC',\n",
       "       'GGTGCTGGAGTCTCCCAGTCCCCAAGGTACAAAGTCGCAAAGAGGGGACGGGATGTAGCTCTCAGGTGTGATTCAATTTCGGGTCATGTAACCCTTTATTGGTACCGACAGACCCTGGGGCAGGGCTCAGAGGTTCTGACTTACTCCCAGAGTGATGCTCAACGAGACAAATCAGGGCGGCCCAGTGGTCGGTTCTCTGCAGAGAGGCCTGAGAGATCCGTCTCCACTCTGAAGATCCAGCGCACAGAGCAGGGGGACTCAGCTGTGTATCTCTGTGCCAGCAGCTTAGC',\n",
       "       'GGTGCTGGAGTCTCCCAGTCCCCAAGGTACAAAGTCGCAAAGAGGGGACGGGATGTAGCTCTCAGGTGTGATTCAATTTCGGGTCATGTAACCCTTTATTGGTACCGACAGACCCTGGGGCAGGGCTCAGAGGTTCTGACTTACTCCCAGAGTGATGCTCAACGAGACAAATCAGGGCGGCCCAGTGGTCGGTTCTCTGCAGAGAGGCCTGAGAGATCCGTCTCCACTCTGAAGATCCAGCGCACAGAGCAGGGGGACTCAGCTGTGTATCTCTGTGCCAGCAGCTTAGC',\n",
       "       ...,\n",
       "       'ACTGAAGTTACCCAGACACCAAAACACCTGGTCATGGGAATGACAAATAAGAAGTCTTTGAAATGTGAACAACATATGGGGCACAGGGCTATGTATTGGTACAAGCAGAAAGCTAAGAAGCCACCGGAGCTCATGTTTGTCTACAGCTATGAGAAACTCTCTATAAATGAAAGTGTGCCAAGTCGCTTCTCACCTGAATGCCCCAACAGCTCTCTCTTAAACCTTCACCTACACGCCCTGCAGCCAGAAGACTCAGCCCTGTATCTCTGCGCCAGCAGCCAAGA',\n",
       "       'ACTGAAGTTACCCAGACACCAAAACACCTGGTCATGGGAATGACAAATAAGAAGTCTTTGAAATGTGAACAACATATGGGGCACAGGGCTATGTATTGGTACAAGCAGAAAGCTAAGAAGCCACCGGAGCTCATGTTTGTCTACAGCTATGAGAAACTCTCTATAAATGAAAGTGTGCCAAGTCGCTTCTCACCTGAATGCCCCAACAGCTCTCTCTTAAACCTTCACCTACACGCCCTGCAGCCAGAAGACTCAGCCCTGTATCTCTGCGCCAGCAGCCAAGA',\n",
       "       'ACTGAAGTTACCCAGACACCAAAACACCTGGTCATGGGAATGACAAATAAGAAGTCTTTGAAATGTGAACAACATATGGGGCACAGGGCTATGTATTGGTACAAGCAGAAAGCTAAGAAGCCACCGGAGCTCATGTTTGTCTACAGCTATGAGAAACTCTCTATAAATGAAAGTGTGCCAAGTCGCTTCTCACCTGAATGCCCCAACAGCTCTCTCTTAAACCTTCACCTACACGCCCTGCAGCCAGAAGACTCAGCCCTGTATCTCTGCGCCAGCAGCCAAGA'],\n",
       "      dtype=object)"
      ]
     },
     "execution_count": 49,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "v_choice.value"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array(['L36092|TRBV7-4*01|Homo sapiens|F|V-REGION|270051..270340|290 nt|1| | | | |290+0=290| | |',\n",
       "       'L36092|TRBV7-4*01|Homo sapiens|F|V-REGION|270051..270340|290 nt|1| | | | |290+0=290| | |',\n",
       "       'L36092|TRBV7-4*01|Homo sapiens|F|V-REGION|270051..270340|290 nt|1| | | | |290+0=290| | |',\n",
       "       ...,\n",
       "       \"U07977|TRBV4-1*01|Homo sapiens|F|V-REGION|10271..10554|284 nt|1| | | | |284+0=284|partial in 5' and 3'| |\",\n",
       "       \"U07977|TRBV4-1*01|Homo sapiens|F|V-REGION|10271..10554|284 nt|1| | | | |284+0=284|partial in 5' and 3'| |\",\n",
       "       \"U07977|TRBV4-1*01|Homo sapiens|F|V-REGION|10271..10554|284 nt|1| | | | |284+0=284|partial in 5' and 3'| |\"],\n",
       "      dtype=object)"
      ]
     },
     "execution_count": 50,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "v_choice.name"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "metadata": {},
   "outputs": [],
   "source": [
    "v_choice_ah = mdl.realization(df_scenarios.iloc[0], 'v_choice')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "77"
      ]
     },
     "execution_count": 53,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "v_choice_ah.id"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'GGTGCTGGAGTCTCCCAGTCCCCAAGGTACAAAGTCGCAAAGAGGGGACGGGATGTAGCTCTCAGGTGTGATTCAATTTCGGGTCATGTAACCCTTTATTGGTACCGACAGACCCTGGGGCAGGGCTCAGAGGTTCTGACTTACTCCCAGAGTGATGCTCAACGAGACAAATCAGGGCGGCCCAGTGGTCGGTTCTCTGCAGAGAGGCCTGAGAGATCCGTCTCCACTCTGAAGATCCAGCGCACAGAGCAGGGGGACTCAGCTGTGTATCTCTGTGCCAGCAGCTTAGC'"
      ]
     },
     "execution_count": 54,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "v_choice_ah.value"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'L36092|TRBV7-4*01|Homo sapiens|F|V-REGION|270051..270340|290 nt|1| | | | |290+0=290| | |'"
      ]
     },
     "execution_count": 55,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "v_choice_ah.name"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "metadata": {},
   "outputs": [],
   "source": [
    "vd_dinucl = mdl.realization(df_scenarios.iloc[0], 'vd_dinucl')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 1, 2, 3]"
      ]
     },
     "execution_count": 60,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "vd_dinucl.id"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array(['C', 'C', 'G', 'T'], dtype=object)"
      ]
     },
     "execution_count": 61,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "vd_dinucl.value"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array(['', '', '', ''], dtype=object)"
      ]
     },
     "execution_count": 62,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "vd_dinucl.name"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "metadata": {},
   "outputs": [],
   "source": [
    "vd_dinucl = mdl.realization(df_scenarios.iloc[0], 'vd_dinucl')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 1, 2, 3]"
      ]
     },
     "execution_count": 65,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "vd_dinucl.id"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array(['C', 'C', 'G', 'T'], dtype=object)"
      ]
     },
     "execution_count": 66,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "vd_dinucl.value"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array(['', '', '', ''], dtype=object)"
      ]
     },
     "execution_count": 67,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "vd_dinucl.name"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 69,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "seq_index\n",
       "998                [1, 1, 2, 3]\n",
       "998                [1, 1, 2, 3]\n",
       "998             [1, 1, 2, 3, 2]\n",
       "998             [1, 1, 1, 2, 3]\n",
       "998          [1, 1, 2, 3, 2, 0]\n",
       "                 ...           \n",
       "703          [2, 2, 1, 0, 3, 3]\n",
       "703             [2, 1, 0, 3, 3]\n",
       "703             [2, 1, 0, 3, 3]\n",
       "703    [2, 2, 1, 0, 3, 3, 2, 1]\n",
       "703    [2, 1, 0, 3, 3, 2, 1, 2]\n",
       "Name: vd_dinucl, Length: 10000, dtype: object"
      ]
     },
     "execution_count": 69,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_scenarios['vd_dinucl']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 77,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([list([1, 1, 2, 3]), list([1, 1, 2, 3]), list([1, 1, 2, 3, 2]), ...,\n",
       "       list([2, 1, 0, 3, 3]), list([2, 2, 1, 0, 3, 3, 2, 1]),\n",
       "       list([2, 1, 0, 3, 3, 2, 1, 2])], dtype=object)"
      ]
     },
     "execution_count": 77,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ids = df_scenarios['vd_dinucl'].values\n",
    "ids"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 74,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "seq_index\n",
       "998                [1, 1, 2, 3]\n",
       "998                [1, 1, 2, 3]\n",
       "998             [1, 1, 2, 3, 2]\n",
       "998             [1, 1, 1, 2, 3]\n",
       "998          [1, 1, 2, 3, 2, 0]\n",
       "                 ...           \n",
       "703          [2, 2, 1, 0, 3, 3]\n",
       "703             [2, 1, 0, 3, 3]\n",
       "703             [2, 1, 0, 3, 3]\n",
       "703    [2, 2, 1, 0, 3, 3, 2, 1]\n",
       "703    [2, 1, 0, 3, 3, 2, 1, 2]\n",
       "Name: vd_dinucl, Length: 10000, dtype: object"
      ]
     },
     "execution_count": 74,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_scenarios['vd_dinucl']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 78,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 78,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "isinstance(df_scenarios['vd_dinucl'], pd.DataFrame)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 159,
   "metadata": {},
   "outputs": [],
   "source": [
    "### As a pandas series\n",
    "def realiz_map(list_of_ids):\n",
    "    pd_dataframe = mdl.parms.Event_dict[event_nickname].loc[list_of_ids]\n",
    "    return pd_dataframe\n",
    "\n",
    "def realiz_map_value(list_of_ids):\n",
    "    pd_dataframe = mdl.parms.Event_dict[event_nickname].loc[list_of_ids]\n",
    "    return pd_dataframe.value.values\n",
    "\n",
    "def realiz_map_name(list_of_ids):\n",
    "    pd_dataframe = mdl.parms.Event_dict[event_nickname].loc[list_of_ids]\n",
    "    return pd_dataframe.name.values\n",
    "v_realiz_map_value = np.vectorize(realiz_map_value)\n",
    "v_realiz_map_name = np.vectorize(realiz_map_name)\n",
    "v_realiz_map = np.vectorize(realiz_map)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 160,
   "metadata": {},
   "outputs": [],
   "source": [
    "# event_nickname = 'v_choice'\n",
    "event_nickname = 'vd_dinucl'\n",
    "id = df_scenarios[event_nickname]\n",
    "if isinstance(id, pd.Series):\n",
    "    if id.values.dtype == 'object':\n",
    "        # So I need to put this as a map\n",
    "        realiz = v_realiz_map(id.values)\n",
    "    else:\n",
    "        realiz = mdl.parms.Event_dict[event_nickname].loc[id.values]\n",
    "# IT ACCEPTS NUMPY ARRAYS AS INDICES.\n",
    "# realiz"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 272,
   "metadata": {},
   "outputs": [],
   "source": [
    "realiz = mdl.realization(df_scenarios, 'v_choice')\n",
    "# realiz"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 278,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/home/olivares/anaconda3/envs/pygor3-dev/lib/python3.7/site-packages/ipykernel_launcher.py:2: SettingWithCopyWarning: \n",
      "A value is trying to be set on a copy of a slice from a DataFrame\n",
      "\n",
      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
      "  \n"
     ]
    }
   ],
   "source": [
    "\n",
    "# realiz.id['value'] = realiz.value"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 209,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "seq_index\n",
       "998                [1, 1, 2, 3]\n",
       "998                [1, 1, 2, 3]\n",
       "998             [1, 1, 2, 3, 2]\n",
       "998             [1, 1, 1, 2, 3]\n",
       "998          [1, 1, 2, 3, 2, 0]\n",
       "                 ...           \n",
       "703          [2, 2, 1, 0, 3, 3]\n",
       "703             [2, 1, 0, 3, 3]\n",
       "703             [2, 1, 0, 3, 3]\n",
       "703    [2, 2, 1, 0, 3, 3, 2, 1]\n",
       "703    [2, 1, 0, 3, 3, 2, 1, 2]\n",
       "Name: vd_dinucl, Length: 10000, dtype: object"
      ]
     },
     "execution_count": 209,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "event_nickname = 'vd_dinucl'\n",
    "id = df_scenarios[event_nickname]\n",
    "id"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 247,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_tmp = pd.DataFrame()\n",
    "df_tmp['id'] = df_scenarios[event_nickname]\n",
    "df_tmp['value'] = df_scenarios[event_nickname].apply(lambda x: mdl.parms.Event_dict[event_nickname].loc[x].value.values)\n",
    "df_tmp['name'] = df_scenarios[event_nickname].apply(lambda x: mdl.parms.Event_dict[event_nickname].loc[x].name.values)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 267,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'CCGT'"
      ]
     },
     "execution_count": 267,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "oop = df_tmp.to_records(index=False)\n",
    "oop[0].value\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 266,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array(['C', 'C', 'G', 'T'], dtype=object)"
      ]
     },
     "execution_count": 266,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "myfunc = lambda x: \"\".join(x.value)\n",
    "myfunc(oop[0])\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 264,
   "metadata": {},
   "outputs": [
    {
     "ename": "AttributeError",
     "evalue": "'tuple' object has no attribute 'value'",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mAttributeError\u001b[0m                            Traceback (most recent call last)",
      "\u001b[0;32m<ipython-input-264-b63bb87d5fcd>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m      1\u001b[0m \u001b[0mv_myfunc\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mvectorize\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mmyfunc\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m \u001b[0mv_myfunc\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0moop\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[0;32m~/anaconda3/envs/pygor3-dev/lib/python3.7/site-packages/numpy/lib/function_base.py\u001b[0m in \u001b[0;36m__call__\u001b[0;34m(self, *args, **kwargs)\u001b[0m\n\u001b[1;32m   2106\u001b[0m             \u001b[0mvargs\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mextend\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0m_n\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0m_n\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mnames\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m   2107\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 2108\u001b[0;31m         \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_vectorize_call\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mfunc\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mfunc\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0margs\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mvargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m   2109\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m   2110\u001b[0m     \u001b[0;32mdef\u001b[0m \u001b[0m_get_ufunc_and_otypes\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mfunc\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0margs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m~/anaconda3/envs/pygor3-dev/lib/python3.7/site-packages/numpy/lib/function_base.py\u001b[0m in \u001b[0;36m_vectorize_call\u001b[0;34m(self, func, args)\u001b[0m\n\u001b[1;32m   2190\u001b[0m                       for a in args]\n\u001b[1;32m   2191\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 2192\u001b[0;31m             \u001b[0moutputs\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mufunc\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0minputs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m   2193\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m   2194\u001b[0m             \u001b[0;32mif\u001b[0m \u001b[0mufunc\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mnout\u001b[0m \u001b[0;34m==\u001b[0m \u001b[0;36m1\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m<ipython-input-262-4ad6a57ece28>\u001b[0m in \u001b[0;36m<lambda>\u001b[0;34m(x)\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mmyfunc\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;32mlambda\u001b[0m \u001b[0mx\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0;34m\"\"\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mjoin\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mx\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mvalue\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m      2\u001b[0m \u001b[0mmyfunc\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0moop\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;31mAttributeError\u001b[0m: 'tuple' object has no attribute 'value'"
     ]
    }
   ],
   "source": [
    "v_myfunc = np.vectorize(myfunc)\n",
    "v_myfunc(oop)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# FIXME: isinstance(id, pd.Series)\n",
    "realiz = \n",
    "realiz.index.values\n",
    "# realiz.value.values\n",
    "# realiz.name.values"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 224,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Original dataframe:\n",
      "g e e k s f o r g e e k s\n",
      "g e e k s f o r g e e k s\n",
      "g e e k s f o r g e e k s\n",
      "g e e k s f o r g e e k s\n",
      "g e e k s f o r g e e k s\n",
      "\n",
      "Transformed dataframe:\n",
      "e e e e f g g k k o r s s\n",
      "e e e e f g g k k o r s s\n",
      "e e e e f g g k k o r s s\n",
      "e e e e f g g k k o r s s\n",
      "e e e e f g g k k o r s s\n",
      "\n"
     ]
    }
   ],
   "source": [
    "import pandas as pd\n",
    "   \n",
    "# Dataframe generation\n",
    "gfg_string = 'geeksforgeeks'\n",
    "gfg_list = 5 * [pd.Series(list(gfg_string))]\n",
    "   \n",
    "gfg_df = pd.DataFrame(data = gfg_list)\n",
    "print(\"Original dataframe:\\n\" + \\\n",
    "      gfg_df.to_string(index = False,\n",
    "      header = False), end = '\\n\\n')\n",
    "   \n",
    "# Using apply method for sorting \n",
    "# rows of characters present in \n",
    "# the original dataframe\n",
    "new_gfg_df = gfg_df.apply(lambda x:x.sort_values(), axis = 1)\n",
    "  \n",
    "print(\"Transformed dataframe:\\n\" + \\\n",
    "       new_gfg_df.to_string(index = False,\n",
    "            header = False), end = '\\n\\n')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 226,
   "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>0</th>\n",
       "      <th>1</th>\n",
       "      <th>2</th>\n",
       "      <th>3</th>\n",
       "      <th>4</th>\n",
       "      <th>5</th>\n",
       "      <th>6</th>\n",
       "      <th>7</th>\n",
       "      <th>8</th>\n",
       "      <th>9</th>\n",
       "      <th>10</th>\n",
       "      <th>11</th>\n",
       "      <th>12</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>g</td>\n",
       "      <td>e</td>\n",
       "      <td>e</td>\n",
       "      <td>k</td>\n",
       "      <td>s</td>\n",
       "      <td>f</td>\n",
       "      <td>o</td>\n",
       "      <td>r</td>\n",
       "      <td>g</td>\n",
       "      <td>e</td>\n",
       "      <td>e</td>\n",
       "      <td>k</td>\n",
       "      <td>s</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>g</td>\n",
       "      <td>e</td>\n",
       "      <td>e</td>\n",
       "      <td>k</td>\n",
       "      <td>s</td>\n",
       "      <td>f</td>\n",
       "      <td>o</td>\n",
       "      <td>r</td>\n",
       "      <td>g</td>\n",
       "      <td>e</td>\n",
       "      <td>e</td>\n",
       "      <td>k</td>\n",
       "      <td>s</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>g</td>\n",
       "      <td>e</td>\n",
       "      <td>e</td>\n",
       "      <td>k</td>\n",
       "      <td>s</td>\n",
       "      <td>f</td>\n",
       "      <td>o</td>\n",
       "      <td>r</td>\n",
       "      <td>g</td>\n",
       "      <td>e</td>\n",
       "      <td>e</td>\n",
       "      <td>k</td>\n",
       "      <td>s</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>g</td>\n",
       "      <td>e</td>\n",
       "      <td>e</td>\n",
       "      <td>k</td>\n",
       "      <td>s</td>\n",
       "      <td>f</td>\n",
       "      <td>o</td>\n",
       "      <td>r</td>\n",
       "      <td>g</td>\n",
       "      <td>e</td>\n",
       "      <td>e</td>\n",
       "      <td>k</td>\n",
       "      <td>s</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>g</td>\n",
       "      <td>e</td>\n",
       "      <td>e</td>\n",
       "      <td>k</td>\n",
       "      <td>s</td>\n",
       "      <td>f</td>\n",
       "      <td>o</td>\n",
       "      <td>r</td>\n",
       "      <td>g</td>\n",
       "      <td>e</td>\n",
       "      <td>e</td>\n",
       "      <td>k</td>\n",
       "      <td>s</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  0  1  2  3  4  5  6  7  8  9  10 11 12\n",
       "0  g  e  e  k  s  f  o  r  g  e  e  k  s\n",
       "1  g  e  e  k  s  f  o  r  g  e  e  k  s\n",
       "2  g  e  e  k  s  f  o  r  g  e  e  k  s\n",
       "3  g  e  e  k  s  f  o  r  g  e  e  k  s\n",
       "4  g  e  e  k  s  f  o  r  g  e  e  k  s"
      ]
     },
     "execution_count": 226,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "gfg_df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 129,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'numpy.ndarray'>\n",
      "unhashable type: 'list'\n"
     ]
    }
   ],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 190,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[77 77 77 ... 45 45 45] <class 'numpy.ndarray'>\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "array([77, 77, 77, ..., 45, 45, 45])"
      ]
     },
     "execution_count": 190,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# I need to vectorize the function\n",
    "# aaa = mdl.realization(df_scenarios, 'v_choice')\n",
    "event_nickname = 'v_choice'\n",
    "# event_nickname = 'vd_dinucl'\n",
    "id = df_scenarios[event_nickname].values\n",
    "print(id, type(id))\n",
    "# FIXME: isinstance(id, pd.Series)\n",
    "realiz = mdl.parms.Event_dict[event_nickname].loc[id]\n",
    "realiz.index.values\n",
    "# realiz.value.values\n",
    "# realiz.name.values\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 185,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[list([1, 1, 2, 3]) list([1, 1, 2, 3]) list([1, 1, 2, 3, 2]) ...\n",
      " list([2, 1, 0, 3, 3]) list([2, 2, 1, 0, 3, 3, 2, 1])\n",
      " list([2, 1, 0, 3, 3, 2, 1, 2])] <class 'numpy.ndarray'>\n"
     ]
    },
    {
     "ename": "TypeError",
     "evalue": "unhashable type: 'list'",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[0;32m<ipython-input-185-a86702870e9f>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m      3\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mid\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtype\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mid\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m      4\u001b[0m \u001b[0;31m# FIXME: isinstance(id, pd.Series)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 5\u001b[0;31m \u001b[0mrealiz\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mmdl\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mparms\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mEvent_dict\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mevent_nickname\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mloc\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mid\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m      6\u001b[0m \u001b[0mrealiz\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m~/anaconda3/envs/pygor3-dev/lib/python3.7/site-packages/pandas/core/indexing.py\u001b[0m in \u001b[0;36m__getitem__\u001b[0;34m(self, key)\u001b[0m\n\u001b[1;32m    892\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    893\u001b[0m             \u001b[0mmaybe_callable\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mcom\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mapply_if_callable\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mkey\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mobj\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 894\u001b[0;31m             \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_getitem_axis\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mmaybe_callable\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0maxis\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0maxis\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    895\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    896\u001b[0m     \u001b[0;32mdef\u001b[0m \u001b[0m_is_scalar_access\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mkey\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mTuple\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m~/anaconda3/envs/pygor3-dev/lib/python3.7/site-packages/pandas/core/indexing.py\u001b[0m in \u001b[0;36m_getitem_axis\u001b[0;34m(self, key, axis)\u001b[0m\n\u001b[1;32m   1110\u001b[0m                     \u001b[0;32mraise\u001b[0m \u001b[0mValueError\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"Cannot index with multidimensional key\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m   1111\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1112\u001b[0;31m                 \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_getitem_iterable\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mkey\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0maxis\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0maxis\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m   1113\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m   1114\u001b[0m             \u001b[0;31m# nested tuple slicing\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m~/anaconda3/envs/pygor3-dev/lib/python3.7/site-packages/pandas/core/indexing.py\u001b[0m in \u001b[0;36m_getitem_iterable\u001b[0;34m(self, key, axis)\u001b[0m\n\u001b[1;32m   1050\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m   1051\u001b[0m         \u001b[0;31m# A collection of keys\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1052\u001b[0;31m         \u001b[0mkeyarr\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mindexer\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_get_listlike_indexer\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mkey\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0maxis\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mraise_missing\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mFalse\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m   1053\u001b[0m         return self.obj._reindex_with_indexers(\n\u001b[1;32m   1054\u001b[0m             \u001b[0;34m{\u001b[0m\u001b[0maxis\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0mkeyarr\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mindexer\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m}\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcopy\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mTrue\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mallow_dups\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mTrue\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m~/anaconda3/envs/pygor3-dev/lib/python3.7/site-packages/pandas/core/indexing.py\u001b[0m in \u001b[0;36m_get_listlike_indexer\u001b[0;34m(self, key, axis, raise_missing)\u001b[0m\n\u001b[1;32m   1258\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m   1259\u001b[0m         \u001b[0;32mif\u001b[0m \u001b[0max\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_index_as_unique\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1260\u001b[0;31m             \u001b[0mindexer\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0max\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mget_indexer_for\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mkeyarr\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m   1261\u001b[0m             \u001b[0mkeyarr\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0max\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mreindex\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mkeyarr\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m   1262\u001b[0m         \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m~/anaconda3/envs/pygor3-dev/lib/python3.7/site-packages/pandas/core/indexes/base.py\u001b[0m in \u001b[0;36mget_indexer_for\u001b[0;34m(self, target, **kwargs)\u001b[0m\n\u001b[1;32m   4958\u001b[0m         \"\"\"\n\u001b[1;32m   4959\u001b[0m         \u001b[0;32mif\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_index_as_unique\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 4960\u001b[0;31m             \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mget_indexer\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtarget\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m   4961\u001b[0m         \u001b[0mindexer\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0m_\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mget_indexer_non_unique\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtarget\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m   4962\u001b[0m         \u001b[0;32mreturn\u001b[0m \u001b[0mindexer\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m~/anaconda3/envs/pygor3-dev/lib/python3.7/site-packages/pandas/core/indexes/base.py\u001b[0m in \u001b[0;36mget_indexer\u001b[0;34m(self, target, method, limit, tolerance)\u001b[0m\n\u001b[1;32m   3165\u001b[0m             \u001b[0mtarget\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mtarget\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mastype\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mobject\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m   3166\u001b[0m             return this.get_indexer(\n\u001b[0;32m-> 3167\u001b[0;31m                 \u001b[0mtarget\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mmethod\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mmethod\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mlimit\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mlimit\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtolerance\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mtolerance\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m   3168\u001b[0m             )\n\u001b[1;32m   3169\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m~/anaconda3/envs/pygor3-dev/lib/python3.7/site-packages/pandas/core/indexes/base.py\u001b[0m in \u001b[0;36mget_indexer\u001b[0;34m(self, target, method, limit, tolerance)\u001b[0m\n\u001b[1;32m   3189\u001b[0m                 )\n\u001b[1;32m   3190\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 3191\u001b[0;31m             \u001b[0mindexer\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_engine\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mget_indexer\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtarget\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_get_engine_target\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m   3192\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m   3193\u001b[0m         \u001b[0;32mreturn\u001b[0m \u001b[0mensure_platform_int\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mindexer\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32mpandas/_libs/index.pyx\u001b[0m in \u001b[0;36mpandas._libs.index.IndexEngine.get_indexer\u001b[0;34m()\u001b[0m\n",
      "\u001b[0;32mpandas/_libs/hashtable_class_helper.pxi\u001b[0m in \u001b[0;36mpandas._libs.hashtable.PyObjectHashTable.lookup\u001b[0;34m()\u001b[0m\n",
      "\u001b[0;31mTypeError\u001b[0m: unhashable type: 'list'"
     ]
    }
   ],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Testando con dataframes"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 318,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.series.Series'>\n"
     ]
    },
    {
     "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>id</th>\n",
       "      <th>value</th>\n",
       "      <th>name</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>seq_index</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>998</th>\n",
       "      <td>77</td>\n",
       "      <td>GGTGCTGGAGTCTCCCAGTCCCCAAGGTACAAAGTCGCAAAGAGGG...</td>\n",
       "      <td>L36092|TRBV7-4*01|Homo sapiens|F|V-REGION|2700...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>998</th>\n",
       "      <td>77</td>\n",
       "      <td>GGTGCTGGAGTCTCCCAGTCCCCAAGGTACAAAGTCGCAAAGAGGG...</td>\n",
       "      <td>L36092|TRBV7-4*01|Homo sapiens|F|V-REGION|2700...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>998</th>\n",
       "      <td>77</td>\n",
       "      <td>GGTGCTGGAGTCTCCCAGTCCCCAAGGTACAAAGTCGCAAAGAGGG...</td>\n",
       "      <td>L36092|TRBV7-4*01|Homo sapiens|F|V-REGION|2700...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>998</th>\n",
       "      <td>77</td>\n",
       "      <td>GGTGCTGGAGTCTCCCAGTCCCCAAGGTACAAAGTCGCAAAGAGGG...</td>\n",
       "      <td>L36092|TRBV7-4*01|Homo sapiens|F|V-REGION|2700...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>998</th>\n",
       "      <td>77</td>\n",
       "      <td>GGTGCTGGAGTCTCCCAGTCCCCAAGGTACAAAGTCGCAAAGAGGG...</td>\n",
       "      <td>L36092|TRBV7-4*01|Homo sapiens|F|V-REGION|2700...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "           id                                              value  \\\n",
       "seq_index                                                          \n",
       "998        77  GGTGCTGGAGTCTCCCAGTCCCCAAGGTACAAAGTCGCAAAGAGGG...   \n",
       "998        77  GGTGCTGGAGTCTCCCAGTCCCCAAGGTACAAAGTCGCAAAGAGGG...   \n",
       "998        77  GGTGCTGGAGTCTCCCAGTCCCCAAGGTACAAAGTCGCAAAGAGGG...   \n",
       "998        77  GGTGCTGGAGTCTCCCAGTCCCCAAGGTACAAAGTCGCAAAGAGGG...   \n",
       "998        77  GGTGCTGGAGTCTCCCAGTCCCCAAGGTACAAAGTCGCAAAGAGGG...   \n",
       "\n",
       "                                                        name  \n",
       "seq_index                                                     \n",
       "998        L36092|TRBV7-4*01|Homo sapiens|F|V-REGION|2700...  \n",
       "998        L36092|TRBV7-4*01|Homo sapiens|F|V-REGION|2700...  \n",
       "998        L36092|TRBV7-4*01|Homo sapiens|F|V-REGION|2700...  \n",
       "998        L36092|TRBV7-4*01|Homo sapiens|F|V-REGION|2700...  \n",
       "998        L36092|TRBV7-4*01|Homo sapiens|F|V-REGION|2700...  "
      ]
     },
     "execution_count": 318,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# input should be df_scenarios and event_nickname\n",
    "event_nickname = 'v_choice'\n",
    "df_scenarios[event_nickname]\n",
    "id = df_scenarios[event_nickname]\n",
    "print(type(id))\n",
    "if id.dtype == 'object':\n",
    "    print(True)\n",
    "realiz = mdl.parms.Event_dict[event_nickname].loc[id.values]\n",
    "final_df = pd.DataFrame(\n",
    "    {\n",
    "        'id' : id.values,\n",
    "        'value' : realiz.value.values,\n",
    "        'name' : realiz.name.values\n",
    "    })\n",
    "\n",
    "# id.values\n",
    "# realiz.value\n",
    "\n",
    "final_df.index = df_scenarios[event_nickname].index\n",
    "# output\n",
    "final_df.head()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "modelpath :  /home/olivares/.local/share/igor/models\n",
      "modelpath :  /home/olivares/.local/share/igor/models\n",
      "Parms filename:  /home/olivares/.local/share/igor/models/human/tcr_beta/models/model_parms.txt\n",
      "Marginals filename:  /home/olivares/.local/share/igor/models/human/tcr_beta/models/model_marginals.txt\n",
      "modelpath :  /home/olivares/.local/share/igor/models\n",
      "igor_fln_generated_realizations_werr:  delete_me/ttmmpp_output/best_scenarios_counts.csv\n"
     ]
    }
   ],
   "source": [
    "from pygor3 import *\n",
    "mdl = IgorModel.load_default(\"human\", \"tcr_beta\")\n",
    "fln_scenarios = \"delete_me/ttmmpp_output/best_scenarios_counts.csv\"\n",
    "df_scenarios = mdl.get_dataframe_scenarios(fln_scenarios)\n",
    "df_realizations = mdl.get_df_realizations_dinucl(df_scenarios, 'vd_dinucl')\n",
    "vd_seq = df_realizations.value.apply(lambda x: \"\".join(x))\n",
    "vd_counts = vd_seq.value_counts()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "82"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "vd_counts.loc['AG']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<AxesSubplot:>"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 35344 characters]\n",
      "text/plain": [
       "<Figure size 2880x720 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "import matplotlib.pyplot as plt\n",
    "fig, ax = plt.subplots(figsize=(40,10))\n",
    "# ax.set_yscale('log')\n",
    "vd_counts.head(100).plot.bar(ax)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
