torchdms.utils

Utility functions.

Functions

activation_of_string

build_beta_map

This function creates a beta matrix for one latent layer of a torchdms model.

cartesian_product

Expand an option dict, collecting the choices made in the first return value of the tuple.

cat_list_values

>>> cat_list_values({"a":[1,2], "b":[3,4], "c":[5]}, ["a", "c"])

count_variants_with_a_mutation_towards_an_aa

Count mutations towards a given amino acid.

defunkified_str

Apply str, then replace shell-problematic characters with underscores.

float_list_of_comma_separated_string

Parse a string into a list of floats.

from_json_file

Load an object from a JSON file.

from_pickle_file

Load an object from a pickle file.

get_first_key_with_an_option

Return the first key that maps to a list.

get_mutation_indicies

Returns a list of beta indicies for a given list of mutations(aa - site - aa fomat).

get_observed_training_mutations

Returns a list of all aa subs in training data list.

get_only_entry_from_constant_list

Assert that a list is constant and return that single value.

make_all_possible_mutations

This function creates a set of all possible amino acid substitutions.

make_cartesian_product_hierarchy

Make a directory hierarchy, starting with _output, expanding the option_dict via a cartesian product.

make_legal_filename

Remove spaces and non-alphanumeric characters from a given string.

parse_sites

Parse site dictionary and return beta indicies for given alphabet.

positions_in_list

Give the positions of the things in a series relative to a list of items.

to_json_file

Write an object to a JSON file.

to_pickle_file

Write an object to a pickle file.

torchdms.utils.from_pickle_file(path)[source]

Load an object from a pickle file.

torchdms.utils.to_pickle_file(obj, path)[source]

Write an object to a pickle file.

torchdms.utils.from_json_file(path)[source]

Load an object from a JSON file.

torchdms.utils.to_json_file(obj, path)[source]

Write an object to a JSON file.

torchdms.utils.float_list_of_comma_separated_string(in_str)[source]

Parse a string into a list of floats.

torchdms.utils.count_variants_with_a_mutation_towards_an_aa(series_of_aa_substitutions, aa)[source]

Count mutations towards a given amino acid.

If an amino acid appears multiple times at different positions, we only count it once.

Remove spaces and non-alphanumeric characters from a given string.

torchdms.utils.positions_in_list(series, items)[source]

Give the positions of the things in a series relative to a list of items.

Example: >>> positions_in_list(pd.Series([4., -3., -1., 9.]), [-2., 0.]) 0 2 1 0 2 1 3 2 dtype: int64

The first item is 2 because 4 is bigger than -2 and 0. The second item is 0 because -3 is smaller than everything. The third item is 1 because -1 is between -2 and 0.

torchdms.utils.get_only_entry_from_constant_list(items)[source]

Assert that a list is constant and return that single value.

torchdms.utils.get_first_key_with_an_option(option_dict)[source]

Return the first key that maps to a list.

We will call such a key-value pair an “option”. An “option dict” will be a dict that (may) have such a key-value pair.

torchdms.utils.cat_list_values(list_valued_dict, desired_keys)[source]
>>> cat_list_values({"a":[1,2], "b":[3,4], "c":[5]}, ["a", "c"])
[1, 2, 5]
torchdms.utils.cartesian_product(option_dict)[source]

Expand an option dict, collecting the choices made in the first return value of the tuple.

The best way to understand this function is to look at the test in test/test_utils.py.

torchdms.utils.defunkified_str(in_object)[source]

Apply str, then replace shell-problematic characters with underscores.

torchdms.utils.make_cartesian_product_hierarchy(dict_of_option_dicts, dry_run=False)[source]

Make a directory hierarchy, starting with _output, expanding the option_dict via a cartesian product.

torchdms.utils.build_beta_map(wtseq, alphabet, beta_vec)[source]

This function creates a beta matrix for one latent layer of a torchdms model.

Takes a binary map object and beta vector as input. Returns a 21xL matrix of beta-coefficients and the amino acid alphabet.

torchdms.utils.make_all_possible_mutations(wtseq, alphabet)[source]

This function creates a set of all possible amino acid substitutions.

Takes a wild type sequence, and a character alphabet. Returns a 20*L list of possible mutations.

torchdms.utils.get_observed_training_mutations(train_data_list)[source]

Returns a list of all aa subs in training data list.

torchdms.utils.get_mutation_indicies(mutation_list, alphabet)[source]

Returns a list of beta indicies for a given list of mutations(aa - site - aa fomat).

torchdms.utils.parse_sites(site_dict, model)[source]

Parse site dictionary and return beta indicies for given alphabet.