From 4965dd473be87150a05eefe6da70da984bf79341 Mon Sep 17 00:00:00 2001 From: Donald Campbell <125581724+donaldcampbelljr@users.noreply.github.com> Date: Mon, 20 May 2024 11:37:25 -0400 Subject: [PATCH] fix for #459 --- peppy/project.py | 4 ++++ tests/conftest.py | 5 +++++ .../example_custom_index/project_config.yaml | 2 +- .../example_custom_index/sample_table.csv | 2 +- tests/test_Project.py | 11 +++++++++++ 5 files changed, 22 insertions(+), 2 deletions(-) diff --git a/peppy/project.py b/peppy/project.py index 1e0ebb68..5c4524bd 100644 --- a/peppy/project.py +++ b/peppy/project.py @@ -659,6 +659,10 @@ def _assert_samples_have_names(self): ) else: raise InvalidSampleTableFileException(message) + else: + if self.st_index != SAMPLE_NAME_ATTR: + sample[SAMPLE_NAME_ATTR] = self.st_index + _LOGGER.warning(f"Setting sample.sample_name: {self.st_index}") def _auto_merge_duplicated_names(self): """ diff --git a/tests/conftest.py b/tests/conftest.py index 50c7ffd5..a689ffc1 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -51,6 +51,11 @@ def example_pep_cfg_noname_path(request): return get_path_to_example_file(EPB, "noname", request.param) +@pytest.fixture +def example_pep_cfg_custom_index(request): + return get_path_to_example_file(EPB, "custom_index", request.param) + + @pytest.fixture def example_peps_cfg_paths(request): """ diff --git a/tests/data/example_peps-master/example_custom_index/project_config.yaml b/tests/data/example_peps-master/example_custom_index/project_config.yaml index 83f85a88..a9a777be 100644 --- a/tests/data/example_peps-master/example_custom_index/project_config.yaml +++ b/tests/data/example_peps-master/example_custom_index/project_config.yaml @@ -1,3 +1,3 @@ pep_version: "2.0.0" sample_table: sample_table.csv -sample_table_index: sample_id +sample_table_index: NOT_SAMPLE_NAME diff --git a/tests/data/example_peps-master/example_custom_index/sample_table.csv b/tests/data/example_peps-master/example_custom_index/sample_table.csv index 30228147..c9965421 100644 --- a/tests/data/example_peps-master/example_custom_index/sample_table.csv +++ b/tests/data/example_peps-master/example_custom_index/sample_table.csv @@ -1,3 +1,3 @@ -sample_id,protocol,file +NOT_SAMPLE_NAME,protocol,file frog_1,anySampleType,data/frog1_data.txt frog_2,anySampleType,data/frog2_data.txt diff --git a/tests/test_Project.py b/tests/test_Project.py index c77439ec..3c3c975f 100644 --- a/tests/test_Project.py +++ b/tests/test_Project.py @@ -322,6 +322,17 @@ def test_missing_sample_name_custom_index(self, example_pep_cfg_noname_path): p = Project(cfg=example_pep_cfg_noname_path, sample_table_index="id") assert p.sample_name_colname == "id" + @pytest.mark.parametrize( + "example_pep_cfg_custom_index", ["project_config.yaml"], indirect=True + ) + def test_sample_name_custom_index(self, example_pep_cfg_custom_index): + """ + Verify that sample_name attribute becomes st_index from cfg + """ + p = Project(cfg=example_pep_cfg_custom_index) + assert p.sample_name_colname == "NOT_SAMPLE_NAME" + assert p.samples[0].sample_name == "NOT_SAMPLE_NAME" + @pytest.mark.parametrize( "example_pep_cfg_path", ["basic"],