{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# `natsel_sitehet` -- a test of site heterogeneity\n",
    "\n",
    "This app evaluates evidence for whether sites differ in their mode of natural selection ([Nielsen and Yang 1998](https://www.ncbi.nlm.nih.gov/pubmed/9539414))."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<style>\n",
       "tr:last-child {border-bottom: 1px solid #000;} tr > th {text-align: center !important;} tr > td {text-align: left !important;}\n",
       "</style>\n",
       "<caption style=\"color: rgb(250, 250, 250); background: rgba(30, 140, 200, 1); align=top;\"><span style=\"font-weight: bold;\">Statistics</span><span></span></caption>\n",
       "<thead style=\"background: rgba(161, 195, 209, 0.75); font-weight: bold; text-align: center;\">\n",
       "<th>LR</th>\n",
       "<th>df</th>\n",
       "<th>pvalue</th>\n",
       "</thead>\n",
       "<tbody>\n",
       "<tr>\n",
       "<td style=\"font-family: monospace !important;\">1.4048</td>\n",
       "<td style=\"font-family: monospace !important;\">2</td>\n",
       "<td style=\"font-family: monospace !important;\">0.4954</td>\n",
       "</tr>\n",
       "</tbody>\n",
       "</table>\n",
       "\n",
       "<table>\n",
       "<style>\n",
       "tr:last-child {border-bottom: 1px solid #000;} tr > th {text-align: center !important;} tr > td {text-align: left !important;}\n",
       "</style>\n",
       "<thead style=\"background: rgba(161, 195, 209, 0.75); font-weight: bold; text-align: center;\">\n",
       "<th>hypothesis</th>\n",
       "<th>key</th>\n",
       "<th>lnL</th>\n",
       "<th>nfp</th>\n",
       "<th>DLC</th>\n",
       "<th>unique_Q</th>\n",
       "</thead>\n",
       "<tbody>\n",
       "<tr>\n",
       "<td>null</td>\n",
       "<td>'GNC-null'</td>\n",
       "<td style=\"font-family: monospace !important;\">-6708.3119</td>\n",
       "<td style=\"font-family: monospace !important;\">24</td>\n",
       "<td>True</td>\n",
       "<td></td>\n",
       "</tr>\n",
       "<tr>\n",
       "<td>alt</td>\n",
       "<td>'GNC-alt'</td>\n",
       "<td style=\"font-family: monospace !important;\">-6707.6095</td>\n",
       "<td style=\"font-family: monospace !important;\">26</td>\n",
       "<td>True</td>\n",
       "<td></td>\n",
       "</tr>\n",
       "</tbody>\n",
       "</table>\n"
      ],
      "text/plain": [
       "Statistics\n",
       "======================\n",
       "    LR    df    pvalue\n",
       "----------------------\n",
       "1.4048     2    0.4954\n",
       "----------------------\n",
       "=================================================================\n",
       "hypothesis           key           lnL    nfp     DLC    unique_Q\n",
       "-----------------------------------------------------------------\n",
       "      null    'GNC-null'    -6708.3119     24    True            \n",
       "       alt     'GNC-alt'    -6707.6095     26    True            \n",
       "-----------------------------------------------------------------"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from cogent3.app import io, evo\n",
    "\n",
    "loader = io.load_aligned(format=\"fasta\", moltype=\"dna\")\n",
    "aln = loader(\"../data/primate_brca1.fasta\")\n",
    "\n",
    "sites_differ = evo.natsel_sitehet(\"GNC\",\n",
    "                                  tree=\"../data/primate_brca1.tree\",\n",
    "                                  optimise_motif_probs=False)\n",
    "\n",
    "result = sites_differ(aln)\n",
    "result"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The models have been constructed such that site-class bins have names indicating the mode of natural selection: -ve is purifying (omega<1); neutral (omega=1); and +ve is positive natural selection (omega>1). The two parameters of interest relating to these are the `bprobs` (the maximum likelihood estimate of the frequency of the site-class) and the corresponding value of omega."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<h4>GNC-alt</h4>\n",
       "<p>log-likelihood = -6707.6095</p>\n",
       "<p>number of free parameters = 26</p>\n",
       "<table>\n",
       "<style>\n",
       "tr:last-child {border-bottom: 1px solid #000;} tr > th {text-align: center !important;} tr > td {text-align: left !important;}\n",
       "</style>\n",
       "<caption style=\"color: rgb(250, 250, 250); background: rgba(30, 140, 200, 1); align=top;\"><span style=\"font-weight: bold;\">Global params</span><span></span></caption>\n",
       "<thead style=\"background: rgba(161, 195, 209, 0.75); font-weight: bold; text-align: center;\">\n",
       "<th>A&gt;C</th>\n",
       "<th>A&gt;G</th>\n",
       "<th>A&gt;T</th>\n",
       "<th>C&gt;A</th>\n",
       "<th>C&gt;G</th>\n",
       "<th>C&gt;T</th>\n",
       "<th>G&gt;A</th>\n",
       "<th>G&gt;C</th>\n",
       "<th>G&gt;T</th>\n",
       "<th>T&gt;A</th>\n",
       "</thead>\n",
       "<tbody>\n",
       "<tr>\n",
       "<td style=\"font-family: monospace !important;\">0.8530</td>\n",
       "<td style=\"font-family: monospace !important;\">3.5646</td>\n",
       "<td style=\"font-family: monospace !important;\">0.9734</td>\n",
       "<td style=\"font-family: monospace !important;\">1.6404</td>\n",
       "<td style=\"font-family: monospace !important;\">2.1801</td>\n",
       "<td style=\"font-family: monospace !important;\">6.3218</td>\n",
       "<td style=\"font-family: monospace !important;\">8.0814</td>\n",
       "<td style=\"font-family: monospace !important;\">1.2347</td>\n",
       "<td style=\"font-family: monospace !important;\">0.7829</td>\n",
       "<td style=\"font-family: monospace !important;\">1.2798</td>\n",
       "</tr>\n",
       "</tbody>\n",
       "</table>\n",
       "<table>\n",
       "<thead style=\"background: rgba(161, 195, 209, 0.75); font-weight: bold; text-align: center;\">\n",
       "<th>T&gt;C</th>\n",
       "</thead>\n",
       "<tbody>\n",
       "<tr>\n",
       "<td style=\"font-family: monospace !important;\">3.0292</td>\n",
       "</tr>\n",
       "</tbody>\n",
       "</table>\n",
       "\n",
       "<table>\n",
       "<style>\n",
       "tr:last-child {border-bottom: 1px solid #000;} tr > th {text-align: center !important;} tr > td {text-align: left !important;}\n",
       "</style>\n",
       "<caption style=\"color: rgb(250, 250, 250); background: rgba(30, 140, 200, 1); align=top;\"><span style=\"font-weight: bold;\">Bin params</span><span></span></caption>\n",
       "<thead style=\"background: rgba(161, 195, 209, 0.75); font-weight: bold; text-align: center;\">\n",
       "<th>bin</th>\n",
       "<th>bprobs</th>\n",
       "<th>omega</th>\n",
       "</thead>\n",
       "<tbody>\n",
       "<tr>\n",
       "<td style=\"background: rgba(161, 195, 209, 0.25); font-weight: 600;\">-ve</td>\n",
       "<td style=\"font-family: monospace !important;\">0.1043</td>\n",
       "<td style=\"font-family: monospace !important;\">0.0000</td>\n",
       "</tr>\n",
       "<tr>\n",
       "<td style=\"background: rgba(161, 195, 209, 0.25); font-weight: 600;\">neutral</td>\n",
       "<td style=\"font-family: monospace !important;\">0.8052</td>\n",
       "<td style=\"font-family: monospace !important;\">1.0000</td>\n",
       "</tr>\n",
       "<tr>\n",
       "<td style=\"background: rgba(161, 195, 209, 0.25); font-weight: 600;\">+ve</td>\n",
       "<td style=\"font-family: monospace !important;\">0.0905</td>\n",
       "<td style=\"font-family: monospace !important;\">20.0000</td>\n",
       "</tr>\n",
       "</tbody>\n",
       "</table>\n",
       "\n",
       "<table>\n",
       "<style>\n",
       "tr:last-child {border-bottom: 1px solid #000;} tr > th {text-align: center !important;} tr > td {text-align: left !important;}\n",
       "</style>\n",
       "<caption style=\"color: rgb(250, 250, 250); background: rgba(30, 140, 200, 1); align=top;\"><span style=\"font-weight: bold;\">Edge params</span><span></span></caption>\n",
       "<thead style=\"background: rgba(161, 195, 209, 0.75); font-weight: bold; text-align: center;\">\n",
       "<th>edge</th>\n",
       "<th>parent</th>\n",
       "<th>length</th>\n",
       "</thead>\n",
       "<tbody>\n",
       "<tr>\n",
       "<td style=\"background: rgba(161, 195, 209, 0.25); font-weight: 600;\">Galago</td>\n",
       "<td>root</td>\n",
       "<td style=\"font-family: monospace !important;\">0.5463</td>\n",
       "</tr>\n",
       "<tr>\n",
       "<td style=\"background: rgba(161, 195, 209, 0.25); font-weight: 600;\">HowlerMon</td>\n",
       "<td>root</td>\n",
       "<td style=\"font-family: monospace !important;\">0.1364</td>\n",
       "</tr>\n",
       "<tr>\n",
       "<td style=\"background: rgba(161, 195, 209, 0.25); font-weight: 600;\">Rhesus</td>\n",
       "<td>edge.3</td>\n",
       "<td style=\"font-family: monospace !important;\">0.0649</td>\n",
       "</tr>\n",
       "<tr>\n",
       "<td style=\"background: rgba(161, 195, 209, 0.25); font-weight: 600;\">Orangutan</td>\n",
       "<td>edge.2</td>\n",
       "<td style=\"font-family: monospace !important;\">0.0235</td>\n",
       "</tr>\n",
       "<tr>\n",
       "<td style=\"background: rgba(161, 195, 209, 0.25); font-weight: 600;\">Gorilla</td>\n",
       "<td>edge.1</td>\n",
       "<td style=\"font-family: monospace !important;\">0.0075</td>\n",
       "</tr>\n",
       "<tr>\n",
       "<td style=\"background: rgba(161, 195, 209, 0.25); font-weight: 600;\">Human</td>\n",
       "<td>edge.0</td>\n",
       "<td style=\"font-family: monospace !important;\">0.0182</td>\n",
       "</tr>\n",
       "<tr>\n",
       "<td style=\"background: rgba(161, 195, 209, 0.25); font-weight: 600;\">Chimpanzee</td>\n",
       "<td>edge.0</td>\n",
       "<td style=\"font-family: monospace !important;\">0.0085</td>\n",
       "</tr>\n",
       "<tr>\n",
       "<td style=\"background: rgba(161, 195, 209, 0.25); font-weight: 600;\">edge.0</td>\n",
       "<td>edge.1</td>\n",
       "<td style=\"font-family: monospace !important;\">0.0000</td>\n",
       "</tr>\n",
       "<tr>\n",
       "<td style=\"background: rgba(161, 195, 209, 0.25); font-weight: 600;\">edge.1</td>\n",
       "<td>edge.2</td>\n",
       "<td style=\"font-family: monospace !important;\">0.0099</td>\n",
       "</tr>\n",
       "<tr>\n",
       "<td style=\"background: rgba(161, 195, 209, 0.25); font-weight: 600;\">edge.2</td>\n",
       "<td>edge.3</td>\n",
       "<td style=\"font-family: monospace !important;\">0.0364</td>\n",
       "</tr>\n",
       "<tr>\n",
       "<td style=\"background: rgba(161, 195, 209, 0.25); font-weight: 600;\">edge.3</td>\n",
       "<td>root</td>\n",
       "<td style=\"font-family: monospace !important;\">0.0233</td>\n",
       "</tr>\n",
       "</tbody>\n",
       "</table>\n",
       "\n",
       "<table>\n",
       "<style>\n",
       "tr:last-child {border-bottom: 1px solid #000;} tr > th {text-align: center !important;} tr > td {text-align: left !important;}\n",
       "</style>\n",
       "<caption style=\"color: rgb(250, 250, 250); background: rgba(30, 140, 200, 1); align=top;\"><span style=\"font-weight: bold;\">Motif params</span><span></span></caption>\n",
       "<thead style=\"background: rgba(161, 195, 209, 0.75); font-weight: bold; text-align: center;\">\n",
       "<th>AAA</th>\n",
       "<th>AAC</th>\n",
       "<th>AAG</th>\n",
       "<th>AAT</th>\n",
       "<th>ACA</th>\n",
       "<th>ACC</th>\n",
       "<th>ACG</th>\n",
       "<th>ACT</th>\n",
       "<th>AGA</th>\n",
       "<th>AGC</th>\n",
       "</thead>\n",
       "<tbody>\n",
       "<tr>\n",
       "<td style=\"font-family: monospace !important;\">0.0556</td>\n",
       "<td style=\"font-family: monospace !important;\">0.0235</td>\n",
       "<td style=\"font-family: monospace !important;\">0.0344</td>\n",
       "<td style=\"font-family: monospace !important;\">0.0556</td>\n",
       "<td style=\"font-family: monospace !important;\">0.0228</td>\n",
       "<td style=\"font-family: monospace !important;\">0.0046</td>\n",
       "<td style=\"font-family: monospace !important;\">0.0008</td>\n",
       "<td style=\"font-family: monospace !important;\">0.0289</td>\n",
       "<td style=\"font-family: monospace !important;\">0.0231</td>\n",
       "<td style=\"font-family: monospace !important;\">0.0286</td>\n",
       "</tr>\n",
       "</tbody>\n",
       "</table>\n",
       "<table>\n",
       "<thead style=\"background: rgba(161, 195, 209, 0.75); font-weight: bold; text-align: center;\">\n",
       "<th>AGG</th>\n",
       "<th>AGT</th>\n",
       "<th>ATA</th>\n",
       "<th>ATC</th>\n",
       "<th>ATG</th>\n",
       "<th>ATT</th>\n",
       "<th>CAA</th>\n",
       "<th>CAC</th>\n",
       "<th>CAG</th>\n",
       "<th>CAT</th>\n",
       "</thead>\n",
       "<tbody>\n",
       "<tr>\n",
       "<td style=\"font-family: monospace !important;\">0.0140</td>\n",
       "<td style=\"font-family: monospace !important;\">0.0381</td>\n",
       "<td style=\"font-family: monospace !important;\">0.0186</td>\n",
       "<td style=\"font-family: monospace !important;\">0.0070</td>\n",
       "<td style=\"font-family: monospace !important;\">0.0128</td>\n",
       "<td style=\"font-family: monospace !important;\">0.0192</td>\n",
       "<td style=\"font-family: monospace !important;\">0.0196</td>\n",
       "<td style=\"font-family: monospace !important;\">0.0052</td>\n",
       "<td style=\"font-family: monospace !important;\">0.0238</td>\n",
       "<td style=\"font-family: monospace !important;\">0.0221</td>\n",
       "</tr>\n",
       "</tbody>\n",
       "</table>\n",
       "<table>\n",
       "<thead style=\"background: rgba(161, 195, 209, 0.75); font-weight: bold; text-align: center;\">\n",
       "<th>CCA</th>\n",
       "<th>CCC</th>\n",
       "<th>CCG</th>\n",
       "<th>CCT</th>\n",
       "<th>CGA</th>\n",
       "<th>CGC</th>\n",
       "<th>CGG</th>\n",
       "<th>CGT</th>\n",
       "<th>CTA</th>\n",
       "<th>CTC</th>\n",
       "</thead>\n",
       "<tbody>\n",
       "<tr>\n",
       "<td style=\"font-family: monospace !important;\">0.0195</td>\n",
       "<td style=\"font-family: monospace !important;\">0.0062</td>\n",
       "<td style=\"font-family: monospace !important;\">0.0006</td>\n",
       "<td style=\"font-family: monospace !important;\">0.0263</td>\n",
       "<td style=\"font-family: monospace !important;\">0.0011</td>\n",
       "<td style=\"font-family: monospace !important;\">0.0009</td>\n",
       "<td style=\"font-family: monospace !important;\">0.0023</td>\n",
       "<td style=\"font-family: monospace !important;\">0.0032</td>\n",
       "<td style=\"font-family: monospace !important;\">0.0137</td>\n",
       "<td style=\"font-family: monospace !important;\">0.0078</td>\n",
       "</tr>\n",
       "</tbody>\n",
       "</table>\n",
       "<table>\n",
       "<thead style=\"background: rgba(161, 195, 209, 0.75); font-weight: bold; text-align: center;\">\n",
       "<th>CTG</th>\n",
       "<th>CTT</th>\n",
       "<th>GAA</th>\n",
       "<th>GAC</th>\n",
       "<th>GAG</th>\n",
       "<th>GAT</th>\n",
       "<th>GCA</th>\n",
       "<th>GCC</th>\n",
       "<th>GCG</th>\n",
       "<th>GCT</th>\n",
       "</thead>\n",
       "<tbody>\n",
       "<tr>\n",
       "<td style=\"font-family: monospace !important;\">0.0125</td>\n",
       "<td style=\"font-family: monospace !important;\">0.0105</td>\n",
       "<td style=\"font-family: monospace !important;\">0.0755</td>\n",
       "<td style=\"font-family: monospace !important;\">0.0105</td>\n",
       "<td style=\"font-family: monospace !important;\">0.0303</td>\n",
       "<td style=\"font-family: monospace !important;\">0.0315</td>\n",
       "<td style=\"font-family: monospace !important;\">0.0158</td>\n",
       "<td style=\"font-family: monospace !important;\">0.0096</td>\n",
       "<td style=\"font-family: monospace !important;\">0.0014</td>\n",
       "<td style=\"font-family: monospace !important;\">0.0137</td>\n",
       "</tr>\n",
       "</tbody>\n",
       "</table>\n",
       "<table>\n",
       "<thead style=\"background: rgba(161, 195, 209, 0.75); font-weight: bold; text-align: center;\">\n",
       "<th>GGA</th>\n",
       "<th>GGC</th>\n",
       "<th>GGG</th>\n",
       "<th>GGT</th>\n",
       "<th>GTA</th>\n",
       "<th>GTC</th>\n",
       "<th>GTG</th>\n",
       "<th>GTT</th>\n",
       "<th>TAC</th>\n",
       "<th>TAT</th>\n",
       "</thead>\n",
       "<tbody>\n",
       "<tr>\n",
       "<td style=\"font-family: monospace !important;\">0.0161</td>\n",
       "<td style=\"font-family: monospace !important;\">0.0090</td>\n",
       "<td style=\"font-family: monospace !important;\">0.0067</td>\n",
       "<td style=\"font-family: monospace !important;\">0.0133</td>\n",
       "<td style=\"font-family: monospace !important;\">0.0148</td>\n",
       "<td style=\"font-family: monospace !important;\">0.0070</td>\n",
       "<td style=\"font-family: monospace !important;\">0.0069</td>\n",
       "<td style=\"font-family: monospace !important;\">0.0213</td>\n",
       "<td style=\"font-family: monospace !important;\">0.0023</td>\n",
       "<td style=\"font-family: monospace !important;\">0.0101</td>\n",
       "</tr>\n",
       "</tbody>\n",
       "</table>\n",
       "<table>\n",
       "<thead style=\"background: rgba(161, 195, 209, 0.75); font-weight: bold; text-align: center;\">\n",
       "<th>TCA</th>\n",
       "<th>TCC</th>\n",
       "<th>TCG</th>\n",
       "<th>TCT</th>\n",
       "<th>TGC</th>\n",
       "<th>TGG</th>\n",
       "<th>TGT</th>\n",
       "<th>TTA</th>\n",
       "<th>TTC</th>\n",
       "<th>TTG</th>\n",
       "</thead>\n",
       "<tbody>\n",
       "<tr>\n",
       "<td style=\"font-family: monospace !important;\">0.0221</td>\n",
       "<td style=\"font-family: monospace !important;\">0.0082</td>\n",
       "<td style=\"font-family: monospace !important;\">0.0015</td>\n",
       "<td style=\"font-family: monospace !important;\">0.0251</td>\n",
       "<td style=\"font-family: monospace !important;\">0.0018</td>\n",
       "<td style=\"font-family: monospace !important;\">0.0040</td>\n",
       "<td style=\"font-family: monospace !important;\">0.0201</td>\n",
       "<td style=\"font-family: monospace !important;\">0.0212</td>\n",
       "<td style=\"font-family: monospace !important;\">0.0078</td>\n",
       "<td style=\"font-family: monospace !important;\">0.0108</td>\n",
       "</tr>\n",
       "</tbody>\n",
       "</table>\n",
       "<table>\n",
       "<thead style=\"background: rgba(161, 195, 209, 0.75); font-weight: bold; text-align: center;\">\n",
       "<th>TTT</th>\n",
       "</thead>\n",
       "<tbody>\n",
       "<tr>\n",
       "<td style=\"font-family: monospace !important;\">0.0187</td>\n",
       "</tr>\n",
       "</tbody>\n",
       "</table>\n"
      ],
      "text/plain": [
       "GNC-alt\n",
       "log-likelihood = -6707.6095\n",
       "number of free parameters = 26\n",
       "============================================================================\n",
       "   A>C       A>G       A>T       C>A       C>G       C>T       G>A       G>C\n",
       "----------------------------------------------------------------------------\n",
       "0.8530    3.5646    0.9734    1.6404    2.1801    6.3218    8.0814    1.2347\n",
       "----------------------------------------------------------------------------\n",
       "\n",
       "continued: \n",
       "==========================\n",
       "   G>T       T>A       T>C\n",
       "--------------------------\n",
       "0.7829    1.2798    3.0292\n",
       "--------------------------\n",
       "\n",
       "============================\n",
       "    bin    bprobs      omega\n",
       "----------------------------\n",
       "    -ve    0.1043     0.0000\n",
       "neutral    0.8052     1.0000\n",
       "    +ve    0.0905    20.0000\n",
       "----------------------------\n",
       "==============================\n",
       "      edge    parent    length\n",
       "------------------------------\n",
       "    Galago      root    0.5463\n",
       " HowlerMon      root    0.1364\n",
       "    Rhesus    edge.3    0.0649\n",
       " Orangutan    edge.2    0.0235\n",
       "   Gorilla    edge.1    0.0075\n",
       "     Human    edge.0    0.0182\n",
       "Chimpanzee    edge.0    0.0085\n",
       "    edge.0    edge.1    0.0000\n",
       "    edge.1    edge.2    0.0099\n",
       "    edge.2    edge.3    0.0364\n",
       "    edge.3      root    0.0233\n",
       "------------------------------\n",
       "============================================================================\n",
       "   AAA       AAC       AAG       AAT       ACA       ACC       ACG       ACT\n",
       "----------------------------------------------------------------------------\n",
       "0.0556    0.0235    0.0344    0.0556    0.0228    0.0046    0.0008    0.0289\n",
       "----------------------------------------------------------------------------\n",
       "\n",
       "continued: \n",
       "============================================================================\n",
       "   AGA       AGC       AGG       AGT       ATA       ATC       ATG       ATT\n",
       "----------------------------------------------------------------------------\n",
       "0.0231    0.0286    0.0140    0.0381    0.0186    0.0070    0.0128    0.0192\n",
       "----------------------------------------------------------------------------\n",
       "\n",
       "continued: \n",
       "============================================================================\n",
       "   CAA       CAC       CAG       CAT       CCA       CCC       CCG       CCT\n",
       "----------------------------------------------------------------------------\n",
       "0.0196    0.0052    0.0238    0.0221    0.0195    0.0062    0.0006    0.0263\n",
       "----------------------------------------------------------------------------\n",
       "\n",
       "continued: \n",
       "============================================================================\n",
       "   CGA       CGC       CGG       CGT       CTA       CTC       CTG       CTT\n",
       "----------------------------------------------------------------------------\n",
       "0.0011    0.0009    0.0023    0.0032    0.0137    0.0078    0.0125    0.0105\n",
       "----------------------------------------------------------------------------\n",
       "\n",
       "continued: \n",
       "============================================================================\n",
       "   GAA       GAC       GAG       GAT       GCA       GCC       GCG       GCT\n",
       "----------------------------------------------------------------------------\n",
       "0.0755    0.0105    0.0303    0.0315    0.0158    0.0096    0.0014    0.0137\n",
       "----------------------------------------------------------------------------\n",
       "\n",
       "continued: \n",
       "============================================================================\n",
       "   GGA       GGC       GGG       GGT       GTA       GTC       GTG       GTT\n",
       "----------------------------------------------------------------------------\n",
       "0.0161    0.0090    0.0067    0.0133    0.0148    0.0070    0.0069    0.0213\n",
       "----------------------------------------------------------------------------\n",
       "\n",
       "continued: \n",
       "============================================================================\n",
       "   TAC       TAT       TCA       TCC       TCG       TCT       TGC       TGG\n",
       "----------------------------------------------------------------------------\n",
       "0.0023    0.0101    0.0221    0.0082    0.0015    0.0251    0.0018    0.0040\n",
       "----------------------------------------------------------------------------\n",
       "\n",
       "continued: \n",
       "==============================================\n",
       "   TGT       TTA       TTC       TTG       TTT\n",
       "----------------------------------------------\n",
       "0.0201    0.0212    0.0078    0.0108    0.0187\n",
       "----------------------------------------------"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "result.alt.lf"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Getting the individual site posterior probabilities\n",
    "\n",
    "I'm just displaying the posterior-probabuilities from the first 20 positions only."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<style>\n",
       "tr:last-child {border-bottom: 1px solid #000;} tr > th {text-align: center !important;} tr > td {text-align: left !important;}\n",
       "</style>\n",
       "<thead style=\"background: rgba(161, 195, 209, 0.75); font-weight: bold; text-align: center;\">\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",
       "</thead>\n",
       "<tbody>\n",
       "<tr>\n",
       "<td style=\"background: rgba(161, 195, 209, 0.25); font-weight: 600;\">-ve</td>\n",
       "<td style=\"font-family: monospace !important;\">0.149</td>\n",
       "<td style=\"font-family: monospace !important;\">0.084</td>\n",
       "<td style=\"font-family: monospace !important;\">0.000</td>\n",
       "<td style=\"font-family: monospace !important;\">0.131</td>\n",
       "<td style=\"font-family: monospace !important;\">0.115</td>\n",
       "<td style=\"font-family: monospace !important;\">0.157</td>\n",
       "<td style=\"font-family: monospace !important;\">0.084</td>\n",
       "<td style=\"font-family: monospace !important;\">0.119</td>\n",
       "<td style=\"font-family: monospace !important;\">0.102</td>\n",
       "<td style=\"font-family: monospace !important;\">0.080</td>\n",
       "</tr>\n",
       "<tr>\n",
       "<td style=\"background: rgba(161, 195, 209, 0.25); font-weight: 600;\">neutral</td>\n",
       "<td style=\"font-family: monospace !important;\">0.773</td>\n",
       "<td style=\"font-family: monospace !important;\">0.813</td>\n",
       "<td style=\"font-family: monospace !important;\">0.864</td>\n",
       "<td style=\"font-family: monospace !important;\">0.785</td>\n",
       "<td style=\"font-family: monospace !important;\">0.796</td>\n",
       "<td style=\"font-family: monospace !important;\">0.767</td>\n",
       "<td style=\"font-family: monospace !important;\">0.812</td>\n",
       "<td style=\"font-family: monospace !important;\">0.793</td>\n",
       "<td style=\"font-family: monospace !important;\">0.803</td>\n",
       "<td style=\"font-family: monospace !important;\">0.814</td>\n",
       "</tr>\n",
       "<tr>\n",
       "<td style=\"background: rgba(161, 195, 209, 0.25); font-weight: 600;\">+ve</td>\n",
       "<td style=\"font-family: monospace !important;\">0.078</td>\n",
       "<td style=\"font-family: monospace !important;\">0.103</td>\n",
       "<td style=\"font-family: monospace !important;\">0.136</td>\n",
       "<td style=\"font-family: monospace !important;\">0.084</td>\n",
       "<td style=\"font-family: monospace !important;\">0.089</td>\n",
       "<td style=\"font-family: monospace !important;\">0.076</td>\n",
       "<td style=\"font-family: monospace !important;\">0.103</td>\n",
       "<td style=\"font-family: monospace !important;\">0.088</td>\n",
       "<td style=\"font-family: monospace !important;\">0.095</td>\n",
       "<td style=\"font-family: monospace !important;\">0.106</td>\n",
       "</tr>\n",
       "</tbody>\n",
       "</table>\n",
       "<table>\n",
       "<thead style=\"background: rgba(161, 195, 209, 0.75); font-weight: bold; text-align: center;\">\n",
       "<th></th>\n",
       "<th>10</th>\n",
       "<th>11</th>\n",
       "<th>12</th>\n",
       "<th>13</th>\n",
       "<th>14</th>\n",
       "<th>15</th>\n",
       "<th>16</th>\n",
       "<th>17</th>\n",
       "<th>18</th>\n",
       "<th>19</th>\n",
       "</thead>\n",
       "<tbody>\n",
       "<tr>\n",
       "<td style=\"background: rgba(161, 195, 209, 0.25); font-weight: 600;\">-ve</td>\n",
       "<td style=\"font-family: monospace !important;\">0.076</td>\n",
       "<td style=\"font-family: monospace !important;\">0.157</td>\n",
       "<td style=\"font-family: monospace !important;\">0.094</td>\n",
       "<td style=\"font-family: monospace !important;\">0.000</td>\n",
       "<td style=\"font-family: monospace !important;\">0.156</td>\n",
       "<td style=\"font-family: monospace !important;\">0.517</td>\n",
       "<td style=\"font-family: monospace !important;\">0.080</td>\n",
       "<td style=\"font-family: monospace !important;\">0.070</td>\n",
       "<td style=\"font-family: monospace !important;\">0.115</td>\n",
       "<td style=\"font-family: monospace !important;\">0.122</td>\n",
       "</tr>\n",
       "<tr>\n",
       "<td style=\"background: rgba(161, 195, 209, 0.25); font-weight: 600;\">neutral</td>\n",
       "<td style=\"font-family: monospace !important;\">0.816</td>\n",
       "<td style=\"font-family: monospace !important;\">0.767</td>\n",
       "<td style=\"font-family: monospace !important;\">0.807</td>\n",
       "<td style=\"font-family: monospace !important;\">0.865</td>\n",
       "<td style=\"font-family: monospace !important;\">0.767</td>\n",
       "<td style=\"font-family: monospace !important;\">0.482</td>\n",
       "<td style=\"font-family: monospace !important;\">0.814</td>\n",
       "<td style=\"font-family: monospace !important;\">0.820</td>\n",
       "<td style=\"font-family: monospace !important;\">0.796</td>\n",
       "<td style=\"font-family: monospace !important;\">0.791</td>\n",
       "</tr>\n",
       "<tr>\n",
       "<td style=\"background: rgba(161, 195, 209, 0.25); font-weight: 600;\">+ve</td>\n",
       "<td style=\"font-family: monospace !important;\">0.108</td>\n",
       "<td style=\"font-family: monospace !important;\">0.076</td>\n",
       "<td style=\"font-family: monospace !important;\">0.099</td>\n",
       "<td style=\"font-family: monospace !important;\">0.135</td>\n",
       "<td style=\"font-family: monospace !important;\">0.077</td>\n",
       "<td style=\"font-family: monospace !important;\">0.000</td>\n",
       "<td style=\"font-family: monospace !important;\">0.106</td>\n",
       "<td style=\"font-family: monospace !important;\">0.111</td>\n",
       "<td style=\"font-family: monospace !important;\">0.089</td>\n",
       "<td style=\"font-family: monospace !important;\">0.087</td>\n",
       "</tr>\n",
       "</tbody>\n",
       "</table>\n"
      ],
      "text/plain": [
       "===============================================================================================================================================================================================================\n",
       "                0         1         2         3         4         5         6         7         8         9        10        11        12        13        14        15        16        17        18        19\n",
       "---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\n",
       "    -ve    0.1491    0.0839    0.0000    0.1313    0.1146    0.1569    0.0843    0.1191    0.1020    0.0798    0.0760    0.1569    0.0937    0.0000    0.1563    0.5173    0.0798    0.0695    0.1146    0.1216\n",
       "neutral    0.7725    0.8127    0.8643    0.7851    0.7961    0.7668    0.8125    0.7927    0.8032    0.8141    0.8164    0.7668    0.8070    0.8655    0.7670    0.4824    0.8141    0.8197    0.7961    0.7909\n",
       "    +ve    0.0784    0.1034    0.1357    0.0837    0.0893    0.0764    0.1032    0.0882    0.0948    0.1061    0.1076    0.0764    0.0993    0.1345    0.0766    0.0003    0.1061    0.1108    0.0893    0.0875\n",
       "---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "bprobs = result.alt.lf.get_bin_probs()\n",
    "bprobs[:, :20]"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python [conda env:c3dev] *",
   "language": "python",
   "name": "conda-env-c3dev-py"
  },
  "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.8.1"
  },
  "widgets": {
   "application/vnd.jupyter.widget-state+json": {
    "state": {},
    "version_major": 2,
    "version_minor": 0
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
