Skip to content

Commit

Permalink
Replace repository with revised folder
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabriela Lobinska committed Jun 8, 2023
1 parent 6dbe996 commit ffdb8a3
Show file tree
Hide file tree
Showing 9,891 changed files with 33,362 additions and 0 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
526 changes: 526 additions & 0 deletions ERF_heatmaps/.ipynb_checkpoints/Heatmaps ERF-checkpoint.ipynb

Large diffs are not rendered by default.

354 changes: 354 additions & 0 deletions ERF_heatmaps/.ipynb_checkpoints/Parsing Cmaps Omicron-checkpoint.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,354 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "09c64da6",
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"import pickle\n",
"import pandas as pd\n",
"import numpy as np\n",
"from itertools import combinations\n",
"import matplotlib.pyplot as plt\n",
"from numpy import nan"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "2bd7d713",
"metadata": {},
"outputs": [],
"source": [
"files = [x for x in os.listdir('heatmap_ERF_omicron/') if 'results' in x]"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "a9a05c92",
"metadata": {},
"outputs": [],
"source": [
"all_results = []\n",
"for file in files:\n",
" with open('heatmap_ERF_omicron/'+file, 'rb') as f:\n",
" result_file = pickle.load(f)\n",
" for r in result_file['results']:\n",
" all_results.append(r)\n",
" \n",
"result_df = pd.DataFrame(all_results)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "72331064",
"metadata": {},
"outputs": [],
"source": [
"with open('heatmap_ERF_omicron/paramgrid_params_omicron.txt','rb') as f:\n",
" param_grid = pickle.load(f)"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "05876920",
"metadata": {},
"outputs": [],
"source": [
"along_ap = sorted(list(set(result_df['ap'])))"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "b63751be",
"metadata": {},
"outputs": [],
"source": [
"along_m = sorted(list(set(result_df['m'])))\n",
"along_n = sorted(list(set(result_df['n'])))\n",
"along_ap = sorted(list(set(result_df['ap'])))\n",
"along_ttr = sorted(list(set(result_df['ttr'])))\n",
"along_qd = sorted(list(set(result_df['qd'])))\n",
"along_m.remove(20000)\n",
"along_ap.remove(6.03)\n",
"along_ttr.remove(5)\n",
"along_qd.remove(1-3e-6)\n",
"along_n.remove(100)\n",
"all_along_params = [('m',along_m), ('n',along_n), ('ap',along_ap), ('ttr',along_ttr), ('qd',along_qd)]\n",
"all_names_params = ['m', 'n', 'ap', 'ttr', 'qd']"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "9d0ad0e1",
"metadata": {},
"outputs": [],
"source": [
"all_colormap_params = list(combinations(all_along_params, 2))\n",
"all_colormap_names = list(combinations(all_names_params,2))"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "23534600",
"metadata": {},
"outputs": [],
"source": [
"dict_other_vals = {'m':20000, 'n':100, 'ap': 6.03, 'qd':1-3e-6, 'ttr':5}"
]
},
{
"cell_type": "markdown",
"id": "6ef4c643",
"metadata": {},
"source": [
"#### 1) Generating all matrices for colormaps"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "79d3ba54",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"('m', 'n')\n",
"('m', 'ap')\n",
"('m', 'ttr')\n"
]
}
],
"source": [
"all_matrices_for_cmap = []\n",
"\n",
"for comb in all_colormap_params:\n",
" params_axes = (comb[0][0], comb[1][0])\n",
" print(params_axes)\n",
" other_params = set(all_names_params)-set(params_axes)\n",
"\n",
" colormap_params = np.zeros((len(comb[0][1]), len(comb[1][1])))\n",
" \n",
" for xind in range(len(comb[0][1])):\n",
" for yind in range(len(comb[0][1])):\n",
" df_axes = result_df.copy()\n",
" for p in other_params:\n",
" df_axes = df_axes[df_axes[p] == dict_other_vals[p]]\n",
" df_axes = df_axes[(df_axes[params_axes[0]] == comb[0][1][xind])&(df_axes[params_axes[1]] == comb[1][1][yind])]\n",
" colormap_params[xind, yind] = list(df_axes['Y_treatment'])[0]/list(df_axes['Y_control'])[0]\n",
" \n",
" all_matrices_for_cmap.append(colormap_params)"
]
},
{
"cell_type": "markdown",
"id": "42e11dce",
"metadata": {},
"source": [
"#### 2) Plotting all 10 cmaps"
]
},
{
"cell_type": "markdown",
"id": "a07eb2d1",
"metadata": {},
"source": [
"##### Indices for plots"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "122828c7",
"metadata": {},
"outputs": [],
"source": [
"indices_colormaps = []\n",
"for i in range(5):\n",
" for j in range(2):\n",
" indices_colormaps.append((i,j))\n",
"indices_colormaps = dict(zip(range(10), indices_colormaps))"
]
},
{
"cell_type": "markdown",
"id": "3e1fd29b",
"metadata": {},
"source": [
"##### Labels for axes"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "9e8378e3",
"metadata": {},
"outputs": [],
"source": [
"def calculate_ticks(ticklabels, truerange, tickrange):\n",
" tick_pos = []\n",
" for l in ticklabels:\n",
" NewValue = (((l - truerange[0]) * (tickrange[1] - tickrange[0])) / (truerange[1] - truerange[0])) + tickrange[0]\n",
" tick_pos.append(NewValue)\n",
" return(np.array(tick_pos))\n",
"\n",
"def calculate_ticks_log(ticklabels, truerange, tickrange):\n",
" tick_labels = np.log(ticklabels)\n",
" true_range = np.log(truerange)\n",
" tick_pos = []\n",
" for l in ticklabels:\n",
" NewValue = (((l - truerange[0]) * (tickrange[1] - tickrange[0])) / (truerange[1] - truerange[0])) + tickrange[0]\n",
" tick_pos.append(NewValue)\n",
" return(np.array(tick_pos))"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "a970b425",
"metadata": {},
"outputs": [],
"source": [
"param_ticks = {'m':[1500,5000,10000,15000,20000,25000,29900],\n",
" 'n':[1,200,400,600,800,1000],\n",
" 'ap':[7.7,8.0,8.3,8.6,8.8],\n",
" 'qd':[1-1e-6,1-3e-6,1-5e-6,1-7.5e-6,1-1e-5], \n",
" 'ttr':[0,3,7,10,14]}\n",
"param_ranges = {'m':[1500,29900],\n",
" 'n':[1,1000],\n",
" 'ap':[7.7,8.8],\n",
" 'qd':[1e-6,1e-5],\n",
" 'ttr':[0,14]}"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "ca6b4494",
"metadata": {},
"outputs": [],
"source": [
"all_xticks, all_yticks = [],[]\n",
"all_xticklabels, all_yticklabels = [],[]\n",
"\n",
"for i in range(10):\n",
" \n",
" x_param, y_param = all_colormap_names[i]\n",
"\n",
" if y_param == 'qd':\n",
" ticks_y = calculate_ticks_log(1-np.array(param_ticks[y_param]), param_ranges[y_param], [0,19])\n",
" else:\n",
" ticks_y = calculate_ticks(np.array(param_ticks[y_param]), param_ranges[y_param], [0,19])\n",
" \n",
" if y_param == 'qd':\n",
" labels_y = list([\"{:.1e}\".format(1-x) for x in np.array(param_ticks[y_param])])\n",
" elif y_param == 'ap':\n",
" labels_y = [np.round(x,2) for x in param_ticks[y_param]]\n",
" else:\n",
" labels_y = [int(np.round(x)) for x in param_ticks[y_param]]\n",
" \n",
" if x_param == 'qd': \n",
" ticks_x = 19-np.array(calculate_ticks_log(1-np.array(param_ticks[x_param]), param_ranges[x_param], [0,19])[::-1])\n",
" else:\n",
" ticks_x = 19-np.array(calculate_ticks(np.array(param_ticks[x_param]), param_ranges[x_param], [0,19])[::-1])\n",
" \n",
"\n",
" if x_param == 'qd':\n",
" labels_x = list([\"{:.1e}\".format(1-x) for x in np.array(param_ticks[x_param])])\n",
" elif x_param == 'ap':\n",
" labels_x = [np.round(x,2) for x in param_ticks[x_param]]\n",
" else:\n",
" labels_x = [int(np.round(x)) for x in param_ticks[x_param]]\n",
" \n",
" \n",
" all_xticks.append(ticks_x)\n",
" all_yticks.append(ticks_y)\n",
" all_xticklabels.append(labels_x)\n",
" all_yticklabels.append(labels_y)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "3f2160fa",
"metadata": {},
"outputs": [],
"source": [
"params_description = {'m':'Number of lethal positions $m$',\n",
" 'n':'Number of gain-of-function positions $n$',\n",
" 'ap': 'Clearance rate in clearance phase $a_1$',\n",
" 'qd': 'Viral mutation rate under treatment $u_1$',\n",
" 'ttr': 'Time of start of treatment'}"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "f5a8b86c",
"metadata": {},
"outputs": [],
"source": [
"fig, ax = plt.subplots(5,2,figsize=(8,18))\n",
"\n",
"for i in range(10):\n",
" im = ax[indices_colormaps[i]].imshow(all_matrices_for_cmap[i][::-1], cmap = 'seismic', vmin = 0., vmax = 2)\n",
" if all_colormap_params[i][1][0] in ['qd']:\n",
" im = ax[indices_colormaps[i]].imshow(np.flip(all_matrices_for_cmap[i][::-1],1), cmap = 'seismic', vmin = 0., vmax = 2)\n",
"\n",
" ax[indices_colormaps[i]].set_xticks(all_yticks[i])\n",
" ax[indices_colormaps[i]].set_xticklabels(all_yticklabels[i])\n",
" \n",
" ax[indices_colormaps[i]].set_yticks(all_xticks[i])\n",
" ax[indices_colormaps[i]].set_yticklabels(all_xticklabels[i][::-1]) \n",
" \n",
" \n",
" ax[indices_colormaps[i]].set_ylabel(params_description[all_colormap_params[i][0][0]])\n",
" ax[indices_colormaps[i]].set_xlabel(params_description[all_colormap_params[i][1][0]])\n",
" \n",
" \n",
"plt.tight_layout(pad=1.0)\n",
"#plt.savefig('colormaps_gradualclearance_all_params_FEB1.jpg', dpi = 600)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "7a86a303",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"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.8.8"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Loading

0 comments on commit ffdb8a3

Please sign in to comment.