Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev 459 sample table index #484

Merged
merged 6 commits into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions peppy/project.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Build a Project object.
"""

import os
import sys
from collections.abc import Mapping, MutableMapping
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):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it be named like sample_name or should it be different property name
Do you have a suggestion @nsheff ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was there another suggestion for this? Otherwise, I will leave it as sample_name.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's fine. we're kind of locked into that terminology at this point :)

"""
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 @@ -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 == "frog_1"

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