General Helper Functions¶
user_errors_group¶
-
autoprotocol_utilities.misc_helpers.
user_errors_group
(error_msgs, info=None)[source]¶ Takes a list error messages and neatly displays as a single UserError
Will automatically remove instances of None and only report errors if list is not empty.
Parameters: error_msgs (list) – List of strings that are the error messages Raises: ValueError
– If error_msgs is not of type list
char_limit¶
-
autoprotocol_utilities.misc_helpers.
char_limit
(label, length=22, trunc=False, clip=False)[source]¶ Enforces a string limit on the label provided
Can either throw an error message if length is exceeded or correct the string and return the corrected string.
Parameters: - label (str) – String to test.
- length (int, optional) – Maximum label length for this string. Default: 22.
- trunc (bool, optional) – Truncate the label if it is too long. Default: False.
- clip (bool, optional) – Clip the label (remove from beginning of the string) if it is too long Default: False. If both trunc and clip are True, trunc will take effect and not clip.
Returns: label (str) and error_message (string) that is empty on success label is the unmodified, truncated to clipped label as indicated
Return type: namedtuple
Raises: ValueError
– If label is not of type string
det_new_group¶
-
autoprotocol_utilities.misc_helpers.
det_new_group
(i, base=0)[source]¶ Determine if new_group should be added to pipetting operation.
Helper to determine if new_group should be added. Returns true when ‘i’ matches the base, which defaults to 0.
Parameters: - i (int) – The iteration you are on.
- base (int, optional) – The value at which you want to trigger a new group. Default: 0.
Returns: True if iteration equals base case.
Return type: bool
Raises: ValueError
– If i is not of type integerValueError
– If base is not of type integer
printdatetime¶
printdate¶
make_list¶
-
autoprotocol_utilities.misc_helpers.
make_list
(my_str, integer=False)[source]¶ Return a list of strings (or ints) from a string containing comma separated elements.
Parameters: - my_str (str) – String with individual elements separated by comma.
- interger (bool) – If true list of integers instead of list of strings is returned. Default: False.
Returns: List of strings or integers
Return type: list
Raises: ValueError
– If my_str is not of type string
flatten_list¶
-
autoprotocol_utilities.misc_helpers.
flatten_list
(l)[source]¶ Flatten a list recursively without for loops or additional modules
Example Usage:
from autoprotocol_utilities.misc_helpers import flatten_list l = [-1, 0, [1,2], "string", [3, [4, 5]]] flatten_list(l)
Returns:
[-1, 0, 1, 2, 'string', 3, 4, 5]
Parameters: l (list, list of WellGroup) – List or list of WellGroups to flatten Returns: Flat list Return type: list Raises: ValueError
– If l is not of type list
recursive_search¶
-
autoprotocol_utilities.misc_helpers.
recursive_search
(params, class_name=None, method=None, args={})[source]¶ Recursive params checker
Iterates through all items of a passed in dict, tuple, or list and either returns everything as a list, returns an optional subset of them or calls a specified method on the subset
Example Usage:
from autoprotocol.protocol import Protocol from autoprotocol.container import Well from autoprotocol_utilities import recursive_search p = Protocol() example_container = p.ref(name="example", id=None, cont_type="96-pcr", storage="ambient") p.dispense(ref=example_container, reagent="water", columns=[{"column": 0, "volume": "20:microliters"}, {"column": 1, "volume": "10:microliters"} ]) wells = example_container.wells_from(start=0, num=9, columnwise=True) recursive_search(params=wells.wells, class_name=Well, method=volume_check, args={"usage_volume": 15})
Returns:
["1 volume errors: You want to pipette 15.0 ul from a container with " "3.0 ul dead volume (18.0 ul total). However, your aliquot: example-1," "only has 10.0 ul."]
Parameters: - params (list, tuple or dict) – Structure to parse
- class_name (Class name, optional) – Optionally return only instances of a class.
- method (function, optional) – A function that will be applied to all instances found of a class, must include class name.
- args (parameters, optional) – Parameters to pass to a method, if desired.
Returns: Will return a list of all items, or the found items of a specified class, or the response (if not None) from a method called on found items.
Return type: list