Skip to content

Commit

Permalink
add row link display override with assay comment (#1968)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikkonie committed Jul 18, 2024
1 parent a4b5410 commit eed609e
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Added
- **Samplesheets**
- ``template_output_dir_display`` user setting (#1960)
- Display BAM/CRAM/VCF omit patterns in study shortcut modal (#1963)
- Row links display override using assay comment (#1968)
- **Taskflowbackend**
- ``BatchCalculateChecksumTask`` retrying in case of timeouts (#1941)

Expand Down
12 changes: 12 additions & 0 deletions docs_manual/source/metadata_advanced.rst
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,18 @@ override the latter. Example:
Study Assay File Name a_assay.txt
Comment[SODAR Assay Plugin] samplesheets_assay_generic_raw
Similarly, you can override the assay table row link display with the comment
``SODAR Assay Row Display``. Set it to "true" or "false" (or 1/0) to control
whether row links should be displayed for this assay. Note that if you set this
to true, the assay plugin used for the assay should implement the
``get_row_path()`` method.

.. code-block::
STUDY ASSAYS
Study Assay File Name a_assay.txt
Comment[SODAR Assay Row Display] false
SODAR currently supports the following assay plugins:

- **DNA Sequencing**
Expand Down
1 change: 1 addition & 0 deletions docs_manual/source/sodar_release_notes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ v0.15.0 (WIP)
Feature update.

- Add BAM/CRAM/VCF omit pattern display in study shortcut modal
- Add row links display override using assay comment
- Add iRODS checksum calculation retrying
- Add Cyberduck documentation
- Disable lock requirement for project and role update taskflows
Expand Down
21 changes: 21 additions & 0 deletions samplesheets/tests/test_views_ajax.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
RENDER_HEIGHT_ROW,
RENDER_HEIGHT_SCROLLBAR,
STUDY_PLUGIN_NOT_FOUND_MSG,
ROW_LINK_DISPLAY_COMMENT,
)


Expand Down Expand Up @@ -462,6 +463,26 @@ def test_get_inherited_owner(self):
response_data = json.loads(response.data)
self.assertEqual(response_data['perms']['edit_config'], True)

def test_get_display_row_links_override(self):
"""Test GET with assay row link display override"""
self.assay.comments[ROW_LINK_DISPLAY_COMMENT] = 'false'
self.assay.save()
with self.login(self.user):
response = self.client.get(
reverse(
'samplesheets:ajax_context',
kwargs={'project': self.project.sodar_uuid},
)
)
self.assertEqual(response.status_code, 200)
response_data = json.loads(response.data)
# Initial value was True
self.assertFalse(
response_data['studies'][str(self.study.sodar_uuid)]['assays'][
str(self.assay.sodar_uuid)
]['display_row_links']
)


class TestStudyTablesAjaxView(IrodsAccessTicketMixin, SamplesheetsViewTestBase):
"""Tests for StudyTablesAjaxView"""
Expand Down
19 changes: 19 additions & 0 deletions samplesheets/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,3 +375,22 @@ def get_latest_file_path(paths):
:param paths: List of strings
"""
return sorted(paths, key=lambda x: x.split('/')[-1], reverse=True)[0]


def get_bool(bool_string):
"""
Return freeform string as boolean.
NOTE: Doing this as distutils is deprecated/removed..
:param bool_string: String
:raise: ValueError if value is not a string or can't be parsed
:return: bool
"""
if not isinstance(bool_string, str):
raise ValueError('Value is not a string')
if bool_string.strip().lower() in ['1', 't', 'true', 'y', 'yes']:
return True
if bool_string.strip().lower() in ['0', 'f', 'false', 'n', 'no']:
return False
raise ValueError('Unable to parse value: {}'.format(bool_string))
24 changes: 21 additions & 3 deletions samplesheets/views_ajax.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
get_node_obj,
get_webdav_url,
get_ext_link_labels,
get_bool,
)
from samplesheets.views import (
IrodsDataRequestModifyMixin,
Expand Down Expand Up @@ -86,6 +87,7 @@
ERROR_NOT_FOUND = 'Collection not found'
ERROR_NO_AUTH = 'User not authorized for iRODS collection'
STUDY_PLUGIN_NOT_FOUND_MSG = 'Plugin not found for study'
ROW_LINK_DISPLAY_COMMENT = 'SODAR Assay Row Display'


# Base Ajax View Classes and Mixins --------------------------------------------
Expand Down Expand Up @@ -443,6 +445,24 @@ def get(self, request, *args, **kwargs):
# Set up assay data
for a in s.assays.all().order_by('pk'):
assay_plugin = a.get_plugin()
row_links = True
if ROW_LINK_DISPLAY_COMMENT in a.comments:
try:
row_links = get_bool(
a.comments[ROW_LINK_DISPLAY_COMMENT]
)
except Exception as ex:
logger.error(
'Exception in retrieving row display comment "{}" '
'for assay "{} ({})": {}'.format(
ROW_LINK_DISPLAY_COMMENT,
a.get_display_name(),
a.sodar_uuid,
ex,
)
)
elif assay_plugin:
row_links = assay_plugin.display_row_links
ret_data['studies'][str(s.sodar_uuid)]['assays'][
str(a.sodar_uuid)
] = {
Expand All @@ -451,9 +471,7 @@ def get(self, request, *args, **kwargs):
'irods_path': (
irods_backend.get_path(a) if irods_backend else None
),
'display_row_links': (
assay_plugin.display_row_links if assay_plugin else True
),
'display_row_links': row_links,
'plugin': assay_plugin.title if assay_plugin else None,
}

Expand Down

0 comments on commit eed609e

Please sign in to comment.