Skip to content

Commit

Permalink
Implemented UnsupportedActionException
Browse files Browse the repository at this point in the history
  • Loading branch information
eudesbarbosa committed Apr 7, 2021
1 parent c88743a commit 8cc86c7
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
4 changes: 4 additions & 0 deletions snappy_pipeline/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ class MissingConfiguration(InvalidConfiguration):
"""Raised on missing configuration"""


class UnsupportedActionException(Exception):
"""Raised when user try to call action that isn't supported."""


def expand_ref(config_path, dict_data, lookup_paths=None, dict_class=OrderedDict):
"""Expand "$ref" in JSON-like data ``dict_data``
Expand Down
15 changes: 13 additions & 2 deletions snappy_pipeline/workflows/somatic_wgs_cnv_calling/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
from biomedsheets.shortcuts import CancerCaseSheet, CancerCaseSheetOptions, is_not_background
from snakemake.io import expand

from snappy_pipeline.base import UnsupportedActionException
from ..abstract import BaseStepPart, BaseStep, LinkOutStepPart
from ..ngs_mapping import NgsMappingWorkflow
from ...utils import listify, dictify
Expand Down Expand Up @@ -381,7 +382,18 @@ class ControlFreecSomaticWgsStepPart(SomaticWgsCnvCallingStepPart):
name = "control_freec"

def get_output_files(self, action):
# Initialise variable
valid_action_list = ["run", "transform", "plot"]
result = {}

# Validate input
if action not in valid_action_list:
valid_actions_str = ", ".join(valid_action_list)
error_message = "Action {action} is not supported. Valid options: {options}".format(
action=action, options=valid_actions_str
)
raise UnsupportedActionException(error_message)

if action == "run":
result["ratio"] = self.base_path_out.format(var_caller=self.name, ext=".ratio.txt")
result["ratio_md5"] = self.base_path_out.format(
Expand Down Expand Up @@ -411,8 +423,7 @@ def get_output_files(self, action):
expand(self.base_path_out, var_caller=[self.name], ext=plot_ext_values),
)
)
else:
raise "Unsupported action"

return result

def check_config(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,16 @@ def test_control_freec_somatic_step_part_get_output_files(somatic_wgs_cnv_callin
assert actual == expected


def test_control_freec_somatic_step_part_get_output_exception(somatic_wgs_cnv_calling_workflow):
"""Tests if ControlFreecSomaticWgsStepPart::get_output_files() raises exception for invalid
action."""
# Exception raised cause no RNA mapper defined in config
with pytest.raises(Exception) as exec_info:
somatic_wgs_cnv_calling_workflow.get_output_files("control_freec", "invalid_action")
error_msg = "Called unsupported action, exceptions should have been raised."
assert exec_info.value.args[0] is not None, error_msg


def test_control_freec_somatic_step_part_get_log_file(somatic_wgs_cnv_calling_workflow):
# Define expected
base_name = (
Expand Down

0 comments on commit 8cc86c7

Please sign in to comment.