Skip to content

Commit

Permalink
feat: pass workflow as CLI parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
breakthewall committed Dec 21, 2021
1 parent 9c8bbb2 commit 355fa9c
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 23 deletions.
9 changes: 9 additions & 0 deletions retropath2_wrapper/Args.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@

from argparse import ArgumentParser
from retropath2_wrapper._version import __version__
from os import path as os_path
here = os_path.dirname(os_path.realpath(__file__))

DEFAULT_TIMEOUT = 60
DEFAULT_RETROPATH2_KWF = os_path.join(here, 'workflows', 'RetroPath2.0_r20210127.knwf')

def build_args_parser():
parser = ArgumentParser(prog='retropath2_wrapper', description='Python wrapper to parse RP2 to generate rpSBML collection of unique and complete (cofactors) pathways')
Expand Down Expand Up @@ -65,6 +68,12 @@ def _add_arguments(parser):
default=None,
help='InChI of compound to produce (not compliant with --source_file).'
)
parser.add_argument(
'--workflow',
type=str,
default=DEFAULT_RETROPATH2_KWF,
help=f'RetroPath2.0 workflow to wrap (default: {DEFAULT_RETROPATH2_KWF}).'
)
parser.add_argument(
'--kexec',
type=str,
Expand Down
22 changes: 5 additions & 17 deletions retropath2_wrapper/RetroPath2.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@
from logging import StreamHandler
from csv import reader
from .Args import (
DEFAULT_TIMEOUT
DEFAULT_TIMEOUT,
DEFAULT_RETROPATH2_KWF
)


Expand All @@ -56,7 +57,6 @@ def set_vars(
kexec: str,
kver: str,
kpkg_install: bool,
workflow: str
) -> Dict:
"""
Set variables and store them into a dictionary.
Expand All @@ -69,21 +69,11 @@ def set_vars(
Version of KNIME to install.
kpkg_install : bool
Boolean to know if KNIME packages have to be installed.
workflow: str
Path to workflow to process.
logger : Logger
The logger object.
"""

# Take workflow in the package if not passed as an argument
if workflow is None:
workflow = os_path.join(
os_path.dirname(os_path.abspath(__file__)),
'workflows',
__RETROPATH2_KWF__
)

# Setting kexec, kpath, kinstall, kver
kexec_install = False
if kexec is None:
Expand Down Expand Up @@ -111,16 +101,15 @@ def set_vars(
'kver' : kver,
'kpath' : kpath,
'kinstall' : kinstall,
'kpkg_install' : kpkg_install,
'workflow' : workflow
'kpkg_install' : kpkg_install
}


def retropath2(
sink_file: str, source_file: str, rules_file: str,
outdir: str,
kexec: str = None, kpkg_install: bool = True, kver: str = None,
workflow: str = None,
workflow: str = DEFAULT_RETROPATH2_KWF,
kvars: Dict = None,
max_steps: int = 3,
topx: int = 100,
Expand All @@ -135,8 +124,7 @@ def retropath2(
kvars = set_vars(
kexec,
kver,
kpkg_install,
workflow
kpkg_install
)
logger.debug('kvars: ' + str(kvars))
# Store RetroPath2 params into a dictionary
Expand Down
5 changes: 3 additions & 2 deletions retropath2_wrapper/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ def _cli():
kvars = set_vars(
args.kexec,
args.kver,
args.kpkg_install,
args.kwf
args.kpkg_install
)
kvars['workflow'] = args.workflow

# Print out configuration
if not args.silent and args.log.lower() not in ['critical', 'error']:
Expand All @@ -106,6 +106,7 @@ def _cli():
outdir=args.outdir,
kvars=kvars,
max_steps=args.max_steps, topx=args.topx, dmin=args.dmin, dmax=args.dmax, mwmax_source=args.mwmax_source, mwmax_cof=args.mwmax_cof,
workflow=args.workflow,
timeout=args.timeout,
logger=logger
)
Expand Down
6 changes: 2 additions & 4 deletions tests/test_RP2.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ def test_set_vars_None(self):
kvars = set_vars(
kexec = None,
kver = None,
kpkg_install = True,
workflow = None
kpkg_install = True
)

# Prepare expectd data
Expand All @@ -108,8 +107,7 @@ def test_set_vars_None(self):
'kver' : kver,
'kpath' : kpath,
'kinstall' : kinstall,
'kpkg_install' : True,
'workflow' : workflow
'kpkg_install' : True
}
self.assertDictEqual(kvars, kvars_expected)

Expand Down

0 comments on commit 355fa9c

Please sign in to comment.