Skip to content

Multivariate rules tab resets signal at wrong times #355

Description

@drbergman

Observed behavior

Updating the Signal range scale +/- (%) QSpinBox sets the signal in Plot the signal: QComboBox back to the first item in that list. This is from the callback to update_rules.

Expected behavior

Signal remains unchanged when the range scale is updated.

Suggested fix

Not sure. I'm unclear what the scope of update_rules is and how to refactor it.

Relevant lines

  • Connecting the callback:
    self.signal_variation.valueChanged.connect(self.update_rules)
  • update_rules definition:
    def update_rules(self):
    # Remove the behavior widgets from layout
    while self.layout_behavior_sliders.count():
    widget = self.layout_behavior_sliders.takeAt(0).widget()
    if widget is not None:
    widget.deleteLater()
    # Get the behavior values
    list_baseValue = self.dataframe.loc[(self.dataframe["cell"] == self.combobox_cell.currentText()) &
    (self.dataframe['behavior'] == self.combobox_behavior.currentText()) &
    (self.dataframe['direction'] == "decreases")]['base_behavior'].tolist()
    list_UpReg = self.dataframe.loc[(self.dataframe["cell"] == self.combobox_cell.currentText()) &
    (self.dataframe['behavior'] == self.combobox_behavior.currentText()) &
    (self.dataframe['direction'] == "increases")]['saturation'].tolist()
    list_DownReg = self.dataframe.loc[(self.dataframe["cell"] == self.combobox_cell.currentText()) &
    (self.dataframe['behavior'] == self.combobox_behavior.currentText()) &
    (self.dataframe['direction'] == "decreases")]['saturation'].tolist()
    # Using the max and min of saturation to define UP and Down regulation
    try: baseBehavior = list_baseValue[0]
    except IndexError: baseBehavior = 0.0
    try: minBehavior = min(list_DownReg)
    except ValueError: minBehavior = 0.0
    try: maxBehavior = max(list_UpReg)
    except ValueError: maxBehavior = 0.0
    # print(self.combobox_behavior.currentText(), baseBehavior, maxBehavior, minBehavior)
    # Sliders of behavior
    self.sliders_behavior = BehaviorWidget( self.combobox_behavior.currentText(), baseBehavior, maxBehavior, minBehavior, 0.01*self.behavior_variation.value() )
    self.layout_behavior_sliders.addWidget( self.sliders_behavior )
    # Disable sliders
    if len(list_DownReg) == 0:
    self.sliders_behavior.slider_down_behavior.setEnabled(False)
    self.sliders_behavior.slider_down_behavior.label.setStyleSheet("color: gray;") # gray color on the label
    if len(list_UpReg) == 0:
    self.sliders_behavior.slider_up_behavior.setEnabled(False)
    self.sliders_behavior.slider_up_behavior.label.setStyleSheet("color: gray;") # gray color on the label
    # Get the signals list
    list_signals = self.dataframe.loc[(self.dataframe["cell"] == self.combobox_cell.currentText()) &
    (self.dataframe['behavior'] == self.combobox_behavior.currentText())]['signal'].unique().tolist()
    # Clear the combo box of signals to plot
    self.combobox_signal_plot.clear()
    self.combobox_signal_plot.addItems(list_signals)
    # Remove the signals widgets from layout
    while self.layout_signals.count():
    widget = self.layout_signals.takeAt(0).widget()
    if widget is not None:
    widget.deleteLater()
    # Label and Sliders of signals
    halfmax_max = -np.inf
    # Signal variation input
    frac_var = 0.01*self.signal_variation.value()
    for signal in list_signals:
    signal_direction = self.dataframe.loc[(self.dataframe["cell"] == self.combobox_cell.currentText()) &
    (self.dataframe['behavior'] == self.combobox_behavior.currentText()) &
    (self.dataframe['signal'] == signal)]['direction'].to_numpy()
    signal_halfmax = self.dataframe.loc[(self.dataframe["cell"] == self.combobox_cell.currentText()) &
    (self.dataframe['behavior'] == self.combobox_behavior.currentText()) &
    (self.dataframe['signal'] == signal)]['half_max'].to_numpy()
    signal_hillpower = self.dataframe.loc[(self.dataframe["cell"] == self.combobox_cell.currentText()) &
    (self.dataframe['behavior'] == self.combobox_behavior.currentText()) &
    (self.dataframe['signal'] == signal)]['hill_power'].to_numpy()
    if ( len(signal_direction) > 1): # two rules with same signal and different directions
    # Add the signal sliders
    self.layout_signals.addWidget( SignalWidget( signal, signal_direction[0], signal_halfmax[0], signal_hillpower[0], frac_var= frac_var) )
    self.layout_signals.addWidget( SignalWidget( signal, signal_direction[1], signal_halfmax[1], signal_hillpower[1], frac_var= frac_var) )
    # Check maximum half max of signal
    halfmax_max_temp = max([signal_halfmax[0], signal_halfmax[1]]) # the signal discretization based on the max halfmax
    if (halfmax_max < halfmax_max_temp): halfmax_max = halfmax_max_temp
    else:
    # Add the signal sliders
    self.layout_signals.addWidget( SignalWidget( signal, signal_direction[0], signal_halfmax[0], signal_hillpower[0], frac_var= frac_var) )
    # Check maximum half max of signal
    if (halfmax_max < signal_halfmax[0]): halfmax_max = signal_halfmax[0]
    # Set initial value of plot signal (customizable)
    self.float_min_signal.setValue(halfmax_max*(1-frac_var))
    self.float_max_signal.setValue(halfmax_max*(1+frac_var))
  • Reseting signals:
    # Clear the combo box of signals to plot
    self.combobox_signal_plot.clear()
    self.combobox_signal_plot.addItems(list_signals)

Note on update_rule

update_rules is also issued in two other places:

  • Updating +/- Behavior range sacle +/- (%) QSpinBox
    • the signal is below this, so it is somewhat reasonable to expect users to set this first
  • Updating Behavior: QComboBox
    • we probably should reset the signal list when the behavior changes (we could, for minimal gain, support keepign the same signal if the new behavior / cell type still has the current signal)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions