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(Optional, 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"IfsepisNoneor=, 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)"whenFalsetodot(str | none, 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::mutatefunction. Because the later arguments can refer to the earlier ones.skip(int, optional) — Levels to skip fortodot. For example,skip=1will skipthe first level of the keys. Whentodotis"-",skip=1will 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, chdir=False)
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.
If your process is used in a cloud environment, it is recommended to
use the read filter to load the script content instead of sourcing it using
the source function in R to void the path issue (path could be different
in different environments).
Parameters
path(str | pathlib.path) — The path to the R script
Returns (str)
The R code to source the script