<jupyter_start><jupyter_text>Activity<jupyter_code>all_residues = pd.read_csv('../wt_STOP_matrices/Glu_Gal.csv', index_col = 0)

visualize.make_heatmap(
        all_residues, [x for x in list(all_residues.columns)], 
         grouped_aa, wt_full[1:], show = True, save = False)
# compute average fitness at each position
residue_x = [x for x in all_residues.columns]
mean_fitness = all_residues.drop(['*']).mean()
mean_fitness_df = pd.DataFrame(mean_fitness)

# compute rolling average of fitness
for i in range(0,mean_fitness_df.shape[0]-2):
    mean_fitness_df.loc[mean_fitness_df.index[i+2],'rolling_av'] = \
    np.round(((mean_fitness_df.iloc[i,0]+ mean_fitness_df.iloc[i+1,0] 
               + mean_fitness_df.iloc[i+2,0])/3),1)
    
# load rate for evolutionary rates data
r4s = pd.read_csv('CSVs/consurf_3cl_score.csv')
r4s['protease_screen_score'] = list(mean_fitness)
# categorize evolutionary conservation by category
grade = []
for x in r4s['COLOR']:
    if int(x)<=3.0:
        grade.append('Low')
    elif int(x)<=6.0:
        grade.append('Moderate')
    elif int(x)<=9.0:
        grade.append('High')
    else:
        grade.append('none')
r4s['Evolution score'] = grade

# Initialize the figure with a logarithmic x axis
f, ax = plt.subplots(figsize=(7, 6))

# Plot the orbital period with vertical boxes
sns_plot = sns.boxplot(x="Evolution score", y="protease_screen_score", data=r4s,
            whis=[0, 100], width=.6, palette="colorblind", 
                       order = ['Low', 'Moderate', 'High'])

# Add in points to show each observation
sns.stripplot(x="Evolution score", y="protease_screen_score", data=r4s,
              size=4, color=".3", linewidth=0,
             order = ['Low', 'Moderate', 'High'])

# Tweak the visual presentation
ax.xaxis.grid(True)
ax.set(ylabel='Protease activity score')
fig = sns_plot.get_figure()
fig.savefig(fig_folder+"Fig2_evolution_activity.png", dpi=400)<jupyter_output><empty_output><jupyter_text>EV model from Marks lab<jupyter_code>ev_model = pd.read_csv('CSVs/EVcouplings_model_Nsp5.csv')
test = []

for x in set(ev_model['pos']):
    for y in amino_acid_list[:-1]:
        if y!= wt_full[x]:
#             ev = ev_model[(ev_model['pos']==x)&(ev_model['subs']==y)]['prediction_epistatic']
#             print(x, y, ev)
            ev = float(ev_model[(ev_model['pos']==x)&(ev_model['subs']==y)]['prediction_epistatic'])
            screen = all_residues['Res '+str(x)].loc[y]
            test.append([ev, screen])
            
plt.scatter([x[0] for x in test],[x[1] for x in test])
test = pd.DataFrame(ev_model.groupby('pos').mean()['prediction_epistatic'])
corr = []
for ind in test.index:
    ev_score = test['prediction_epistatic'].loc[ind]
    screen_score = mean_fitness.loc['Res '+ str(ind)]
    corr.append([ev_score, screen_score])
plt.scatter([x[0] for x in corr], [x[1] for x in corr])
stats.stats.spearmanr([x[0] for x in corr], [x[1] for x in corr])<jupyter_output><empty_output><jupyter_text>rolling means<jupyter_code># Create figure with secondary y-axis
fig = make_subplots(specs=[[{"secondary_y": True}],
                          [{"secondary_y": True}],
                          [{"secondary_y": True}]],
        rows=3, cols=1, vertical_spacing=0.3, 
        subplot_titles=("Window: 3", "Window: 5", "Window: 7"))


for ind, x in enumerate([3,5, 7]):
    rolling_evo = r4s['SCORE'].rolling(x).mean()
    rolling_screen = r4s['protease_screen_score'].rolling(3).mean()
    
# Add traces
    fig.add_trace(
                go.Scatter(x=r4s[' POS'], 
                y=rolling_evo, 
                name="Evolutionary score",
                mode='lines'),
                secondary_y=False, 
                row = ind+1, col = 1
    )

    fig.add_trace(
                go.Scatter(x=r4s[' POS'], 
                y=rolling_screen,
                name="screen",
                mode='lines'),
        secondary_y=True,
        row = ind+1, col = 1
    )


    # Set x-axis title
    fig.update_xaxes(title_text="Residue")
    fig.update_layout(dict(
    template="simple_white",
        xaxis=dict(ticks="outside", showline=True),
        yaxis=dict(ticks="outside", showline=True)))
    # Set y-axes titles
    fig.update_yaxes(title_text="<b>Evolution rate</b>", secondary_y=False)
    fig.update_yaxes(title_text="<b>Screen</b>", secondary_y=True)
    fig.update_layout({
            'plot_bgcolor': 'rgba(255,255,255, 0.7)',
            'paper_bgcolor': 'rgba(0, 0, 0, 0)',
            })

fig.show()
# offline.plot(fig, filename = fig_folder+'rolling_average_evolution_screen.html')
fig.write_image(fig_folder+"rolling_average_evolution_screen.pdf")
# Create figure with secondary y-axis
fig = make_subplots(specs=[[{"secondary_y": True}],
                          [{"secondary_y": True}],
                          [{"secondary_y": True}]],
        rows=3, cols=1, vertical_spacing=0.3, 
        subplot_titles=("Window: 2", "Window: 4", "Window: 6"))


for ind, x in enumerate([2,4,6]):
    rolling_evo = r4s['SCORE'].rolling(x).mean()
    rolling_screen = r4s['protease_screen_score'].rolling(x).mean()
    evo_zscore = (rolling_evo - rolling_evo.mean())/rolling_evo.std()
    screen_zscore = (rolling_screen - rolling_screen.mean())/rolling_screen.std()
    diff =  screen_zscore - evo_zscore
    
# Add traces
    fig.add_trace(
                go.Scatter(x=r4s[' POS'], 
                y=evo_zscore, 
                name="Evolutionary score",
                mode='lines'),
                secondary_y=False, 
                row = ind+1, col = 1
    )

    fig.add_trace(
                go.Scatter(x=r4s[' POS'], 
                y=screen_zscore,
                name="screen",
                mode='lines'),
        secondary_y=True,
        row = ind+1, col = 1
    )


    # Set x-axis title
    fig.update_xaxes(title_text="Residue")
    fig.update_layout(dict(
    template="simple_white",
        xaxis=dict(ticks="outside", showline=True),
        yaxis=dict(ticks="outside", showline=True)))
    # Set y-axes titles
    fig.update_yaxes(title_text="<b>Evolution rate</b>", secondary_y=False)
    fig.update_yaxes(title_text="<b>Screen</b>", secondary_y=True)
    fig.update_layout({
            'plot_bgcolor': 'rgba(255,255,255, 0.7)',
            'paper_bgcolor': 'rgba(0, 0, 0, 0)',
            })

fig.show()
# offline.plot(fig, filename = fig_folder+'rolling_average_evolution_screen.html')
fig.write_image(fig_folder+"rolling_average_evolution_screen.pdf")
pd.DataFrame(diff).to_csv('CSVs/evolution_screen_diff.csv')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1546077684691546, 'fraction_numerical': 0.017517136329017517, 'mean_word_length': 3.0706757594544327, 'pattern_counts': {'":': 6, '<': 24, '<?xml version=': 0, '>': 21, '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': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '103359', 'license': 'MIT', 'n_tokens_mistral': 2444, 'n_tokens_neox': 2279, 'n_words': 400, 'path': 'scripts/Fig2-Generate_evolution_figs_with_glu_stop-codon_norm.ipynb', 'repo_name': 'ChavezResearchLab/3CL_protease_DMS', 'size': '6565'}