Skip to content

Commit

Permalink
Simplified association interface when there is only a single sequence
Browse files Browse the repository at this point in the history
  • Loading branch information
e-pettersen committed Oct 3, 2023
1 parent 516ac87 commit 9211870
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/bundles/seq_view/bundle_info.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<BundleInfo name="ChimeraX-SeqView" version="2.10"
<BundleInfo name="ChimeraX-SeqView" version="2.11"
package="chimerax.seq_view"
supercedes="ChimeraX-SEQ-VIEW"
minSessionVersion="1" maxSessionVersion="1">
Expand Down
70 changes: 63 additions & 7 deletions src/bundles/seq_view/src/associations_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ def __init__(self, sv, tool_window):
layout = QHBoxLayout()

# Widgets for multi-sequence alignment
multi_seq_area = QWidget()
layout.addWidget(multi_seq_area)
self.multi_seq_area = QWidget()
layout.addWidget(self.multi_seq_area)
ms_layout = QHBoxLayout()
multi_seq_area.setLayout(ms_layout)
self.multi_seq_area.setLayout(ms_layout)

from chimerax.atomic.widgets import ChainListWidget
self.chain_list = ChainListWidget(sv.session, autoselect='single')
self.chain_list = ChainListWidget(sv.session, autoselect=ChainListWidget.AUTOSELECT_SINGLE)
self.chain_list.value_changed.connect(self._chain_changed)
ms_layout.addWidget(self.chain_list)

Expand Down Expand Up @@ -59,6 +59,23 @@ def showEvent(s, *args):
self.assoc_button.value_changed.connect(self._seq_changed)
menu_layout.addWidget(self.assoc_button)

# Widgets for single sequence
self.single_seq_area = QWidget()
layout.addWidget(self.single_seq_area)
ss_layout = QVBoxLayout()
self.single_seq_area.setLayout(ss_layout)

ss_layout.addWidget(
QLabel("Chains chosen/unchosen below will be associated/disassocated with sequence"))

from chimerax.atomic.widgets import ChainListWidget
self.ss_chain_list = ChainListWidget(sv.session, autoselect=ChainListWidget.AUTOSELECT_NONE)
self.ss_chain_list.value_changed.connect(self._ss_chain_changed)
ss_layout.addWidget(self.ss_chain_list)
self._processing_ss_list = False

self._choose_widgets()

tool_window.ui_area.setLayout(layout)

# get initial assoc info correct
Expand All @@ -68,9 +85,18 @@ def showEvent(s, *args):
self.chain_list.blockSignals(False)
self.assoc_button.blockSignals(False)

self._set_ss_data()

def _align_arg(self):
if len(self.sv.session.alignments) > 1:
return ' ' + self.sv.alignment.ident
return ''

def _assoc_mod(self, note_data):
# called from sequence viewer if associations modified
self._chain_changed()
if not self._processing_ss_list:
self._set_ss_data()

def _chain_changed(self):
self.assoc_button.blockSignals(True)
Expand Down Expand Up @@ -98,6 +124,12 @@ def _chain_changed(self):
self.pick_a_chain.setHidden(show_button)
self.assoc_button.blockSignals(False)

def _choose_widgets(self):
# also called from sequence viewer if sequences added/deleted
show_single = len(self.sv.alignment.seqs) == 1
self.multi_seq_area.setHidden(show_single)
self.single_seq_area.setHidden(not show_single)

def _seq_changed(self):
# this can also get called if sequences get deleted, so try to do some checking
chains = self.chain_list.value
Expand All @@ -115,13 +147,37 @@ def _seq_changed(self):
continue
from chimerax.core.commands import run
if not req_assoc:
run(self.sv.session, "sequence disassoc %s" % chain.string(style="command"))
run(self.sv.session, "sequence disassoc %s%s" % (chain.string(style="command"),
self._align_arg()))
elif req_assoc == self.best_assoc_label:
run(self.sv.session, "sequence assoc %s %s" % (chain.string(style="command"),
self.sv.alignment.ident))
run(self.sv.session, "sequence assoc %s%s" % (chain.string(style="command"),
self._align_arg()))
else:
run(self.sv.session, "sequence assoc %s %s:%d" % (chain.string(style="command"),
self.sv.alignment.ident, self.sv.alignment.seqs.index(req_assoc)+1))
self.chain_list.blockSignals(False)
self.assoc_button.blockSignals(False)
self._chain_changed()

def _set_ss_data(self):
self.ss_chain_list.blockSignals(True)
self.ss_chain_list.value = self.sv.alignment.associations.keys()
self.ss_chain_list.blockSignals(False)

def _ss_chain_changed(self):
self._processing_ss_list = True
chosen = set(self.ss_chain_list.value)
for chain in self.ss_chain_list.all_values:
is_associated = chain in self.sv.alignment.associations
want_association = chain in chosen
if is_associated == want_association:
continue
from chimerax.core.commands import run
if want_association:
run(self.sv.session, "sequence assoc %s%s" % (chain.string(style="command"),
self._align_arg()))
else:
run(self.sv.session, "sequence disassoc %s%s" % (chain.string(style="command"),
self._align_arg()))
self._processing_ss_list = False
self._set_ss_data()
3 changes: 3 additions & 0 deletions src/bundles/seq_view/src/tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,9 @@ def alignment_notification(self, note_name, note_data):
elif note_name == alignment.NOTE_RMSD_UPDATE:
if self._regions_tool:
self._regions_tool.alignment_rmsd_update()
elif note_name == alignment.NOTE_ADD_DEL_SEQS:
if self._associations_tool:
self._associations_tool._choose_widgets()

self.seq_canvas.alignment_notification(note_name, note_data)

Expand Down

0 comments on commit 9211870

Please sign in to comment.