Skip to main content

benchling.utils.mini_utils

function flatten_nested_lists

This method will flatten nested lists while preserving the original order.

Parameters

lists : Iterator[list | list[list]]]
        Nested lists
benchling_filter : dict | None
        Optional filter to apply to the flattened list
as_dict : bool
        Optional flag to return each item as a dictionary. Default is True

Returns

list
        Flattened version of the nested lists

function remove_empties_from_result_dict

Removes empty values from a dictionary.

Parameters

result_dict : dict
        The dictionary from which to remove empty values.

Returns

dict
        The updated dictionary with empty values removed.

Example

>>> data = \{'name': 'John', 'age': 30, 'city': ''\}  
>>> remove_empties_from_result_dict(data)
\{'name': 'John', 'age': 30\}

function clean_df_for_benchling

Fill null values to to pass Benchling validations

Parameters

df_in : pd.DataFrame
        Input DataFrame
string_fill_na : str
        Value to replace NA values with, default is ""
numeric_fill_na : int | None
        Optional value to replace numeric na with. Default is None. Will raise a ValueError if
        numeric NA's are detected

Returns

pd.DataFrame
        Sanitized DataFrame

function serialize_benchling

Serialize dictionary for transmission to Benchling

Parameters

recs_to_serialize : Dict
        Dictionary containing records to serialize

Returns

Fields
        Serialized dictionary

function check_if_exists

Check if an entity exists in Benchling

Parameters

benchling_context : BenchlingContext
        Benchling context object
name : str
        Name of the entity to check
type : str
        Type of entity to check, default is "custom_entity"

Returns

benchling_sdk.models
        The entity if it exists, otherwise None

function check_task_status

Check the status of a task in Benchling

Parameters

benchling_context : BenchlingContext
        Benchling context object
task_id : str
        ID of the task to check

Returns

str
        Status of the task

function divide_list_into_chunks

Divide a list into chunks of size n

Parameters

list_to_chunk : list
        List to divide
int
        Size of the chunks

Returns

Iterator[List]
        Iterator of lists of size n

class ChemicalStructure

Custom ChemicalStructure class to allow Benchling to call to_dict on a dictionary