Skip to content

Commit

Permalink
- Change: Optimized the correlation heatmap plot.
Browse files Browse the repository at this point in the history
  • Loading branch information
byemaxx committed Dec 5, 2024
1 parent 9f0fc74 commit e5cb941
Show file tree
Hide file tree
Showing 9 changed files with 229 additions and 73 deletions.
5 changes: 5 additions & 0 deletions Docs/ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# Version: 1.119.6
## Date: 2024-12-5
### Changes:
- Change: Optimized the correlation heatmap plot.

# Version: 1.119.5
## Date: 2024-12-3
### Changes:
Expand Down
23 changes: 18 additions & 5 deletions metax/gui/main_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,7 @@ def __init__(self, MainWindow):
self.comboBox_method_of_protein_inference.currentIndexChanged.connect(self.update_method_of_protein_inference)
self.comboBox_3dbar_sub_meta.currentIndexChanged.connect(self.change_event_comboBox_3dbar_sub_meta)
self.comboBox_tflink_sub_meta.currentIndexChanged.connect(self.change_event_comboBox_tflink_sub_meta)
self.comboBox_sub_meta_pca.currentIndexChanged.connect(self.change_event_comboBox_sub_meta_pca)

## Basic Stat
self.pushButton_plot_pca_sns.clicked.connect(lambda: self.plot_basic_info_sns('pca'))
Expand Down Expand Up @@ -889,6 +890,13 @@ def change_event_comboBox_3dbar_sub_meta(self):
# self.comboBox_3dbar_sub_meta.setEnabled(False)
# else:
# self.comboBox_3dbar_sub_meta.setEnabled(True)

def change_event_comboBox_sub_meta_pca(self):
if self.comboBox_sub_meta_pca.currentText() != 'None':
self.checkBox_corr_plot_samples.setEnabled(False)
else:
self.checkBox_corr_plot_samples.setEnabled(True)

def change_event_comboBox_tflink_sub_meta(self):
# when the sub_meta comboBox is not None, the mean plot is not available
if self.comboBox_tflink_sub_meta.currentText() != 'None':
Expand Down Expand Up @@ -4509,6 +4517,8 @@ def get_title_by_table_name(self, table_name):
cluster = self.checkBox_corr_cluster.isChecked()
show_all_labels = (self.checkBox_corr_show_all_labels_x.isChecked(), self.checkBox_corr_show_all_labels_y.isChecked())
cmap = self.comboBox_basic_corr_cmap.currentText()
corr_method = self.comboBox_basic_corr_method.currentText()
plot_mean = False if self.checkBox_corr_plot_samples.isChecked() else True
# checek if the dataframe has at least 2 rows and 2 columns
if df.shape[0] < 2 or df.shape[1] < 2:
QMessageBox.warning(self.MainWindow, 'Warning', 'The number of rows or columns is less than 2, correlation cannot be plotted!')
Expand All @@ -4520,7 +4530,8 @@ def get_title_by_table_name(self, table_name):
BasicPlot(self.tfa, **self.heatmap_params_dict).plot_corr_sns(df=df, title_name=title_name, cluster= cluster,
width=width, height=height, font_size=font_size,
show_all_labels=show_all_labels, theme=theme, cmap=cmap,
rename_sample = rename_sample)
rename_sample = rename_sample, corr_method=corr_method,
plot_mean = plot_mean, sub_meta = sub_meta)

elif method == 'alpha_div':
self.show_message('Alpha diversity is running, please wait...')
Expand Down Expand Up @@ -5355,22 +5366,24 @@ def plot_co_expr(self, plot_type = 'network'):
self.show_message('Co-expression heatmap is plotting...\n\n It may take a long time! Please wait...')
try:
print(f'Calculate correlation with {corr_method} method...')
df = self.tfa.BasicStats.get_correlation(df_type = df_type, sample_list = sample_list, focus_list = focus_list, plot_list_only = plot_list_only, rename_taxa = rename_taxa, method=corr_method)
df = self.tfa.BasicStats.get_correlation(df_type = df_type, sample_list = sample_list,
focus_list = focus_list, plot_list_only = plot_list_only,
rename_taxa = rename_taxa, method=corr_method)
# save df to table_dict
self.update_table_dict(f'expression correlation heatmap({df_type})', df)
self.update_table_dict(f'{corr_method} correlation heatmap({df_type})', df)

show_all_labels = (
self.checkBox_corr_hetatmap_show_all_labels_x.isChecked(),
self.checkBox_corr_hetatmap_show_all_labels_y.isChecked(),
)
cmap = self.comboBox_corr_hetatmap_cmap.currentText()
BasicPlot(self.tfa, **self.heatmap_params_dict).plot_items_corr_heatmap(df=df,
title_name=f'Expression Correlation Heatmap({df_type})',
title_name=f'{corr_method.capitalize()} Correlation of {df_type}',
cluster=True,
cmap=cmap,
width=width, height=height,
font_size=font_size,
show_all_labels=show_all_labels
show_all_labels=show_all_labels,
)

except Exception:
Expand Down
90 changes: 79 additions & 11 deletions metax/gui/metax_gui/main_window.ui
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
<enum>Qt::LeftToRight</enum>
</property>
<property name="currentIndex">
<number>5</number>
<number>3</number>
</property>
<property name="documentMode">
<bool>false</bool>
Expand Down Expand Up @@ -1447,7 +1447,7 @@
<enum>QTabWidget::Triangular</enum>
</property>
<property name="currentIndex">
<number>1</number>
<number>0</number>
</property>
<widget class="QWidget" name="tab_12">
<attribute name="title">
Expand Down Expand Up @@ -1830,7 +1830,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>799</width>
<width>885</width>
<height>239</height>
</rect>
</property>
Expand Down Expand Up @@ -2406,25 +2406,59 @@
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<widget class="QLabel" name="label_129">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Show All Labels</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBox_corr_show_all_labels_x">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>X</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBox_corr_show_all_labels_y">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Y</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_192">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Theme</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="comboBox_basic_corr_cmap"/>
</item>
</layout>
</item>
<item row="4" column="0">
Expand Down Expand Up @@ -2471,6 +2505,13 @@
</item>
<item row="4" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QCheckBox" name="checkBox_corr_plot_samples">
<property name="text">
<string>Plot Samples</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBox_corr_cluster">
<property name="sizePolicy">
Expand All @@ -2488,20 +2529,42 @@
</widget>
</item>
<item>
<widget class="QLabel" name="label_192">
<widget class="QLabel" name="label_98">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Theme</string>
<string>Method</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="comboBox_basic_corr_cmap"/>
<widget class="QComboBox" name="comboBox_basic_corr_method">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<item>
<property name="text">
<string>pearson</string>
</property>
</item>
<item>
<property name="text">
<string>spearman</string>
</property>
</item>
<item>
<property name="text">
<string>kendall</string>
</property>
</item>
</widget>
</item>
</layout>
</item>
Expand Down Expand Up @@ -6532,7 +6595,7 @@
<enum>QTabWidget::Triangular</enum>
</property>
<property name="currentIndex">
<number>1</number>
<number>0</number>
</property>
<widget class="QWidget" name="tab_5">
<attribute name="title">
Expand Down Expand Up @@ -6840,6 +6903,11 @@
<string>spearman</string>
</property>
</item>
<item>
<property name="text">
<string>kendall</string>
</property>
</item>
</widget>
</item>
</layout>
Expand Down Expand Up @@ -7131,7 +7199,7 @@
<bool>false</bool>
</property>
<property name="text">
<string>Plot Co-Expression Heatmap</string>
<string>Plot Correlation Heatmap</string>
</property>
</widget>
</item>
Expand Down Expand Up @@ -8350,8 +8418,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>885</width>
<height>225</height>
<width>775</width>
<height>102</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_69">
Expand Down
Loading

0 comments on commit e5cb941

Please sign in to comment.