<jupyter_start><jupyter_text>Load PWMs<jupyter_code>pwms = pd.read_hdf('../DATA/PWMS/attract_rbpdb_encode_filtered_human_pwms.h5', key='data')
len(pwms)
len(np.unique(pwms.Gene_name))<jupyter_output><empty_output><jupyter_text>Select RBPs with multiple PWMs<jupyter_code>rbp_counts = pwms.Gene_name.value_counts()
multi_rbps = np.array(rbp_counts[rbp_counts > 1].index)
print(multi_rbps)
print(len(multi_rbps))
# Similarity metric: normalized correlation
# Clustering method: Hierarchical (agglomerative) clustering
# Threshold for clustering: minimum pairwise similarity < 0.2
rep_Matrix_ids = []
for rbp in multi_rbps:
    sel_pwms = pwms[pwms.Gene_name==rbp].reset_index(drop=True)
    np.array(sel_pwms.Matrix_id)
    choice = get_rep_mats(sel_pwms)
    rep_Matrix_ids.append(choice['reps'])
len(rep_Matrix_ids)
sum([type(x)==list for x in rep_Matrix_ids])<jupyter_output><empty_output><jupyter_text>ELAVL1<jupyter_code>sel_pwms = pwms[pwms.Gene_name=='ELAVL1'].reset_index(drop=True)
np.array(sel_pwms.Matrix_id)
plot_ppm(sel_pwms, 'M108_0.6', 5)
plot_ppm(sel_pwms, 'M112_0.6', 5)
plot_ppm(sel_pwms, 'M232_0.6', 5)
plot_ppm(sel_pwms, 's101', 5)
plot_ppm(sel_pwms, 'M031_0.6', 5)
plot_ppm(sel_pwms, 'M127_0.6', 5)
plot_pwm(sel_pwms, '1170', 5)
choice = get_rep_mats(sel_pwms)
print(choice)
plot_ppm(sel_pwms, choice, 5)
rep_Matrix_ids.append('M232_0.6')<jupyter_output><empty_output><jupyter_text>EIF4B<jupyter_code>sel_pwms = pwms[pwms.Gene_name=='EIF4B'].reset_index(drop=True)
np.array(sel_pwms.Matrix_id)
print(np.min(pairwise_ncorrs(list(sel_pwms.weights))))
plot_ppm(sel_pwms, 'M290_0.6', 4)
plot_ppm(sel_pwms, '351', 4)
plot_ppm(sel_pwms, '352', 4)
choice = choose_representative_pm(sel_pwms)
plot_pwm(sel_pwms, choice, 4)
rep_Matrix_ids.append('352')<jupyter_output><empty_output><jupyter_text>Final list of representative PWMs<jupyter_code>rep_Matrix_ids = list(pd.core.common.flatten(rep_Matrix_ids))
print(len(rep_Matrix_ids))
rep_Matrix_ids[:5]
single_pwms = pwms[~pwms.Gene_name.isin(rbp_counts[rbp_counts > 1].index)]
representative_multi_pwms = pwms[pwms.Matrix_id.isin(rep_Matrix_ids)]
representative_pwms = pd.concat([single_pwms, representative_multi_pwms]).reset_index(drop=True)
len(representative_pwms)
len(representative_pwms.Gene_name.unique())
len(pwms.Gene_name.unique())
set(pwms.Gene_name) - set(representative_pwms.Gene_name)
representative_pwms.Gene_name.value_counts()<jupyter_output><empty_output><jupyter_text>Save list<jupyter_code>representative_pwms.Matrix_id.to_csv('../DATA/PWMs/attract_rbpdb_encode_representative_matrices.txt', index=False, header=False)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1377997716025885, 'fraction_numerical': 0.027788351732013702, 'mean_word_length': 10.732142857142858, 'pattern_counts': {'":': 0, '<': 26, '<?xml version=': 0, '>': 27, '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': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '192504', 'license': 'MIT', 'n_tokens_mistral': 1205, 'n_tokens_neox': 1116, 'n_words': 121, 'path': 'notebooks/curate_attract_rbpdb_encode.ipynb', 'repo_name': 'gruber-sciencelab/VirusHostInteractionAtlas', 'size': '2627'}