Utils
check_command_available(command)
Check if a command is available.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
command |
str
|
The command to check. |
required |
Returns:
Name | Type | Description |
---|---|---|
bool |
True if the command is available, False otherwise. |
Examples:
Source code in src/snk_cli/utils.py
convert_key_to_snakemake_format(key, value, sep=':')
Convert key to a format that can be passed over the cli to snakemake.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key |
str
|
The key to convert. |
required |
value |
any
|
The value associated with the key. |
required |
sep |
str
|
The separator to use between keys. Defaults to ':'. |
':'
|
Returns:
Name | Type | Description |
---|---|---|
dict |
The converted key-value pair in snakemake format. |
Source code in src/snk_cli/utils.py
flatten(d, parent_key='', sep=':')
Flattens a nested dictionary.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
d |
dict
|
The dictionary to flatten. |
required |
parent_key |
str
|
The parent key of the dictionary. Defaults to ''. |
''
|
sep |
str
|
The separator to use between keys. Defaults to ':'. |
':'
|
Returns:
Name | Type | Description |
---|---|---|
dict |
A flattened dictionary. |
Examples:
Source code in src/snk_cli/utils.py
parse_config_args(args, options)
Parses a list of arguments and a list of options.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
args |
List[str]
|
A list of arguments. |
required |
options |
List[Option]
|
A list of options. |
required |
Returns:
Type | Description |
---|---|
Tuple[List[str], List[dict]]: A tuple of parsed arguments and config. |
Examples:
>>> parse_config_args(['-name', 'John', '-age', '20'], [{'name': 'name', 'default': '', 'help': '', 'type': 'str', 'required': True}, {'name': 'age', 'default': '', 'help': '', 'type': 'int', 'required': True}])
(['John', '20'], [{'name': 'name', 'John'}, {'age': 20}])
Source code in src/snk_cli/utils.py
serialise(d)
Serialises a data structure into a string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
d |
any
|
The data structure to serialise. |
required |
Returns:
Name | Type | Description |
---|---|---|
any |
The serialised data structure. |
Examples: