{"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":"code","source":"import numpy as np \nimport pandas as pd \n\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\n\nimport os\nimport gc\nfrom tqdm import tqdm\nimport matplotlib.pyplot as plt\nimport seaborn as sns\n\n\n","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-12-07T18:23:50.340840Z","iopub.execute_input":"2022-12-07T18:23:50.341328Z","iopub.status.idle":"2022-12-07T18:23:51.095555Z","shell.execute_reply.started":"2022-12-07T18:23:50.341287Z","shell.execute_reply":"2022-12-07T18:23:51.094061Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"target = pd.read_hdf(\"/kaggle/input/open-problems-multimodal/train_cite_targets.h5\")","metadata":{"execution":{"iopub.status.busy":"2022-12-07T18:23:51.098385Z","iopub.execute_input":"2022-12-07T18:23:51.098768Z","iopub.status.idle":"2022-12-07T18:23:51.969681Z","shell.execute_reply.started":"2022-12-07T18:23:51.098735Z","shell.execute_reply":"2022-12-07T18:23:51.967934Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"meta=pd.read_csv('/kaggle/input/feature-shop-for-multimodal-singlecell-competition/_citeseq_meta_all_text_also.csv')\nmeta.head()","metadata":{"execution":{"iopub.status.busy":"2022-12-07T18:23:51.971691Z","iopub.execute_input":"2022-12-07T18:23:51.972170Z","iopub.status.idle":"2022-12-07T18:23:52.279453Z","shell.execute_reply.started":"2022-12-07T18:23:51.972120Z","shell.execute_reply":"2022-12-07T18:23:52.277834Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"meta.head()","metadata":{"execution":{"iopub.status.busy":"2022-12-07T18:23:52.281161Z","iopub.execute_input":"2022-12-07T18:23:52.281720Z","iopub.status.idle":"2022-12-07T18:23:52.299045Z","shell.execute_reply.started":"2022-12-07T18:23:52.281671Z","shell.execute_reply":"2022-12-07T18:23:52.297602Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"meta=meta.loc[meta['Train0OrTest1']==0]\nmeta_copy=meta.drop(columns=['cell_id','Train0OrTest1', 'day', 'donor', 'cell_type', 'technology', 'Gender'], axis=1)\nmeta_copy.head()","metadata":{"execution":{"iopub.status.busy":"2022-12-07T18:23:52.302023Z","iopub.execute_input":"2022-12-07T18:23:52.302404Z","iopub.status.idle":"2022-12-07T18:23:52.336374Z","shell.execute_reply.started":"2022-12-07T18:23:52.302369Z","shell.execute_reply":"2022-12-07T18:23:52.335298Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.metrics import roc_auc_score\n\nl=list()\nres=pd.DataFrame()\ny=1\nfor i in meta_copy.columns:    #для каждого клеточного типа\n    ix=1\n    for j in target.columns:   #для каждого cd-белка\n        res.loc[ix,y]=roc_auc_score(meta_copy[i], target[j])\n        ix+=1\n    y+=1","metadata":{"execution":{"iopub.status.busy":"2022-12-07T18:23:52.337674Z","iopub.execute_input":"2022-12-07T18:23:52.338101Z","iopub.status.idle":"2022-12-07T18:24:17.021152Z","shell.execute_reply.started":"2022-12-07T18:23:52.338070Z","shell.execute_reply":"2022-12-07T18:24:17.019949Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"n_i=['CD86','CD274','CD270','CD155' ,'CD112','CD47','CD48','CD40','CD154','CD52','CD3','CD8','CD56','CD19','CD33','CD11c','HLA-A-B-C','CD45RA','CD123','CD7','CD105','CD49f','CD194','CD4','CD44','CD14','CD16','CD25',\n'CD45RO','CD279','TIGIT','Mouse-IgG1','Mouse-IgG2a','Mouse-IgG2b','Rat-IgG2b','CD20','CD335','CD31','Podoplanin','CD146','IgM','CD5','CD195','CD32',\n'CD196','CD185','CD103','CD69','CD62L','CD161','CD152','CD223','KLRG1','CD27','CD107a','CD95','CD134','HLA-DR','CD1c','CD11b','CD64','CD141','CD1d',\n'CD314','CD35','CD57','CD272','CD278','CD58','CD39','CX3CR1','CD24','CD21','CD11a','CD79b','CD244','CD169','integrinB7','CD268','CD42b','CD54','CD62P',\n'CD119','TCR','Rat-IgG1','Rat-IgG2a','CD192','CD122','FceRIa','CD41','CD137','CD163','CD83','CD124','CD13','CD2','CD226','CD29','CD303','CD49b','CD81','IgD',\n'CD18','CD28','CD38','CD127','CD45','CD22','CD71','CD26','CD115','CD63','CD304','CD36','CD172a','CD72','CD158','CD93','CD49a','CD49d','CD73',\n'CD9','TCRVa7.2','TCRVd2','LOX-1','CD158b','CD158e1','CD142','CD319','CD352','CD94','CD162','CD85j','CD23','CD328','HLA-E','CD82','CD101','CD88','CD224']","metadata":{"execution":{"iopub.status.busy":"2022-12-07T18:24:17.022508Z","iopub.execute_input":"2022-12-07T18:24:17.022880Z","iopub.status.idle":"2022-12-07T18:24:17.033784Z","shell.execute_reply.started":"2022-12-07T18:24:17.022846Z","shell.execute_reply":"2022-12-07T18:24:17.032280Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"res1=res.to_numpy()\nres2=pd.DataFrame(data=res1, index=n_i, columns=meta_copy.columns)","metadata":{"execution":{"iopub.status.busy":"2022-12-07T18:24:17.035427Z","iopub.execute_input":"2022-12-07T18:24:17.035804Z","iopub.status.idle":"2022-12-07T18:24:17.054864Z","shell.execute_reply.started":"2022-12-07T18:24:17.035772Z","shell.execute_reply":"2022-12-07T18:24:17.053700Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"res2.to_csv('analys_cd_and_cell_type.csv')","metadata":{"execution":{"iopub.status.busy":"2022-12-07T18:24:17.056819Z","iopub.execute_input":"2022-12-07T18:24:17.057321Z","iopub.status.idle":"2022-12-07T18:24:17.069027Z","shell.execute_reply.started":"2022-12-07T18:24:17.057286Z","shell.execute_reply":"2022-12-07T18:24:17.067628Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# сортируем по аук","metadata":{}},{"cell_type":"code","source":"auc=pd.DataFrame()\nfor i in res2.columns:\n   # auc=auc.reset_index(drop=True)\n    res2=res2.sort_values(by=i)\n    df1=res2.index.to_frame(name=i+' GeneName ')\n    df1=df1.reset_index(drop=True)\n\n    df2=res2[i].to_frame(name='Auc for '+i)\n    df2=df2.reset_index(drop=True)  \n    auc =pd.concat([auc,df1], axis=1)\n    auc =pd.concat([auc,df2], axis=1)\nauc\nauc.to_csv('sorted_cd_by_auc.csv')","metadata":{"execution":{"iopub.status.busy":"2022-12-07T18:24:17.070769Z","iopub.execute_input":"2022-12-07T18:24:17.071607Z","iopub.status.idle":"2022-12-07T18:24:17.099313Z","shell.execute_reply.started":"2022-12-07T18:24:17.071559Z","shell.execute_reply":"2022-12-07T18:24:17.098157Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"auc","metadata":{"execution":{"iopub.status.busy":"2022-12-07T18:24:17.100790Z","iopub.execute_input":"2022-12-07T18:24:17.101151Z","iopub.status.idle":"2022-12-07T18:24:17.132570Z","shell.execute_reply.started":"2022-12-07T18:24:17.101119Z","shell.execute_reply":"2022-12-07T18:24:17.131165Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pd.set_option('display.max_columns', None)\ndisplay( auc.head(10).T)","metadata":{"execution":{"iopub.status.busy":"2022-12-07T18:30:17.821731Z","iopub.execute_input":"2022-12-07T18:30:17.822195Z","iopub.status.idle":"2022-12-07T18:30:17.845028Z","shell.execute_reply.started":"2022-12-07T18:30:17.822123Z","shell.execute_reply":"2022-12-07T18:30:17.843303Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"display( auc.tail(10).T)","metadata":{"execution":{"iopub.status.busy":"2022-12-07T18:29:59.499655Z","iopub.execute_input":"2022-12-07T18:29:59.500513Z","iopub.status.idle":"2022-12-07T18:29:59.523919Z","shell.execute_reply.started":"2022-12-07T18:29:59.500472Z","shell.execute_reply":"2022-12-07T18:29:59.522386Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"res3=pd.DataFrame()\ny=1\nfor i in meta_copy.columns:    #для каждого клеточного типа\n    ix=1\n    for j in target.columns:   #для каждого cd-белка\n        res3.loc[ix,y]=np.abs((roc_auc_score(meta_copy[i], target[j]))-0.5)\n        ix+=1\n    y+=1","metadata":{"execution":{"iopub.status.busy":"2022-12-07T18:24:17.201504Z","iopub.execute_input":"2022-12-07T18:24:17.201902Z","iopub.status.idle":"2022-12-07T18:24:41.803851Z","shell.execute_reply.started":"2022-12-07T18:24:17.201870Z","shell.execute_reply":"2022-12-07T18:24:41.802544Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"res1=res3.to_numpy()\ndf_any_metrics=pd.DataFrame(data=res1, index=n_i, columns=meta_copy.columns)","metadata":{"execution":{"iopub.status.busy":"2022-12-07T18:24:41.805358Z","iopub.execute_input":"2022-12-07T18:24:41.806000Z","iopub.status.idle":"2022-12-07T18:24:41.812694Z","shell.execute_reply.started":"2022-12-07T18:24:41.805962Z","shell.execute_reply":"2022-12-07T18:24:41.811445Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"metric=pd.DataFrame()\nfor i in target.columns:\n    metric.loc[i, 'avg']=target[i].mean()\n    metric.loc[i, 'std']=target[i].std()\nmetric\n    ","metadata":{"execution":{"iopub.status.busy":"2022-12-07T18:24:41.814629Z","iopub.execute_input":"2022-12-07T18:24:41.815455Z","iopub.status.idle":"2022-12-07T18:24:42.057932Z","shell.execute_reply.started":"2022-12-07T18:24:41.815408Z","shell.execute_reply":"2022-12-07T18:24:42.056725Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# |roc_auc-0.5|+среднее и стд","metadata":{}},{"cell_type":"code","source":"full_metric=pd.concat([df_any_metrics, metric], axis=1)\nfull_metric=full_metric.sort_values(by='EryP cell_type')\nfull_metric.to_csv('metric_cd_cell_type.csv')\nfull_metric","metadata":{"execution":{"iopub.status.busy":"2022-12-07T18:24:42.059554Z","iopub.execute_input":"2022-12-07T18:24:42.060065Z","iopub.status.idle":"2022-12-07T18:24:42.087352Z","shell.execute_reply.started":"2022-12-07T18:24:42.060017Z","shell.execute_reply":"2022-12-07T18:24:42.086153Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}