{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "/home/alfaceor/Dropbox/PosDoc/IGoR/dev/MyGithub/pygor3/demo/thi/synthetic_data\n",
      "ErrorRate_record :  ('SingleErrorRate', '0.000396072')\n",
      "----- Marginals -----\n",
      "d_3_del\n",
      "d_5_del\n",
      "d_gene\n",
      "dj_dinucl\n",
      "dj_ins\n",
      "j_5_del\n",
      "j_choice\n",
      "v_3_del\n",
      "v_choice\n",
      "vd_dinucl\n",
      "vd_ins\n"
     ]
    }
   ],
   "source": [
    "import pygor3 as p3\n",
    "%cd /home/alfaceor/Dropbox/PosDoc/IGoR/dev/MyGithub/pygor3/demo/thi/synthetic_data\n",
    "db = p3.IgorSqliteDB.create_db(\"Ajam.db\")\n",
    "mdl = db.get_IgorModel()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<xarray.DataArray (d_gene: 3)>\n",
       "array([0.561407, 0.236121, 0.202472])\n",
       "Coordinates:\n",
       "  * d_gene       (d_gene) int64 0 1 2\n",
       "    lbl__d_gene  (d_gene) object ' TRBD1*01' ' TRBD2*01' ' TRBD2*02'\n",
       "    seq__d_gene  (d_gene) object 'GGGACAGGGGGC' ... 'GGGACTAGCGGGAGGG'"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "mdl.Pmarginal['d_gene']#.plot()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'id_v_choice': 49,\n",
       " 'id_j_choice': 1,\n",
       " 'id_d_gene': 0,\n",
       " 'id_v_3_del': 8,\n",
       " 'id_d_5_del': 2,\n",
       " 'id_d_3_del': 11,\n",
       " 'id_j_5_del': 7,\n",
       " 'id_vd_ins': 9,\n",
       " 'vd_dinucl': [2, 2, 0, 0, 2, 2, 2, 0, 1],\n",
       " 'id_dj_ins': 6,\n",
       " 'dj_dinucl': [1, 3, 3, 3, 3, 3],\n",
       " 'mismatches': [],\n",
       " 'mismatcheslen': 0}"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Get the CDR3 length from a bs\n",
    "seq_index = 0\n",
    "data = db.get_IgorBestScenarios_By_seq_index(seq_index)\n",
    "scen = data[0]\n",
    "#print(scen.to_dict())\n",
    "dicto = scen.realizations_ids_dict\n",
    "dicto"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "#scen.realizations_ids_dict"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "# scen.to_dict()\n",
    "# mdl.get_CDR3_fjrom_scenario(scen)\n",
    "\n",
    "# rechange dict keys\n",
    "# for key in mdl.xdata.keys():\n",
    "#     #dictionary[new_key] = dictionary.pop(old_key)\n",
    "#     new_key = key\n",
    "#     old_key = 'id_'+key\n",
    "    \n",
    "#     print(key, old_key, new_key)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'id_v_choice': 49, 'id_j_choice': 1, 'id_d_gene': 0, 'id_v_3_del': 8, 'id_d_5_del': 2, 'id_d_3_del': 11, 'id_j_5_del': 7, 'id_vd_ins': 9, 'vd_dinucl': [2, 2, 0, 0, 2, 2, 2, 0, 1], 'id_dj_ins': 6, 'dj_dinucl': [1, 3, 3, 3, 3, 3], 'mismatches': [], 'mismatcheslen': 0}\n",
      "vd_dinucl DinucMarkov\n",
      "dj_dinucl DinucMarkov\n",
      "====================\n",
      "{'vd_dinucl': [2, 2, 0, 0, 2, 2, 2, 0, 1], 'dj_dinucl': [1, 3, 3, 3, 3, 3], 'mismatches': [], 'mismatcheslen': 0, 'v_choice': 49, 'd_gene': 0, 'j_choice': 1, 'v_3_del': 8, 'd_3_del': 11, 'd_5_del': 2, 'j_5_del': 7, 'vd_ins': 9, 'dj_ins': 6}\n"
     ]
    }
   ],
   "source": [
    "print(dicto)\n",
    "for event in mdl.parms.Event_list:\n",
    "    if (event.event_type == 'DinucMarkov'):\n",
    "        print(event.nickname, event.event_type)\n",
    "    else:\n",
    "        dicto[event.nickname] = dicto.pop('id_'+event.nickname)\n",
    "print('='*20)\n",
    "print(dicto)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "name     U66059|TRBV5-1*01|Homo sapiens|F|V-REGION|1138...\n",
       "value    AAGGCTGGAGTCACTCAAACTCCAAGATATCTGATCAAAACGAGAG...\n",
       "Name: 49, dtype: object"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "mdl.parms.Event_dict['v_choice'].loc[dicto['v_choice']]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[]"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "mdl.BestScenariosHeaderList"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'seq_index': 0,\n",
       " 'gene_id': 49,\n",
       " 'score': 1405.0,\n",
       " 'offset': 0,\n",
       " 'insertions': [],\n",
       " 'deletions': [],\n",
       " 'mismatches': [282, 283, 284, 285],\n",
       " 'length': 282,\n",
       " 'offset_5_p': 0,\n",
       " 'offset_3_p': 281,\n",
       " 'strGene_name': 'U66059|TRBV5-1*01|Homo sapiens|F|V-REGION|113806..114091|286 nt|1| | | | |286+0=286| | |',\n",
       " 'strGene_class': 'V',\n",
       " 'strGene_seq': 'aaggctggagtcactcaaactccaagatatctgatcaaaacgagaggacagcaagtgacactgagctgctcccctatctctgggcataggagtgtatcctggtaccaacagaccccaggacagggccttcagttcctctttgaatacttcagtgagacacagagaaacaaaggaaacttccctggtcgattctcagggcgccagttctctaactctcgctctgagatgaatgtgagcaccttggagctgggggactcggccctttatctttgcgccagcagcttgg'}"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "aln_data = db.get_IgorAlignment_data_list_By_seq_index(\"V\", seq_index)\n",
    "aln_data[0].to_dict()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[('V',\n",
       "  1405.0,\n",
       "  'U66059|TRBV5-1*01|Homo sapiens|F|V-REGION|113806..114091|286 nt|1| | | | |286+0=286| | |'),\n",
       " ('V',\n",
       "  531.0,\n",
       "  'X61439|TRBV5-3*01|Homo sapiens|ORF|V-REGION|417..702|286 nt|1| | | | |286+0=286| | |'),\n",
       " ('V',\n",
       "  531.0,\n",
       "  'AF009660|TRBV5-3*02|Homo sapiens|ORF|V-REGION|44205..44490|286 nt|1| | | | |286+0=286| | |'),\n",
       " ('V',\n",
       "  398.0,\n",
       "  'L36092|TRBV5-8*01|Homo sapiens|F|V-REGION|355117..355402|286 nt|1| | | | |286+0=286| | |'),\n",
       " ('V',\n",
       "  388.0,\n",
       "  'L36092|TRBV5-5*01|Homo sapiens|F|V-REGION|297450..297735|286 nt|1| | | | |286+0=286| | |'),\n",
       " ('V',\n",
       "  360.0,\n",
       "  'L36092|TRBV5-6*01|Homo sapiens|F|V-REGION|314963..315248|286 nt|1| | | | |286+0=286| | |'),\n",
       " ('V',\n",
       "  312.0,\n",
       "  'L36092|TRBV5-7*01|Homo sapiens|ORF|V-REGION|334981..335266|286 nt|1| | | | |286+0=286| | |'),\n",
       " ('V',\n",
       "  284.0,\n",
       "  'L36092|TRBV5-4*01|Homo sapiens|F|V-REGION|278005..278290|286 nt|1| | | | |286+0=286| | |'),\n",
       " ('V',\n",
       "  265.0,\n",
       "  'X57615|TRBV5-4*02|Homo sapiens|(F)|V-REGION|65..346|282 nt|1| | | | |282+0=282| Extended by 4 | |'),\n",
       " ('V',\n",
       "  71.0,\n",
       "  'U66059|TRBV9*01|Homo sapiens|F|V-REGION|206836..207121|286 nt|1| | | | |286+0=286| | |'),\n",
       " ('V',\n",
       "  60.0,\n",
       "  'X61447|TRBV6-9*01|Homo sapiens|F|V-REGION|380..666|287 nt|1| | | | |287+0=287| | |'),\n",
       " ('V',\n",
       "  55.0,\n",
       "  'X61446|TRBV6-1*01|Homo sapiens|F|V-REGION|412..698|287 nt|1| | | | |287+0=287| | |'),\n",
       " ('V',\n",
       "  50.0,\n",
       "  'L36092|TRBV6-6*01|Homo sapiens|F|V-REGION|284442..284728|287 nt|1| | | | |287+0=287| | |'),\n",
       " ('V',\n",
       "  50.0,\n",
       "  'AF009662|TRBV6-6*02|Homo sapiens|F|V-REGION|24864..25150|287 nt|1| | | | |287+0=287| | |')]"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "[(aln.strGene_class, aln.score, aln.strGene_name) for aln in aln_data]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "aln_data[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "gene;anchor_index\n",
      "TRBV10-1*01;270\n",
      "TRBV10-1*02;270\n",
      "TRBV10-1*04;270\n",
      "TRBV10-2*01;270\n",
      "TRBV10-3*01;270\n",
      "TRBV10-3*02;267\n",
      "TRBV11-1*01;273\n",
      "TRBV11-2*01;273\n",
      "TRBV11-2*02;273\n"
     ]
    }
   ],
   "source": [
    "!head modif_ref_genome/V_gene_CDR3_anchors.csv"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [
    {
     "ename": "AttributeError",
     "evalue": "module 'pandas' has no attribute 'Dataframe'",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mAttributeError\u001b[0m                            Traceback (most recent call last)",
      "\u001b[0;32m<ipython-input-41-fec26b3eccac>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m      1\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mpandas\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0mpd\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m      2\u001b[0m \u001b[0mgene_data\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mdict\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----> 3\u001b[0;31m \u001b[0mgene_data\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m\"V\"\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mpd\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mDataframe\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[0;31mAttributeError\u001b[0m: module 'pandas' has no attribute 'Dataframe'"
     ]
    }
   ],
   "source": [
    "import pandas as pd\n",
    "gene_data = dict()\n",
    "gene_data[\"V\"] = pd.Dataframe()"
   ]
  },
  {
   "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>gene_name</th>\n",
       "      <th>anchor_index</th>\n",
       "      <th>function</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>K02545|TRBJ1-1*01|Homo sapiens|F|J-REGION|749....</td>\n",
       "      <td>17</td>\n",
       "      <td></td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>K02545|TRBJ1-2*01|Homo sapiens|F|J-REGION|886....</td>\n",
       "      <td>17</td>\n",
       "      <td></td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>M14158|TRBJ1-3*01|Homo sapiens|F|J-REGION|1499...</td>\n",
       "      <td>19</td>\n",
       "      <td></td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>M14158|TRBJ1-4*01|Homo sapiens|F|J-REGION|2095...</td>\n",
       "      <td>20</td>\n",
       "      <td></td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>M14158|TRBJ1-5*01|Homo sapiens|F|J-REGION|2368...</td>\n",
       "      <td>19</td>\n",
       "      <td></td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>M14158|TRBJ1-6*01|Homo sapiens|F|J-REGION|2859...</td>\n",
       "      <td>22</td>\n",
       "      <td></td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>L36092|TRBJ1-6*02|Homo sapiens|F|J-REGION|6430...</td>\n",
       "      <td>22</td>\n",
       "      <td></td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>X02987|TRBJ2-1*01|Homo sapiens|F|J-REGION|800....</td>\n",
       "      <td>19</td>\n",
       "      <td></td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>X02987|TRBJ2-2*01|Homo sapiens|F|J-REGION|995....</td>\n",
       "      <td>20</td>\n",
       "      <td></td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>X02987|TRBJ2-3*01|Homo sapiens|F|J-REGION|1282...</td>\n",
       "      <td>18</td>\n",
       "      <td></td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>X02987|TRBJ2-4*01|Homo sapiens|F|J-REGION|1432...</td>\n",
       "      <td>19</td>\n",
       "      <td></td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>X02987|TRBJ2-5*01|Homo sapiens|F|J-REGION|1553...</td>\n",
       "      <td>17</td>\n",
       "      <td></td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>X02987|TRBJ2-6*01|Homo sapiens|F|J-REGION|1673...</td>\n",
       "      <td>22</td>\n",
       "      <td></td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>M14159|TRBJ2-7*01|Homo sapiens|F|J-REGION|2316...</td>\n",
       "      <td>16</td>\n",
       "      <td></td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>X02987|TRBJ2-7*02|Homo sapiens|ORF|J-REGION|18...</td>\n",
       "      <td>16</td>\n",
       "      <td></td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                            gene_name  anchor_index function\n",
       "0   K02545|TRBJ1-1*01|Homo sapiens|F|J-REGION|749....            17         \n",
       "1   K02545|TRBJ1-2*01|Homo sapiens|F|J-REGION|886....            17         \n",
       "2   M14158|TRBJ1-3*01|Homo sapiens|F|J-REGION|1499...            19         \n",
       "3   M14158|TRBJ1-4*01|Homo sapiens|F|J-REGION|2095...            20         \n",
       "4   M14158|TRBJ1-5*01|Homo sapiens|F|J-REGION|2368...            19         \n",
       "5   M14158|TRBJ1-6*01|Homo sapiens|F|J-REGION|2859...            22         \n",
       "6   L36092|TRBJ1-6*02|Homo sapiens|F|J-REGION|6430...            22         \n",
       "7   X02987|TRBJ2-1*01|Homo sapiens|F|J-REGION|800....            19         \n",
       "8   X02987|TRBJ2-2*01|Homo sapiens|F|J-REGION|995....            20         \n",
       "9   X02987|TRBJ2-3*01|Homo sapiens|F|J-REGION|1282...            18         \n",
       "10  X02987|TRBJ2-4*01|Homo sapiens|F|J-REGION|1432...            19         \n",
       "11  X02987|TRBJ2-5*01|Homo sapiens|F|J-REGION|1553...            17         \n",
       "12  X02987|TRBJ2-6*01|Homo sapiens|F|J-REGION|1673...            22         \n",
       "13  M14159|TRBJ2-7*01|Homo sapiens|F|J-REGION|2316...            16         \n",
       "14  X02987|TRBJ2-7*02|Homo sapiens|ORF|J-REGION|18...            16         "
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pandas as pd\n",
    "\n",
    "pd.DataFrame.from_records(db.fetch_IgorGeneAnchors_By_Gene(\"J\"), columns=['gene_name', 'anchor_index', 'function'])\n",
    "# Dont get the anchors sequences"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "db.fetch_IgorGeneTemplate_By_gene_name"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "db.fetch_IgorGeneTemplate_By_gene_name"
   ]
  },
  {
   "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": 42,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "\n",
    "df = pd.DataFrame([['Julie', 'Sheets were dirty'],\n",
    "                   ['Samantha', 'Meal arrived cold'],\n",
    "                   ['Rachel', 'Cocktails were delicious']],\n",
    "                  columns=['User', 'Review'])\n",
    "\n",
    "d = {'Keyword': ['Sheets','Cocktails','Meal'],\n",
    "     'Department' : ['Bedrooms','Restaurant','Restaurant'],\n",
    "     'Issue Type': ['Beds','Drinks','Food']}\n",
    "\n",
    "d2 = {key: (dep, iss) for key, dep, iss in \\\n",
    "           zip(d['Keyword'], d['Department'], d['Issue Type'])}\n",
    "\n",
    "def mapper(x):\n",
    "    return d2.get(next((i for i in d2 if i in x), None))\n",
    "\n",
    "df[['Department', 'IssueType']] = df['Review'].apply(mapper).apply(pd.Series)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "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>User</th>\n",
       "      <th>Review</th>\n",
       "      <th>Department</th>\n",
       "      <th>IssueType</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Julie</td>\n",
       "      <td>Sheets were dirty</td>\n",
       "      <td>Bedrooms</td>\n",
       "      <td>Beds</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Samantha</td>\n",
       "      <td>Meal arrived cold</td>\n",
       "      <td>Restaurant</td>\n",
       "      <td>Food</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Rachel</td>\n",
       "      <td>Cocktails were delicious</td>\n",
       "      <td>Restaurant</td>\n",
       "      <td>Drinks</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       User                    Review  Department IssueType\n",
       "0     Julie         Sheets were dirty    Bedrooms      Beds\n",
       "1  Samantha         Meal arrived cold  Restaurant      Food\n",
       "2    Rachel  Cocktails were delicious  Restaurant    Drinks"
      ]
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'Keyword': ['Sheets', 'Cocktails', 'Meal'],\n",
       " 'Department': ['Bedrooms', 'Restaurant', 'Restaurant'],\n",
       " 'Issue Type': ['Beds', 'Drinks', 'Food']}"
      ]
     },
     "execution_count": 44,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "d"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'\\n        SELECT gene.xgene_id, gene.gene_name, gene.sequence, \\n                anch.anchor_index, anch.function \\n        FROM IgorXGeneTemplate gene \\n        LEFT JOIN IgorXGeneCDR3Anchors anch \\n        ON gene.xgene_id = anch.xgene_id;\\n        '"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sqlselect = \"\"\"\n",
    "        SELECT gene.{lower}gene_id, gene.gene_name, gene.sequence, \n",
    "                anch.anchor_index, anch.function \n",
    "        FROM Igor{upper}GeneTemplate gene \n",
    "        LEFT JOIN Igor{upper}GeneCDR3Anchors anch \n",
    "        ON gene.{lower}gene_id = anch.{lower}gene_id;\n",
    "        \"\"\"\n",
    "sqlselect.format(upper='X', lower='x')"
   ]
  },
  {
   "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.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
