Skip to content

Commit

Permalink
1. Set the HTML plot(e.g. bar, sankey, sunburst, network) as the dark…
Browse files Browse the repository at this point in the history
… theme when the MetaX theme is dark.

2. Save theme profile to the configuration file when save MetaX_obj.pkl.
  • Loading branch information
byemaxx committed Jun 17, 2024
1 parent af7909e commit 91dfae1
Show file tree
Hide file tree
Showing 16 changed files with 178 additions and 117 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.107.4
## Date: 2024-06-17
### Changes:
- Change: Set the HTML plot(e.g. bar, sankey, sunburst, network) as the dark theme when the MetaX theme is dark.

# Version: 1.107.3
## Date: 2024-06-16
### Changes:
Expand Down
39 changes: 27 additions & 12 deletions utils/GUI.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@ def __init__(self, MainWindow):
# Check and load settings
self.load_basic_Settings()

# set the default theme mode
self.theme = 'white'

#check update
self.update_required = False
self.check_update(manual_check_trigger=False)
Expand Down Expand Up @@ -163,7 +166,7 @@ def __init__(self, MainWindow):
self.tf_link_net_params_dict = {'taxa_shape': 'circle', 'func_shape': 'rect',
'taxa_color': '#374E55','taxa_focus_color': '#6A6599',
'func_color': '#DF8F44', 'func_focus_color': '#B24745',
'line_opacity': 0.5, 'line_width': 2, 'line_curve': 0,
'line_opacity': 0.5, 'line_width': 3, 'line_curve': 0,
'line_color': '#9aa7b1', 'repulsion': 500, 'font_weight': 'bold'
}

Expand Down Expand Up @@ -714,6 +717,10 @@ def change_theme(self, theme, silent=False):
self.show_message(f"Changing theme to {theme}...")
# save the theme to settings
self.settings.setValue("theme", theme)
# save the theme mode to GUI attribute (dark or light)
self.theme = 'dark' if 'dark' in theme else 'white'
print(f"Theme mode: {self.theme}")

# recover the .xml suffix
theme = theme + '.xml'

Expand Down Expand Up @@ -978,6 +985,10 @@ def save_basic_settings(self, line_edit_name: str | None = None):
# save update_branch setting
self.settings.setValue("update_branch", self.update_branch)
self.settings.setValue("auto_check_update", self.auto_check_update)
#save theme
if self.settings.contains("theme"):
self.settings.setValue("theme", self.settings.value("theme", type=str))



def save_set_multi_table_settings(self):
Expand Down Expand Up @@ -3400,7 +3411,7 @@ def plot_basic_list(self, plot_type='heatmap'):
if reply == QMessageBox.No:
return None
self.show_message(f'Plotting {plot_type}...')
pic = BarPlot_js(self.tfa).plot_intensity_bar(df = df, width=width, height=height,
pic = BarPlot_js(self.tfa, theme=self.theme).plot_intensity_bar(df = df, width=width, height=height,
title= '', rename_taxa=rename_taxa,
show_legend=show_legend, font_size=font_size,
rename_sample=rename_sample, plot_mean = plot_mean,
Expand Down Expand Up @@ -3436,7 +3447,7 @@ def plot_basic_list(self, plot_type='heatmap'):
else:
title_new = ''
subtitle = ''
pic = SankeyPlot(self.tfa).plot_intensity_sankey(df=df, width=width, height=height,
pic = SankeyPlot(self.tfa, theme=self.theme).plot_intensity_sankey(df=df, width=width, height=height,
title=title_new, subtitle=subtitle, font_size=font_size,
show_legend=self.checkBox_basic_bar_show_legend.isChecked())
self.save_and_show_js_plot(pic, title)
Expand Down Expand Up @@ -3721,7 +3732,7 @@ def plot_trends_interactive_line(self):


try:
pic = TrendsPlot_js(self.tfa).plot_trends_js( df=df, width=width, height= height, title=title,
pic = TrendsPlot_js(self.tfa, theme=self.theme).plot_trends_js( df=df, width=width, height= height, title=title,
rename_taxa=rename_taxa, show_legend=show_legend,
add_group_name = plot_samples, font_size=font_size)
self.save_and_show_js_plot(pic, f'Cluster {cluster_num+1} of {table_name}')
Expand Down Expand Up @@ -3796,7 +3807,7 @@ def save_and_show_js_plot(self, pic, title, width=None, height=None):
pic.render(save_path)
self.logger.write_log(f'html saved: {save_path}', 'i')

web = webDialog.MyDialog(save_path, None)
web = webDialog.WebDialog(save_path, None, theme=self.theme)
if title:
web.setWindowTitle(title)

Expand Down Expand Up @@ -4039,7 +4050,9 @@ def get_title_by_table_name(self, table_name):
QMessageBox.warning(self.MainWindow, 'Warning', 'The number of rows is less than 3, PCA 3D cannot be plotted!')
return None
self.show_message('PCA is running, please wait...')
pic = PcaPlot_js(self.tfa).plot_pca_pyecharts_3d(df=df, title_name=title_name, show_label = show_label,
pic = PcaPlot_js(self.tfa,
theme=self.theme
).plot_pca_pyecharts_3d(df=df, title_name=title_name, show_label = show_label,
rename_sample = rename_sample,
width=width, height=height, font_size=font_size, legend_col_num=legend_col_num)
self.save_and_show_js_plot(pic, f'PCA 3D of {title_name}')
Expand Down Expand Up @@ -4096,7 +4109,7 @@ def get_title_by_table_name(self, table_name):
else:
show_label = False

pic = SunburstPlot().create_sunburst_chart(taxa_df= taxa_df, width=width, height=height,
pic = SunburstPlot(theme=self.theme).create_sunburst_chart(taxa_df= taxa_df, width=width, height=height,
title='Sunburst of Taxa', show_label=show_label,
label_font_size = font_size)
self.save_and_show_js_plot(pic, 'Sunburst of Taxa')
Expand All @@ -4108,7 +4121,7 @@ def get_title_by_table_name(self, table_name):

taxa_df = self.tfa.taxa_df[sample_list]

pic = TreeMapPlot().create_treemap_chart(taxa_df= taxa_df, width=width, height=height,
pic = TreeMapPlot(theme=self.theme).create_treemap_chart(taxa_df= taxa_df, width=width, height=height,
show_sub_title = self.checkBox_pca_if_show_lable.isChecked(),
font_size = font_size)
self.save_and_show_js_plot(pic, 'Treemap of Taxa')
Expand All @@ -4122,7 +4135,7 @@ def get_title_by_table_name(self, table_name):
df = df[sample_list]
title = 'Sankey of Taxa' if table_name == 'Taxa' else 'Sankey of Taxa-Functions'

pic = SankeyPlot(self.tfa).plot_intensity_sankey(df=df, width=width, height=height,
pic = SankeyPlot(self.tfa, theme=self.theme).plot_intensity_sankey(df=df, width=width, height=height,
font_size = font_size, title='', subtitle='')
self.save_and_show_js_plot(pic, title)

Expand Down Expand Up @@ -4791,7 +4804,7 @@ def plot_deseq2_volcano(self):
# VolcanoPlot().plot_volcano(df, padj = pvalue, log2fc = log2fc, title_name='2 groups', width=width, height=height)
try:
df = self.table_dict[table_name]
pic = VolcanoPlot().plot_volcano_js(df, pvalue = pvalue, p_type = p_type,
pic = VolcanoPlot(theme=self.theme).plot_volcano_js(df, pvalue = pvalue, p_type = p_type,
log2fc_min = log2fc_min, log2fc_max=log2fc_max,
title_name=title_name, font_size = font_size,
width=width, height=height)
Expand Down Expand Up @@ -4844,6 +4857,7 @@ def plot_co_expr_network(self):
show_labels=show_labels,
rename_taxa=rename_taxa,
font_size=font_size,
theme=self.theme,
**self.tf_link_net_params_dict
).plot_co_expression_network(df_type= df_type, corr_method=corr_method,
corr_threshold=corr_threshold, sample_list=sample_list, width=width, height=height, focus_list=focus_list, plot_list_only=plot_list_only)
Expand Down Expand Up @@ -4890,7 +4904,7 @@ def deseq2_plot_sankey(self):
df = self.table_dict[table_name]
title_name = f'{group1} vs {group2} of {table_name.split("(")[1].split(")")[0]}'

pic = SankeyPlot(self.tfa).plot_fc_sankey(df, width=width, height=height, pvalue=pvalue, p_type = p_type,
pic = SankeyPlot(self.tfa, theme=self.theme).plot_fc_sankey(df, width=width, height=height, pvalue=pvalue, p_type = p_type,
log2fc_min=log2fc_min, log2fc_max=log2fc_max, title =title_name, font_size=font_size)
self.save_and_show_js_plot(pic, f'Sankay plot {title_name}')

Expand Down Expand Up @@ -5072,6 +5086,7 @@ def plot_network(self):
show_labels=show_labels,
rename_taxa=rename_taxa,
font_size=font_size,
theme=self.theme,
**self.tf_link_net_params_dict
).plot_tflink_network(sample_list=sample_list, width=width, height=height, focus_list=focus_list,plot_list_only=plot_list_only)
self.save_and_show_js_plot(pic, 'taxa-func link Network')
Expand Down Expand Up @@ -5340,7 +5355,7 @@ def plot_tflink_bar(self):
params['show_all_labels'] = show_all_labels

self.show_message('Plotting bar plot, please wait...')
pic = BarPlot_js(self.tfa).plot_intensity_bar(**params)
pic = BarPlot_js(self.tfa, theme=self.theme).plot_intensity_bar(**params)
self.save_and_show_js_plot(pic, 'Intensity Bar Plot')


Expand Down
44 changes: 9 additions & 35 deletions utils/MetaX_GUI/MainWindow.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>6</number>
</property>
<widget class="QWidget" name="tab">
<attribute name="title">
Expand Down Expand Up @@ -240,7 +240,7 @@
<x>0</x>
<y>0</y>
<width>496</width>
<height>373</height>
<height>377</height>
</rect>
</property>
<attribute name="label">
Expand Down Expand Up @@ -5301,6 +5301,9 @@
<property name="text">
<string>Rename Taxa</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
Expand Down Expand Up @@ -7081,6 +7084,9 @@
<property name="text">
<string>Raname Taxa</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
Expand Down Expand Up @@ -8020,7 +8026,7 @@
<x>0</x>
<y>0</y>
<width>1059</width>
<height>23</height>
<height>21</height>
</rect>
</property>
<widget class="QMenu" name="menuTools">
Expand Down Expand Up @@ -8546,37 +8552,5 @@
</hint>
</hints>
</connection>
<connection>
<sender>checkBox_co_expr_show_label</sender>
<signal>clicked(bool)</signal>
<receiver>spinBox_co_expr_font_size</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>917</x>
<y>336</y>
</hint>
<hint type="destinationlabel">
<x>1012</x>
<y>313</y>
</hint>
</hints>
</connection>
<connection>
<sender>checkBox_tf_link_net_show_label</sender>
<signal>clicked(bool)</signal>
<receiver>spinBox_network_font_size</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>203</x>
<y>123</y>
</hint>
<hint type="destinationlabel">
<x>203</x>
<y>127</y>
</hint>
</hints>
</connection>
</connections>
</ui>
2 changes: 1 addition & 1 deletion utils/MetaX_GUI/Setting.ui
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@
<double>1.000000000000000</double>
</property>
<property name="value">
<double>2.000000000000000</double>
<double>3.000000000000000</double>
</property>
</widget>
</item>
Expand Down
12 changes: 6 additions & 6 deletions utils/MetaX_GUI/Ui_MainWindow.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'c:\Users\max\OneDrive - University of Ottawa\code\TaxaFunc\MetaX\utils\MetaX_GUI\MainWindow.ui'
# Form implementation generated from reading ui file 'c:\Users\Qing\OneDrive - University of Ottawa\code\TaxaFunc\MetaX\utils\MetaX_GUI\MainWindow.ui'
#
# Created by: PyQt5 UI code generator 5.15.9
#
Expand Down Expand Up @@ -145,7 +145,7 @@ def setupUi(self, metaX_main):
self.toolBox_2.setMaximumSize(QtCore.QSize(1677, 16777215))
self.toolBox_2.setObjectName("toolBox_2")
self.page_2 = QtWidgets.QWidget()
self.page_2.setGeometry(QtCore.QRect(0, 0, 496, 373))
self.page_2.setGeometry(QtCore.QRect(0, 0, 496, 377))
self.page_2.setObjectName("page_2")
self.gridLayout_27 = QtWidgets.QGridLayout(self.page_2)
self.gridLayout_27.setObjectName("gridLayout_27")
Expand Down Expand Up @@ -2779,6 +2779,7 @@ def setupUi(self, metaX_main):
self.formLayout.setWidget(3, QtWidgets.QFormLayout.LabelRole, self.checkBox_co_expr_show_label)
self.checkBox_co_expr_rename_taxa = QtWidgets.QCheckBox(self.tab_5)
self.checkBox_co_expr_rename_taxa.setEnabled(True)
self.checkBox_co_expr_rename_taxa.setChecked(True)
self.checkBox_co_expr_rename_taxa.setObjectName("checkBox_co_expr_rename_taxa")
self.formLayout.setWidget(3, QtWidgets.QFormLayout.FieldRole, self.checkBox_co_expr_rename_taxa)
self.verticalLayout_3.addLayout(self.formLayout)
Expand Down Expand Up @@ -3721,6 +3722,7 @@ def setupUi(self, metaX_main):
self.horizontalLayout_57.addWidget(self.checkBox_tf_link_net_show_label)
self.checkBox_tf_link_net_rename_taxa = QtWidgets.QCheckBox(self.tab_9)
self.checkBox_tf_link_net_rename_taxa.setEnabled(True)
self.checkBox_tf_link_net_rename_taxa.setChecked(True)
self.checkBox_tf_link_net_rename_taxa.setObjectName("checkBox_tf_link_net_rename_taxa")
self.horizontalLayout_57.addWidget(self.checkBox_tf_link_net_rename_taxa)
self.gridLayout_6.addLayout(self.horizontalLayout_57, 10, 3, 1, 1)
Expand Down Expand Up @@ -4206,7 +4208,7 @@ def setupUi(self, metaX_main):
self.statusbar.setObjectName("statusbar")
metaX_main.setStatusBar(self.statusbar)
self.menuBar = QtWidgets.QMenuBar(metaX_main)
self.menuBar.setGeometry(QtCore.QRect(0, 0, 1059, 23))
self.menuBar.setGeometry(QtCore.QRect(0, 0, 1059, 21))
self.menuBar.setObjectName("menuBar")
self.menuTools = QtWidgets.QMenu(self.menuBar)
self.menuTools.setObjectName("menuTools")
Expand Down Expand Up @@ -4266,7 +4268,7 @@ def setupUi(self, metaX_main):

self.retranslateUi(metaX_main)
self.stackedWidget.setCurrentIndex(0)
self.tabWidget_TaxaFuncAnalyzer.setCurrentIndex(5)
self.tabWidget_TaxaFuncAnalyzer.setCurrentIndex(6)
self.toolBox_2.setCurrentIndex(0)
self.tabWidget_4.setCurrentIndex(1)
self.tabWidget_3.setCurrentIndex(0)
Expand Down Expand Up @@ -4300,8 +4302,6 @@ def setupUi(self, metaX_main):
self.checkBox_pca_if_show_lable.clicked['bool'].connect(self.checkBox_pca_if_adjust_pca_label.setEnabled) # type: ignore
self.checkBox_pca_if_show_lable.clicked['bool'].connect(self.checkBox_sunburst_show_all_lables.setEnabled) # type: ignore
self.checkBox_pca_if_show_lable.clicked['bool'].connect(self.doubleSpinBox_basic_pca_label_font_transparency.setEnabled) # type: ignore
self.checkBox_co_expr_show_label.clicked['bool'].connect(self.spinBox_co_expr_font_size.setEnabled) # type: ignore
self.checkBox_tf_link_net_show_label.clicked['bool'].connect(self.spinBox_network_font_size.setEnabled) # type: ignore
QtCore.QMetaObject.connectSlotsByName(metaX_main)
metaX_main.setTabOrder(self.comboBox_taxa_level_to_stast, self.toolButton_meta_table_help)
metaX_main.setTabOrder(self.toolButton_meta_table_help, self.comboBox_function_to_stast)
Expand Down
4 changes: 2 additions & 2 deletions utils/MetaX_GUI/Ui_Setting.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'c:\Users\max\OneDrive - University of Ottawa\code\TaxaFunc\MetaX\utils\MetaX_GUI\Setting.ui'
# Form implementation generated from reading ui file 'c:\Users\Qing\OneDrive - University of Ottawa\code\TaxaFunc\MetaX\utils\MetaX_GUI\Setting.ui'
#
# Created by: PyQt5 UI code generator 5.15.9
#
Expand Down Expand Up @@ -132,7 +132,7 @@ def setupUi(self, Settings):
self.doubleSpinBox_tf_link_net_line_width.setDecimals(1)
self.doubleSpinBox_tf_link_net_line_width.setMinimum(0.1)
self.doubleSpinBox_tf_link_net_line_width.setSingleStep(1.0)
self.doubleSpinBox_tf_link_net_line_width.setProperty("value", 2.0)
self.doubleSpinBox_tf_link_net_line_width.setProperty("value", 3.0)
self.doubleSpinBox_tf_link_net_line_width.setObjectName("doubleSpinBox_tf_link_net_line_width")
self.gridLayout_6.addWidget(self.doubleSpinBox_tf_link_net_line_width, 2, 1, 1, 1)
self.lineEdit_tf_link_net_line_color = QtWidgets.QLineEdit(self.page_2)
Expand Down
21 changes: 14 additions & 7 deletions utils/MetaX_GUI/webDialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
import os
from PyQt5.QtWidgets import QApplication

class MyDialog(QDialog):
def __init__(self, html_path=None, parent=None):
super(MyDialog, self).__init__(parent)
class WebDialog(QDialog):
def __init__(self, html_path=None, parent=None, theme="white"):
super(WebDialog, self).__init__(parent)
self.setWindowTitle('HTML Viewer')
self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
self.resize(1800, 1000)
Expand All @@ -21,13 +21,14 @@ def __init__(self, html_path=None, parent=None):
self.exportButton.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Fixed)
self.webEngineView = QWebEngineView(self)
self.html_path = html_path


self.init_background_color(theme)

layout = QVBoxLayout(self)
layout.addWidget(self.exportButton)
layout2 = QHBoxLayout() # 创建一个水平布局
layout2 = QHBoxLayout()

layout.addLayout(layout2) # 将水平布局添加到垂直布局中
layout.addLayout(layout2)
layout.addWidget(self.webEngineView)

self.exportButton.clicked.connect(self.export_html)
Expand All @@ -42,6 +43,12 @@ def __init__(self, html_path=None, parent=None):
icon_path = os.path.join(os.path.dirname(__file__), "./resources/logo.png")
self.setWindowIcon(QIcon(icon_path))

def init_background_color(self, theme_mode):
if theme_mode == "dark":
# set background color to #100c2a
from PyQt5.QtGui import QColor
self.webEngineView.page().setBackgroundColor(QColor("#100c2a"))

def zoom(self, value):
self.webEngineView.setZoomFactor(value / 100)

Expand Down Expand Up @@ -74,6 +81,6 @@ def export_html(self):

if __name__ == '__main__':
app = QApplication(sys.argv)
dialog = MyDialog(html_path="./sankey.html")
dialog = WebDialog(html_path="C:/Users/Qing/MetaX/html/Bar_of_Functions.html", theme="dark")
dialog.show()
sys.exit(app.exec_())
Loading

0 comments on commit 91dfae1

Please sign in to comment.