Skip to content

Commit

Permalink
make sample_name a property of sample instead
Browse files Browse the repository at this point in the history
  • Loading branch information
donaldcampbelljr committed May 21, 2024
1 parent d68d31e commit f1bd23f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
3 changes: 0 additions & 3 deletions peppy/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -660,9 +660,6 @@ 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

def _auto_merge_duplicated_names(self):
"""
Expand Down
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
2 changes: 1 addition & 1 deletion tests/test_Project.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ def test_sample_name_custom_index(self, example_pep_cfg_custom_index):
"""
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"
assert p.samples[0].sample_name == "frog_1"

@pytest.mark.parametrize(
"example_pep_cfg_path",
Expand Down

0 comments on commit f1bd23f

Please sign in to comment.