Skip to content

Commit

Permalink
Merge pull request #484 from pepkit/dev_459_sample_table_index
Browse files Browse the repository at this point in the history
Dev 459 sample table index
  • Loading branch information
donaldcampbelljr authored May 24, 2024
2 parents fc1d407 + f1bd23f commit 78ee8d1
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 2 deletions.
10 changes: 10 additions & 0 deletions peppy/sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,16 @@ def project(self):
"""
return self[PRJ_REF]

@property
def sample_name(self):
"""
Get the sample's name
:return str: current sample name derived from project's st_index
"""

return self[self[PRJ_REF].st_index]

# The __reduce__ function provides an interface for
# correct object serialization with the pickle module.
def __reduce__(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 @@ -330,6 +330,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 == "frog_1"

@pytest.mark.parametrize(
"example_pep_cfg_path",
["basic"],
Expand Down

0 comments on commit 78ee8d1

Please sign in to comment.