Skip to content

Commit

Permalink
Fixed #393
Browse files Browse the repository at this point in the history
  • Loading branch information
khoroshevskyi committed Jul 12, 2024
1 parent fc1d407 commit 88264c3
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 3 deletions.
5 changes: 4 additions & 1 deletion peppy/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -1316,7 +1316,10 @@ def _read_sample_data(self):
if self[SUBSAMPLE_TABLES_FILE_KEY] is not None:
sst = self[SUBSAMPLE_TABLES_FILE_KEY]
else:
if CONFIG_KEY in self and CFG_SUBSAMPLE_TABLE_KEY in self[CONFIG_KEY]:
if (
CONFIG_KEY in self
and self[CONFIG_KEY].get(CFG_SUBSAMPLE_TABLE_KEY) is not None
):
sst = make_list(self[CONFIG_KEY][CFG_SUBSAMPLE_TABLE_KEY], str)
else:
sst = None
Expand Down
6 changes: 4 additions & 2 deletions peppy/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import logging
import os
from typing import Dict, Mapping
from typing import Dict, Mapping, Type, Union
from urllib.request import urlopen

import yaml
Expand Down Expand Up @@ -76,14 +76,16 @@ def grab_project_data(prj):
raise KeyError("Project lacks section '{}'".format(CONFIG_KEY))


def make_list(arg, obj_class):
def make_list(arg: Union[list, str], obj_class: Type) -> list:
"""
Convert an object of predefined class to a list of objects of that class or
ensure a list is a list of objects of that class
:param list[obj] | obj arg: string or a list of strings to listify
:param str obj_class: name of the class of intrest
:return list: list of objects of the predefined class
:raise TypeError: if a faulty argument was provided
"""

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pep_version: "2.0.0"
sample_table: sample_table.csv
subsample_table: null
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
sample_name,protocol,file
frog_1,anySampleType,multi
frog_2,anySampleType,multi
frog_3,anySampleType,multi
8 changes: 8 additions & 0 deletions tests/test_Project.py
Original file line number Diff line number Diff line change
Expand Up @@ -715,3 +715,11 @@ def test_sample_len(self, example_pep_cfg_path):
"""
p = Project(cfg=example_pep_cfg_path)
assert len(p.samples[0]) == 4

@pytest.mark.parametrize("example_pep_cfg_path", ["subsamples_none"], indirect=True)
def test_config_with_subsample_null(self, example_pep_cfg_path):
"""
Tests if config can have value with subsample=null
"""
p = Project(cfg=example_pep_cfg_path)
assert p.subsample_table is None

0 comments on commit 88264c3

Please sign in to comment.