{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "cbcaae60",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "import seaborn as sns\n",
    "from matplotlib import pyplot as plt\n",
    "import statistics\n",
    "plt.rc('figure', facecolor='w', figsize=[4,3])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "44f380ba",
   "metadata": {},
   "outputs": [],
   "source": [
    "ksizes = list(map(int,\"2 4 6 8 10 12 15\".split()))\n",
    "\n",
    "data_kminmers = []\n",
    "for k in ksizes:\n",
    "    mean = 0\n",
    "    nb_items = 0\n",
    "    nb_missing = 0\n",
    "    for line in open(f\"hifimap-k{k}-d0.01-l31.read_stats.abbrv.hist\"):\n",
    "        abundance,x= map(int,line.split())\n",
    "        mean += abundance*x\n",
    "        nb_items += abundance\n",
    "        if x == 0: nb_missing=abundance\n",
    "    mean /= nb_items\n",
    "    data_kminmers += [(k,mean,nb_missing)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1437142b",
   "metadata": {},
   "outputs": [],
   "source": [
    "df = pd.DataFrame([x for x in data_kminmers],columns=(\"k\",\"avg_nb_seed_hits\",\"nb_missing\"))\n",
    "\n",
    "print(df)\n",
    "sns_plot = sns.lineplot(df, x=\"k\", y=\"avg_nb_seed_hits\",color=sns.color_palette()[1])\n",
    "\n",
    "#sns_plot.set(xscale=\"log\")\n",
    "sns_plot.set(xticks=[x for x in range(2,17,2)])\n",
    "#sns_plot.set_xticklabels([str(int(x)) for x in range(2,19,2)])\n",
    "\n",
    "#ylabels = ['{:}%'.format(int(x*100))  for x in sns_plot.get_yticks()]\n",
    "#sns_plot.set_yticklabels(ylabels)\n",
    "\n",
    "#plt.xticks(sns_plot.get_xticks(), list(map(lambda x:\"%d\"%x,sns_plot.get_xticks())))\n",
    "sns_plot.set(xlabel=\"k-min-mer's k value\", ylabel='')\n",
    "#sns_plot.get_legend().remove()\n",
    "plt.title('Average number of reference locations\\nper read using unique k-min-mers as seeds')\n",
    "sns_plot.axhline(1, color='k', linestyle='--')\n",
    "plt.ylim(0.95,1.3)\n",
    "\n",
    "fig = sns_plot.get_figure()\n",
    "\n",
    "\"\"\"\n",
    "# create second Axes. Note the 0.0 height\n",
    "ax2 = fig.add_axes((0.15,-0.1,0.72,0.0))\n",
    "ax2.yaxis.set_visible(False) # hide the yaxis\n",
    "new_tick_locations = np.array([0,.25, .5,.75,1])\n",
    "def tick_function(X):\n",
    "    ksizes = list(map(int,\" 2 4 6 8 10 12 15\".split()))\n",
    "    density=0.01\n",
    "    return [\"%d\" % (ksizes[i]/density) for i,z in enumerate(X)]\n",
    "ax2.set_xticks(new_tick_locations)\n",
    "ax2.set_xticklabels(tick_function(new_tick_locations))\n",
    "ax2.set_xlabel(\"Equivalent k span in bases\")\n",
    "\"\"\"\n",
    "plt.show()\n",
    "\n",
    "fig.savefig(\"seeds_avg_hits_to_ref.pdf\", bbox_inches='tight', dpi =300)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "84e39e78",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "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.9.15"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
