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

Release 0.2.4 #77

Merged
merged 3 commits into from
Sep 30, 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
2 changes: 1 addition & 1 deletion eido/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.2.3"
__version__ = "0.2.4"
5 changes: 2 additions & 3 deletions eido/conversion_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ def yaml_pep_filter(p, **kwargs) -> Dict[str, str]:
"""
from yaml import dump

data = p.config.to_dict()
return {"project": dump(data, default_flow_style=False)}
return {"project": dump(p.config, default_flow_style=False)}


def csv_pep_filter(p, **kwargs) -> Dict[str, str]:
Expand All @@ -70,7 +69,7 @@ def processed_pep_filter(p, **kwargs) -> Dict[str, str]:
samples_as_objects = kwargs.get("samples_as_objects")
subsamples_as_objects = kwargs.get("subsamples_as_objects")

prj_repr = p.config.to_dict()
prj_repr = p.config

return {
"project": str(prj_repr),
Expand Down
2 changes: 1 addition & 1 deletion eido/output_formatters.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def _convert_sample_to_row(
):
value = sample[attribute][sample_index]
else:
value = sample[attribute]
value = sample.get(attribute)

sample_row.append(value or "")

Expand Down
4 changes: 4 additions & 0 deletions eido/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ def _validate_object(obj: Mapping, schema: Union[str, dict], sample_name_colname
instance_name = error.instance[sample_name_colname]
except KeyError:
instance_name = "project"
except TypeError:
instance_name = obj["samples"][error.absolute_path[1]][
sample_name_colname
]
errors_by_type[error.message].append(
{
"type": error.message,
Expand Down
2 changes: 1 addition & 1 deletion requirements/requirements-all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ importlib-metadata; python_version < '3.10'
jsonschema>=3.0.1
logmuse>=0.2.5
pandas
peppy>=0.40.6
peppy>=0.40.7
ubiquerg>=0.5.2
21 changes: 18 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,25 @@ def save_result_mock(mocker):


@pytest.fixture
def test_file_existence_schema(schemas_path):
def test_file_existing_schema(schemas_path):
return os.path.join(schemas_path, "schema_test_file_exist.yaml")


@pytest.fixture
def test_file_existance_pep(peps_path):
return os.path.join(peps_path, "test_file_existence", "project_config.yaml")
def test_file_existing_pep(peps_path):
return os.path.join(peps_path, "test_file_existing", "project_config.yaml")


@pytest.fixture
def test_schema_value_check(schemas_path):
return os.path.join(schemas_path, "value_check_schema.yaml")


@pytest.fixture
def test_file_value_check(peps_path):
return os.path.join(peps_path, "value_check_pep", "project_config.yaml")


@pytest.fixture
def test_multiple_subs(peps_path):
return os.path.join(peps_path, "multiple_subsamples", "project_config.yaml")
19 changes: 19 additions & 0 deletions tests/data/peps/multiple_subsamples/project_config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
pep_version: "2.1.0"
sample_table: sample_table.csv
subsample_table:
- subsample_table1.csv
- subsample_table2.csv

sample_modifiers:
append:
local_files: LOCAL
genome: "fg"
derive:
attributes: [local_files]
sources:
LOCAL: "../data/{file_path}"
imply:
- if:
identifier: "frog1"
then:
genome: "frog_frog"
5 changes: 5 additions & 0 deletions tests/data/peps/multiple_subsamples/sample_table.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
sample_id,protocol,identifier
frog_1,anySampleType,frog1
frog_2,anySampleType,frog2
frog_3,anySampleType,frog3
frog_4,anySampleType,frog4
6 changes: 6 additions & 0 deletions tests/data/peps/multiple_subsamples/subsample_table1.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
sample_id,file_path,subsample_name
frog_1,file/a.txt,a
frog_1,file/b.txt,b
frog_1,file/c.txt,c
frog_2,file/a.txt,a
frog_2,file/b.txt,b
6 changes: 6 additions & 0 deletions tests/data/peps/multiple_subsamples/subsample_table2.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
sample_id,random_string,subsample_name
frog_1,x_x,x
frog_1,y_y,y
frog_1,z_z,z
frog_2,xy_yx,xy
frog_2,xx_xx,xx
6 changes: 6 additions & 0 deletions tests/data/peps/value_check_pep/project_config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
description: None
name: encode_prj
pep_version: 2.0.0
project_name: value_check_pep
sample_table: sample_table.csv
subsample_table: []
7 changes: 7 additions & 0 deletions tests/data/peps/value_check_pep/sample_table.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
sample_name,file_name,genome,assay,cell_line,target,format_type
encode_4,ENCFF452DAM.bed.gz,hg38,Histone ChIP-seq,skeletal muscle myoblast,H3K36me3,narrowPeak
encode_20,ENCFF121AXG.bed.gz,hg38,DNase-seq,RPMI7951,,tssPeak
encode_21,ENCFF710ECJ.bed.gz,hg38,DNase-seq,RPMI7951,,broadPeak
encode_22,ENCFF945FZN.bed.gz,hg38,DNase-seq,RPMI7951,,narrowPeak
encode_23,ENCFF322PQO.bed.gz,hg38,DNase-seq,RPMI7951,,tssPeak
encode_24,ENCFF322PQO.bed.gz,hg38,DNase-seq,RPMI7951,,tssPeak1
16 changes: 16 additions & 0 deletions tests/data/schemas/value_check_schema.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
description: bedboss run-all pep schema
properties:
samples:
items:
properties:
format_type:
description: whether the regions are narrow (transcription factor implies
narrow, histone mark implies broad peaks)
enum:
- narrowPeak
- broadPeak
type: string
type: object
type: array
required:
- samples
32 changes: 31 additions & 1 deletion tests/test_conversions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
from eido.conversion import *
from eido.conversion import (
run_filter,
get_available_pep_filters,
pep_conversion_plugins,
convert_project,
)
import peppy


class TestConversionInfrastructure:
Expand Down Expand Up @@ -74,3 +80,27 @@ def test_eido_csv_filter_filters_nextflow_taxprofiler_input_correctly(

assert save_result_mock.called
assert conv_result == {"samples": output_pep_nextflow_taxprofiler}

def test_multiple_subsamples(self, test_multiple_subs):
project = peppy.Project(test_multiple_subs, sample_table_index="sample_id")

conversion = convert_project(
project,
"csv",
)
assert isinstance(conversion["samples"], str)
conversion = convert_project(
project,
"basic",
)
assert isinstance(conversion["project"], str)
conversion = convert_project(
project,
"yaml",
)
assert isinstance(conversion["project"], str)
conversion = convert_project(
project,
"yaml-samples",
)
assert isinstance(conversion["samples"], str)
13 changes: 9 additions & 4 deletions tests/test_validations.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import urllib

import pytest
from jsonschema.exceptions import ValidationError
from peppy import Project
from peppy.utils import load_yaml

Expand Down Expand Up @@ -140,9 +139,15 @@ def test_validate_detects_invalid(self, schema_invalid_file_path, remote_pep_cfg
)

def test_validate_file_existance(
self, test_file_existance_pep, test_file_existence_schema
self, test_file_existing_pep, test_file_existing_schema
):
schema_path = test_file_existence_schema
prj = Project(test_file_existance_pep)
schema_path = test_file_existing_schema
prj = Project(test_file_existing_pep)
with pytest.raises(PathAttrNotFoundError):
validate_input_files(prj, schema_path)

def test_validation_values(self, test_schema_value_check, test_file_value_check):
schema_path = test_schema_value_check
prj = Project(test_file_value_check)
with pytest.raises(EidoValidationError):
validate_project(project=prj, schema=schema_path)
Loading