Skip to content

Commit

Permalink
- New: Added a parameter in Settting to enable user to set the linkag…
Browse files Browse the repository at this point in the history
…es method and linkage distance for the heatmap plot.(removed some metrices due to when the data has zero, the linkage will raise error.)
  • Loading branch information
byemaxx committed Jun 9, 2024
1 parent 26d2be8 commit d4c1bd0
Show file tree
Hide file tree
Showing 9 changed files with 394 additions and 74 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.106.0
## Date: 2024-06-09
### Changes:
- New: Added a parameter in Settting to enable user to set the linkages method and linkage distance for the heatmap plot.(removed some metrices due to when the data has zero, the linkage will raise error.)

# Version: 1.105.4
## Date: 2024-06-05
### Changes:
Expand Down
34 changes: 32 additions & 2 deletions Docs/example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,24 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"et `function` and `multi tables` "
"Set `function` and `multi tables` \n",
"\n",
"\n",
"# set_multi_tables()\n",
"Sets multiple tables including Function table, Taxa table, and Taxa-Function table.\n",
"\n",
"Parameters:\n",
"- `level (str)`: The taxonomic level to consider. Default is 's' (species).\n",
"- `func_threshold (float)`: The threshold for function proportion. Default is 1.00.\n",
"- `processing_after_sum (bool)`: Whether to perform data preprocessing after summing protein intensity. Default is False.\n",
"- `data_preprocess_params (dict)`: Parameters for data preprocessing. Default is {'normalize_method': None, 'transform_method': None,\n",
" 'batch_meta': None, 'outlier_detect_method': None, 'outlier_handle_method': None,\n",
" 'outlier_detect_by_group': None, 'outlier_handle_by_group': None, 'processing_order': None}.\n",
"- `peptide_num_threshold (dict)`: Thresholds for peptide numbers in Function table, Taxa table, and Taxa-Function table.\n",
" Default is {'taxa': 1, 'func': 1, 'taxa_func': 1}.\n",
"- `sum_protein (bool)`: Whether to sum protein intensity. Default is False.\n",
"- `sum_protein_params (dict)`: Parameters for summing protein intensity. Default is {'method': 'razor', 'by_sample': False,\n",
" 'rank_method': 'unique_counts'}.\n"
]
},
{
Expand Down Expand Up @@ -401,7 +418,20 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Use the `get_df` method to get the Taxa, Function, OTFs, and Peptides tables"
"Use the `get_df` method to get the Taxa, Function, OTFs, and Peptides tables\n",
"Get the dataframe without peptide_num column\n",
"\n",
"### Parameters:\n",
"- table_name (str): The name of the table to retrieve. Valid options are:\n",
" - `peptide`: Returns the peptide_df table.\n",
" - `taxa`: Returns the taxa_df table.\n",
" - `func`: Returns the func_df table.\n",
" - `taxa_func`: Returns the taxa_func_df table.\n",
" - `func_taxa`: Returns the func_taxa_df table.\n",
" - `custom`: Returns the custom_df table.\n",
"\n",
"Returns:\n",
"- `pandas.DataFrame`\n"
]
},
{
Expand Down
43 changes: 26 additions & 17 deletions utils/GUI.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,9 @@ def __init__(self, MainWindow):
self.temp_params_dict = {} # 1.save the temp params for thread callback function 2.as a flag to check if the thread is running
self.executors = [] # save all FunctionExecutor object
self.add_theme_to_combobox()

# ploting parameters
self.heatmap_params_dict = {'linkage_method': 'average', 'distance_metric': 'euclidean'}


# set icon
Expand Down Expand Up @@ -617,20 +620,21 @@ def show_settings_window(self):
if self.settings_dialog is None:
self.settings_dialog = QDialog(self.MainWindow)
self.settings_dialog.setWindowTitle("Settings")
self.settings_dialog.setModal(True)
self.settings_dialog.setModal(False)
layout = QVBoxLayout(self.settings_dialog)
# reszie the settings dialog
self.settings_dialog.resize(600, 400)

settings_widget = SettingsWidget(self.settings_dialog, self.update_branch, self.auto_check_update)
settings_widget.update_mode_changed.connect(self.on_update_mode_changed)
settings_widget.auto_check_update_changed.connect(self.on_auto_check_update_changed)

settings_widget.heatmap_params_dict_changed.connect(self.on_heatmap_params_changed)

layout.addWidget(settings_widget)
self.settings_dialog.setLayout(layout)

self.settings_dialog.exec_()

self.settings_dialog.show()


# handle the update mode changed from settings window
def on_update_mode_changed(self, mode):
self.update_branch = mode
Expand All @@ -640,6 +644,11 @@ def on_update_mode_changed(self, mode):
def on_auto_check_update_changed(self, auto_check):
self.auto_check_update = auto_check
print(f"Auto check update set to: {auto_check}")

# handle the heatmap params changed from settings window
def on_heatmap_params_changed(self, params_dict):
self.heatmap_params_dict = params_dict
print(f"Heatmap params changed to: {params_dict}")

############### basic function End ###############

Expand Down Expand Up @@ -3261,7 +3270,7 @@ def plot_basic_list(self, plot_type='heatmap'):

# plot heatmap
self.show_message(f'Plotting {plot_type}...')
HeatmapPlot(self.tfa).plot_basic_heatmap(df=df, title=title, fig_size=(int(width), int(height)),
HeatmapPlot(self.tfa, **self.heatmap_params_dict).plot_basic_heatmap(df=df, title=title, fig_size=(int(width), int(height)),
scale=scale, row_cluster=row_cluster, col_cluster=col_cluster,
cmap=cmap, rename_taxa=rename_taxa, font_size=font_size,
show_all_labels=show_all_labels, rename_sample=rename_sample,
Expand Down Expand Up @@ -4064,7 +4073,7 @@ def plot_top_heatmap(self):
try:
self.show_message(f'Plotting heatmap for {table_name}...')
if table_name.startswith('dunnett_test'):
fig = HeatmapPlot(self.tfa).plot_heatmap_of_dunnett_test_res(df=df,
fig = HeatmapPlot(self.tfa, **self.heatmap_params_dict).plot_heatmap_of_dunnett_test_res(df=df,
fig_size=fig_size, pvalue=pvalue, cmap=cmap,
scale = scale, col_cluster = col_luster, row_cluster = row_luster,
rename_taxa=rename_taxa, font_size=font_size,
Expand All @@ -4073,7 +4082,7 @@ def plot_top_heatmap(self):
p_type = self.comboBox_top_heatmap_sort_type.currentText()
three_levels_df_type = self.comboBox_cross_3_level_plot_df_type.currentText()

fig = HeatmapPlot(self.tfa).plot_heatmap_of_all_condition_res(df=df, res_df_type='deseq2',
fig = HeatmapPlot(self.tfa, **self.heatmap_params_dict).plot_heatmap_of_all_condition_res(df=df, res_df_type='deseq2',
fig_size=fig_size, pvalue=pvalue, cmap=cmap,
log2fc_min =self.doubleSpinBox_mini_log2fc_heatmap.value(),
log2fc_max =self.doubleSpinBox_max_log2fc_heatmap.value(),
Expand All @@ -4093,7 +4102,7 @@ def plot_top_heatmap(self):
elif table_name.startswith('dunnettAllCondtion'):
three_levels_df_type = self.comboBox_cross_3_level_plot_df_type.currentText()

fig = HeatmapPlot(self.tfa).plot_heatmap_of_all_condition_res(df=df, res_df_type='dunnett',
fig = HeatmapPlot(self.tfa, **self.heatmap_params_dict).plot_heatmap_of_all_condition_res(df=df, res_df_type='dunnett',
fig_size=fig_size, pvalue=pvalue, cmap=cmap,
scale = scale, col_cluster = col_luster, row_cluster = row_luster,
rename_taxa=rename_taxa, font_size=font_size,
Expand Down Expand Up @@ -4126,13 +4135,13 @@ def plot_top_heatmap(self):
title = "Functions Non-Significant; Related Taxa Significantly Different Across Groups"
else:
title = ""
fig = HeatmapPlot(self.tfa).plot_top_taxa_func_heatmap_of_test_res(df=df,
fig = HeatmapPlot(self.tfa, **self.heatmap_params_dict).plot_top_taxa_func_heatmap_of_test_res(df=df,
top_number=top_num, value_type=value_type, fig_size=fig_size,
col_cluster = col_luster, row_cluster = row_luster,
pvalue=pvalue, cmap=cmap, rename_taxa=rename_taxa, font_size=font_size, title=title,
show_all_labels = show_all_labels)
else:
fig = HeatmapPlot(self.tfa).plot_basic_heatmap_of_test_res(df=df, top_number=top_num,
fig = HeatmapPlot(self.tfa, **self.heatmap_params_dict).plot_basic_heatmap_of_test_res(df=df, top_number=top_num,
value_type=value_type, fig_size=fig_size, pvalue=pvalue,
scale = scale, col_cluster = col_luster, row_cluster = row_luster,
cmap = cmap, rename_taxa=rename_taxa, font_size=font_size,
Expand Down Expand Up @@ -4169,12 +4178,12 @@ def get_top_cross_table(self):

try:
if table_name.startswith('dunnett_test'):
df_top_cross = HeatmapPlot(self.tfa).get_heatmap_table_of_dunnett_res(df = df, pvalue=pvalue,scale = scale,
df_top_cross = HeatmapPlot(self.tfa, **self.heatmap_params_dict).get_heatmap_table_of_dunnett_res(df = df, pvalue=pvalue,scale = scale,
col_cluster = col_luster, row_cluster = row_luster,
rename_taxa=rename_taxa)
elif 'deseq2all' in table_name:
p_type = self.comboBox_top_heatmap_sort_type.currentText()
df_top_cross = HeatmapPlot(self.tfa).plot_heatmap_of_all_condition_res(df = df, res_df_type='deseq2',
df_top_cross = HeatmapPlot(self.tfa, **self.heatmap_params_dict).plot_heatmap_of_all_condition_res(df = df, res_df_type='deseq2',
pvalue=pvalue,scale = scale,
log2fc_min =self.doubleSpinBox_mini_log2fc_heatmap.value(),
log2fc_max =self.doubleSpinBox_max_log2fc_heatmap.value(),
Expand All @@ -4184,7 +4193,7 @@ def get_top_cross_table(self):
remove_zero_col = remove_zero_col
)
elif 'dunnettAllCondtion' in table_name:
df_top_cross = HeatmapPlot(self.tfa).plot_heatmap_of_all_condition_res(df = df, res_df_type='dunnett',
df_top_cross = HeatmapPlot(self.tfa, **self.heatmap_params_dict).plot_heatmap_of_all_condition_res(df = df, res_df_type='dunnett',
pvalue=pvalue,scale = scale,
col_cluster = col_luster, row_cluster = row_luster,
rename_taxa=rename_taxa, return_type = 'table',
Expand All @@ -4195,12 +4204,12 @@ def get_top_cross_table(self):

else:
if 'taxa-functions' in table_name:
df_top_cross = HeatmapPlot(self.tfa).get_top_across_table(df=df, top_number=top_num,
df_top_cross = HeatmapPlot(self.tfa, **self.heatmap_params_dict).get_top_across_table(df=df, top_number=top_num,
col_cluster = col_luster, row_cluster = row_luster,
value_type=value_type, pvalue=pvalue,
rename_taxa=rename_taxa)
else:
df_top_cross = HeatmapPlot(self.tfa).get_top_across_table_basic(df=df, top_number=top_num,
df_top_cross = HeatmapPlot(self.tfa, **self.heatmap_params_dict).get_top_across_table_basic(df=df, top_number=top_num,
col_cluster = col_luster, row_cluster = row_luster,
value_type=value_type, pvalue=pvalue,
scale = scale, rename_taxa=rename_taxa)
Expand Down Expand Up @@ -5107,7 +5116,7 @@ def plot_tflink_heatmap(self):

try:
self.show_message('Plotting heatmap, please wait...')
HeatmapPlot(self.tfa).plot_basic_heatmap(df=df, title=title, fig_size=(int(width), int(height)),
HeatmapPlot(self.tfa, **self.heatmap_params_dict).plot_basic_heatmap(df=df, title=title, fig_size=(int(width), int(height)),
scale=scale, row_cluster=row_cluster, col_cluster=col_cluster,
cmap=cmap, rename_taxa=rename_taxa, font_size=font_size, show_all_labels=show_all_labels,
rename_sample=self.checkBox_tflink_hetatmap_rename_sample.isChecked(), plot_mean=plot_mean
Expand Down
133 changes: 132 additions & 1 deletion utils/MetaX_GUI/Setting.ui
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<item row="0" column="0">
<widget class="QToolBox" name="toolBox">
<property name="currentIndex">
<number>0</number>
<number>1</number>
</property>
<widget class="QWidget" name="page">
<property name="geometry">
Expand Down Expand Up @@ -77,6 +77,137 @@
<attribute name="label">
<string>Others</string>
</attribute>
<layout class="QGridLayout" name="gridLayout_4">
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>HeatMap</string>
</property>
</widget>
</item>
<item row="0" column="1">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>Linkage Method</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="comboBox_heatmap_linkage_method">
<property name="currentText">
<string>average</string>
</property>
<item>
<property name="text">
<string>average</string>
</property>
</item>
<item>
<property name="text">
<string>single</string>
</property>
</item>
<item>
<property name="text">
<string>complete</string>
</property>
</item>
<item>
<property name="text">
<string>centroid</string>
</property>
</item>
<item>
<property name="text">
<string>median</string>
</property>
</item>
<item>
<property name="text">
<string>weighted</string>
</property>
</item>
<item>
<property name="text">
<string>ward</string>
</property>
</item>
</widget>
</item>
</layout>
</item>
<item row="0" column="2">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="label_3">
<property name="text">
<string>Linkage Metric</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="comboBox_heatmap_linkage_metric">
<property name="currentText">
<string>euclidean</string>
</property>
<item>
<property name="text">
<string>euclidean</string>
</property>
</item>
<item>
<property name="text">
<string>chebyshev</string>
</property>
</item>
<item>
<property name="text">
<string>cityblock</string>
</property>
</item>
<item>
<property name="text">
<string>hamming</string>
</property>
</item>
<item>
<property name="text">
<string>matching</string>
</property>
</item>
<item>
<property name="text">
<string>minkowski</string>
</property>
</item>
<item>
<property name="text">
<string>rogerstanimoto</string>
</property>
</item>
<item>
<property name="text">
<string>russellrao</string>
</property>
</item>
<item>
<property name="text">
<string>sqeuclidean</string>
</property>
</item>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</widget>
</item>
Expand Down
Loading

0 comments on commit d4c1bd0

Please sign in to comment.