From eed609e76da465ea657d7ed859a3343702667365 Mon Sep 17 00:00:00 2001 From: Mikko Nieminen Date: Thu, 18 Jul 2024 17:47:49 +0200 Subject: [PATCH] add row link display override with assay comment (#1968) --- CHANGELOG.rst | 1 + docs_manual/source/metadata_advanced.rst | 12 +++++++++++ docs_manual/source/sodar_release_notes.rst | 1 + samplesheets/tests/test_views_ajax.py | 21 +++++++++++++++++++ samplesheets/utils.py | 19 +++++++++++++++++ samplesheets/views_ajax.py | 24 +++++++++++++++++++--- 6 files changed, 75 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 3e005af9..97b69655 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -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) diff --git a/docs_manual/source/metadata_advanced.rst b/docs_manual/source/metadata_advanced.rst index 774b0701..5902de79 100644 --- a/docs_manual/source/metadata_advanced.rst +++ b/docs_manual/source/metadata_advanced.rst @@ -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** diff --git a/docs_manual/source/sodar_release_notes.rst b/docs_manual/source/sodar_release_notes.rst index 158af392..ec7c3149 100644 --- a/docs_manual/source/sodar_release_notes.rst +++ b/docs_manual/source/sodar_release_notes.rst @@ -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 diff --git a/samplesheets/tests/test_views_ajax.py b/samplesheets/tests/test_views_ajax.py index 6c30a7ff..2e5e8e5b 100644 --- a/samplesheets/tests/test_views_ajax.py +++ b/samplesheets/tests/test_views_ajax.py @@ -61,6 +61,7 @@ RENDER_HEIGHT_ROW, RENDER_HEIGHT_SCROLLBAR, STUDY_PLUGIN_NOT_FOUND_MSG, + ROW_LINK_DISPLAY_COMMENT, ) @@ -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""" diff --git a/samplesheets/utils.py b/samplesheets/utils.py index 02907e69..a0c316ac 100644 --- a/samplesheets/utils.py +++ b/samplesheets/utils.py @@ -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)) diff --git a/samplesheets/views_ajax.py b/samplesheets/views_ajax.py index 2276f451..8a0e4a67 100644 --- a/samplesheets/views_ajax.py +++ b/samplesheets/views_ajax.py @@ -45,6 +45,7 @@ get_node_obj, get_webdav_url, get_ext_link_labels, + get_bool, ) from samplesheets.views import ( IrodsDataRequestModifyMixin, @@ -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 -------------------------------------------- @@ -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) ] = { @@ -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, }