module
biopipen.core.filters
Additional filters for pipen
Functions
function
biopipen.core.filters.
dict_to_cli_args
(
dic
, exclude=None
, prefix=None
, sep=' '
, dup_key=True
, join=False
, start_key=''
, end_key='_'
, dashify=False
)
Convert a python dict to a string of CLI arguments
Parameters
dic
(Mapping) — The dict to convertexclude
(List, optional) — The keys to excludeprefix
(str | none, optional) — The prefix of the keys after conversionDefaults toNone
, mean-
for short keys and--
for long keyssep
(str | none, optional) — The separator between key and valueIfNone
, using" "
for short keys and"="
for long keysdup_key
(bool, optional) — Whether to duplicate the key in cli arguments for list valuesWhenTrue
,{"a": [1, 2]}
will be converted to"-a 1 -a 2"
WhenFalse
,{"a": [1, 2]}
will be converted to"-a 1 2"
Ifsep
isNone
or=
, this must be True, otherwise an error will be raisedjoin
(bool, optional) — Whether to join the arguments into a single stringstart_key
(str, optional) — The key to start the argumentsThis is useful when you want to put some arguments at the beginning of the command lineend_key
(str, optional) — The key to end the argumentsThis is useful when you want to put some arguments at the end of the command linedashify
(bool, optional) — Whether to replace_
with-
in the keys
Returns (Union)
The converted string or list of strings
function
biopipen.core.filters.
r
(
obj
, ignoreintkey=True
, todot=None
, sortkeys=False
, skip=0
, _i=0
)
Convert a python object into R repr
Examples
>>> True -> "TRUE">>> None -> "NULL"
>>> [1, 2] -> c(1, 2)
>>> {"a": 1, "b": 2} -> list(a = 1, b = 2)
Parameters
obj
(Any) — The object to convertignoreintkey
(bool, optional) — When keys of a dict are integers, whether we shouldignore them. For example, whenTrue
,{1: 1, 2: 2}
will be translated into"list(1, 2)"
, but"list(
1= 1,
2= 2)"
whenFalse
todot
(str, optional) — If not None, the string will be converted to a dotFor example,todot="-"
will convert"a-b"
to"a.b"
Only applies to the keys of obj when it is a dictsortkeys
(bool, optional) — Whether to sort the keys of a dict.True by default, in case the order of keys matters, for example, it could affect whether a job is cached. But sometimes, you want to keep orginal order, for example, arguments passed thedplyr::mutate
function. Because the later arguments can refer to the earlier ones.skip
(int, optional) — Levels to skip fortodot
. For example,skip=1
will skipthe first level of the keys. Whentodot
is"-"
,skip=1
will convert{"a-b": {"c-d": 1}}
tolist(`a-b` = list(`c.d` = 1))
_i
(int, optional) — Current level of the keys. Used internally
Returns (str)
Then converted string representation of the object
function
biopipen.core.filters.
source_r
(
path
)
Source an R script.
In addition to generating source(path)
, we also include the mtime for the script
to trigger the job not cached when the script is updated.
Parameters
path
(str | pathlib.path) — The path to the R script
Returns (str)
The R code to source the script