-
Notifications
You must be signed in to change notification settings - Fork 0
/
epistasis_analysis.py
461 lines (343 loc) · 23.2 KB
/
epistasis_analysis.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
# -*- coding: utf-8 -*-
"""Epistasis_analysis.ipynb
Automatically generated by Colab.
Original file is located at
https://colab.research.google.com/github/fweberling/epistasis/blob/main/Epistasis_analysis.ipynb
[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/fweberling/epistasis/blob/main/Epistasis_analysis.ipynb)
"""
import pandas as pd
from matplotlib import pyplot as plt
import networkx as nx
from analysis_utils import preprocessing, double_mut_pos, epistasis_graph, epistatic_triangles, comb_pos_mut, construct_structural_epistasis_graph
from plotting_utils import plot_node_degree_distribution, plot_node_degree_aa_distribution, \
plot_mutation_distribution, plot_epistasis_model, plot_obs_fitness_heatmap
import numpy as np
import itertools
import scipy as sp
"""# Combinability and epistasis analysis of *Sr*IRED
This notebook showcases the analyses for combinability and epistasis for the *Streptosporangium roseum* IRED (*Sr*IRED). These analyses are the foundation of plots in Figure 3 and S8 of the paper.
## Wildtype Sequence
Define the wildtype sequence of the *Sr*IRED
"""
# Specify sequence of reference protein
reference = "MRDTDVTVLGLGLMGQALAGAFLKDGHATTVWNRSEGKAGQLAEQGAVLASSARDAAEASPLVVVCVSDHAAVRAVLDPLGDVLAGRVLVNLTSGTSEQARATAEWAAERGITYLDGAIMAIPQVVGTADAFLLYSGPEAAYEAHEPTLRSLGAGTTYLGADHGLSSLYDVALLGIMWGTLNSFLHGAALLGTAKVEATTFAPFANRWIEAVTGFVSAYAGQVDQGAYPALDATIDTHVATVDHLIHESEAAGVNTELPRLVRTLADRALAGGQGGLGYAAMIEQFRSPS*" #SrIRED
"""## Data Pre-Processing
This is is the pre-processing of the IRED DMS data for the combinability and epistasis analysis. To run the pre-processing, the data containing .csv file must be loaded into a pandas dataframe.
"""
# Upload input files into panda data frame
PATH = "srired_active_data.csv"
data_frame = pd.read_csv(PATH)
"""For the pre-processing, the maximum order of mutations to be analysed (e.g. double, triple, quadruple etc.) must be defined\
"""
# Specify maximum order of mutations to be analysed i.e. mutations up to that order will be analysed
num_mut = 5
"""Then, the pre-processing pipeline can be run. The number of variants belonging to a certain order of mutations are printed."""
# Preprocess the data
preprocessed_data = preprocessing(data_frame, num_mut, reference)
# Lists of sequences, observed and expected fitness scores, and epistatic scores for each mutation order (e.g. 2,3,4,5)
for i in range(2, num_mut + 1):
locals()["mut_" + str(i) + "_sequence_list"] = preprocessed_data[str(i) + " Mutation"]["Sequence of mutants"]
locals()["mut_" + str(i) + "_W_observed_list"] = preprocessed_data[str(i) + " Mutation"]["Observed fitness"]
locals()["mut_" + str(i) + "_W_observed_std_list"] = preprocessed_data[str(i) + " Mutation"]["Observed std of " \
"fitness"]
locals()["mut_" + str(i) + "_W_expected_list"] = preprocessed_data[str(i) + " Mutation"]["Expected fitness"]
locals()["mut_" + str(i) + "_W_expected_std_list"] = preprocessed_data[str(i) + " Mutation"]["Expected std of " \
"fitness"]
locals()["mut_" + str(i) + "_epistatic_score_list"] = preprocessed_data[str(i) + " Mutation"]["Epistatic score"]
# Lists of sequences, observed and expected fitness scores, and epistatic scores for all mutation orders i.e. 2 - 5
full_mut_sequence_list = []
full_mut_W_observed_list = []
full_mut_W_observed_std_list = []
full_mut_W_expected_list = []
full_mut_W_expected_std_list = []
full_mut_epistatic_score_list = []
for mut_num_i in range(2, num_mut + 1):
full_mut_sequence_list = full_mut_sequence_list + locals()["mut_" + str(mut_num_i) + "_sequence_list"]
full_mut_W_observed_list = full_mut_W_observed_list + locals()["mut_" + str(mut_num_i) + "_W_observed_list"]
full_mut_W_observed_std_list = full_mut_W_observed_std_list + locals()[
"mut_" + str(mut_num_i) + "_W_observed_std_list"]
full_mut_W_expected_list = full_mut_W_expected_list + locals()["mut_" + str(mut_num_i) + "_W_expected_list"]
full_mut_W_expected_std_list = full_mut_W_expected_std_list + locals()[
"mut_" + str(mut_num_i) + "_W_expected_std_list"]
full_mut_epistatic_score_list = full_mut_epistatic_score_list + locals()[
"mut_" + str(mut_num_i) + "_epistatic_score_list"]
"""## Epistasis model
The epistasis model is created for the order of mutations that has been selected. Here, the model is plotted for mutations of order 2 to 5. The pearson correlation coefficient is printed as well.
"""
# Plot epistasis model for mutations 2 - 5
r_d_s, p_d_s = sp.stats.pearsonr(full_mut_W_expected_list, full_mut_W_observed_list)
print(f"correlation calculated double mutations fitness / double mutation fitness: pearson r = {r_d_s} with p = {p_d_s}")
plot_epistasis_model(full_mut_W_expected_list, full_mut_W_observed_list, full_mut_epistatic_score_list)
"""A Heatmap showing pairwise combinatorial fitness effects convoluted from data from variants with mutations of order 2 to 5. The $x$ and $y$ axis display the mutated amino acid positions."""
# Fitness Heatmap
plot_obs_fitness_heatmap(reference, full_mut_sequence_list, full_mut_W_observed_list)
"""## Combinability graph with $k_{obs} = 1$ and $k_{exp} = -1$
Given the user defined multiples $k_{obs}$ of the standard deviation of observed fitness $\sigma_{obs}$ and $k_{exp}$ of the expected fitness $\sigma_{exp}$, a list of at residue positions is created which are at least double mutations. Here, $k_{obs} = 1$ and $k_{exp} = -1$ are chosen such that combinable mutations are analysed.
"""
# Multiples of standard deviation for observed and expected fitness
k_obs = 1
k_exp = -1
fitness_threshold = 0.0
# List of all positive / combinable mutations
comb_pos_mut_pos_list, comb_pos_mut_aa_list = comb_pos_mut(
full_mut_epistatic_score_list,
full_mut_W_observed_list,
full_mut_W_expected_list,
full_mut_W_observed_std_list,
full_mut_sequence_list,
reference,
k_obs,
k_exp,
mean_fitness = fitness_threshold,
pos_epistasis = True
)
"""This list of is then used to construct a combinability graph $\mathcal{G}=(V,E)$ where the set of nodes $V$ are residue positions and the set of edges $E$ display the combinability of two residue positions.
"""
# Unpack list of into pairs
pos_comb_mut_edges = []
pos_comb_mut_aa = []
for higher_ord_mut in range(0, len(comb_pos_mut_pos_list)):
higher_order_mut_list = (list(map(list, itertools.combinations(comb_pos_mut_pos_list[higher_ord_mut], 2))))
higher_order_mut_aa_list = (list(map(list, itertools.combinations(comb_pos_mut_aa_list[higher_ord_mut], 2))))
if len(higher_order_mut_list) == 2:
pos_comb_mut_edges.append(higher_order_mut_list)
pos_comb_mut_aa.append(higher_order_mut_aa_list)
else:
for higher_order_mut_list_ele in range(0, len(higher_order_mut_list)):
pos_comb_mut_edges.append(higher_order_mut_list[higher_order_mut_list_ele])
pos_comb_mut_aa.append(higher_order_mut_aa_list[higher_order_mut_list_ele])
"""The node degree distribution of the combinability graph is plotted along the residue positions. The contribution of each amino acid type is coloured. This plot corresponds to Figure S8 D and is the foundation of Figure 3 C."""
# Node degree and amino acid distribution
pos_comb_higher_mut_pos = np.concatenate(
(np.array(pos_comb_mut_edges)[:, 0], np.array(pos_comb_mut_edges)[:, 1].astype(int)), axis=0)
pos_comb_higher_mut_mut_aa = np.concatenate((np.array(pos_comb_mut_aa)[:, 0], np.array(pos_comb_mut_aa)[:, 1]), axis=0)
pos_comb_higher_mut_pos_aa = np.stack((pos_comb_higher_mut_pos, pos_comb_higher_mut_mut_aa), axis=1)
pos_per_aa_dict = plot_node_degree_aa_distribution(pos_comb_higher_mut_pos_aa, len(reference), node_degree_type="Combinability")
"""For the combinability graph $\mathcal{G}={V, E}$, the position of the nodes is inferred from a distance matrix that stores the minimal distances of residues of the IRED dimer. This distance matrix reduced to two dimensions via principal component analysis. These two dimensions are then used as coordinates of the nodes of the combinability graph. Thus, a node's position represents how close a residue position is to all others. The plot corresponds to Figure S8 B and is the foundation of Figure 3 D."""
# Load distance matrix
dist_matrix = np.load("srIRED_min_ca_dimer_distances.npy")
# Minimal number of counts for an amino acid position to be included in the graph
minimal_count_per_node = 0
# Combinability graph for all mutants 2 - 5
structural_epistasis_graph = construct_structural_epistasis_graph(pos_comb_mut_edges, minimal_count_per_node, dist_matrix, len(reference), zero_edge_nodes=True, stop_codon=True)
pos = nx.get_node_attributes(structural_epistasis_graph, 'pos')
plt.figure()
nx.draw(structural_epistasis_graph, pos, with_labels=True, font_weight='bold')
plt.show()
"""Given the graph, a csv file is created that contains the list of edges that are the foundation for the plot in Figure 3 D."""
graph_edges_list = list(structural_epistasis_graph.edges)
# Create a list of column names
col_names = ["AA Residue 1", "AA Residue 2"]
# Create a pandas dataframe from the list of tuples
df = pd.DataFrame(graph_edges_list, columns=col_names)
df.to_csv('combinability_SrIRED_graph_edges_list_1_-1.csv')
"""## Epistasis graph with $k_{obs} = 1$ and $k_{exp} = 1$, and $\mu = 0$
Given the user defined multiples $k_{obs}$ of the standard deviation of observed fitness $\sigma_{obs}$ and $k_{exp}$ of the expected fitness $\sigma_{exp}$, a list of at residue positions is created which are at least double mutations. Here, $k_{obs} = 1$, $k_{exp} = 1$, and $\mu=0$ are chosen such that positively epistatic, combinable mutations are analysed.
"""
# Multiples of standard deviation for observed and expected fitness
k_obs = 1
k_exp = 1
fitness_threshold = 0.0
# List of all positive / combinable mutations
comb_pos_mut_pos_list, comb_pos_mut_aa_list = comb_pos_mut(
full_mut_epistatic_score_list,
full_mut_W_observed_list,
full_mut_W_expected_list,
full_mut_W_observed_std_list,
full_mut_sequence_list,
reference,
k_obs,
k_exp,
mean_fitness = fitness_threshold,
pos_epistasis = True
)
"""This list of is then used to construct an epistasis graph $\mathcal{G}=(V,E)$ where the set of nodes $V$ are residue positions and the set of edges $E$ display the positive epistatic interaction of two residue positions."""
# Unpack list of into pairs
pos_comb_mut_edges = []
pos_comb_mut_aa = []
for higher_ord_mut in range(0, len(comb_pos_mut_pos_list)):
higher_order_mut_list = (list(map(list, itertools.combinations(comb_pos_mut_pos_list[higher_ord_mut], 2))))
higher_order_mut_aa_list = (list(map(list, itertools.combinations(comb_pos_mut_aa_list[higher_ord_mut], 2))))
if len(higher_order_mut_list) == 2:
pos_comb_mut_edges.append(higher_order_mut_list)
pos_comb_mut_aa.append(higher_order_mut_aa_list)
else:
for higher_order_mut_list_ele in range(0, len(higher_order_mut_list)):
pos_comb_mut_edges.append(higher_order_mut_list[higher_order_mut_list_ele])
pos_comb_mut_aa.append(higher_order_mut_aa_list[higher_order_mut_list_ele])
"""The node degree distribution of the combinability graph is plotted along the residue positions. The contribution of each amino acid type is coloured. This plot corresponds to Figure S8 E."""
# Node degree and amino acid distribution
pos_comb_higher_mut_pos = np.concatenate(
(np.array(pos_comb_mut_edges)[:, 0], np.array(pos_comb_mut_edges)[:, 1].astype(int)), axis=0)
pos_comb_higher_mut_mut_aa = np.concatenate((np.array(pos_comb_mut_aa)[:, 0], np.array(pos_comb_mut_aa)[:, 1]), axis=0)
pos_comb_higher_mut_pos_aa = np.stack((pos_comb_higher_mut_pos, pos_comb_higher_mut_mut_aa), axis=1)
pos_per_aa_dict = plot_node_degree_aa_distribution(
pos_comb_higher_mut_pos_aa,
len(reference),
node_degree_type="Epistasis"
)
"""For the epistasis graph $\mathcal{G}={V, E}$, the position of the nodes is inferred from a distance matrix that stores the minimal distances of residues of the IRED dimer. This distance matrix reduced to two dimensions via principal component analysis. These two dimensions are then used as coordinates of the nodes of the combinability graph. Thus, a node's position represents how close a residue position is to all others. The plot corresponds to Figure S8 C and is the foundation of Figure 3 E (for that `minimal_count_per_node = 5` to filter out nodes with less than 5 edges)."""
# Load distance matrix
dist_matrix = np.load("srIRED_min_ca_dimer_distances.npy")
# Minimal number of counts for an amino acid position to be included in the graph
minimal_count_per_node = 0
# Combinability graph for all mutants 2 - 5
structural_epistasis_graph = construct_structural_epistasis_graph(
pos_comb_mut_edges,
minimal_count_per_node,
dist_matrix,
len(reference),
zero_edge_nodes=True,
stop_codon=True
)
pos = nx.get_node_attributes(structural_epistasis_graph, 'pos')
plt.figure()
nx.draw(structural_epistasis_graph, pos, with_labels=True, font_weight='bold')
plt.show()
"""Given the graph created using `minimal_count_per_node = 5`, a csv file is created that contains the list of edges that are the foundation for the plot in Figure 3 E."""
graph_edges_list = list(structural_epistasis_graph.edges)
# Create a list of column names
col_names = ["AA Residue 1", "AA Residue 2"]
# Create a pandas dataframe from the list of tuples
df = pd.DataFrame(graph_edges_list, columns=col_names)
df.to_csv('epistasis_SrIRED_graph_edges_list_1_1.csv')
"""# Combinability analysis of *Pc*IRED
This section showcases the combinability analyses conducted for the *Penicillium camemberti* IRED (*Pc*IRED)
## Wildtype Sequence
Define the wildtype sequence of the *Pc*IRED
"""
# Specify sequence of reference protein
reference = "MSTSEPKSISILGLGQMGHAIASNFVSQGFKTFVWNRTPSKAADLVEQGAIQSPSSTECIRSSPLSILCVNTDDIVMDILAAAGDIPGHTIVNIVNGSPQQVRKTAEKSISQYMAAGYLHGSVMASPGLVRSGGAMTIFAGSSETFKKWELTLQPLGVTLWLLDDVGAAPLYDNSLLSIVAGIFSGFMQALAMIGAAGHSETEFARGFVIPLLGQTEEWLVRTAEEVQNKDYVAEKNGSPIAVALDATKNIFETAKELGVSSRLLQGFLDVVKEGVQRGQGREEISGLVRLLREPK"
"""## Data Pre-Processing
This is is the pre-processing of the *Pc*IRED DMS data for the combinability. To run the pre-processing, the data containing .csv file must be loaded into a pandas dataframe.
"""
# Upload input files into panda data frame
PATH = "pcired_active_data.csv"
pre_data_frame = pd.read_csv(PATH)
pre_data_frame = pre_data_frame[["aa_seq", "hamming_to_wildtype", "fitness", "sigma"]]
data_frame =pre_data_frame.rename(columns={"hamming_to_wildtype": "Nham_aa"})
"""For the pre-processing, the maximum order of mutations to be analysed (e.g. double, triple, quadruple etc.) must be defined
"""
# Specify maximum order of mutations to be analysed i.e. mutations up to that order will be analysed
num_mut = 5
"""Then, the pre-processing pipeline can be run. The number of variants belonging to a certain order of mutations are printed."""
# Preprocess the data
preprocessed_data = preprocessing(data_frame, num_mut, reference)
# Lists of sequences, observed and expected fitness scores, and epistatic scores for each mutation order (e.g. 2,3,4,5)
for i in range(2, num_mut + 1):
locals()["mut_" + str(i) + "_pre_sequence_list"] = preprocessed_data[str(i) + " Mutation"]["Pre sequence list"] # new
locals()["mut_" + str(i) + "_pre_fitness_list"] = preprocessed_data[str(i) + " Mutation"]["Fitness"] # new
locals()["mut_" + str(i) + "_pre_W_observed_std_list"] = preprocessed_data[str(i) + " Mutation"]["Pre observed " \
"std of " \
"fitness"] # new
locals()["mut_" + str(i) + "_sequence_list"] = preprocessed_data[str(i) + " Mutation"]["Sequence of mutants"]
locals()["mut_" + str(i) + "_W_observed_list"] = preprocessed_data[str(i) + " Mutation"]["Observed fitness"]
locals()["mut_" + str(i) + "_W_observed_std_list"] = preprocessed_data[str(i) + " Mutation"]["Observed std of " \
"fitness"]
locals()["mut_" + str(i) + "_W_expected_list"] = preprocessed_data[str(i) + " Mutation"]["Expected fitness"]
locals()["mut_" + str(i) + "_W_expected_std_list"] = preprocessed_data[str(i) + " Mutation"]["Expected std of " \
"fitness"]
locals()["mut_" + str(i) + "_epistatic_score_list"] = preprocessed_data[str(i) + " Mutation"]["Epistatic score"]
# Lists of sequences, observed and expected fitness scores, and epistatic scores for all mutation orders i.e. 2 - 5
full_pre_sequence_list = [] # new
full_pre_fitness_list = [] # new
full_pre_W_observed_std_list = [] # new
full_mut_sequence_list = []
full_mut_W_observed_list = []
full_mut_W_observed_std_list = []
full_mut_W_expected_list = []
full_mut_W_expected_std_list = []
full_mut_epistatic_score_list = []
for mut_num_i in range(2, num_mut + 1):
full_pre_sequence_list = full_pre_sequence_list + locals()["mut_" + str(mut_num_i) + "_pre_sequence_list"] # new
full_pre_fitness_list = full_pre_fitness_list + locals()["mut_" + str(mut_num_i) + "_pre_fitness_list"] # new
full_pre_W_observed_std_list = full_pre_W_observed_std_list + locals()["mut_" + str(mut_num_i) + "_pre_W_observed_std_list"] # new
full_mut_sequence_list = full_mut_sequence_list + locals()["mut_" + str(mut_num_i) + "_sequence_list"]
full_mut_W_observed_list = full_mut_W_observed_list + locals()["mut_" + str(mut_num_i) + "_W_observed_list"]
full_mut_W_observed_std_list = full_mut_W_observed_std_list + locals()[
"mut_" + str(mut_num_i) + "_W_observed_std_list"]
full_mut_W_expected_list = full_mut_W_expected_list + locals()["mut_" + str(mut_num_i) + "_W_expected_list"]
full_mut_W_expected_std_list = full_mut_W_expected_std_list + locals()[
"mut_" + str(mut_num_i) + "_W_expected_std_list"]
full_mut_epistatic_score_list = full_mut_epistatic_score_list + locals()[
"mut_" + str(mut_num_i) + "_epistatic_score_list"]
"""## Epistasis model
The epistasis model is created for the order of mutations that has been selected and all mutants were single mutant information is availabl. Here, the model is plotted for mutations of order 2 to 5. The pearson correlation coefficient is printed as well.
"""
# Plot epistasis model for mutations 2 - 5
r_d_s, p_d_s = sp.stats.pearsonr(full_mut_W_expected_list, full_mut_W_observed_list)
print(f"correlation calculated double mutations fitness / double mutation fitness: pearson r = {r_d_s} with p = {p_d_s}")
plot_epistasis_model(full_mut_W_expected_list, full_mut_W_observed_list, full_mut_epistatic_score_list)
"""A Heatmap showing pairwise combinatorial fitness effects convoluted from data from all variants with mutations of order 2 to 5. The $x$ and $y$ axis display the mutated amino acid positions."""
# Fitness Heatmap
plot_obs_fitness_heatmap(reference, full_pre_sequence_list, full_pre_fitness_list)
"""## Combinability graph with $k_{obs} = 0$ and $k_{exp} = 0$ and $\mu > 2$
Given the user defined multiples $k_{obs}$ of the standard deviation of observed fitness $\sigma_{obs}$ and $k_{exp}$ of the expected fitness $\sigma_{exp}$ and the minimum fitness threshold $\mu$, a list of at residue positions is created which are at least double mutations. Here, $k_{obs} = 0$, $k_{exp} = 0$, and $\mu > 2$ are chosen such that combinable mutations are analysed.
"""
# Multiples of standard deviation for observed and expected fitness and fitness thresholds
k_obs = 0
k_exp = 0
fitness_threshold = 2.0
comb_pos_mut_pos_list, comb_pos_mut_aa_list = comb_pos_mut(
[],
full_pre_fitness_list,
[],
full_pre_W_observed_std_list,
full_pre_sequence_list,
reference,
k_obs,
k_exp,
mean_fitness=fitness_threshold,
pos_epistasis=False
)
"""This list of is then used to construct a combinability graph $\mathcal{G}=(V,E)$ where the set of nodes $V$ are residue positions and the set of edges $E$ display the combinability of two residue positions.
"""
# Unpack list of into pairs
pos_comb_mut_edges = []
pos_comb_mut_aa = []
for higher_ord_mut in range(0, len(comb_pos_mut_pos_list)):
higher_order_mut_list = (list(map(list, itertools.combinations(comb_pos_mut_pos_list[higher_ord_mut], 2))))
higher_order_mut_aa_list = (list(map(list, itertools.combinations(comb_pos_mut_aa_list[higher_ord_mut], 2))))
if len(higher_order_mut_list) == 2:
pos_comb_mut_edges.append(higher_order_mut_list)
pos_comb_mut_aa.append(higher_order_mut_aa_list)
else:
for higher_order_mut_list_ele in range(0, len(higher_order_mut_list)):
pos_comb_mut_edges.append(higher_order_mut_list[higher_order_mut_list_ele])
pos_comb_mut_aa.append(higher_order_mut_aa_list[higher_order_mut_list_ele])
"""The node degree distribution of the combinability graph is plotted along the residue positions. The contribution of each amino acid type is coloured. This plot corresponds to Figure S8 D and is the foundation of Figure 3 C."""
# Node degree and amino acid distribution
pos_comb_higher_mut_pos = np.concatenate(
(np.array(pos_comb_mut_edges)[:, 0], np.array(pos_comb_mut_edges)[:, 1].astype(int)), axis=0)
pos_comb_higher_mut_mut_aa = np.concatenate((np.array(pos_comb_mut_aa)[:, 0], np.array(pos_comb_mut_aa)[:, 1]), axis=0)
pos_comb_higher_mut_pos_aa = np.stack((pos_comb_higher_mut_pos, pos_comb_higher_mut_mut_aa), axis=1)
pos_per_aa_dict = plot_node_degree_aa_distribution(
pos_comb_higher_mut_pos_aa,
len(reference),
node_degree_type="Combinability"
)
"""For the combinability graph $\mathcal{G}={V, E}$, the position of the nodes is inferred from a distance matrix that stores the minimal distances of residues of the IRED dimer. This distance matrix reduced to two dimensions via principal component analysis. These two dimensions are then used as coordinates of the nodes of the combinability graph. Thus, a node's position represents how close a residue position is to all others. The plot corresponds to Figure S8 B and is the foundation of Figure 3 D."""
# Load distance matrix
dist_matrix = np.load("pcIRED_min_ca_dimer_distances.npy")
# Minimal number of counts for an amino acid position to be included in the graph
minimal_count_per_node = 0
# Combinability graph for all mutants 2 - 5
structural_epistasis_graph = construct_structural_epistasis_graph(
pos_comb_mut_edges,
minimal_count_per_node,
dist_matrix,
len(reference),
zero_edge_nodes=True,
stop_codon=False
)
pos = nx.get_node_attributes(structural_epistasis_graph, 'pos')
plt.figure()
nx.draw(structural_epistasis_graph, pos, with_labels=True, font_weight='bold')
plt.show()
"""Given the graph, a csv file is created that contains the list of edges that are the foundation for the plot in Figure 3 D."""
graph_edges_list = list(structural_epistasis_graph.edges)
# Create a list of column names
col_names = ["AA Residue 1", "AA Residue 2"]
# Create a pandas dataframe from the list of tuples
df = pd.DataFrame(graph_edges_list, columns=col_names)
df.to_csv('combinability_PcIRED_graph_edges_list_0_0_2.csv')