| 42 | |
| 43 | |
| 44 | def get_cell(cellFeature_dicts, synergy_cellset, cell_omics, cell_filtered_by, matrix=False): |
| 45 | |
| 46 | def filter_by_variance(): |
| 47 | if len(cell_omics) > 1: |
| 48 | # if mut/cnv/exp, use exp |
| 49 | temp = cellFeature_dicts['exp'] |
| 50 | else: |
| 51 | temp = cellFeature_dicts[cell_omics[0]] |
| 52 | var_df = temp.var(axis=1) |
| 53 | selected_genes = list(var_df.sort_values(ascending=False).iloc[:1000].index) |
| 54 | |
| 55 | return selected_genes |
| 56 | |
| 57 | def filter_by_2000_genes(): |
| 58 | # following is copied from prepare_data |
| 59 | data_dicts = np.load(os.path.join(ROOT_DIR, 'data', 'drug_data','input_drug_data.npy'),allow_pickle=True).item() |
| 60 | selected_genes = data_dicts['drug_target_rwr'].index |
| 61 | return selected_genes |
| 62 | |
| 63 | def filter_by_706_genes(): |
| 64 | # following is copied from prepare_data |
| 65 | temp = pd.read_csv(os.path.join(ROOT_DIR, 'data', 'cell_line_data', 'CCLE','CCLE_exp.csv'), index_col=0) |
| 66 | temp.columns = ['Entrez gene id']+[split_it_cell(_) for _ in list(temp.columns)[1:]] |
| 67 | df_transpose = temp.T |
| 68 | df_transpose.columns = df_transpose.iloc[0] |
| 69 | processed_data = df_transpose.drop(df_transpose.index[0]) |
| 70 | |
| 71 | var_df = processed_data.var(axis=1) |
| 72 | gene_list = list(var_df.sort_values(ascending=False).iloc[:1000].index) |
| 73 | |
| 74 | # |
| 75 | ppi_data = pd.read_csv(os.path.join(ROOT_DIR, 'data', 'cell_line_data','PPI','protein-protein_network.csv')) |
| 76 | ppi_data_genes = set(list(ppi_data['protein_a']) + list(ppi_data['protein_b'])) |
| 77 | selected_genes = list(set(gene_list) & set(ppi_data_genes)) |
| 78 | return selected_genes |
| 79 | |
| 80 | def ALL(): |
| 81 | # use before batch corrected CCLE most vairance genes |
| 82 | # index is drug, so we need clean up the df |
| 83 | temp = pd.read_csv(os.path.join(ROOT_DIR, 'data', 'cell_line_data','CCLE','CCLE_exp.csv'),sep=',') |
| 84 | temp.columns = ['Entrez gene id']+[split_it_cell(_) for _ in list(temp.columns)[1:]] |
| 85 | df_transpose = temp.T |
| 86 | df_transpose.columns = df_transpose.iloc[0] |
| 87 | processed_data = df_transpose.drop(df_transpose.index[0]) |
| 88 | |
| 89 | var_df = processed_data.var(axis=1) |
| 90 | selected_genes = list(var_df.sort_values(ascending=False).iloc[:1000].index) |
| 91 | with open(os.path.join(ROOT_DIR, 'data', 'drug_data','input_drug_data.npy'), 'rb') as file: |
| 92 | data_dicts = np.load(file, allow_pickle=True).item() |
| 93 | |
| 94 | drug_target = list(data_dicts['drug_target'].index) |
| 95 | |
| 96 | return list(set(selected_genes+drug_target)) |
| 97 | |
| 98 | # select genes based on criterion (variance or STRING) |
| 99 | function_mapping = {'variance':'filter_by_variance', 'STRING':'filter_by_706_genes', 'dti':'filter_by_2000_genes',\ |
| 100 | 'all':'ALL'} |
| 101 | selected_genes = locals()[function_mapping[cell_filtered_by]]() |