<jupyter_start><jupyter_text>Make a heat map using the normalized table<jupyter_code>##Add a color row to the metadata table.
my_palette = dict(zip(MetaData["Type"].unique(), ["olive","yellow","saddlebrown","orange"]))
MetaData["colors"] = MetaData["Type"].map(my_palette)
MetaData.head()

#Create a dictionary mappinng the column names inthe heatmap to the colors
hm_pallate = dict(zip(list(MetaData.Sample), list(MetaData.colors)))

#Map the colors to the COLUMNS on the count matrix for heat map
col_colors = LFC3_Counts_RowNorm.columns.map(hm_pallate)
col_colors
#Heatmap with Rows normalized by AVERAGE. Add the color bar legend in Adobe Illustrator
sns.set(font_scale=1.0)
colbar_kws = {'label':'GE relative to avg. across all samples'}
m = sns.clustermap(LFC3_Counts_RowNorm, cmap="BuPu", col_colors=col_colors, linewidths=.5)

#Add a legend for Column color bar:
for label in MetaData["Type"].unique():
    m.ax_row_dendrogram.bar(0, 0, color=my_palette[label],
                            label=label, linewidth=0)
m.ax_row_dendrogram.legend(loc="upper left", bbox_to_anchor=(5.0, 1.35), fontsize="large", title="Mesocosm host type")

#adjust the size and rotation of axes labels
plt.setp(m.ax_heatmap.get_yticklabels(), fontsize=12)  # For y axis
plt.setp(m.ax_heatmap.get_xticklabels(), rotation=90, fontsize=18) # For x axis
plt.show()

#bbos_inches makes sure the whole image is included in the pdf
#plt.savefig("DA_KEGGS_noD7_heatmap.pdf", format='pdf', bbox_inches='tight')
# Normalize ROWS wihth standard scale: Either 0 (rows) or 1 (columns). 
# Whether or not to standardize that dimension, 
# meaning for each row or column, subtract the minimum and divide each by its maximum.
sns.set_palette(sns.color_palette("coolwarm"))
sns.clustermap(LFC3_Counts_Norm, standard_scale=0,cmap="BuPu")<jupyter_output><empty_output><jupyter_text>Do the same thing for the D7 vs. Animal comparison<jupyter_code>LFC3_Counts2 = pd.read_table("summarized_DA_KEGGS.txt", index_col=0)
LFC3_Counts2
#Metadata table ROWS must be in the same order as the Count matrix COLUMS!
GE2 = MetaData.GE.values
MetaData
#Divide gene counts by GE by COLUMN
LFC3_Counts_Norm2 = LFC3_Counts2.iloc[:,:].div(GE2[:], axis=1)
LFC3_Counts_Norm2.head()
#Get the AVERAGE of each row
row_avg2 = LFC3_Counts_Norm2.iloc[:,:].mean(axis=1)

#Divide by the row AVG to normalize
LFC3_Counts_RowNorm2 = LFC3_Counts_Norm2.iloc[:,:].div(row_avg2,axis=0)
LFC3_Counts_RowNorm2.head()
LFC3_Counts_Norm2.to_csv("summarized_DA_KEGGs.GEnorm.txt", sep='\t')
LFC3_Counts_RowNorm2.to_csv("summarized_DA_KEGGs.GE_RowNorm.txt", sep='\t')
#Map the colors to the COLUMNS on the count matrix for heat map
col_colors = LFC3_Counts_RowNorm2.columns.map(hm_pallate)
col_colors
plt.figure(figsize = (260,50))
m = sns.clustermap(LFC3_Counts_RowNorm2, cmap="BuPu", col_colors=col_colors, yticklabels=1, linewidths=.5)

#Add a legend for Column color bar:
for label in MetaData["Type"].unique():
    m.ax_row_dendrogram.bar(0, 0, color=my_palette[label],
                            label=label, linewidth=0)
m.ax_row_dendrogram.legend(loc="upper left", bbox_to_anchor=(5.0, 1.35), fontsize="large", title="Mesocosm host type")

#adjust the size and rotation of axes labels
plt.setp(m.ax_heatmap.get_yticklabels(), fontsize=11)  # For y axis
plt.setp(m.ax_heatmap.get_xticklabels(), rotation=90, fontsize=17) # For x axis
#plt.show()

plt.savefig("DA_KEGGS_heatmap.pdf", format='pdf', bbox_inches='tight')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12244897959183673, 'fraction_numerical': 0.022995113538373097, 'mean_word_length': 6.219917012448133, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '60379', 'license': 'MIT', 'n_tokens_mistral': 1363, 'n_tokens_neox': 1314, 'n_words': 307, 'path': 'Normalize_count_tables and KEGG heatmaps.ipynb', 'repo_name': 'brittanysuttner/Bioinformatics_Scripts', 'size': '3479'}