<jupyter_start><jupyter_text>Fig. 2B: Feature overall contributions for responsive vs unresponsive targets under Yeast TF Lys14 perturbation- Left: For yeast TF Lys14, the positive (red) or negative (blue) SHAP values for each feature, summed over genomic positions relative to each gene and averaged over genes that respond to Lys14 perturbation. - Right: The same analysis for genes that do not respond to Lys14 perturbation.<jupyter_code>organism = 'yeast'
tf_name = 'YDR034C'
tf_dir = '../OUTPUT/Yeast_cc_zev/all_feats/xgb/{}'.format(tf_name)

sss_df = calculate_resp_and_unresp_signed_shap_sum(tf_dir, tf_name, organism)
ax = (
    ggplot(sss_df, aes(x='feat_type_name', y='shap', fill='shap_dir'))
    + geom_bar(stat='identity', alpha=.8)
    + scale_fill_manual([COLORS['red'], COLORS['dark_blue']])
    + coord_flip()
    + facet_wrap('label_name')
    + labs(x=None, y='Mean SHAP values across genes')
    + theme_classic()
    + theme(
        figure_size=(5, 2.5), dpi=150,
        axis_text_x=element_text(color='#000000'),
        axis_text_y=element_text(color='#000000'))
)
display(ax)<jupyter_output><empty_output><jupyter_text>Fig. 2C: Net influence of yeast features- Distribution across TFs of the “net influence” of each feature on predictions, averaged over responsive targets. - Net influence is the sum of all SHAP values for a feature, regardless of sign or genomic position.<jupyter_code>organism = 'yeast'
cc_dir = '../OUTPUT/Yeast_cc_zev/all_feats/xgb/'
chipexo_dir = '../OUTPUT/Yeast_chipexo_zev/all_feats/xgb/'
tf_names = np.union1d(
    np.loadtxt('../RESOURCES/Yeast_CallingCards_TFs.txt', dtype=str),
    np.loadtxt('../RESOURCES/Yeast_ChIPexo_TFs.txt', dtype=str))

sss_df_list = []

for tf_name in tf_names:
    try:
        tf_dir, is_cc, acc = get_best_yeast_model((cc_dir, chipexo_dir), tf_name)
        print('... working on', tf_dir)
        
        sss_df = calculate_resp_and_unresp_signed_shap_sum(tf_dir, tf_name, organism)
        sss_df['tf'] = tf_name
        sss_df['acc'] = acc
        sss_df_list.append(sss_df)
        
    except:
        print('TF {} not available in Calling Cards or ChIP-exo'.format(tf_name))

sss_tfs_df = pd.concat(sss_df_list)
sss_tfs_df = calculate_shap_net_influence(sss_tfs_df)
# Only plot models with AUPRC > 0.1
plot_df = sss_tfs_df[(sss_tfs_df['acc'] > .1) & (sss_tfs_df['label_name'] == 'Responsive')]

ax = (
    ggplot(plot_df, aes(x='feat_type_name', y='shap_diff'))
    + geom_boxplot(outlier_size=.5, size=.7, width=.4, color=COLORS['orange'])
    + coord_flip()
    + ylim(-.1, .6)
    + labs(x=None, y='Net influence of SHAP values\nfor responsive genes')
    + theme_classic()
    + theme(
        figure_size=(2.5, 3), dpi=150,
        axis_text_x=element_text(color='#000000'),
        axis_text_y=element_text(color='#000000'),
        axis_title=element_text(size=10, lineheight=1.5))
)
display(ax)<jupyter_output><empty_output><jupyter_text>Fig. 2E: Net influence of human K562 features- Distribution across TFs of the “net influence” of each feature on predictions, averaged over responsive targets. - Net influence is the sum of all SHAP values for a feature, regardless of sign or genomic position.<jupyter_code>organism = 'human'
data_dir = '../OUTPUT/Human_chip_pert_enhanPromo500kbSingle_5primPromo2kb/all_feats/xgb/'
tf_names = np.loadtxt('../RESOURCES/Human_ENCODE_K562_TFs.txt', dtype=str, usecols=[0])

sss_df_list = []

for tf_name in tf_names:
    tf_dir = '{}/{}'.format(data_dir, tf_name)
    try:
        acc = pd.read_csv('{}/stats.csv.gz'.format(tf_dir))['auprc'].median()
        print('... working on', tf_name)

        sss_df = calculate_resp_and_unresp_signed_shap_sum(tf_dir, tf_name, organism)
        sss_df['tf'] = tf_name
        sss_df['acc'] = acc
        sss_df_list.append(sss_df)
        
    except:
        print('TF {} not available in human K562'.format(tf_name))

sss_tfs_df = pd.concat(sss_df_list)
sss_tfs_df = calculate_shap_net_influence(sss_tfs_df)
# Only plot models with AUPRC > 0.1
plot_df = sss_tfs_df[(sss_tfs_df['acc'] > .1) & (sss_tfs_df['label_name'] == 'Responsive')]

ax = (
    ggplot(plot_df, aes(x='feat_type_name', y='shap_diff'))
    + geom_boxplot(outlier_size=.5, size=.7, width=.4, color=COLORS['orange'])
    + coord_flip()
    + ylim(-.2, 1.6)
    + labs(x=None, y='Net influence of SHAP values\nfor responsive genes')
    + theme_classic()
    + theme(
        figure_size=(2.5, 3), dpi=150,
        axis_text_x=element_text(color='#000000'),
        axis_text_y=element_text(color='#000000'),
        axis_title=element_text(size=10, lineheight=1.5))
)
display(ax)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13450795015040826, 'fraction_numerical': 0.023635582294800173, 'mean_word_length': 4.2837684449489215, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 17, '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': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '379598', 'license': 'MIT', 'n_tokens_mistral': 1855, 'n_tokens_neox': 1721, 'n_words': 347, 'path': 'NOTEBOOKS/Feature_overall_influence.ipynb', 'repo_name': 'wsjung/TFPertRespExplainer', 'size': '4654'}