{"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":"# What is about ?\n\nCreate files with meta features and/or information\n\n    '_citeseq_meta_Gender_and_CellType1Hot.csv' - Gender 0,1 coded, CellType -OneHot Coded\n    '_citeseq_meta_all_text_also.csv' - all orginal meta information concatenated with gender, etc..\n     '_citeseq_meta_day_only.csv' - only day - not recommended to use it as a feature, but can try \n     '_citeseq_cell_ids_only.csv' - just cell_ids - template to create other features ","metadata":{}},{"cell_type":"code","source":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))\n\n# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-10-14T12:49:26.072776Z","iopub.execute_input":"2022-10-14T12:49:26.073966Z","iopub.status.idle":"2022-10-14T12:49:26.145607Z","shell.execute_reply.started":"2022-10-14T12:49:26.073848Z","shell.execute_reply":"2022-10-14T12:49:26.144694Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"DATA_DIR = \"/kaggle/input/open-problems-multimodal/\"\nFP_CELL_METADATA = os.path.join(DATA_DIR,\"metadata.csv\")\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\")\n\ndf_cell = pd.read_csv(FP_CELL_METADATA)\ndf_cell","metadata":{"execution":{"iopub.status.busy":"2022-10-14T12:49:26.147403Z","iopub.execute_input":"2022-10-14T12:49:26.148237Z","iopub.status.idle":"2022-10-14T12:49:26.647293Z","shell.execute_reply.started":"2022-10-14T12:49:26.148200Z","shell.execute_reply":"2022-10-14T12:49:26.645771Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fn = '/kaggle/input/feature-shop-for-multimodal-singlecell-competition/df_cite_only_index_and_train0_and_test1.csv'\ndf = pd.read_csv(fn, index_col = 0)\ndf","metadata":{"execution":{"iopub.status.busy":"2022-10-14T12:49:26.649303Z","iopub.execute_input":"2022-10-14T12:49:26.649789Z","iopub.status.idle":"2022-10-14T12:49:26.809105Z","shell.execute_reply.started":"2022-10-14T12:49:26.649742Z","shell.execute_reply":"2022-10-14T12:49:26.807803Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df2 = df.join(df_cell.set_index('cell_id'), how = 'left')\ndf2.shape,df.shape","metadata":{"execution":{"iopub.status.busy":"2022-10-14T12:49:26.812097Z","iopub.execute_input":"2022-10-14T12:49:26.812572Z","iopub.status.idle":"2022-10-14T12:49:26.995610Z","shell.execute_reply.started":"2022-10-14T12:49:26.812526Z","shell.execute_reply":"2022-10-14T12:49:26.994205Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df2","metadata":{"execution":{"iopub.status.busy":"2022-10-14T12:49:26.997179Z","iopub.execute_input":"2022-10-14T12:49:26.997634Z","iopub.status.idle":"2022-10-14T12:49:27.016969Z","shell.execute_reply.started":"2022-10-14T12:49:26.997591Z","shell.execute_reply":"2022-10-14T12:49:27.015769Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"np.where(df2['Train0OrTest1'].values > 0)[0][0]","metadata":{"execution":{"iopub.status.busy":"2022-10-14T12:49:27.018604Z","iopub.execute_input":"2022-10-14T12:49:27.018950Z","iopub.status.idle":"2022-10-14T12:49:27.026829Z","shell.execute_reply.started":"2022-10-14T12:49:27.018919Z","shell.execute_reply":"2022-10-14T12:49:27.025619Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"(df2['Train0OrTest1']==0).sum(),(df2['Train0OrTest1']==1).sum()","metadata":{"execution":{"iopub.status.busy":"2022-10-14T12:49:27.028359Z","iopub.execute_input":"2022-10-14T12:49:27.028805Z","iopub.status.idle":"2022-10-14T12:49:27.041361Z","shell.execute_reply.started":"2022-10-14T12:49:27.028763Z","shell.execute_reply":"2022-10-14T12:49:27.040221Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df2['donor'].unique()\t","metadata":{"execution":{"iopub.status.busy":"2022-10-14T12:49:27.042890Z","iopub.execute_input":"2022-10-14T12:49:27.043508Z","iopub.status.idle":"2022-10-14T12:49:27.054331Z","shell.execute_reply.started":"2022-10-14T12:49:27.043464Z","shell.execute_reply":"2022-10-14T12:49:27.052980Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df2['Gender'] = 0\nm = (df2['donor'] == 13176)\ndf2.loc[m,'Gender'] = 1\ndf2","metadata":{"execution":{"iopub.status.busy":"2022-10-14T12:49:27.056093Z","iopub.execute_input":"2022-10-14T12:49:27.056808Z","iopub.status.idle":"2022-10-14T12:49:27.082957Z","shell.execute_reply.started":"2022-10-14T12:49:27.056763Z","shell.execute_reply":"2022-10-14T12:49:27.081732Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df2['cell_type'].unique(), df2['cell_type'].nunique(), ","metadata":{"execution":{"iopub.status.busy":"2022-10-14T12:49:27.087216Z","iopub.execute_input":"2022-10-14T12:49:27.087881Z","iopub.status.idle":"2022-10-14T12:49:27.119289Z","shell.execute_reply.started":"2022-10-14T12:49:27.087833Z","shell.execute_reply":"2022-10-14T12:49:27.118053Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for cell_type in ['HSC', 'EryP', 'NeuP', 'MasP', 'MkP', 'BP', 'MoP']:\n    mask = df2['cell_type'] == cell_type\n    df2[cell_type+' cell_type'] = 0\n    df2.loc[mask,cell_type+' cell_type'] = 1\ndf2    ","metadata":{"execution":{"iopub.status.busy":"2022-10-14T12:49:27.121036Z","iopub.execute_input":"2022-10-14T12:49:27.121880Z","iopub.status.idle":"2022-10-14T12:49:27.229182Z","shell.execute_reply.started":"2022-10-14T12:49:27.121834Z","shell.execute_reply":"2022-10-14T12:49:27.228101Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df3=df2.iloc[:,5:]\ndf3","metadata":{"execution":{"iopub.status.busy":"2022-10-14T12:49:27.230698Z","iopub.execute_input":"2022-10-14T12:49:27.231347Z","iopub.status.idle":"2022-10-14T12:49:27.258174Z","shell.execute_reply.started":"2022-10-14T12:49:27.231300Z","shell.execute_reply":"2022-10-14T12:49:27.256904Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df3.to_csv('_citeseq_meta_Gender_and_CellType1Hot.csv')","metadata":{"execution":{"iopub.status.busy":"2022-10-14T12:49:27.259301Z","iopub.execute_input":"2022-10-14T12:49:27.260389Z","iopub.status.idle":"2022-10-14T12:49:27.467631Z","shell.execute_reply.started":"2022-10-14T12:49:27.260352Z","shell.execute_reply":"2022-10-14T12:49:27.466459Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_day = df2[['day']]\ndf_day","metadata":{"execution":{"iopub.status.busy":"2022-10-14T12:49:27.469242Z","iopub.execute_input":"2022-10-14T12:49:27.469602Z","iopub.status.idle":"2022-10-14T12:49:27.498941Z","shell.execute_reply.started":"2022-10-14T12:49:27.469569Z","shell.execute_reply":"2022-10-14T12:49:27.497879Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_day.to_csv('_citeseq_meta_day_only.csv')","metadata":{"execution":{"iopub.status.busy":"2022-10-14T12:49:27.500530Z","iopub.execute_input":"2022-10-14T12:49:27.501246Z","iopub.status.idle":"2022-10-14T12:49:27.587535Z","shell.execute_reply.started":"2022-10-14T12:49:27.501202Z","shell.execute_reply":"2022-10-14T12:49:27.586286Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df2.to_csv('_citeseq_meta_all_text_also.csv')\ndf2","metadata":{"execution":{"iopub.status.busy":"2022-10-14T12:49:27.590537Z","iopub.execute_input":"2022-10-14T12:49:27.591378Z","iopub.status.idle":"2022-10-14T12:49:27.973322Z","shell.execute_reply.started":"2022-10-14T12:49:27.591337Z","shell.execute_reply":"2022-10-14T12:49:27.972085Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"os.listdir()","metadata":{"execution":{"iopub.status.busy":"2022-10-14T12:49:27.975849Z","iopub.execute_input":"2022-10-14T12:49:27.976196Z","iopub.status.idle":"2022-10-14T12:49:27.983827Z","shell.execute_reply.started":"2022-10-14T12:49:27.976165Z","shell.execute_reply":"2022-10-14T12:49:27.982667Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df3 =pd.DataFrame(index = df2.index )# .to_csv('_citeseq_meta_all_text_also.csv')\ndf3","metadata":{"execution":{"iopub.status.busy":"2022-10-14T12:50:24.357075Z","iopub.execute_input":"2022-10-14T12:50:24.357614Z","iopub.status.idle":"2022-10-14T12:50:24.372094Z","shell.execute_reply.started":"2022-10-14T12:50:24.357569Z","shell.execute_reply":"2022-10-14T12:50:24.370831Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df3.to_csv('_citeseq_cell_ids_only.csv')","metadata":{"execution":{"iopub.status.busy":"2022-10-14T12:50:50.462515Z","iopub.execute_input":"2022-10-14T12:50:50.463802Z","iopub.status.idle":"2022-10-14T12:50:50.536192Z","shell.execute_reply.started":"2022-10-14T12:50:50.463745Z","shell.execute_reply":"2022-10-14T12:50:50.534965Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}