{
 "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": "0be1234d",
   "metadata": {},
   "outputs": [],
   "source": [
    "kmers = list(map(int,\"11 13 15 17 19 21 25 31 41 51 61 81 101 151 201 251 301 501 1001 2001\".split()))\n",
    "\n",
    "data_kmers = []\n",
    "for k in kmers:\n",
    "    abundances = []\n",
    "    mean = 0\n",
    "    nb_items = 0\n",
    "    for line in open(\"chm13v2.0-\"+str(k)+\".histo\"):\n",
    "        x, abundance = map(int,line.split())\n",
    "        #abundances += [x]*abundance\n",
    "        mean += x*abundance\n",
    "        nb_items += abundance\n",
    "    mean_abundance = mean/ nb_items\n",
    "    stdev_abundance = 0\n",
    "    # too slow\n",
    "    #mean_abundance = statistics.mean(abundances)\n",
    "    #stdev_abundance = statistics.stdev(abundances)\n",
    "    print(k,mean_abundance, stdev_abundance)\n",
    "    data_kmers += [(k,mean_abundance, stdev_abundance)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4b7479b4",
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "df = pd.DataFrame([x for x in data_kmers],columns=(\"k\",\"mean\",\"stdev\"))\n",
    "\n",
    "print(df)\n",
    "sns_plot = sns.lineplot(df[\"k\"], df[\"mean\"])\n",
    "\n",
    "sns_plot.set(xscale=\"log\")\n",
    "sns_plot.set(yscale=\"log\")\n",
    "#sns_plot.set(xticks=[x/100 for x in range(0,10+1,2)])\n",
    "#sns_plot.set_xticklabels([str(x-2) for x in range(0,10+3,2)])\n",
    "\n",
    "#ylabels = ['{:,.1f}'.format(x)  for x in sns_plot.get_yticks()/1000000.0]\n",
    "#sns_plot.set_yticklabels(ylabels)\n",
    "\n",
    "#plt.xticks(sns_plot.get_xticks(), sns_plot.get_xticks() * 100)\n",
    "sns_plot.set(xlabel='k value', ylabel='Average occurences in reference')\n",
    "#sns_plot.get_legend().remove()\n",
    "plt.title('')\n",
    "\n",
    "fig = sns_plot.get_figure()\n",
    "fig.savefig(\"seeds_kmers.pdf\", bbox_inches='tight', dpi =300)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "44f380ba",
   "metadata": {},
   "outputs": [],
   "source": [
    "ksizes = list(map(int,\" 2 4 6 8 10 12 15 20\".split()))\n",
    "\n",
    "data_kminmers = []\n",
    "for k in ksizes:\n",
    "    abundances = []\n",
    "    mean = 0\n",
    "    nb_items = 0\n",
    "    for line in open(\"kminmers-k\"+str(k)+\".hist\"):\n",
    "        x, abundance = map(int,line.split())\n",
    "        #abundances += [x]*abundance\n",
    "        mean += x*abundance\n",
    "        nb_items += abundance\n",
    "    mean_abundance = mean/ nb_items\n",
    "    stdev_abundance = 0\n",
    "    # too slow\n",
    "    #mean_abundance = statistics.mean(abundances)\n",
    "    #stdev_abundance = statistics.stdev(abundances)\n",
    "    print(k,mean_abundance, stdev_abundance)\n",
    "    data_kminmers += [(k,mean_abundance, stdev_abundance)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1437142b",
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "df = pd.DataFrame([x for x in data_kminmers],columns=(\"k\",\"mean\",\"stdev\"))\n",
    "\n",
    "print(df)\n",
    "sns_plot = sns.lineplot(df[\"k\"], df[\"mean\"])\n",
    "\n",
    "#sns_plot.set(xscale=\"log\")\n",
    "#sns_plot.set(yscale=\"log\")\n",
    "#sns_plot.set(xticks=[x/100 for x in range(0,10+1,2)])\n",
    "#sns_plot.set_xticklabels([str(x-2) for x in range(0,10+3,2)])\n",
    "\n",
    "#ylabels = ['{:,.1f}'.format(x)  for x in sns_plot.get_yticks()]\n",
    "#sns_plot.set_yticklabels(ylabels)\n",
    "\n",
    "#plt.xticks(sns_plot.get_xticks(), sns_plot.get_xticks() * 100)\n",
    "sns_plot.set(xlabel='k value', ylabel='Average occurences in reference')\n",
    "#sns_plot.get_legend().remove()\n",
    "plt.title('')\n",
    "\n",
    "fig = sns_plot.get_figure()\n",
    "fig.savefig(\"seeds_kminers.pdf\", bbox_inches='tight', dpi =300)\n"
   ]
  }
 ],
 "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.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
