{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import seaborn as sns\n",
    "import matplotlib.pyplot as plt\n",
    "from statannot import add_stat_annotation\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "xoxo = pd.read_excel('../results_diversity/2024-03-20/stats_raw.xlsx', sheet_name='POOL4')\n",
    "xoxo.loc[['Fungi' in i for i in xoxo['lineage'].values]].iloc[:10]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "fungi = ['Saccharomycodes', 'Malassezia', 'Coccidioides', 'Parastagonospora', 'Pleurotus', 'Psilocybe', 'Plenodomus', 'Aspergillus', 'Alternaria', 'Candida']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "for fungi_i in fungi:\n",
    "    df_candida_full = pd.DataFrame(index = [f'POOL{i}' for i in range(1, 13)] + ['ACIDOLA', 'BLACTIS'], columns=['kaiju', 'kraken_2', 'krakenuniq', 'centrifuge', 'mean', 'quality'])\n",
    "    for POOL in [f'POOL{i}' for i in range(1, 13)] + ['ACIDOLA', 'BLACTIS']:\n",
    "        df = pd.read_excel('../results_diversity/2024-03-20/stats_raw.xlsx', sheet_name=POOL)\n",
    "        df_candida = df[df['name'] == fungi_i]\n",
    "\n",
    "        if len(df_candida) > 0:\n",
    "            \n",
    "            df_candida_full.loc[POOL, ['kaiju', 'kraken_2', 'krakenuniq', 'centrifuge']] = df_candida.iloc[0][['kaiju_norm', 'kraken_2_norm', 'krakenuniq_norm', 'centrifuge_norm']].values\n",
    "            df_candida_full.loc[POOL, ['mean', 'quality']] = df_candida.iloc[0][['mean', 'quality']].values\n",
    "\n",
    "    df_candida_full = df_candida_full.iloc[:-2] # To remove ACIDOLA and BLACTIS\n",
    "    df_candida_full['sample'] = ['RR'] * 4 + ['SP'] * 4 + ['HC'] * 4\n",
    "\n",
    "    print(fungi_i)\n",
    "    df_candida_full['sample'] = df_candida_full['sample'].astype('category')\n",
    "    df_candida_full['mean'] = df_candida_full['mean'].astype('float')\n",
    "\n",
    "    sns.swarmplot(data = df_candida_full, x = 'sample', y = 'mean')\n",
    "    plt.show()\n",
    "\n",
    "    ax = sns.boxplot(data = df_candida_full, x = 'sample', y = 'mean')\n",
    "    add_stat_annotation(ax, data=df_candida_full[['sample', 'mean']], x = 'sample', y = 'mean', \n",
    "                    box_pairs=[(\"HC\", \"RR\"), (\"HC\", \"SP\"), (\"RR\", \"SP\")],\n",
    "                    test='t-test_ind', text_format='star', loc='outside', verbose=0)\n",
    "    plt.show()\n",
    "\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "NGS_pipeline",
   "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.10.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
