<jupyter_start><jupyter_text>Model parameters and mutation effects (EVmutation) ContentThis notebook demonstrates how to explore the parameters of undirected graphical models inferred using EVcouplings, and how to use those to quantitatively predict the effects of mutations. Reference<NAME>., <NAME>., <NAME>., <NAME>., <NAME>., <NAME>., & <NAME>. (2017). Mutation effects predicted from sequence co-variation. *Nature Biotechnology* **35**, 128–135 doi:10.1038/nbt.3769 Tutorial Part 1: Load the model parameters from fileThis file is generated by the couplings stage of the pipeline (using plmc) and has the extension .model<jupyter_code>from evcouplings.couplings import CouplingsModel
# load parameters from file to create a pairwise model
c = CouplingsModel("example/PABP_YEAST.model_params")<jupyter_output><empty_output><jupyter_text>Part 2: Predict mutation effects<jupyter_code>import pandas as pd
from evcouplings.mutate import predict_mutation_table, single_mutant_matrix
# read the experimental mutational scanning dataset for PABP by Melamed et al., RNA, 2013
data = pd.read_csv(
    "example/PABP_YEAST_Fields2013-singles.csv", sep=";", comment="#"
)

# predict mutations using our model
data_pred = predict_mutation_table(
    c, data, "effect_prediction_epistatic"
)
# can also add predictions by the corresponding independent model
c0 = c.to_independent_model()

data_pred = predict_mutation_table(
    c0, data_pred, "effect_prediction_independent"
)
data_pred.head()<jupyter_output><empty_output><jupyter_text>Predicting single-substitution landscape (independent of experiment)<jupyter_code>singles = single_mutant_matrix(
    c, output_column="effect_prediction_epistatic"
)

singles.head()<jupyter_output><empty_output><jupyter_text>Predicting arbitary mutations<jupyter_code># double mutant L186M, G188A
delta_E, delta_E_couplings, delta_E_fields = c.delta_hamiltonian([(186, "L", "M"), (188, "G", "A")])
delta_E<jupyter_output><empty_output><jupyter_text>Short-cuts to single and double mutations<jupyter_code># single mutation matrix
c.smm(127, "E")
# double mutation matrix (double mutant L186M, G188A)
c.dmm(186, 188, "M", "A")<jupyter_output><empty_output><jupyter_text>Statistical energy of a sequence (rather than delta to WT)<jupyter_code>E, E_couplings, E_fields = c.hamiltonians([c.seq()])[0]
E<jupyter_output><empty_output><jupyter_text>Part 3: Explore model parametersPlease see the documentation of evcouplings.couplings.model.CouplingsModel for all available methods. Note that most of these methods can be accessed using lists of positions/symbols. Examples include:<jupyter_code># full sequence
print(c.seq())

# symbol for particular position (or list of positions)
print(c.seq(127))
# positions in model
print(c.index_list)
# alphabet
print(c.alphabet)
# pair coupling parameters
c.Jij(127, 172, c.seq(127), c.seq(172))
# field parameters
c.hi(127, c.seq(127))<jupyter_output><empty_output><jupyter_text>Part 4: Index mapping for complexesWhen inferring parameters for a concatenated sequence alignment (e.g. protein complexes or other discontinuous sequence segments), the internal model numbering does not match the numbering of the actual sequence. In this case, the model numbering can be manually remapped such that the model can be indexed using tuples (segment_id, position_in_segment).*(Note this example does not execute here and is intended as a reference of how to use the code only)*<jupyter_code>from evcouplings.couplings import Segment, SegmentIndexMapper
# Define which segments the concatenated sequence in the model is made of.
# Most important parameters are region_start and region_end of Segment
s_pare = Segment("aa", "F7YBW7", 1, 103, segment_id="parE")
s_pard = Segment("aa", "F7YBW8", 1, 93, segment_id="parD")

# Create index mapper
mapper = SegmentIndexMapper(True, 1, s_pare, s_pard)

# Update indices in model to complex numbering
c_mapped = mapper.patch_model(c, inplace=False)

# Now access model using tuples of indices rather than single positions alone
print(c.seq(("parD", 59)))
print(c.smm(("parD", 59), "A"))<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09521496235122662, 'fraction_numerical': 0.024532426524168083, 'mean_word_length': 6.858778625954199, 'pattern_counts': {'":': 0, '<': 40, '<?xml version=': 0, '>': 40, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '99363', 'license': 'MIT', 'n_tokens_mistral': 1405, 'n_tokens_neox': 1269, 'n_words': 411, 'path': 'notebooks/model_parameters_mutation_effects.ipynb', 'repo_name': 'b-schubert/EVcouplings', 'size': '4157'}