{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# `natsel_zhang` -- a branch-site test\n",
    "\n",
    "This is the hypothesis test presented in [Zhang et al](https://www.ncbi.nlm.nih.gov/pubmed/16107592). This test evaluates the hypothesis that a set of sites have undergone positive natural selection on a pre-specified set of lineages.\n",
    "\n",
    "For this model class, there are groups of branches for which all positions are evolving neutrally but some proportion of those neutrally evolving sites change to adaptively evolving on so-called foreground edges. For the current example, we'll define the Chimpanzee and Human branches as foreground and everything else as background. The following table defines the parameter scopes.\n",
    "\n",
    "| Site Class |    Proportion |          Background Edges |          Foreground Edges |\n",
    "|------------|---------------|---------------------------|---------------------------|\n",
    "|          0 | p<sub>0</sub> | 0 < omega<sub>0</sub> < 1 | 0 < omega<sub>0</sub> < 1 |\n",
    "|          1 | p<sub>1</sub> |     omega<sub>1</sub> = 1 |     omega<sub>1</sub> = 1 |\n",
    "|         2a | p<sub>2</sub> | 0 < omega<sub>0</sub> < 1 | 0 < omega<sub>2</sub> > 1 |\n",
    "|         2b | p<sub>3</sub> |     omega<sub>1</sub> = 1 | 0 < omega<sub>0</sub> < 1 |\n",
    "\n",
    "**NOTE:** Our implementation is not as parametrically succinct as that of Zhang et al, we have 1 additional bin probability."
   ]
  },
  {
   "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;\">4.9647</td>\n",
       "<td style=\"font-family: monospace !important;\">3</td>\n",
       "<td style=\"font-family: monospace !important;\">0.1744</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;\">-6705.8296</td>\n",
       "<td style=\"font-family: monospace !important;\">27</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",
       "4.9647     3    0.1744\n",
       "----------------------\n",
       "=================================================================\n",
       "hypothesis           key           lnL    nfp     DLC    unique_Q\n",
       "-----------------------------------------------------------------\n",
       "      null    'GNC-null'    -6708.3119     24    True            \n",
       "       alt     'GNC-alt'    -6705.8296     27    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",
    "zhang_test = evo.natsel_zhang(\"GNC\",\n",
    "                              tree=\"../data/primate_brca1.tree\",\n",
    "                              optimise_motif_probs=False,\n",
    "                              tip1=\"Human\",\n",
    "                              tip2=\"Chimpanzee\")\n",
    "\n",
    "result = zhang_test(aln)\n",
    "result"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<h4>GNC-alt</h4>\n",
       "<p>log-likelihood = -6705.8296</p>\n",
       "<p>number of free parameters = 27</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.8554</td>\n",
       "<td style=\"font-family: monospace !important;\">3.5343</td>\n",
       "<td style=\"font-family: monospace !important;\">0.9744</td>\n",
       "<td style=\"font-family: monospace !important;\">1.6586</td>\n",
       "<td style=\"font-family: monospace !important;\">2.1937</td>\n",
       "<td style=\"font-family: monospace !important;\">6.2585</td>\n",
       "<td style=\"font-family: monospace !important;\">8.0104</td>\n",
       "<td style=\"font-family: monospace !important;\">1.2418</td>\n",
       "<td style=\"font-family: monospace !important;\">0.7942</td>\n",
       "<td style=\"font-family: monospace !important;\">1.2667</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;\">2.9645</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",
       "</thead>\n",
       "<tbody>\n",
       "<tr>\n",
       "<td style=\"background: rgba(161, 195, 209, 0.25); font-weight: 600;\">0</td>\n",
       "<td style=\"font-family: monospace !important;\">0.0532</td>\n",
       "</tr>\n",
       "<tr>\n",
       "<td style=\"background: rgba(161, 195, 209, 0.25); font-weight: 600;\">1</td>\n",
       "<td style=\"font-family: monospace !important;\">0.2655</td>\n",
       "</tr>\n",
       "<tr>\n",
       "<td style=\"background: rgba(161, 195, 209, 0.25); font-weight: 600;\">2a</td>\n",
       "<td style=\"font-family: monospace !important;\">0.0403</td>\n",
       "</tr>\n",
       "<tr>\n",
       "<td style=\"background: rgba(161, 195, 209, 0.25); font-weight: 600;\">2b</td>\n",
       "<td style=\"font-family: monospace !important;\">0.6410</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.5419</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.1359</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.0648</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.0365</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.0234</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 bin 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>bin</th>\n",
       "<th>omega</th>\n",
       "</thead>\n",
       "<tbody>\n",
       "<tr>\n",
       "<td style=\"background: rgba(161, 195, 209, 0.25); font-weight: 600;\">Galago</td>\n",
       "<td style=\"font-family: monospace !important;\">0</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;\">Galago</td>\n",
       "<td style=\"font-family: monospace !important;\">1</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;\">Galago</td>\n",
       "<td>2a</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;\">Galago</td>\n",
       "<td>2b</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;\">HowlerMon</td>\n",
       "<td style=\"font-family: monospace !important;\">0</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;\">HowlerMon</td>\n",
       "<td style=\"font-family: monospace !important;\">1</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;\">HowlerMon</td>\n",
       "<td>2a</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;\">HowlerMon</td>\n",
       "<td>2b</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;\">Rhesus</td>\n",
       "<td style=\"font-family: monospace !important;\">0</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;\">Rhesus</td>\n",
       "<td style=\"font-family: monospace !important;\">1</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;\">Rhesus</td>\n",
       "<td>2a</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;\">Rhesus</td>\n",
       "<td>2b</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;\">Orangutan</td>\n",
       "<td style=\"font-family: monospace !important;\">0</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;\">Orangutan</td>\n",
       "<td style=\"font-family: monospace !important;\">1</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;\">Orangutan</td>\n",
       "<td>2a</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;\">Orangutan</td>\n",
       "<td>2b</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;\">Gorilla</td>\n",
       "<td style=\"font-family: monospace !important;\">0</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;\">Gorilla</td>\n",
       "<td style=\"font-family: monospace !important;\">1</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;\">Gorilla</td>\n",
       "<td>2a</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;\">Gorilla</td>\n",
       "<td>2b</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;\">Human</td>\n",
       "<td style=\"font-family: monospace !important;\">0</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;\">Human</td>\n",
       "<td style=\"font-family: monospace !important;\">1</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;\">Human</td>\n",
       "<td>2a</td>\n",
       "<td style=\"font-family: monospace !important;\">20.0000</td>\n",
       "</tr>\n",
       "<tr>\n",
       "<td style=\"background: rgba(161, 195, 209, 0.25); font-weight: 600;\">Human</td>\n",
       "<td>2b</td>\n",
       "<td style=\"font-family: monospace !important;\">20.0000</td>\n",
       "</tr>\n",
       "<tr>\n",
       "<td style=\"background: rgba(161, 195, 209, 0.25); font-weight: 600;\">Chimpanzee</td>\n",
       "<td style=\"font-family: monospace !important;\">0</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;\">Chimpanzee</td>\n",
       "<td style=\"font-family: monospace !important;\">1</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;\">Chimpanzee</td>\n",
       "<td>2a</td>\n",
       "<td style=\"font-family: monospace !important;\">20.0000</td>\n",
       "</tr>\n",
       "<tr>\n",
       "<td style=\"background: rgba(161, 195, 209, 0.25); font-weight: 600;\">Chimpanzee</td>\n",
       "<td>2b</td>\n",
       "<td style=\"font-family: monospace !important;\">20.0000</td>\n",
       "</tr>\n",
       "<tr>\n",
       "<td style=\"background: rgba(161, 195, 209, 0.25); font-weight: 600;\">edge.0</td>\n",
       "<td style=\"font-family: monospace !important;\">0</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.0</td>\n",
       "<td style=\"font-family: monospace !important;\">1</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;\">edge.0</td>\n",
       "<td>2a</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.0</td>\n",
       "<td>2b</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;\">edge.1</td>\n",
       "<td style=\"font-family: monospace !important;\">0</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 style=\"font-family: monospace !important;\">1</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;\">edge.1</td>\n",
       "<td>2a</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>2b</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;\">edge.2</td>\n",
       "<td style=\"font-family: monospace !important;\">0</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.2</td>\n",
       "<td style=\"font-family: monospace !important;\">1</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;\">edge.2</td>\n",
       "<td>2a</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.2</td>\n",
       "<td>2b</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;\">edge.3</td>\n",
       "<td style=\"font-family: monospace !important;\">0</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.3</td>\n",
       "<td style=\"font-family: monospace !important;\">1</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;\">edge.3</td>\n",
       "<td>2a</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.3</td>\n",
       "<td>2b</td>\n",
       "<td style=\"font-family: monospace !important;\">1.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;\">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 = -6705.8296\n",
       "number of free parameters = 27\n",
       "============================================================================\n",
       "   A>C       A>G       A>T       C>A       C>G       C>T       G>A       G>C\n",
       "----------------------------------------------------------------------------\n",
       "0.8554    3.5343    0.9744    1.6586    2.1937    6.2585    8.0104    1.2418\n",
       "----------------------------------------------------------------------------\n",
       "\n",
       "continued: \n",
       "==========================\n",
       "   G>T       T>A       T>C\n",
       "--------------------------\n",
       "0.7942    1.2667    2.9645\n",
       "--------------------------\n",
       "\n",
       "=============\n",
       "bin    bprobs\n",
       "-------------\n",
       "  0    0.0532\n",
       "  1    0.2655\n",
       " 2a    0.0403\n",
       " 2b    0.6410\n",
       "-------------\n",
       "==============================\n",
       "      edge    parent    length\n",
       "------------------------------\n",
       "    Galago      root    0.5419\n",
       " HowlerMon      root    0.1359\n",
       "    Rhesus    edge.3    0.0648\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.0365\n",
       "    edge.3      root    0.0234\n",
       "------------------------------\n",
       "============================\n",
       "      edge    bin      omega\n",
       "----------------------------\n",
       "    Galago      0     0.0000\n",
       "    Galago      1     1.0000\n",
       "    Galago     2a     0.0000\n",
       "    Galago     2b     1.0000\n",
       " HowlerMon      0     0.0000\n",
       " HowlerMon      1     1.0000\n",
       " HowlerMon     2a     0.0000\n",
       " HowlerMon     2b     1.0000\n",
       "    Rhesus      0     0.0000\n",
       "    Rhesus      1     1.0000\n",
       "    Rhesus     2a     0.0000\n",
       "    Rhesus     2b     1.0000\n",
       " Orangutan      0     0.0000\n",
       " Orangutan      1     1.0000\n",
       " Orangutan     2a     0.0000\n",
       " Orangutan     2b     1.0000\n",
       "   Gorilla      0     0.0000\n",
       "   Gorilla      1     1.0000\n",
       "   Gorilla     2a     0.0000\n",
       "   Gorilla     2b     1.0000\n",
       "     Human      0     0.0000\n",
       "     Human      1     1.0000\n",
       "     Human     2a    20.0000\n",
       "     Human     2b    20.0000\n",
       "Chimpanzee      0     0.0000\n",
       "Chimpanzee      1     1.0000\n",
       "Chimpanzee     2a    20.0000\n",
       "Chimpanzee     2b    20.0000\n",
       "    edge.0      0     0.0000\n",
       "    edge.0      1     1.0000\n",
       "    edge.0     2a     0.0000\n",
       "    edge.0     2b     1.0000\n",
       "    edge.1      0     0.0000\n",
       "    edge.1      1     1.0000\n",
       "    edge.1     2a     0.0000\n",
       "    edge.1     2b     1.0000\n",
       "    edge.2      0     0.0000\n",
       "    edge.2      1     1.0000\n",
       "    edge.2     2a     0.0000\n",
       "    edge.2     2b     1.0000\n",
       "    edge.3      0     0.0000\n",
       "    edge.3      1     1.0000\n",
       "    edge.3     2a     0.0000\n",
       "    edge.3     2b     1.0000\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 posterior probabilities of site-class membership"
   ]
  },
  {
   "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",
       "<th>10</th>\n",
       "</thead>\n",
       "<tbody>\n",
       "<tr>\n",
       "<td style=\"background: rgba(161, 195, 209, 0.25); font-weight: 600;\">0</td>\n",
       "<td style=\"font-family: monospace !important;\">0.076</td>\n",
       "<td style=\"font-family: monospace !important;\">0.043</td>\n",
       "<td style=\"font-family: monospace !important;\">0.000</td>\n",
       "<td style=\"font-family: monospace !important;\">0.067</td>\n",
       "<td style=\"font-family: monospace !important;\">0.059</td>\n",
       "<td style=\"font-family: monospace !important;\">0.080</td>\n",
       "<td style=\"font-family: monospace !important;\">0.043</td>\n",
       "<td style=\"font-family: monospace !important;\">0.061</td>\n",
       "<td style=\"font-family: monospace !important;\">0.052</td>\n",
       "<td style=\"font-family: monospace !important;\">0.041</td>\n",
       "<td style=\"font-family: monospace !important;\">0.039</td>\n",
       "</tr>\n",
       "<tr>\n",
       "<td style=\"background: rgba(161, 195, 209, 0.25); font-weight: 600;\">1</td>\n",
       "<td style=\"font-family: monospace !important;\">0.255</td>\n",
       "<td style=\"font-family: monospace !important;\">0.270</td>\n",
       "<td style=\"font-family: monospace !important;\">0.293</td>\n",
       "<td style=\"font-family: monospace !important;\">0.259</td>\n",
       "<td style=\"font-family: monospace !important;\">0.263</td>\n",
       "<td style=\"font-family: monospace !important;\">0.253</td>\n",
       "<td style=\"font-family: monospace !important;\">0.270</td>\n",
       "<td style=\"font-family: monospace !important;\">0.262</td>\n",
       "<td style=\"font-family: monospace !important;\">0.266</td>\n",
       "<td style=\"font-family: monospace !important;\">0.271</td>\n",
       "<td style=\"font-family: monospace !important;\">0.272</td>\n",
       "</tr>\n",
       "<tr>\n",
       "<td style=\"background: rgba(161, 195, 209, 0.25); font-weight: 600;\">2a</td>\n",
       "<td style=\"font-family: monospace !important;\">0.057</td>\n",
       "<td style=\"font-family: monospace !important;\">0.033</td>\n",
       "<td style=\"font-family: monospace !important;\">0.000</td>\n",
       "<td style=\"font-family: monospace !important;\">0.050</td>\n",
       "<td style=\"font-family: monospace !important;\">0.044</td>\n",
       "<td style=\"font-family: monospace !important;\">0.060</td>\n",
       "<td style=\"font-family: monospace !important;\">0.033</td>\n",
       "<td style=\"font-family: monospace !important;\">0.046</td>\n",
       "<td style=\"font-family: monospace !important;\">0.040</td>\n",
       "<td style=\"font-family: monospace !important;\">0.032</td>\n",
       "<td style=\"font-family: monospace !important;\">0.030</td>\n",
       "</tr>\n",
       "<tr>\n",
       "<td style=\"background: rgba(161, 195, 209, 0.25); font-weight: 600;\">2b</td>\n",
       "<td style=\"font-family: monospace !important;\">0.613</td>\n",
       "<td style=\"font-family: monospace !important;\">0.654</td>\n",
       "<td style=\"font-family: monospace !important;\">0.707</td>\n",
       "<td style=\"font-family: monospace !important;\">0.624</td>\n",
       "<td style=\"font-family: monospace !important;\">0.634</td>\n",
       "<td style=\"font-family: monospace !important;\">0.608</td>\n",
       "<td style=\"font-family: monospace !important;\">0.654</td>\n",
       "<td style=\"font-family: monospace !important;\">0.632</td>\n",
       "<td style=\"font-family: monospace !important;\">0.643</td>\n",
       "<td style=\"font-family: monospace !important;\">0.657</td>\n",
       "<td style=\"font-family: monospace !important;\">0.659</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>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;\">0</td>\n",
       "<td style=\"font-family: monospace !important;\">0.080</td>\n",
       "<td style=\"font-family: monospace !important;\">0.048</td>\n",
       "<td style=\"font-family: monospace !important;\">0.000</td>\n",
       "<td style=\"font-family: monospace !important;\">0.080</td>\n",
       "<td style=\"font-family: monospace !important;\">0.262</td>\n",
       "<td style=\"font-family: monospace !important;\">0.041</td>\n",
       "<td style=\"font-family: monospace !important;\">0.036</td>\n",
       "<td style=\"font-family: monospace !important;\">0.059</td>\n",
       "<td style=\"font-family: monospace !important;\">0.062</td>\n",
       "</tr>\n",
       "<tr>\n",
       "<td style=\"background: rgba(161, 195, 209, 0.25); font-weight: 600;\">1</td>\n",
       "<td style=\"font-family: monospace !important;\">0.253</td>\n",
       "<td style=\"font-family: monospace !important;\">0.268</td>\n",
       "<td style=\"font-family: monospace !important;\">0.293</td>\n",
       "<td style=\"font-family: monospace !important;\">0.253</td>\n",
       "<td style=\"font-family: monospace !important;\">0.156</td>\n",
       "<td style=\"font-family: monospace !important;\">0.271</td>\n",
       "<td style=\"font-family: monospace !important;\">0.273</td>\n",
       "<td style=\"font-family: monospace !important;\">0.263</td>\n",
       "<td style=\"font-family: monospace !important;\">0.261</td>\n",
       "</tr>\n",
       "<tr>\n",
       "<td style=\"background: rgba(161, 195, 209, 0.25); font-weight: 600;\">2a</td>\n",
       "<td style=\"font-family: monospace !important;\">0.060</td>\n",
       "<td style=\"font-family: monospace !important;\">0.037</td>\n",
       "<td style=\"font-family: monospace !important;\">0.000</td>\n",
       "<td style=\"font-family: monospace !important;\">0.059</td>\n",
       "<td style=\"font-family: monospace !important;\">0.202</td>\n",
       "<td style=\"font-family: monospace !important;\">0.032</td>\n",
       "<td style=\"font-family: monospace !important;\">0.028</td>\n",
       "<td style=\"font-family: monospace !important;\">0.044</td>\n",
       "<td style=\"font-family: monospace !important;\">0.047</td>\n",
       "</tr>\n",
       "<tr>\n",
       "<td style=\"background: rgba(161, 195, 209, 0.25); font-weight: 600;\">2b</td>\n",
       "<td style=\"font-family: monospace !important;\">0.608</td>\n",
       "<td style=\"font-family: monospace !important;\">0.648</td>\n",
       "<td style=\"font-family: monospace !important;\">0.707</td>\n",
       "<td style=\"font-family: monospace !important;\">0.608</td>\n",
       "<td style=\"font-family: monospace !important;\">0.379</td>\n",
       "<td style=\"font-family: monospace !important;\">0.657</td>\n",
       "<td style=\"font-family: monospace !important;\">0.664</td>\n",
       "<td style=\"font-family: monospace !important;\">0.634</td>\n",
       "<td style=\"font-family: monospace !important;\">0.630</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",
       " 0    0.0759    0.0427    0.0000    0.0670    0.0586    0.0800    0.0430    0.0608    0.0519    0.0411    0.0392    0.0800    0.0480    0.0000    0.0797    0.2618    0.0411    0.0355    0.0586    0.0620\n",
       " 1    0.2546    0.2700    0.2929    0.2588    0.2628    0.2527    0.2699    0.2617    0.2658    0.2706    0.2716    0.2527    0.2676    0.2926    0.2528    0.1564    0.2706    0.2733    0.2628    0.2611\n",
       "2a    0.0568    0.0329    0.0000    0.0504    0.0444    0.0597    0.0331    0.0460    0.0396    0.0317    0.0303    0.0597    0.0367    0.0000    0.0595    0.2023    0.0317    0.0275    0.0444    0.0468\n",
       "2b    0.6127    0.6543    0.7071    0.6237    0.6343    0.6076    0.6540    0.6315    0.6428    0.6566    0.6589    0.6076    0.6477    0.7074    0.6080    0.3794    0.6566    0.6636    0.6343    0.6301\n",
       "----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "bprobs = result.alt.lf.get_bin_probs()\n",
    "bprobs[:, :20]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Getting all the statistics in tabular form"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "5x tabular_result('global params': Table, 'bin params': Table, 'edge params': Table, 'edge bin params': Table)"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "tab = evo.tabulate_stats()\n",
    "stats = tab(result.alt)\n",
    "stats"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "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;\">edge bin 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>bin</th>\n",
       "<th>omega</th>\n",
       "</thead>\n",
       "<tbody>\n",
       "<tr>\n",
       "<td style=\"background: rgba(161, 195, 209, 0.25); font-weight: 600;\">Galago</td>\n",
       "<td style=\"font-family: monospace !important;\">0</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;\">Galago</td>\n",
       "<td style=\"font-family: monospace !important;\">1</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;\">Galago</td>\n",
       "<td>2a</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;\">Galago</td>\n",
       "<td>2b</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;\">HowlerMon</td>\n",
       "<td style=\"font-family: monospace !important;\">0</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;\">HowlerMon</td>\n",
       "<td style=\"font-family: monospace !important;\">1</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;\">HowlerMon</td>\n",
       "<td>2a</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;\">HowlerMon</td>\n",
       "<td>2b</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;\">Rhesus</td>\n",
       "<td style=\"font-family: monospace !important;\">0</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;\">Rhesus</td>\n",
       "<td style=\"font-family: monospace !important;\">1</td>\n",
       "<td style=\"font-family: monospace !important;\">1.0000</td>\n",
       "</tr>\n",
       "</tbody>\n",
       "</table>\n",
       "<p>\n",
       "10 rows x 3 columns</p>"
      ],
      "text/plain": [
       "edge bin params\n",
       "==========================\n",
       "     edge    bin     omega\n",
       "--------------------------\n",
       "   Galago      0    0.0000\n",
       "   Galago      1    1.0000\n",
       "   Galago     2a    0.0000\n",
       "   Galago     2b    1.0000\n",
       "HowlerMon      0    0.0000\n",
       "HowlerMon      1    1.0000\n",
       "HowlerMon     2a    0.0000\n",
       "HowlerMon     2b    1.0000\n",
       "   Rhesus      0    0.0000\n",
       "   Rhesus      1    1.0000\n",
       "--------------------------\n",
       "\n",
       "10 rows x 3 columns"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stats[\"edge bin params\"][:10]  # truncating the table"
   ]
  }
 ],
 "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.7.3"
  },
  "widgets": {
   "application/vnd.jupyter.widget-state+json": {
    "state": {},
    "version_major": 2,
    "version_minor": 0
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
