<jupyter_start><jupyter_text>*** Heatmap for syn res<jupyter_code>dir_out_fig4 = './figure4/'
dir_anlyze = '../mutsig_out/anlyze'

# Read the significant gene dataframe after FDR calculation
feature_type = 'histology';syn_nsyn = 'syn';run = 'cohort_090821';
df_syn = pd.read_csv(os.path.join(dir_out_fig4,feature_type+'.syn.df_all_forheatmap.'+run+'.csv'),\
index_col = 0)
df_syn['FDR'] = -np.log10(df_syn['FDR']) # Transform into log scale
### Sort by genes
df_pivot_syn = df_syn.pivot_table('FDR', index='gene', columns='feature')
for feat in lfeat:
    if feat not in df_pivot_syn.columns:
#         df_pivot_syn[feat] = float('NaN')
        print(f'No significant genes: {feat}')
df_pivot_syn['n_sig_gene'] = df_pivot_syn.notnull().sum(axis=1)
df_pivot_gene_syn = df_pivot_syn.sort_values(by = 'n_sig_gene', ascending = False)
df_pivot_gene_syn = df_pivot_gene_syn.iloc[:, 0:-1]
def draw_heatmap(df):
    shape = df.shape
    fig, ax = plt.subplots(figsize = (shape[1]/3+3, shape[0]/3+2))
    cmap = plt.get_cmap("YlGnBu",30);cmap.set_under('white')
    ax = sns.heatmap(df,cmap=cmap,yticklabels=True,xticklabels=True,\
                     square=True,linewidth = 0.5,linecolor="grey", cbar_kws={"shrink": 0.3})
    ax.set_xlabel('Significant Genes'); ax.set_ylabel('Histology Cohort')
    # add patient number to ticks
    labels=[]
    for label in ax.get_yticklabels():
        feat = label.get_text()
        new_label =feat +  ' (n='+str(dict_feat_np[feat])+') '
        labels.append(new_label)
        label.set_ha("right")
    ax.set_yticklabels(labels)

    plt.tight_layout()
    plt.show()
    plt.close()
draw_heatmap(df_pivot_gene_syn.transpose())<jupyter_output><empty_output><jupyter_text>*** Candidate number between synonymous and non-synonymous<jupyter_code>dir_out = './figure4'

feature_type = 'histology'; run = 'cohort_072221'
df_nsig_feat = pd.read_csv(os.path.join(dir_out, feature_type+'.syn_nsyn.'+run+'.nsig.csv'), index_col = 0)
fig,ax = plt.subplots(figsize = (8,4))
ax = sns.barplot(x='index', y='nsig',hue = 'syn.nsyn' ,data=df)
plt.xticks(rotation = 90)
ax.set_ylabel('Number of significant genes'); ax.set_xlabel('')
plt.tight_layout()
plt.show()<jupyter_output>findfont: Font family ['sans-serif'] not found. Falling back to DejaVu Sans.
findfont: Font family ['sans-serif'] not found. Falling back to DejaVu Sans.
findfont: Font family ['sans-serif'] not found. Falling back to DejaVu Sans.
findfont: Font family ['sans-serif'] not found. Falling back to DejaVu Sans.
{'fraction_non_alphanumeric': 0.15556441962504985, 'fraction_numerical': 0.015556441962504986, 'mean_word_length': 4.957244655581948, 'pattern_counts': {'":': 1, '<': 8, '<?xml version=': 0, '>': 8, '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': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '463749', 'license': 'MIT', 'n_tokens_mistral': 1018, 'n_tokens_neox': 967, 'n_words': 181, 'path': 'notebook/04-figure4.ipynb', 'repo_name': 'ryy1221/MutSigCVsyn', 'size': '2507'}