<jupyter_start><jupyter_text>In this notebook you can find your answer to these questions:1. What genes are related to your CP feature?2. What CP features are related to your Gene under study?* Due to quality of overall predictions as reported in the paper, we use:   - **LINCS** dataset for chemical perturbation reference    - **LUAD** dataset for genetic perturbation reference   User input parameters<jupyter_code># In which perturbation context you want to explore your features
# "genetic" or "chemical"
which_dataset_to_use="genetic"

cp_features_under_test=['Cells_Texture_InfoMeas1_RNA_3_0']
# Cells_Texture_InfoMeas1_RNA_3_0,Cytoplasm_AreaShape_Zernike_9_3
ge_features_under_test=['AARS']<jupyter_output><empty_output><jupyter_text>Paths<jupyter_code>procProf_dir='/home/ubuntu/datasetsbucket/Rosetta-GE-CP/'
# procProf_dir='/home/ubuntu/bucket/projects/2018_04_20_Rosetta/workspace/'
metadata_dir='/home/ubuntu/bucket/projects/2018_04_20_Rosetta/workspace/metadata/'
results_dir='./results/'<jupyter_output><empty_output><jupyter_text>What genes are related to your CP feature?<jupyter_code>if which_dataset_to_use=="genetic":
    dataset='LUAD';
elif which_dataset_to_use=="chemical":
    dataset='LINCS';    


################################################
pertColName='PERT'

mergProf_repLevel,mergProf_treatLevel,cp_features,l1k_features=\
readMergedProfiles(procProf_dir,dataset,'normalized','treatment',1,'highRepOverlap');


l1k=mergProf_treatLevel[[pertColName]+l1k_features]
cp=mergProf_treatLevel[[pertColName]+cp_features]


if dataset=='LINCS':     
    cp.loc[:,'Compounds']=cp.loc[:,'PERT'].str[0:13]
    l1k.loc[:,'Compounds']=l1k.loc[:,'PERT'].str[0:13]
else:
    cp.loc[:,'Compounds']=cp.loc[:,'PERT'].values
    l1k.loc[:,'Compounds']=l1k.loc[:,'PERT'].values


scaler_ge = preprocessing.StandardScaler()
scaler_cp = preprocessing.StandardScaler()
l1k_scaled=l1k.copy()
l1k_scaled[l1k_features] = scaler_ge.fit_transform(l1k[l1k_features].values)
cp_scaled=cp.copy()
cp_scaled[cp_features] = scaler_cp.fit_transform(cp[cp_features].values.astype('float64'))


if 1:
    cp=cp_scaled.copy()
    l1k=l1k_scaled.copy()

##############################
meta=pd.read_csv("/home/ubuntu/bucket/projects/2018_04_20_Rosetta/workspace/metadata/affy_probe_gene_mapping.txt",delimiter="\t",header=None, names=["probe_id", "gene"])
meta_gene_probID=meta.set_index('probe_id')
d = dict(zip(meta_gene_probID.index, meta_gene_probID['gene']))
l1k_features_gn=[d[l] for l in l1k_features]
l1k = l1k.rename(columns=d)    

for g in ge_features_under_test:
#     viz = FeatureImportances(linear_model.Lasso(),relative=True, topn=20)
#     viz = FeatureImportances(linear_model.Lasso(alpha=0.001), labels=l1k_features_gn, relative=False,topn=20)
    print(g)
    model = linear_model.LinearRegression()
    model.fit(cp[cp_features],l1k[g])
# #     model = RandomForestClassifier(n_estimators=10)
    viz = FeatureImportances(model,topn=20)    
    
    viz.fit(cp[cp_features],l1k[g])
    viz.show()<jupyter_output>/home/ubuntu/anaconda3/lib/python3.8/site-packages/IPython/core/interactiveshell.py:3263: DtypeWarning: Columns (1023,1028) have mixed types.Specify dtype option on import or set low_memory=False.
  if (await self.run_code(code, result,  async_=asy)):<jupyter_text>What are the Genes invloved in predicting a CP feature<jupyter_code>if which_dataset_to_use=="genetic":
    dataset='LUAD';
elif which_dataset_to_use=="chemical":
    dataset='LINCS';    


################################################
pertColName='PERT'

mergProf_repLevel,mergProf_treatLevel,cp_features,l1k_features=\
readMergedProfiles(procProf_dir,dataset,'normalized','treatment',1,'highRepOverlap');


l1k=mergProf_treatLevel[[pertColName]+l1k_features]
cp=mergProf_treatLevel[[pertColName]+cp_features]


if dataset=='LINCS':     
    cp.loc[:,'Compounds']=cp.loc[:,'PERT'].str[0:13]
    l1k.loc[:,'Compounds']=l1k.loc[:,'PERT'].str[0:13]
else:
    cp.loc[:,'Compounds']=cp.loc[:,'PERT'].values
    l1k.loc[:,'Compounds']=l1k.loc[:,'PERT'].values


scaler_ge = preprocessing.StandardScaler()
scaler_cp = preprocessing.StandardScaler()
l1k_scaled=l1k.copy()
l1k_scaled[l1k_features] = scaler_ge.fit_transform(l1k[l1k_features].values)
cp_scaled=cp.copy()
cp_scaled[cp_features] = scaler_cp.fit_transform(cp[cp_features].values.astype('float64'))


if 1:
    cp=cp_scaled.copy()
    l1k=l1k_scaled.copy()

##############################
meta=pd.read_csv("/home/ubuntu/bucket/projects/2018_04_20_Rosetta/workspace/metadata/affy_probe_gene_mapping.txt",delimiter="\t",header=None, names=["probe_id", "gene"])
meta_gene_probID=meta.set_index('probe_id')
d = dict(zip(meta_gene_probID.index, meta_gene_probID['gene']))
l1k_features_gn=[d[l] for l in l1k_features]
l1k = l1k.rename(columns=d)    

for c in cp_features_under_test:
    print(c)
#     viz = FeatureImportances(linear_model.Lasso(),relative=True, topn=20)
#     viz = FeatureImportances(linear_model.Lasso(alpha=0.001), labels=l1k_features_gn, relative=False,topn=20)
    
    model = linear_model.LinearRegression()
    model.fit(l1k[l1k_features_gn],cp[c])
# #     model = RandomForestClassifier(n_estimators=10)
    viz = FeatureImportances(model,topn=20)    
    
    viz.fit(l1k[l1k_features_gn],cp[c])
    viz.show()
        
# fig, ax = plt.subplots(figsize=(3,5))
# ax.set_title('fdg')
# # viz = FeatureImportances(model,topn=20,ax=ax)
# # viz.show()
# model = linear_model.LinearRegression()
# model.fit(l1k[l1k_features_gn],cp[c])
# # #     model = RandomForestClassifier(n_estimators=10)
# viz = FeatureImportances(model,topn=20,ax=ax)    

# viz.fit(l1k[l1k_features_gn],cp[c])
# viz.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.16900913562895292, 'fraction_numerical': 0.02793394237526353, 'mean_word_length': 7.156160458452722, 'pattern_counts': {'":': 4, '<': 16, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '664446', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 2278, 'n_tokens_neox': 2141, 'n_words': 259, 'path': '3-exploreTheLink.ipynb', 'repo_name': 'carpenterlab/2021_Haghighi_submitted', 'size': '5692'}