From b557328578064b3a550f936285f16c5ddce8fe3c Mon Sep 17 00:00:00 2001 From: Mikko Nieminen Date: Fri, 27 Sep 2024 09:06:27 +0200 Subject: [PATCH] add pep_ms tests, refactor (#1980) --- .../assayapps/meta_ms/tests/test_plugins.py | 2 +- .../microarray/tests/test_plugins.py | 2 +- samplesheets/assayapps/pep_ms/plugins.py | 32 -------- .../assayapps/pep_ms/tests/__init__.py | 0 .../assayapps/pep_ms/tests/test_plugins.py | 73 +++++++++++++++++++ 5 files changed, 75 insertions(+), 34 deletions(-) create mode 100644 samplesheets/assayapps/pep_ms/tests/__init__.py create mode 100644 samplesheets/assayapps/pep_ms/tests/test_plugins.py diff --git a/samplesheets/assayapps/meta_ms/tests/test_plugins.py b/samplesheets/assayapps/meta_ms/tests/test_plugins.py index 9b02a6777..044c61968 100644 --- a/samplesheets/assayapps/meta_ms/tests/test_plugins.py +++ b/samplesheets/assayapps/meta_ms/tests/test_plugins.py @@ -4,13 +4,13 @@ from copy import deepcopy +from samplesheets.assayapps.meta_ms.plugins import RAW_DATA_COLL from samplesheets.assayapps.tests.base import AssayPluginTestBase from samplesheets.rendering import SIMPLE_LINK_TEMPLATE from samplesheets.views import MISC_FILES_COLL, RESULTS_COLL # Local constants -RAW_DATA_COLL = 'RawData' REPORT_NAME = 'report.txt' FILE_NAME = 'file1.txt' FILE_NAME2 = 'file2.txt' diff --git a/samplesheets/assayapps/microarray/tests/test_plugins.py b/samplesheets/assayapps/microarray/tests/test_plugins.py index a57c15848..b6456e63c 100644 --- a/samplesheets/assayapps/microarray/tests/test_plugins.py +++ b/samplesheets/assayapps/microarray/tests/test_plugins.py @@ -6,11 +6,11 @@ from django.conf import settings +from samplesheets.assayapps.microarray.plugins import RAW_DATA_COLL from samplesheets.assayapps.tests.base import AssayPluginTestBase # Local constants -RAW_DATA_COLL = 'RawData' HYBRID_SCAN_NAME = 'alpha-S1-E1-H1' SCAN_NAME_UPDATE = 'alpha-S1-E1-scan-name' IMAGE_FILE = 'image.tiff' diff --git a/samplesheets/assayapps/pep_ms/plugins.py b/samplesheets/assayapps/pep_ms/plugins.py index 1504430cc..fdafe7ef9 100644 --- a/samplesheets/assayapps/pep_ms/plugins.py +++ b/samplesheets/assayapps/pep_ms/plugins.py @@ -84,26 +84,8 @@ def update_row(self, row, table, assay, index): return row base_url = settings.IRODS_WEBDAV_URL + assay_path - # Check if MaxQuant is found - # NOTE: Currently disabled - ''' - max_quant_found = False - - for i in range(len(row)): - header = table['field_header'][i] - - if ( - header['obj_cls'] == 'Process' - and header['value'].lower() == 'analysis software name' - and row[i]['value'] == 'MaxQuant' - ): - max_quant_found = True - break - ''' - for i in range(len(row)): header = table['field_header'][i] - # Data files if ( header['obj_cls'] == 'GenericMaterial' @@ -114,20 +96,6 @@ def update_row(self, row, table, assay, index): row[i]['link'] = ( base_url + '/' + RAW_DATA_COLL + '/' + row[i]['value'] ) - - # Process parameter files - # NOTE: Currently disabled - ''' - elif ( - max_quant_found - and header['obj_cls'] == 'Process' - and header['value'].lower() == 'analysis database file' - ): - row[i]['link'] = ( - base_url + '/' + MAX_QUANT_COLL + '/' + row[i]['value'] - ) - ''' - return row def get_shortcuts(self, assay): diff --git a/samplesheets/assayapps/pep_ms/tests/__init__.py b/samplesheets/assayapps/pep_ms/tests/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/samplesheets/assayapps/pep_ms/tests/test_plugins.py b/samplesheets/assayapps/pep_ms/tests/test_plugins.py new file mode 100644 index 000000000..14564063d --- /dev/null +++ b/samplesheets/assayapps/pep_ms/tests/test_plugins.py @@ -0,0 +1,73 @@ +"""Plugin tests for the the pep_ms assay plugin""" + +import os + +from copy import deepcopy + +from samplesheets.assayapps.pep_ms.plugins import RAW_DATA_COLL, MAX_QUANT_COLL +from samplesheets.assayapps.tests.base import AssayPluginTestBase +from samplesheets.models import ISA_META_ASSAY_PLUGIN + + +# Local constants +PLUGIN_NAME = 'samplesheets_assay_pep_ms' +FILE_NAME = 'file1.txt' +FILE_NAME2 = 'file2.txt' + + +class TestMetaMSAssayPlugin(AssayPluginTestBase): + """Tests for meta_ms assay plugin""" + + plugin_name = PLUGIN_NAME + template_name = 'ms_meta_biocrates' + + def setUp(self): + super().setUp() + # Override plugin + self.assay.comments[ISA_META_ASSAY_PLUGIN] = PLUGIN_NAME + self.assay.save() + + def test_get_row_path(self): + """Test get_row_path()""" + row_path = self.plugin.get_row_path( + self.assay_table['table_data'][0], + self.assay_table, + self.assay, + self.assay_path, + ) + expected = os.path.join(self.assay_path, RAW_DATA_COLL) + self.assertEqual(row_path, expected) + + def test_update_row(self): + """Test update_row()""" + self.assay_table['table_data'][0][44]['value'] = FILE_NAME + self.assay_table['table_data'][0][51]['value'] = FILE_NAME2 + row_ex = deepcopy(self.assay_table['table_data'][0]) + row_ex[44]['link'] = os.path.join( + self.base_url, RAW_DATA_COLL, FILE_NAME + ) + row_ex[51]['link'] = os.path.join( + self.base_url, RAW_DATA_COLL, FILE_NAME2 + ) + row = self.plugin.update_row( + self.assay_table['table_data'][0], self.assay_table, self.assay, 0 + ) + self.assertEqual(row, row_ex) + + # TODO: Test with empty file names after fixing #2017 + + def test_get_shortcuts(self): + """Test get_shortcuts()""" + expected = [ + { + 'id': 'raw_data', + 'label': 'Raw Data', + 'path': os.path.join(self.assay_path, RAW_DATA_COLL), + }, + { + 'id': 'maxquant_results', + 'label': 'MaxQuant Results', + 'path': os.path.join(self.assay_path, MAX_QUANT_COLL), + }, + ] + self.assertEqual(self.plugin.get_shortcuts(self.assay), expected)