From 0a73fa977171e48b0793cf262f5e2870fcaffe8b Mon Sep 17 00:00:00 2001 From: Mikko Nieminen Date: Fri, 27 Sep 2024 12:30:09 +0200 Subject: [PATCH] fix empty file name updating (#2017) --- CHANGELOG.rst | 1 + samplesheets/assayapps/cytof/plugins.py | 2 ++ .../assayapps/cytof/tests/test_plugins.py | 20 ++++++++++++++++++- samplesheets/assayapps/generic_raw/plugins.py | 2 ++ .../generic_raw/tests/test_plugins.py | 12 +++++++++-- samplesheets/assayapps/meta_ms/plugins.py | 2 ++ .../assayapps/meta_ms/tests/test_plugins.py | 15 +++++++++++++- samplesheets/assayapps/pep_ms/plugins.py | 2 ++ .../assayapps/pep_ms/tests/test_plugins.py | 8 +++++++- 9 files changed, 59 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index adc06b76..c26bc686 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -55,6 +55,7 @@ Fixed - **Samplesheets** - Timeline event status not updated in ``SheetDeleteVieW`` with iRODS collections enabled (#1798) + - Assay plugin ``update_row()`` updating links for empty material names (#2017) Removed ------- diff --git a/samplesheets/assayapps/cytof/plugins.py b/samplesheets/assayapps/cytof/plugins.py index 008ff416..0ee0e05b 100644 --- a/samplesheets/assayapps/cytof/plugins.py +++ b/samplesheets/assayapps/cytof/plugins.py @@ -151,6 +151,8 @@ def update_row(self, row, table, assay, index): and header['value'].lower() == 'name' and top_header['value'].lower() in ['raw data file', 'derived data file'] + and row[i]['value'] + and isinstance(row[i]['value'], str) ): row[i]['link'] = ( base_url + '/' + mc_assay_name + '/' + row[i]['value'] diff --git a/samplesheets/assayapps/cytof/tests/test_plugins.py b/samplesheets/assayapps/cytof/tests/test_plugins.py index 2a356c27..5f17167e 100644 --- a/samplesheets/assayapps/cytof/tests/test_plugins.py +++ b/samplesheets/assayapps/cytof/tests/test_plugins.py @@ -111,7 +111,25 @@ def test_update_row_barcode(self): ) self.assertEqual(row, row_ex) - # TODO: Test with empty file names after fixing #2017 + def test_update_row_barcode_empty_file_names(self): + """Test update_row() with filled barcode key and empty file names""" + # Rename header + self.assay_table['field_header'][15]['value'] = 'Barcode Key' + self.assay_table['table_data'][0][15]['value'] = PANEL_NAME + self.assay_table['table_data'][0][20]['value'] = ASSAY_NAME + self.assertEqual(self.assay_table['table_data'][0][26]['value'], '') + self.assertEqual(self.assay_table['table_data'][0][31]['value'], '') + self.assertEqual(self.assay_table['table_data'][0][36]['value'], '') + row_ex = deepcopy(self.assay_table['table_data'][0]) + row_ex[15]['value'] = SIMPLE_LINK_TEMPLATE.format( + label=PANEL_NAME, + url=os.path.join(self.base_url, MISC_FILES_COLL, PANEL_NAME), + ) + # File names should not be updated + row = self.plugin.update_row( + self.assay_table['table_data'][0], self.assay_table, self.assay, 0 + ) + self.assertEqual(row, row_ex) def test_update_row_default(self): """Test update_row() with default template values""" diff --git a/samplesheets/assayapps/generic_raw/plugins.py b/samplesheets/assayapps/generic_raw/plugins.py index 66ec4454..529459e9 100644 --- a/samplesheets/assayapps/generic_raw/plugins.py +++ b/samplesheets/assayapps/generic_raw/plugins.py @@ -83,6 +83,8 @@ def update_row(self, row, table, assay, index): and header['item_type'] == 'DATA' and header['value'].lower() == 'name' and top_header['value'].lower() == 'raw data file' + and row[i]['value'] + and isinstance(row[i]['value'], str) ): row[i]['link'] = ( base_url + '/' + RAW_DATA_COLL + '/' + row[i]['value'] diff --git a/samplesheets/assayapps/generic_raw/tests/test_plugins.py b/samplesheets/assayapps/generic_raw/tests/test_plugins.py index 649bd9af..44116768 100644 --- a/samplesheets/assayapps/generic_raw/tests/test_plugins.py +++ b/samplesheets/assayapps/generic_raw/tests/test_plugins.py @@ -53,6 +53,16 @@ def test_update_row(self): ) self.assertEqual(row, row_ex) + def test_update_row_empty_file_name(self): + """Test update_row() with empty file name""" + self.assay_table['top_header'][7]['value'] = 'Raw Data File' + self.assertEqual(self.assay_table['table_data'][0][44]['value'], '') + row_ex = deepcopy(self.assay_table['table_data'][0]) + row = self.plugin.update_row( + self.assay_table['table_data'][0], self.assay_table, self.assay, 0 + ) + self.assertEqual(row, row_ex) + def test_update_row_default(self): """Test update_row()""" row_ex = deepcopy(self.assay_table['table_data'][0]) @@ -61,8 +71,6 @@ def test_update_row_default(self): ) self.assertEqual(row, row_ex) - # TODO: Test with empty file name for renamed field after fixing #2017 - def test_get_shortcuts(self): """Test get_shortcuts()""" expected = { diff --git a/samplesheets/assayapps/meta_ms/plugins.py b/samplesheets/assayapps/meta_ms/plugins.py index 1aedd475..b45ef451 100644 --- a/samplesheets/assayapps/meta_ms/plugins.py +++ b/samplesheets/assayapps/meta_ms/plugins.py @@ -96,6 +96,8 @@ def update_row(self, row, table, assay, index): and header['value'].lower() == 'name' and top_header['value'].lower() in ['metabolite assignment file', 'raw spectral data file'] + and row[i]['value'] + and isinstance(row[i]['value'], str) ): if top_header['value'].lower() == 'metabolite assignment file': coll_name = MISC_FILES_COLL diff --git a/samplesheets/assayapps/meta_ms/tests/test_plugins.py b/samplesheets/assayapps/meta_ms/tests/test_plugins.py index 044c6196..18d1a8cb 100644 --- a/samplesheets/assayapps/meta_ms/tests/test_plugins.py +++ b/samplesheets/assayapps/meta_ms/tests/test_plugins.py @@ -54,7 +54,20 @@ def test_update_row(self): ) self.assertEqual(row, row_ex) - # TODO: Test with empty file names after fixing #2017 + def test_update_row_empty_file_names(self): + """Test update_row() with empty file names""" + self.assertEqual(self.assay_table['table_data'][0][44]['value'], '') + self.assertEqual(self.assay_table['table_data'][0][51]['value'], '') + self.assay_table['table_data'][0][55]['value'] = REPORT_NAME + row_ex = deepcopy(self.assay_table['table_data'][0]) + row_ex[55]['value'] = SIMPLE_LINK_TEMPLATE.format( + label=REPORT_NAME, + url=os.path.join(self.base_url, RESULTS_COLL, REPORT_NAME), + ) + row = self.plugin.update_row( + self.assay_table['table_data'][0], self.assay_table, self.assay, 0 + ) + self.assertEqual(row, row_ex) def test_get_shortcuts(self): """Test get_shortcuts()""" diff --git a/samplesheets/assayapps/pep_ms/plugins.py b/samplesheets/assayapps/pep_ms/plugins.py index fdafe7ef..59bd72f5 100644 --- a/samplesheets/assayapps/pep_ms/plugins.py +++ b/samplesheets/assayapps/pep_ms/plugins.py @@ -91,6 +91,8 @@ def update_row(self, row, table, assay, index): header['obj_cls'] == 'GenericMaterial' and header['item_type'] == 'DATA' and header['value'].lower() == 'name' + and row[i]['value'] + and isinstance(row[i]['value'], str) ): # We assume all files to be in RawData row[i]['link'] = ( diff --git a/samplesheets/assayapps/pep_ms/tests/test_plugins.py b/samplesheets/assayapps/pep_ms/tests/test_plugins.py index d55d9c1d..85ae279a 100644 --- a/samplesheets/assayapps/pep_ms/tests/test_plugins.py +++ b/samplesheets/assayapps/pep_ms/tests/test_plugins.py @@ -54,7 +54,13 @@ def test_update_row(self): ) self.assertEqual(row, row_ex) - # TODO: Test with empty file names after fixing #2017 + def test_update_row_empty_file_names(self): + """Test update_row() with empty file names""" + row_ex = deepcopy(self.assay_table['table_data'][0]) + row = self.plugin.update_row( + self.assay_table['table_data'][0], self.assay_table, self.assay, 0 + ) + self.assertEqual(row, row_ex) def test_get_shortcuts(self): """Test get_shortcuts()"""