Skip to content

Commit

Permalink
Merge pull request #485 from pepkit/dev
Browse files Browse the repository at this point in the history
v0.40.2
  • Loading branch information
donaldcampbelljr authored May 28, 2024
2 parents 6913e77 + b7a4aca commit fc15511
Show file tree
Hide file tree
Showing 12 changed files with 50 additions and 21 deletions.
2 changes: 0 additions & 2 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
include LICENSE.txt
include requirements/*
include README.md
recursive-include docs *.md
recursive-include tests *.py
4 changes: 4 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html) and [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) format.

## [0.40.2] -- 2024-05-28
### Added
- added `sample_name` property to samples object.

## [0.40.1] -- 2024-01-11
### Fixed
- Initializing Project with `NaN` value instead of `None` in `from_pandas` method
Expand Down
2 changes: 1 addition & 1 deletion peppy/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.40.1"
__version__ = "0.40.2"
17 changes: 2 additions & 15 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 Expand Up @@ -644,21 +645,7 @@ def _assert_samples_have_names(self):
f"{CFG_SAMPLE_TABLE_KEY} is missing '{self.st_index}' column; "
f"you must specify {CFG_SAMPLE_TABLE_KEY}s in {self.st_index} or derive them"
)
if self.st_index != SAMPLE_NAME_ATTR:
try:
custom_sample_name = sample[self.st_index]
except KeyError:
raise InvalidSampleTableFileException(
f"Specified {CFG_SAMPLE_TABLE_KEY} index ({self.st_index}) does not exist"
)
sample[SAMPLE_NAME_ATTR] = custom_sample_name
_LOGGER.warning(
message
+ f"using specified {CFG_SAMPLE_TABLE_KEY} index ({self.st_index}) instead. "
+ f"Setting name: {custom_sample_name}"
)
else:
raise InvalidSampleTableFileException(message)
raise InvalidSampleTableFileException(message)

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 setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def get_static(name, condition=None):

setup(
name=PACKAGE_NAME,
packages=find_packages(),
packages=[PACKAGE_NAME],
version=version,
description="A python-based project metadata manager for portable encapsulated projects",
long_description=long_description,
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pep_version: "2.0.0"
sample_table: sample_table.csv
sample_table_index: sample_id
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
sample_name,protocol,file
frog_1,anySampleType,data/frog1_data.txt
frog_2,anySampleType,data/frog2_data.txt
19 changes: 19 additions & 0 deletions tests/test_Project.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,14 @@ def test_cutsom_sample_table_index_config(self, example_pep_cfg_path):
"""
Project(cfg=example_pep_cfg_path)

@pytest.mark.parametrize("example_pep_cfg_path", ["incorrect_index"], indirect=True)
def test_cutsom_sample_table_index_config_exception(self, example_pep_cfg_path):
"""
Verify that custom sample table index is sourced from the config
"""
with pytest.raises(InvalidSampleTableFileException):
Project(cfg=example_pep_cfg_path)

@pytest.mark.parametrize("example_pep_cfg_path", ["custom_index"], indirect=True)
def test_cutsom_sample_table_index_constructor(self, example_pep_cfg_path):
"""
Expand Down Expand Up @@ -322,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 fc15511

Please sign in to comment.