module

biopipen.core.filters

Additional filters for pipen

Functions
  • dict_to_cli_args(dic, exclude, prefix, sep, dup_key, join, start_key, end_key, dashify) (Union) Convert a python dict to a string of CLI arguments</>
  • r(obj, ignoreintkey, todot, sortkeys, skip, _i) (str) Convert a python object into R repr</>
  • source_r(path) (str) Source an R script.</>
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 convert
  • exclude (List, optional) The keys to exclude
  • prefix (str | none, optional) The prefix of the keys after conversionDefaults to None, mean - for short keys and -- for long keys
  • sep (str | none, optional) The separator between key and valueIf None, using " " for short keys and "=" for long keys
  • dup_key (bool, optional) Whether to duplicate the key in cli arguments for list valuesWhen True, {"a": [1, 2]} will be converted to "-a 1 -a 2" When False, {"a": [1, 2]} will be converted to "-a 1 2" If sep is None or =, this must be True, otherwise an error will be raised
  • join (bool, optional) Whether to join the arguments into a single string
  • start_key (str, optional) The key to start the argumentsThis is useful when you want to put some arguments at the beginning of the command line
  • end_key (str, optional) The key to end the argumentsThis is useful when you want to put some arguments at the end of the command line
  • dashify (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 convert
  • ignoreintkey (bool, optional) When keys of a dict are integers, whether we shouldignore them. For example, when True, {1: 1, 2: 2} will be translated into "list(1, 2)", but "list(1= 1,2= 2)" when False
  • 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 dict
  • sortkeys (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 the dplyr::mutate function. Because the later arguments can refer to the earlier ones.
  • skip (int, optional) Levels to skip for todot. For example, skip=1 will skipthe first level of the keys. When todot is "-", skip=1 will convert {"a-b": {"c-d": 1}} to list(`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