torchdms.utils¶
Utility functions.
Functions
This function creates a beta matrix for one latent layer of a torchdms model. |
|
Expand an option dict, collecting the choices made in the first return value of the tuple. |
|
>>> cat_list_values({"a":[1,2], "b":[3,4], "c":[5]}, ["a", "c"])
|
|
Count mutations towards a given amino acid. |
|
Apply str, then replace shell-problematic characters with underscores. |
|
Parse a string into a list of floats. |
|
Load an object from a JSON file. |
|
Load an object from a pickle file. |
|
Return the first key that maps to a list. |
|
Returns a list of beta indicies for a given list of mutations(aa - site - aa fomat). |
|
Returns a list of all aa subs in training data list. |
|
Assert that a list is constant and return that single value. |
|
This function creates a set of all possible amino acid substitutions. |
|
Make a directory hierarchy, starting with _output, expanding the option_dict via a cartesian product. |
|
Remove spaces and non-alphanumeric characters from a given string. |
|
Parse site dictionary and return beta indicies for given alphabet. |
|
Give the positions of the things in a series relative to a list of items. |
|
Write an object to a JSON file. |
|
Write an object to a pickle 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.
- torchdms.utils.make_legal_filename(label)[source]¶
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.