task_script_utils.extract_to_decorate module#
Derived from extract-to-decorate function from ts-task-script-file-util
- process_metadata(function: Callable, metadata: Dict[str, any]) Dict[str, any][source]#
Applies a function to all values in a metadata object. :param function: a function that can be applied to a string :param metadata: an object of the following structure:
{ "key": "value 1", "key2": "value 2", }
- process_tags(function: Callable, tags: List) List[source]#
Applies a function to all values in a tags list. :param function: a function that can be applied to a string :param tags: a list of stings
- process_labels(function: Callable, labels: List) List[source]#
Applies a function to all values in a labels object. :param function: a function that can be applied to a string :param labels: a list of objects with the following structure:
[ { "name": "key1", "value": "value 1" }, { "name": "key2", "value": "value 2" } ]
- sanitize_output(text: str) str[source]#
Removes characters that will cause pipeline errors if in metadata. Currently, the Regex for metadata values is ^[0-9a-zA-Z-_+.,/ ]+$ Replaces with whitespace, then reduces multiple adjoining whitespace to single
- do_mapping_extraction(mappings: List[Dict[str, any]], source_value: str, logger: Callable, flags=0)[source]#
Iterates through the mapping list and conducts the regex search over the source string.
- Parameters:
mappings –
(list, required) a list of dictionaries. Example:
[ { "example": "/data/raw/Attune/EXP22000214/2022-08-12 vb serp test_experiment_6b5 hep 10k_a9.fcs", "source": "fileKey", "pattern": ".*(exp[0-9]{8})", "targets": [{"type": "metadata", "name": "benchling_entry_id"}], } ]
source_value – (str, required) string to search
logger – (function, required) Logger function
flags – (RegexFlag, optional) flag options to include in re.search, e.g. re.IGNORECASE
- extract_to_decorate(mappings: ~typing.List[~typing.Dict[str, any]], source_value: str, re_flags=0, sanitize=False, title_case=False, logger: ~typing.Callable = <built-in function print>)[source]#
This function uses a user-defined regex pattern search to extract metadata, tags and labels from a filename
- Parameters:
mappings –
(list, required) a list of dictionaries. Example:
[ { "example": "/data/raw/Attune/EXP22000214/2022-08-12 vb serp test_experiment_6b5 hep 10k_a9.fcs", "source": "fileKey", "pattern": ".*(exp[0-9]{8})", "targets": [{"type": "metadata", "name": "benchling_entry_id"}], } ]
source_value – (str, required) string to search
re_flags – (RegexFlag, optional) flag options to include in re.search, e.g. re.IGNORECASE
sanitize – (bool, optional) Removes characters that will cause pipeline errors if in metadata
title_case – (bool, optional) Transforms MTL values to title case
logger – (function, optional) Logger function