{"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":"# CITEseq Protein levels dependency on donors and days","metadata":{}},{"cell_type":"markdown","source":"# Summary\nI plotted average and histgram of CITEseq protein levals(targets) grouped by donors and days. <br>\nProtein levels are dependent on donors. Donor 32606 and 31800 shows similar values, but donor 13176 shows values a little far from them and generally higher.  <br>\nProtein levels are also dependent on days. But Some proteins show increasing dependency on days, some show decreasing dependency. And some have peaks at middle day(day 3).<br>\nIf you like automatic y-scale in average graph, please comment out ax.set_ylim(\\[0, 20\\]) ","metadata":{}},{"cell_type":"code","source":"import os, gc, pickle\nimport pandas as pd\nimport matplotlib.pyplot as plt\nimport numpy as np\nfrom colorama import Fore, Back, Style\nfrom matplotlib.ticker import MaxNLocator\n\nfrom sklearn.base import BaseEstimator, TransformerMixin\nfrom sklearn.model_selection import KFold\nfrom sklearn.preprocessing import StandardScaler, scale\nfrom sklearn.decomposition import PCA\nfrom sklearn.dummy import DummyRegressor\nfrom sklearn.pipeline import make_pipeline, Pipeline\nfrom sklearn.linear_model import Ridge, LinearRegression\nfrom sklearn.metrics import mean_squared_error\n\nfrom scipy.sparse import *\nfrom scipy.sparse import linalg\nfrom sklearn.decomposition import TruncatedSVD\nfrom scipy import interpolate\nimport random as rd\n\nimport psutil\n\ntry:\n    os.environ['SATURN_IMAGE']\n    kernel = \"saturn_cloud\"\nexcept KeyError:\n    kernel = \"kaggle\"\n\nDATA_DIR = \"/kaggle/input/open-problems-multimodal/\"\nFP_CELL_METADATA = os.path.join(DATA_DIR,\"metadata.csv\")\n\nif kernel==\"saturn_cloud\":\n    SPARSE_DIR = \"./\"\n    META_DIR = \"./\"\nelse: # kaggle\n#    SPARSE_DIR = \"../input/opmsci-sparse-data/\"\n    META_DIR = \"../input/open-problems-multimodal-singlecell-metadata/\"\n    SPARSE_DIR = \"../input/open-problems-multimodal-singlecell-metadata/\"\n\nMETA_CITE_TRAIN = os.path.join(META_DIR,\"cite_train_meta.csv\")\nMETA_CITE_TEST = os.path.join(META_DIR,\"cite_test_meta.csv\")\nMETA_MULTI_TRAIN = os.path.join(META_DIR,\"multiome_train_meta.csv\")\nMETA_MULTI_TEST = os.path.join(META_DIR,\"multiome_test_meta.csv\")\n\nSPS_CITE_TRAIN_INPUTS = os.path.join(SPARSE_DIR,\"train_cite_inputs.npz\")\nSPS_CITE_TRAIN_TARGETS = os.path.join(SPARSE_DIR,\"train_cite_targets.npz\")\nSPS_CITE_TEST_INPUTS = os.path.join(SPARSE_DIR,\"test_cite_inputs.npz\")\n\nSPS_MULTIOME_TRAIN_INPUTS = os.path.join(SPARSE_DIR,\"train_multi_inputs.npz\")\nSPS_MULTIOME_TRAIN_TARGETS = os.path.join(SPARSE_DIR,\"train_multi_targets.npz\")\nSPS_MULTIOME_TEST_INPUTS = os.path.join(SPARSE_DIR,\"test_multi_inputs.npz\")\n\nFP_CITE_TRAIN_INPUTS = os.path.join(DATA_DIR,\"train_cite_inputs.h5\")\nFP_CITE_TRAIN_TARGETS = os.path.join(DATA_DIR,\"train_cite_targets.h5\")\nFP_CITE_TEST_INPUTS = os.path.join(DATA_DIR,\"test_cite_inputs.h5\")\n\nFP_MULTIOME_TRAIN_INPUTS = os.path.join(DATA_DIR,\"train_multi_inputs.h5\")\nFP_MULTIOME_TRAIN_TARGETS = os.path.join(DATA_DIR,\"train_multi_targets.h5\")\nFP_MULTIOME_TEST_INPUTS = os.path.join(DATA_DIR,\"test_multi_inputs.h5\")\n\nFP_SUBMISSION = os.path.join(DATA_DIR,\"sample_submission.csv\")\nFP_EVALUATION_IDS = os.path.join(DATA_DIR,\"evaluation_ids.csv\")","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-09-10T06:49:56.771753Z","iopub.execute_input":"2022-09-10T06:49:56.772340Z","iopub.status.idle":"2022-09-10T06:49:57.589300Z","shell.execute_reply.started":"2022-09-10T06:49:56.772225Z","shell.execute_reply":"2022-09-10T06:49:57.587844Z"},"jupyter":{"source_hidden":true},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"if not os.path.exists('/opt/conda/lib/python3.7/site-packages/tables'):  ## AMBROSM's trick\n    !pip install --quiet tables","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-09-10T06:49:57.592036Z","iopub.execute_input":"2022-09-10T06:49:57.592470Z","iopub.status.idle":"2022-09-10T06:50:12.365713Z","shell.execute_reply.started":"2022-09-10T06:49:57.592436Z","shell.execute_reply":"2022-09-10T06:50:12.364182Z"},"_kg_hide-output":true,"jupyter":{"source_hidden":true},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Get protein names from hdf files","metadata":{"_kg_hide-input":true}},{"cell_type":"code","source":"cite_protein_names = pd.read_hdf(FP_CITE_TRAIN_TARGETS,start = 0,stop=5).columns.values\ncite_protein_names","metadata":{"execution":{"iopub.status.busy":"2022-09-10T06:50:12.367832Z","iopub.execute_input":"2022-09-10T06:50:12.368314Z","iopub.status.idle":"2022-09-10T06:50:12.473472Z","shell.execute_reply.started":"2022-09-10T06:50:12.368269Z","shell.execute_reply":"2022-09-10T06:50:12.472098Z"},"_kg_hide-input":true,"_kg_hide-output":true,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"read Cite Seq target data and metadata from pre-sorted files.","metadata":{"_kg_hide-input":true}},{"cell_type":"code","source":"cite_y = load_npz(SPS_CITE_TRAIN_TARGETS)\ncite_y_m = pd.read_csv(META_CITE_TRAIN)","metadata":{"execution":{"iopub.status.busy":"2022-09-10T06:50:12.478330Z","iopub.execute_input":"2022-09-10T06:50:12.478740Z","iopub.status.idle":"2022-09-10T06:50:13.701642Z","shell.execute_reply.started":"2022-09-10T06:50:12.478706Z","shell.execute_reply":"2022-09-10T06:50:13.700258Z"},"_kg_hide-input":true,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Check the days and donors are consistent with give explanation.\n![Diagram](https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F4308072%2F23e8c1f6faea1453998544cdc116a20e%2FNeurIPS%202022%20-%20Frame%204.jpg?generation=1660755395301873&alt=media)","metadata":{"_kg_hide-input":true}},{"cell_type":"code","source":"cite_y_m.day.unique()","metadata":{"execution":{"iopub.status.busy":"2022-09-10T06:50:13.704767Z","iopub.execute_input":"2022-09-10T06:50:13.705677Z","iopub.status.idle":"2022-09-10T06:50:13.718253Z","shell.execute_reply.started":"2022-09-10T06:50:13.705607Z","shell.execute_reply":"2022-09-10T06:50:13.716669Z"},"_kg_hide-input":true,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cite_y_m.donor.unique()","metadata":{"execution":{"iopub.status.busy":"2022-09-10T06:50:13.720031Z","iopub.execute_input":"2022-09-10T06:50:13.720554Z","iopub.status.idle":"2022-09-10T06:50:13.730066Z","shell.execute_reply.started":"2022-09-10T06:50:13.720517Z","shell.execute_reply":"2022-09-10T06:50:13.728574Z"},"_kg_hide-input":true,"_kg_hide-output":true,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Average","metadata":{}},{"cell_type":"code","source":"cite_y_prot = {}\nfor protein_idx in range(len(cite_protein_names)): \n#for protein_idx in range(3): \n    cite_y_prot[protein_idx] = {}\n    protein = cite_protein_names[protein_idx]\n    plt_ind = 0\n    valrange = [cite_y[:,protein_idx].min(),cite_y[:,protein_idx].max()]\n    if protein_idx%4==0:\n        fig, axes = plt.subplots(1,4,figsize=(15,4))\n    ax = axes[protein_idx%4]\n    plt_ind+=1\n    for donor in [32606, 13176, 31800]:\n        cite_y_prot[protein_idx][donor] = np.zeros((3))\n#        cite_y_prot[protein_idx][donor] = {}\n        c = 0\n        for day in [2,3,4]:\n            cite_y_prot[protein_idx][donor][c] = \\\n                np.mean(cite_y[(cite_y_m.day==day)&(cite_y_m.donor==donor),protein_idx].toarray())\n            c+=1\n            \n        _ = ax.plot( [2,3,4],cite_y_prot[protein_idx][donor],label='donor %d'%donor)\n    ax.legend()\n    ax.set_ylim([0, 20])\n    ax.set_title(protein,loc='center')\n    ax.set_xlabel('day',loc='right')\n    ax.set_ylabel('protein level')\n#    plt.clf() \n#    plt.close()\n","metadata":{"execution":{"iopub.status.busy":"2022-09-10T06:50:52.344636Z","iopub.execute_input":"2022-09-10T06:50:52.345202Z","iopub.status.idle":"2022-09-10T06:51:35.796609Z","shell.execute_reply.started":"2022-09-10T06:50:52.345148Z","shell.execute_reply":"2022-09-10T06:51:35.795369Z"},"_kg_hide-input":true,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Histgrams","metadata":{}},{"cell_type":"code","source":"cite_y_prot = {}\nfor protein_idx in range(len(cite_protein_names)): \n#for protein_idx in range(12): \n    cite_y_prot[protein_idx] = {}\n    protein = cite_protein_names[protein_idx]\n    plt_ind = 0\n    valrange = [cite_y[:,protein_idx].min(),cite_y[:,protein_idx].max()]\n    if protein_idx%3==0:\n        fig, axes = plt.subplots(3,3,figsize=(15,15))\n#    for donor in cite_y_m.donor.unique():\n    for donor in [32606, 13176, 31800]:\n        cite_y_prot[protein_idx][donor] = {}\n#        for day in cite_y_m[cite_y_m.donor==donor].day.unique():\n        for day in [2,3,4]:\n            cite_y_prot[protein_idx][donor][day] = cite_y[(cite_y_m.day==day)&(cite_y_m.donor==donor),protein_idx].toarray()\n        ax = axes[plt_ind,protein_idx%3]\n#        _ = ax.hist([cite_y_prot[protein_idx][donor][day].ravel() for day in cite_y_m[cite_y_m.donor==donor].day.unique()],\n        _ = ax.hist([cite_y_prot[protein_idx][donor][day].ravel() for day in [2,3,4]],\n                50,range=valrange,label=['day 2','day 3','day 4'],density=True)\n#        ax.text(10,1000,\"dornor%s\"%donor)\n        ax.legend()\n        ax.set_title(protein + \":%s\"%donor )\n        plt_ind+=1\n","metadata":{"execution":{"iopub.status.busy":"2022-09-10T06:51:35.798410Z","iopub.execute_input":"2022-09-10T06:51:35.798784Z","iopub.status.idle":"2022-09-10T06:55:40.684366Z","shell.execute_reply.started":"2022-09-10T06:51:35.798752Z","shell.execute_reply":"2022-09-10T06:55:40.682908Z"},"_kg_hide-input":true,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}