teemi.utils#

A script that provides utility functions

Functions

counting_occurences(data_with_occurences)

Count the occurences of each key in the input dict and returns the percentage of each key in the total values

location_to_start_end_strand(dictionary)

Convert "location" as Bio.SeqFeature.CompoundLocation to "start", "end", "strand" key-value pairs.

mean(lst)

Get mean from a list.

multiply_list(myList)

Multiplies elements one by one.

nest_dict(dictionary, key_for_nested_dict[, ...])

remove_duplicates_with_name_attribute(...)

Removes duplicate names from a list.

remove_tuple_duplicates(lst)

Removes tuple duplicates.

rename_dict_keys(dictionary, trans_dictionary)

Rename the keys of a dictionary using another dictionary.

split_based_on_keys(dictionary, key_list)

Split a dictionary into two based on a list of keys.

start_end_to_location(dictionary, length)

Start and End Key Value pair to Compound Location Key Value pair.

unnest_dict(dictionary, key_unnest_dict)

Unnest a dictionary by merging the values of a nested dictionary with the original dictionary, and renaming the key "label" to "name"

teemi.utils.counting_occurences(data_with_occurences: dict)[source]#

Count the occurences of each key in the input dict and returns the percentage of each key in the total values

Parameters:

data_with_occurences (dict) – The dictionary containing the data for counting occurences.

Returns:

A tuple containing two lists, the first one is the occurence percentage of each key, the second one is the list of keys.

Return type:

tuple

teemi.utils.location_to_start_end_strand(dictionary: Dict[str, Any]) Dict[str, Any][source]#

Convert “location” as Bio.SeqFeature.CompoundLocation to “start”, “end”, “strand” key-value pairs.

Parameters:#

dictionaryDict[str, Any]

The input dictionary containing “location” key

Returns:#

dictionaryDict[str, Any]

The dictionary with “start”, “end”, “strand” key added and location removed.

teemi.utils.mean(lst: list)[source]#

Get mean from a list.

Parameters:

lst (list of floats.)

Returns:

mean

Return type:

float

teemi.utils.multiply_list(myList)[source]#

Multiplies elements one by one.

Parameters:

myList (list) – list of integers to be multiplied

Returns:

result

Return type:

int

teemi.utils.nest_dict(dictionary: Dict[Any, Any], key_for_nested_dict: str, first_order_keys: List[str] = None) Dict[Any, Any][source]#

” Nest a dictionary by moving the values of specified keys to a nested dictionary.

Parameters:#

dictionaryDict[Any, Any]

The input dictionary

key_for_nested_dictstr

The key to use for the nested dictionary

first_order_keysList[str], optional

List of keys to keep in the first level of the dictionary, by default None

Returns:#

dictionaryDict[Any, Any]

The nested dictionary

teemi.utils.remove_duplicates_with_name_attribute(record_with_duplicates) list[source]#

Removes duplicate names from a list.

Parameters:

record_with_duplicates (list) – list with duplicated elements

Returns:

recs_no_dup – list without duplicates

Return type:

list

teemi.utils.remove_tuple_duplicates(lst: list) list[source]#

Removes tuple duplicates.

Parameters:

lst (list) – list with duplicated elements

Returns:

without duplicates

Return type:

list

teemi.utils.rename_dict_keys(dictionary: Dict, trans_dictionary: Dict) Dict[source]#

Rename the keys of a dictionary using another dictionary.

Parameters:
  • dictionary (Dict[K, V]) – The input dictionary

  • trans_dictionary (Dict[K, K]) – The dictionary containing the keys to be replaced as keys and the new keys as values

Returns:

dictionary – The dictionary with the keys renamed.

Return type:

Dict[K, V]

teemi.utils.split_based_on_keys(dictionary: Dict[Any, Any], key_list: List[str]) Tuple[Dict[Any, Any], Dict[Any, Any]][source]#

Split a dictionary into two based on a list of keys.

Parameters:
  • dictionary (Dict[Any, Any]) – The input dictionary

  • key_list (List[str]) – The list of keys to split the dictionary on

Returns:

  • first_dict (Dict[Any, Any]) – The dictionary containing the keys specified in key_list

  • other_dict (Dict[Any, Any]) – The dictionary containing the keys not specified in key_list

teemi.utils.start_end_to_location(dictionary: Dict[str, Any], length: int) Dict[str, Any][source]#

Start and End Key Value pair to Compound Location Key Value pair.

Parameters:#

dictionaryDict[str, Any]

The input dictionary containing “start” and “end” keys

lengthint

The length of the sequence

Returns:#

dictionaryDict[str, Any]

The dictionary with “location” key added and start, end removed.

teemi.utils.unnest_dict(dictionary: Dict[Any, Any], key_unnest_dict: str) Dict[Any, Any][source]#

Unnest a dictionary by merging the values of a nested dictionary with the original dictionary, and renaming the key “label” to “name”

Parameters:#

dictionaryDict[Any, Any]

The input dictionary

key_unnest_dictstr

The key of the nested dictionary to unnest

Returns:#

dictionaryDict[Any, Any]

The unnested dictionary