<jupyter_start><jupyter_text>Imports<jupyter_code>import pandas as pd
import sys

sys.path.insert(0,'../satori')

from postprocess import *<jupyter_output><empty_output><jupyter_text>Interaction data processing<jupyter_code># For SATORI based interactions
df,suffix = pd.read_csv('../results/Human_Promoter_Analysis_euclidean_v8/Interactions_SATORI/interactions_summary_attnLimit-0.08.txt',sep='\t'),'SATORI'
##df = pd.read_csv('../results/Human_Promoter_Analysis_euclidean_v8/Interactions_SATORI/interactions_summary_attnLimit-0.04.txt',sep='\t')

# For FIS based interactions
#df,suffix = pd.read_csv('../results/Human_Promoter_Analysis_euclidean_v8/Interactions_FIS/interactions_summary_attnLimit-50.0.txt',sep='\t'),'FIS'
##df = pd.read_csv('../results/Human_Promoter_Analysis_euclidean_v8_fixed/Interactions_FIS/interactions_summary_attnLimit-0.txt',sep='\t')<jupyter_output><empty_output><jupyter_text>Filter based on interaction and motif hit p-values, and keep the most significant interactions<jupyter_code>df = filter_data_on_thresholds(df, motifA_pval_cutoff=0.05, motifB_pval_cutoff=0.05)
df.shape<jupyter_output><empty_output><jupyter_text>Load the motif description file to annotate the interactions. Here we use CISBP (U toronto) motif description file.<jupyter_code>df_annotate = pd.read_csv('../../../Basset_Splicing_IR-iDiffIR/Analysis_For_none_network-typeB_lotus_posThresh-0.60/MEME_analysis/Homo_sapiens_2019_01_14_4_17_pm/TF_Information_all_motifs.txt',sep='\t')
df_annotate.head()<jupyter_output><empty_output><jupyter_text>Annotate the interacting motifs<jupyter_code>df['TF1'] = df['motif1'].apply(get_annotation, annotation_data=df_annotate, single_TF=True)
df['TF2'] = df['motif2'].apply(get_annotation, annotation_data=df_annotate, single_TF=True)
df.head()
df['TF_Interaction'] = df.apply(lambda x: x['TF1']+r'$\longleftrightarrow$'+x['TF2'], axis=1)<jupyter_output><empty_output><jupyter_text>Drop same motif interactions<jupyter_code>df = df[df['TF1']!=df['TF2']]
df.shape
df = df.reset_index(drop=True)<jupyter_output><empty_output><jupyter_text>Fix redundant interaction pairs<jupyter_code>df = process_for_redundant_interactions(df, intr_type='TF')
df.head()
df.shape<jupyter_output><empty_output><jupyter_text>Most Frequent TF Family Interactions<jupyter_code>tf_family_dict = {}
for TF in df_annotate['TF_Name']:
    tf_family_dict[TF] = df_annotate[df_annotate['TF_Name']==TF]['Family_Name'].iloc[0]
df['TF1_Family'] = df['TF1'].apply(lambda x: tf_family_dict[x] if x in tf_family_dict else 'UNKNOWN')
df['TF2_Family'] = df['TF2'].apply(lambda x: tf_family_dict[x] if x in tf_family_dict else 'UNKNOWN')
df['Family_Interaction'] = df.apply(lambda x: x['TF1_Family']+r'$\longleftrightarrow$'+x['TF2_Family'],axis=1)
df = process_for_redundant_interactions(df, intr_type='Family')
df.head()
df['filter_interaction'] = df['filter_interaction'].apply(lambda x: x.replace('<-->',r'$\longleftrightarrow$'))
df.head()
df.to_csv(f'output/Human-Promoter_interactions_{suffix}.csv')<jupyter_output><empty_output><jupyter_text>Distribution of individual TF or TF family interactions<jupyter_code>plot_frequent_interactions(df, intr_level='Family_Interaction', first_n=15, store_pdf_path=f'output/Human_TF-Fams_supp_{suffix}.pdf')<jupyter_output><empty_output><jupyter_text>Plot interaction distance distribution<jupyter_code>plot_interaction_distance_distribution(df, nbins=50, fig_size=(8,6))
df['mean_distance'].mean(), df['mean_distance'].median()<jupyter_output><empty_output><jupyter_text>Most frequent interactions and their respective interaction distances<jupyter_code>plot_interactions_and_distances_boxplot(df, first_n=15, sort_distances=False, add_sub_caption=True, show_median_dist=True, store_pdf_path=f'output/human_promoter_main_distance_boxplot_{suffix}.pdf')
plot_interactions_and_distances_histogram(df, first_n=15, dist_nbins=25, add_sub_caption=True, show_median_dist=True, store_pdf_path=f'output/human_promoter_main_distance_histogram_{suffix}.pdf')<jupyter_output><empty_output><jupyter_text>Annotate Interactions using TRRUSTv2 (and other sources)  Read TRRUSTv2 interactions<jupyter_code>#dictionaries with genes/TFs as keys and [target_gene/TF, role, PUBMID ID] as value
with open('/s/jawar/h/nobackup/fahad/Human_Chromatin/TRUSTv2/human_co-regulate_dict.pckl','rb') as f:
    human_dict = pickle.load(f)
df['Interaction_in_TRUSTv2'] = df['TF_Interaction'].apply(db_annotate_interaction, intr_dict = human_dict)
df_resTRUSTv2 = df[df['Interaction_in_TRUSTv2']==1]
df_resTRUSTv2x = df_resTRUSTv2[['TF_Interaction','TF1_Family','TF2_Family','adjusted_pval']].sort_values(by='adjusted_pval').drop_duplicates('TF_Interaction')
df_resTRUSTv2x
df_resTRUSTv2x.to_csv(f'output/Human_ATTN_TRRUSTv2_{suffix}.csv')<jupyter_output><empty_output><jupyter_text>Annotate Interactions using HIPPIE database  Read hippie interactions<jupyter_code>#dictionaries with genes/TFs as keys and [target_gene/TF, role, PUBMID ID] as value
with open('/s/jawar/h/nobackup/fahad/Human_Chromatin/Protein-interactions/hippie/interactions_dict.pckl','rb') as f:
    human_dict = pickle.load(f)
for key,value in human_dict.items():
    human_dict[key] = np.array([[val, '', '0'] for val in value])
df['Interaction_in_HIPPIE'] = df['TF_Interaction'].apply(db_annotate_interaction, intr_dict = human_dict)
df_resHIPPIE = df[df['Interaction_in_HIPPIE']==1]
df_resHIPPIEx = df_resHIPPIE[['TF_Interaction','TF1_Family','TF2_Family','adjusted_pval']].sort_values(by='adjusted_pval').drop_duplicates('TF_Interaction')
df_resHIPPIEx
df_resHIPPIEx.to_csv(f'output/Human_ATTN_HIPPIE_{suffix}.csv')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1355330849742771, 'fraction_numerical': 0.014546744722370055, 'mean_word_length': 11.28322440087146, 'pattern_counts': {'":': 0, '<': 54, '<?xml version=': 0, '>': 54, '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': '13', 'dir': 'jupyter-structured-clean-dedup', 'id': '177927', 'license': 'MIT', 'n_tokens_mistral': 2199, 'n_tokens_neox': 2111, 'n_words': 255, 'path': 'analysis/Post_Process_Human_Promoter.ipynb', 'repo_name': 'jeffhsu3/satori', 'size': '5637'}