Skip to content

Commit

Permalink
- Change: Optimized the x-axis and y-axis labels of the heatmap plot …
Browse files Browse the repository at this point in the history
…to make the labels more clear.
  • Loading branch information
byemaxx committed Aug 21, 2024
1 parent 851d915 commit 4e3b361
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 12 deletions.
6 changes: 6 additions & 0 deletions Docs/ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# Version: 1.111.5
## Date: 2024-08-21
### Changes:
- Change: Optimized the x-axis and y-axis labels of the heatmap plot to make the labels more clear.


# Version: 1.111.4
## Date: 2024-08-21
### Changes:
Expand Down
35 changes: 25 additions & 10 deletions metax/taxafunc_ploter/heatmap_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,21 @@ def __init__(self, tfobj, linkage_method:str = 'average', distance_metric:str =
# reset sns style
sns.set_theme()
plt.style.use('default')

def get_x_labels_ha(self):
x_rotation = self.x_labels_rotation
if x_rotation > 0:
return 'right'
elif x_rotation < 0:
return 'left'
else:
return 'center'
def get_y_labels_va(self):
y_rotation = self.y_labels_rotation
if y_rotation >= 0:
return 'baseline'
else:
return 'top'

def rename_taxa(self, df):
first_index = df.index[0]
Expand Down Expand Up @@ -150,14 +165,14 @@ def plot_top_taxa_func_heatmap_of_test_res(self, df, top_number:int|str= 100,
fig.ax_heatmap.get_xmajorticklabels(),
fontsize=font_size,
rotation=self.x_labels_rotation,
ha = 'right' if self.x_labels_rotation > 0 else 'left'
ha = self.get_x_labels_ha()
)
fig.ax_heatmap.set_yticklabels(
fig.ax_heatmap.get_ymajorticklabels(),
fontsize=font_size,
rotation=self.y_labels_rotation,
ha = 'left',
va = 'baseline' if self.y_labels_rotation > 0 else 'top'
va = self.get_y_labels_va()
)

cbar = fig.ax_heatmap.collections[0].colorbar
Expand Down Expand Up @@ -296,14 +311,14 @@ def plot_basic_heatmap_of_test_res(self, df, top_number:int = 100, value_type:st
fig.ax_heatmap.get_xmajorticklabels(),
fontsize=font_size,
rotation=self.x_labels_rotation,
ha = 'right' if self.x_labels_rotation > 0 else 'left'
ha = self.get_x_labels_ha()
)
fig.ax_heatmap.set_yticklabels(
fig.ax_heatmap.get_ymajorticklabels(),
fontsize=font_size,
rotation=self.y_labels_rotation,
ha = 'left',
va = 'baseline' if self.y_labels_rotation > 0 else 'top'
va = self.get_y_labels_va()
)

scale_title = f", scaled by {scale}" if scale in ['row', 'column', 'all'] else ''
Expand Down Expand Up @@ -396,14 +411,14 @@ def plot_basic_heatmap(self, df, title = 'Heatmap',fig_size:tuple|None = None,
fig.ax_heatmap.get_xmajorticklabels(),
fontsize=font_size,
rotation=self.x_labels_rotation,
ha="right" if self.x_labels_rotation > 0 else "left",
ha=self.get_x_labels_ha()
)
fig.ax_heatmap.set_yticklabels(
fig.ax_heatmap.get_ymajorticklabels(),
fontsize=font_size,
rotation=self.y_labels_rotation,
ha="left",
va="baseline" if self.y_labels_rotation > 0 else "top",
va=self.get_y_labels_va()
)
title = f"{title} (scaled by {scale})" if scale not in [None, 'None'] else title
plt.suptitle(title, weight='bold')
Expand Down Expand Up @@ -556,14 +571,14 @@ def plot_heatmap_of_all_condition_res(self, df, pvalue:float = 0.05,scale:str|N
fig.ax_heatmap.get_xmajorticklabels(),
fontsize=font_size,
rotation=self.x_labels_rotation,
ha = 'right' if self.x_labels_rotation > 0 else 'left'
ha = self.get_x_labels_ha()
)
fig.ax_heatmap.set_yticklabels(
fig.ax_heatmap.get_ymajorticklabels(),
fontsize=font_size,
rotation=self.y_labels_rotation,
ha = 'left',
va = 'baseline' if self.y_labels_rotation > 0 else 'top'
va = self.get_y_labels_va()
)
if res_df_type == 'deseq2':
title = f"The Heatmap of log2FoldChange calculated by DESeq2 ({p_type} <= {pvalue}, {log2fc_min} <= log2fc <= {log2fc_max}, scaled by {scale})"
Expand Down Expand Up @@ -694,14 +709,14 @@ def plot_heatmap_of_dunnett_test_res(self, df, pvalue:float = 0.05,scale:str|No
fig.ax_heatmap.get_xmajorticklabels(),
fontsize=font_size,
rotation=self.x_labels_rotation,
ha = 'right' if self.x_labels_rotation > 0 else 'left'
ha = self.get_x_labels_ha()
)
fig.ax_heatmap.set_yticklabels(
fig.ax_heatmap.get_ymajorticklabels(),
fontsize=font_size,
rotation=self.y_labels_rotation,
ha = 'left',
va = 'baseline' if self.y_labels_rotation > 0 else 'top'
va = self.get_y_labels_va()
)
plt.suptitle(f"The Heatmap of t-statistic calculated by Dunnett test (p-value < {pvalue}, scaled by {scale})",
weight='bold')
Expand Down
2 changes: 1 addition & 1 deletion metax/utils/version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
__version__ = '1.111.4'
__version__ = '1.111.5'
API_version = '2'
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "MetaXTools"
version = "1.111.4"
version = "1.111.5"
description = "MetaXTools is a novel tool for linking peptide sequences with taxonomic and functional information in Metaproteomics."
readme = "README_PyPi.md"
license = { text = "NorthOmics" }
Expand Down

0 comments on commit 4e3b361

Please sign in to comment.