{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"# Histograms of Gene Expression Change per Small Molecule\n\nExactly what it says on the box: just a little histogram generating script and a bunch of histograms it generated, broken down per small molecule.","metadata":{}},{"cell_type":"code","source":"import pandas as pd\nimport seaborn as sns\nfrom matplotlib import pyplot as plt\nfrom IPython.display import display, Markdown\n\n\ndef md(s):\n    display(Markdown(s))\n\n    \ndf = pd.read_parquet(\"/kaggle/input/open-problems-single-cell-perturbations/de_train.parquet\")\nsms = list(df['sm_name'].unique())\n\nfor sm_name in sorted(sms):\n    chem_sub = df[df['sm_name'] == sm_name].copy(deep=True)\n    chem_cell_type = chem_sub['cell_type']\n    chem_sub = chem_sub[chem_sub.columns[5:]]\n    chem_sub.index = chem_cell_type\n    chem_cell_avg = chem_sub[df.columns[5:]].mean(axis=1)\n    chem_subT = chem_sub.transpose()\n    chem_subT.index.names = ['Gene']\n    md(f\"## {sm_name}\")\n    _fig, _ax = plt.subplots(figsize=(7, 7))\n    sns.histplot(chem_subT,\n                 multiple='dodge',\n                 bins=25,\n                 binrange=(-8, 8)).set(\n        title=f\"Log fold change in gene expression by Cell Type for {sm_name}\",\n        xlim=(-8, 8)\n    )\n    plt.show()\n    md(\"### Average Change by Cell Type\\n\")\n    for cell_type, change in zip(list(chem_cell_avg.index),\n                                 list(chem_cell_avg)):\n        md(f\"{cell_type} : {change}\")","metadata":{"execution":{"iopub.status.busy":"2023-10-02T23:15:38.387582Z","iopub.execute_input":"2023-10-02T23:15:38.388761Z","iopub.status.idle":"2023-10-02T23:16:49.821586Z","shell.execute_reply.started":"2023-10-02T23:15:38.388719Z","shell.execute_reply":"2023-10-02T23:16:49.821026Z"},"trusted":true},"execution_count":null,"outputs":[]}]}