Skip to content

Commit

Permalink
- Enabled min/max values definition in 'Color by sequence length' and…
Browse files Browse the repository at this point in the history
… 'Color by custom parameter' features.

- Turned colorbar upside down, so that the minimum will be at the bottom and the maximum at the top (as expected).
- Fixed bug in 2D presentation with Z-index by groups order, when changing some visual parameter.
  • Loading branch information
Inbal Paz committed Sep 22, 2022
1 parent 26d7641 commit acf320c
Show file tree
Hide file tree
Showing 13 changed files with 229 additions and 97 deletions.
34 changes: 16 additions & 18 deletions clans/clans/GUI/group_dialogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -915,11 +915,11 @@ def __init__(self, net_plot_object, dim_num, z_index_mode, color_by, group_by):
self.delete_category_button = QPushButton("Delete")
self.delete_category_button.released.connect(self.delete_category)

self.buttons_layout.addWidget(self.add_button)
self.buttons_layout.addWidget(self.edit_button)
self.buttons_layout.addWidget(self.move_up_button)
self.buttons_layout.addWidget(self.move_down_button)
self.buttons_layout.addWidget(self.delete_category_button)
self.buttons_layout.addWidget(self.add_button)
self.buttons_layout.addStretch()

self.main_layout.addLayout(self.buttons_layout)
Expand Down Expand Up @@ -974,34 +974,24 @@ def add_category(self):
item = QListWidgetItem(cfg.groups_by_categories[category_index]['name'])
self.categories_list.insertItem(category_index+1, item)

is_changed_points_size = 0
is_changed_names_size = 0
is_changed_outline_color = 0
is_changed_bold = 0
is_changed_italic = 0

if points_size != cfg.groups_by_categories[category_index]['nodes_size']:
is_changed_points_size = 1
cfg.groups_by_categories[category_index]['nodes_size'] = points_size
cfg.groups_by_categories[category_index]['nodes_size'] = points_size

if names_size != cfg.groups_by_categories[category_index]['text_size']:
is_changed_names_size = 1
cfg.groups_by_categories[category_index]['text_size'] = names_size
cfg.groups_by_categories[category_index]['text_size'] = names_size

if ColorArray(outline_color).hex != \
ColorArray(cfg.groups_by_categories[category_index]['nodes_outline_color']).hex:
is_changed_outline_color = 1
cfg.groups_by_categories[category_index]['nodes_outline_color'] = outline_color
cfg.groups_by_categories[category_index]['nodes_outline_color'] = outline_color

if is_bold != cfg.groups_by_categories[category_index]['is_bold']:
is_changed_bold = 1
cfg.groups_by_categories[category_index]['is_bold'] = is_bold
cfg.groups_by_categories[category_index]['is_bold'] = is_bold

if is_italic != cfg.groups_by_categories[category_index]['is_italic']:
is_changed_italic = 1
cfg.groups_by_categories[category_index]['is_italic'] = is_italic
cfg.groups_by_categories[category_index]['is_italic'] = is_italic

cfg.groups_by_categories[category_index]['nodes_outline_width'] = outline_width
if outline_width != cfg.groups_by_categories[category_index]['nodes_outline_width']:
cfg.groups_by_categories[category_index]['nodes_outline_width'] = outline_width

# Mark the new category's line
self.categories_list.setCurrentRow(category_index-1)
Expand Down Expand Up @@ -1092,6 +1082,14 @@ def edit_category(self):
error_occurred(self.net_plot_object.hide_group_names, 'hide_group_names', err, error_msg)
return

if self.z_index_mode == 'groups':
try:
self.net_plot_object.hide_scatter_by_groups()
except Exception as err:
error_msg = "An error occurred: cannot remove scatter by groups"
error_occurred(self.net_plot_object.hide_scatter_by_groups, 'hide_scatter_by_groups', err,
error_msg)

try:
self.net_plot_object.update_group_by(self.dim_num, self.z_index_mode, self.color_by, self.group_by)
except Exception as err:
Expand Down
92 changes: 65 additions & 27 deletions clans/clans/GUI/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -820,7 +820,6 @@ def receive_load_status(self, status):
self.round_num_label.setStyleSheet("color: black;")
self.mode_combo.setEnabled(True)
self.select_all_button.setEnabled(True)
self.clear_selection_button.setEnabled(True)
self.select_by_text_button.setEnabled(True)
self.connections_button.setEnabled(True)
self.hide_singeltons_button.setEnabled(True)
Expand Down Expand Up @@ -1092,7 +1091,6 @@ def run_calc(self):
self.mode_combo.setEnabled(False)
self.selection_type_combo.setEnabled(False)
self.select_all_button.setEnabled(False)
self.clear_selection_button.setEnabled(False)
self.select_by_text_button.setEnabled(False)
self.select_by_groups_button.setEnabled(False)
self.edit_groups_button.setEnabled(False)
Expand Down Expand Up @@ -1172,7 +1170,6 @@ def stopped_state(self, error):
if self.is_subset_mode == 0:
self.mode_combo.setEnabled(True)
self.select_all_button.setEnabled(True)
self.clear_selection_button.setEnabled(True)

self.select_by_text_button.setEnabled(True)

Expand Down Expand Up @@ -1861,36 +1858,54 @@ def color_by_seq_length(self):
self.color_by_combo.setCurrentText('Seq. length')
self.color_by_combo.setEnabled(True)

else:
try:
gradient_colormap = colors.generate_colormap_gradient_2_colors(cfg.short_color, cfg.long_color)
except Exception as err:
error_msg = "An error occurred: cannot generate colormap"
error_occurred(colors.generate_colormap_gradient_2_colors, 'generate_colormap_gradient_2_colors', err,
error_msg)
return
# Produce the real colormap
try:
gradient_colormap = colors.generate_colormap_gradient_2_colors(cfg.short_color, cfg.long_color)
except Exception as err:
error_msg = "An error occurred: cannot generate colormap"
error_occurred(colors.generate_colormap_gradient_2_colors, 'generate_colormap_gradient_2_colors', err,
error_msg)
return

try:
self.network_plot.color_by_param(gradient_colormap, cfg.sequences_array['norm_seq_length'],
self.dim_num, self.z_indexing_mode, self.color_by, self.group_by)
except Exception as err:
error_msg = "An error occurred: cannot color the data by sequence-length"
error_occurred(self.network_plot.color_by_param, 'color_by_param', err, error_msg)
return
# Produce an opposite colormap just for the colorbar presentation (workaround a bug in the colorbar visual)
try:
opposite_gradient_colormap = colors.generate_colormap_gradient_2_colors(cfg.long_color, cfg.short_color)
except Exception as err:
error_msg = "An error occurred: cannot generate colormap"
error_occurred(colors.generate_colormap_gradient_2_colors, 'generate_colormap_gradient_2_colors', err,
error_msg)
return

try:
self.colorbar_plot.show_colorbar(gradient_colormap, cfg.sequences_array['seq_length'], 'Sequences length')
except Exception as err:
error_msg = "An error occurred: cannot display the colorbar"
error_occurred(self.colorbar_plot.show_colorbar, 'show_colorbar', err, error_msg)
try:
seq.normalize_seq_length()
except Exception as err:
error_msg = "An error occurred: cannot normalize the new range of sequence length"
error_occurred(seq.normalize_seq_length, 'normalize_seq_length', err, error_msg)
return

try:
self.network_plot.color_by_param(gradient_colormap, cfg.sequences_array['norm_seq_length'],
self.dim_num, self.z_indexing_mode, self.color_by, self.group_by)
except Exception as err:
error_msg = "An error occurred: cannot color the data by sequence-length"
error_occurred(self.network_plot.color_by_param, 'color_by_param', err, error_msg)
return

try:
self.colorbar_plot.show_colorbar(opposite_gradient_colormap, 'Sequences length',
cfg.run_params['min_seq_length'], cfg.run_params['max_seq_length'])
except Exception as err:
error_msg = "An error occurred: cannot display the colorbar"
error_occurred(self.colorbar_plot.show_colorbar, 'show_colorbar', err, error_msg)

def open_color_by_length_dialog(self):

try:
dlg = md.ColorByLengthDialog()

if dlg.exec_():
cfg.short_color, cfg.long_color = dlg.get_colors()
cfg.short_color, cfg.long_color, cfg.run_params['min_seq_length'], cfg.run_params['max_seq_length'] = \
dlg.get_colors()

self.color_by_seq_length()

Expand Down Expand Up @@ -1967,6 +1982,7 @@ def color_by_user_param(self, param):
min_param_color = cfg.sequences_numeric_params[param]['min_color']
max_param_color = cfg.sequences_numeric_params[param]['max_color']

# Produce the real colormap
try:
gradient_colormap = colors.generate_colormap_gradient_2_colors(min_param_color, max_param_color)
except Exception as err:
Expand All @@ -1975,6 +1991,22 @@ def color_by_user_param(self, param):
error_msg)
return

# Produce an opposite colormap just for the colorbar presentation (workaround a bug in the colorbar visual)
try:
opposite_gradient_colormap = colors.generate_colormap_gradient_2_colors(max_param_color, min_param_color)
except Exception as err:
error_msg = "An error occurred: cannot generate colormap"
error_occurred(colors.generate_colormap_gradient_2_colors, 'generate_colormap_gradient_2_colors', err,
error_msg)
return

try:
seq.normalize_numeric_param(param)
except Exception as err:
error_msg = "An error occurred: cannot normalize the new range of values"
error_occurred(seq.normalize_numeric_param, 'normalize_numeric_param', err, error_msg)
return

try:
self.network_plot.color_by_param(gradient_colormap, cfg.sequences_numeric_params[param]['norm'],
self.dim_num, self.z_indexing_mode, self.color_by, self.group_by)
Expand All @@ -1984,7 +2016,8 @@ def color_by_user_param(self, param):
return

try:
self.colorbar_plot.show_colorbar(gradient_colormap, cfg.sequences_numeric_params[param]['raw'], param)
self.colorbar_plot.show_colorbar(opposite_gradient_colormap, param, cfg.sequences_numeric_params[param]['min_val'],
cfg.sequences_numeric_params[param]['max_val'])
except Exception as err:
error_msg = "An error occurred: cannot display the colorbar"
error_occurred(self.colorbar_plot.show_colorbar, 'show_colorbar', err, error_msg)
Expand All @@ -1995,7 +2028,7 @@ def open_color_by_param_dialog(self):
dlg = md.ColorByParamDialog()

if dlg.exec_():
selected_param, added_params_list, min_param_color, max_param_color = dlg.get_param()
selected_param, added_params_list, min_param_color, max_param_color, min_val, max_val = dlg.get_param()

if selected_param:

Expand All @@ -2012,6 +2045,10 @@ def open_color_by_param_dialog(self):
cfg.sequences_numeric_params[selected_param]['min_color'] = min_param_color
cfg.sequences_numeric_params[selected_param]['max_color'] = max_param_color

# Update the values range of the selected parameter
cfg.sequences_numeric_params[selected_param]['min_val'] = min_val
cfg.sequences_numeric_params[selected_param]['max_val'] = max_val

self.color_by_user_param(selected_param)

except Exception as err:
Expand Down Expand Up @@ -2117,7 +2154,6 @@ def select_all(self):
self.show_selected_names_button.setEnabled(True)
self.open_selected_button.setEnabled(True)
self.clear_selection_button.setEnabled(True)
self.inverse_selection_button.setEnabled(True)
self.add_to_group_button.setEnabled(True)
self.remove_selected_button.setEnabled(True)

Expand Down Expand Up @@ -2253,6 +2289,7 @@ def manage_subset_presentation(self):
self.mode_combo.setCurrentIndex(0)
self.select_all_button.setEnabled(False)
self.clear_selection_button.setEnabled(False)
self.inverse_selection_button.setEnabled(False)
self.z_index_mode_combo.setCurrentIndex(0)
self.z_index_mode_combo.setEnabled(False)
self.z_index_mode_label.setStyleSheet("color: " + cfg.inactive_color + ";")
Expand Down Expand Up @@ -2291,6 +2328,7 @@ def manage_subset_presentation(self):
self.mode_combo.setEnabled(True)
self.select_all_button.setEnabled(True)
self.clear_selection_button.setEnabled(True)
self.inverse_selection_button.setEnabled(True)
self.select_by_text_button.setEnabled(True)
self.select_by_groups_button.setEnabled(True)

Expand Down
Loading

0 comments on commit acf320c

Please sign in to comment.