Skip to content

Commit

Permalink
fix for #459
Browse files Browse the repository at this point in the history
  • Loading branch information
donaldcampbelljr committed May 20, 2024
1 parent 9f51bb5 commit 4965dd4
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 2 deletions.
4 changes: 4 additions & 0 deletions peppy/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down
5 changes: 5 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions tests/test_Project.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down

0 comments on commit 4965dd4

Please sign in to comment.