Skip to content

Commit

Permalink
feat: add --kplugins option to handle KNIME plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
breakthewall committed Dec 13, 2023
1 parent 85c11e5 commit 8807098
Show file tree
Hide file tree
Showing 4 changed files with 300 additions and 56 deletions.
58 changes: 45 additions & 13 deletions retropath2_wrapper/Args.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,39 @@
from retropath2_wrapper._version import __version__


DEFAULT_MSC_TIMEOUT = 10 # minutes
DEFAULT_KNIME_VERSION = "4.6.4"
DEFAULT_RP2_VERSION = 'r20220104'
__PACKAGE_FOLDER = os_path.dirname(
os_path.realpath(__file__)
)
DEFAULTS = {
'MSC_TIMEOUT': 10, # minutes
'KNIME_VERSION': "4.6.4",
'RP2_VERSION': 'r20220224',
'KNIME_FOLDER': __PACKAGE_FOLDER,
'KNIME_REPOS': [
# 'http://update.knime.com/partner/',
'http://update.knime.com/community-contributions/trunk/',
'http://update.knime.com/community-contributions/trusted/4.6',
'http://update.knime.com/analytics-platform/4.6'
],
'KNIME_PLUGINS': ','.join(
[
'org.knime.base',
'org.knime.python.nodes',
'org.knime.datageneration',
'org.knime.chem.base',
'org.rdkit.knime.feature.feature.group/4.8.1.v202312052327',
'org.rdkit.knime.nodes/4.8.1.v202312052327',
# 'org.knime.python.nodes/4.6.0.v202203011403',
# 'org.knime.datageneration/4.6.0.v202202251621',
# 'org.knime.chem.base/4.6.0.v202202251610',
# 'org.rdkit.knime.feature.feature.group/4.8.1.v202312052327',
# 'org.rdkit.knime.nodes/4.8.1.v202312052327',
]
)
}
# DEFAULTS['KNIME_PLUGINS'] = ','.join(
# [pkg.split('/')[0] for pkg in DEFAULTS['KNIME_PLUGINS'].split(',')]
# )
KNIME_ZENODO = {"4.6.4": "7515771", "4.7.0": "7564938"} # Map to Zenodo ID
RETCODES = {
'OK': 0,
Expand All @@ -26,10 +56,6 @@
'InChI': 3,
'SinkFileMalformed': 4,
}
__PACKAGE_FOLDER = os_path.dirname(
os_path.realpath(__file__)
)
DEFAULT_KNIME_FOLDER = __PACKAGE_FOLDER


def build_args_parser():
Expand Down Expand Up @@ -92,27 +118,33 @@ def _add_arguments(parser):
parser_knime.add_argument(
'--kinstall',
type=str,
default=DEFAULT_KNIME_FOLDER,
default=DEFAULTS['KNIME_FOLDER'],
help='path to KNIME executable file (KNIME will be \
downloaded if not already installed or path is \
wrong).'
)
parser_knime.add_argument(
'--kver',
type=str,
default=DEFAULT_KNIME_VERSION,
default=DEFAULTS['KNIME_VERSION'],
choices=list(KNIME_ZENODO.keys()),
help='version of KNIME (mandatory if --kexec is passed).',
)
parser_knime.add_argument(
'--kplugins',
type=str,
default="",
help='KNIME plugins to use (separated by a comma).',
)

# RetroPath2.0 workflow options
parser_rp = parser.add_argument_group("Retropath2.0 workflow")
parser_rp.add_argument(
'--rp2_version',
type=str,
default=DEFAULT_RP2_VERSION,
default=DEFAULTS['RP2_VERSION'],
choices=['v9', 'r20210127', 'r20220104', "r20220224"],
help=f'version of RetroPath2.0 workflow (default: {DEFAULT_RP2_VERSION}).'
help=f'version of RetroPath2.0 workflow (default: {DEFAULTS["RP2_VERSION"]}).'
)

parser_rp.add_argument('--max_steps' , type=int, default=3)
Expand All @@ -123,8 +155,8 @@ def _add_arguments(parser):
parser_rp.add_argument(
'--msc_timeout',
type=int,
default=DEFAULT_MSC_TIMEOUT,
help=f'Defines the time after which the RDKit MCS Aggregation method will stop searching for best match (default: {DEFAULT_MSC_TIMEOUT}).'
default=DEFAULTS['MSC_TIMEOUT'],
help=f'Defines the time after which the RDKit MCS Aggregation method will stop searching for best match (default: {DEFAULTS["MSC_TIMEOUT"]}).'
)
# parser.add_argument('--forward' , action='store_true')

Expand Down
22 changes: 12 additions & 10 deletions retropath2_wrapper/RetroPath2.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@
from csv import reader

from .Args import (
DEFAULT_KNIME_FOLDER,
DEFAULT_MSC_TIMEOUT,
DEFAULT_KNIME_VERSION,
DEFAULT_RP2_VERSION,
DEFAULTS,
RETCODES,
)
from retropath2_wrapper.knime import Knime
Expand All @@ -40,17 +37,22 @@


def retropath2(
sink_file: str, source_file: str, rules_file: str,
sink_file: str,
source_file: str,
rules_file: str,
outdir: str,
kinstall: str = DEFAULT_KNIME_FOLDER,
kexec: str = None, kver: str = DEFAULT_KNIME_VERSION,
kinstall: str = DEFAULTS['KNIME_FOLDER'],
kexec: str = None,
kver: str = DEFAULTS['KNIME_VERSION'],
knime: Knime = None,
rp2_version: str = DEFAULT_RP2_VERSION,
kplugins: list = DEFAULTS['KNIME_PLUGINS'],
rp2_version: str = DEFAULTS['RP2_VERSION'],
max_steps: int = 3,
topx: int = 100,
dmin: int = 0, dmax: int = 1000,
dmin: int = 0,
dmax: int = 1000,
mwmax_source: int = 1000,
msc_timeout: int = DEFAULT_MSC_TIMEOUT,
msc_timeout: int = DEFAULTS['MSC_TIMEOUT'],
logger: Logger = getLogger(__name__)
) -> Tuple[str, Dict]:

Expand Down
5 changes: 5 additions & 0 deletions retropath2_wrapper/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,15 @@ def _cli():

# Create Knime object
here = os_path.dirname(os_path.realpath(__file__))
if args.kplugins == "":
kplugins = []
else:
kplugins = args.kplugins.split(',')
knime = Knime(
kexec=args.kexec,
kinstall=args.kinstall,
kver=args.kver,
kplugins=kplugins,
workflow=os_path.join(here, 'workflows', 'RetroPath2.0_%s.knwf' % (args.rp2_version,)),
)
# Print out configuration
Expand Down
Loading

0 comments on commit 8807098

Please sign in to comment.