<jupyter_start><jupyter_text>Fig. 2e: Primary vs secondary cumulative distribution plots* Primary Cas9:     * A549:        * Sanjana (KO)        * Zhang (KO)    * Huh-7.5:        * Poirier (KO)        * Puschnik (KO)    * Caco-2:         * Goujon (KO)    * Calu-3:        * Goujon (KO)        * Goujon (Activation)vs        * Secondary KO:    * A549:        * Cas9 KO Secondary    * Huh-7.5.1:        * Cas9 KO Secondary    * Caco-2:         * Cas9 KO Secondary    * Calu-3:        * Cas9 KO Secondary        * Cas9 Activation Secondary  Read Primary KO screen data<jupyter_code>cell_lines = ['A549', 'Huh7_5', 'Caco_2', 'Calu_3']

A549_dict = {}
Huh7_5_dict = {}
Caco2_dict = {}
Calu3_KO_dict = {}
Calu3_Act_dict = {}

# A549
A549_dict['primary_KO_Sanjana'] = pd.read_excel('../../../Data/Processed/GEO_submission_v2/A549_GeCKOv2_Sanjana_v2.xlsx')
A549_dict['primary_KO_Zhang'] = pd.read_excel('../../../Data/Processed/GEO_submission_v2/A549_Brunello_Zhang.xlsx')

# Huh-7.5
Huh7_5_dict['primary_KO_Poirier'] = pd.read_excel('../../../Data/Processed/GEO_submission_v2/Huh75_Brunello_Poirier_v2.xlsx')
Huh7_5_dict['primary_KO_Puschnik'] = pd.read_excel('../../../Data/Processed/GEO_submission_v2/Huh751_GeCKOv2_Puschnik.xlsx')

# Caco-2
Caco2_dict['primary_KO_Goujon'] = pd.read_excel('../../../Data/Processed/GEO_submission_v2/Caco2_Brunello_Goujon_v2.xlsx')

# Calu-3
Calu3_KO_dict['primary_KO_Goujon'] = pd.read_excel('../../../Data/Processed/GEO_submission_v2/Calu3_Gattinara_Goujon_v2.xlsx')
Calu3_Act_dict['primary_Act_Goujon'] = pd.read_excel('../../../Data/Processed/GEO_submission_v2/Calu3_Calabrese_Goujon_v3.xlsx')<jupyter_output><empty_output><jupyter_text>Read Secondary screen data<jupyter_code># A549
A549_dict['secondary_KO_Goujon'] = pd.read_excel('../../../Data/Processed/GEO_submission_v2/SecondaryLibrary/A549_Cas9SecondaryLibraryKO_Goujon.xlsx')

# Huh-7.5
Huh7_5_dict['secondary_KO_Goujon'] = pd.read_excel('../../../Data/Processed/GEO_submission_v2/SecondaryLibrary/Huh751_Cas9SecondaryLibraryKO_Goujon.xlsx')

# Caco-2
Caco2_dict['secondary_KO_Goujon'] = pd.read_excel('../../../Data/Processed/GEO_submission_v2/SecondaryLibrary/Caco2_Cas9SecondaryLibraryKO_Goujon.xlsx')                                          

# Calu-3
Calu3_KO_dict['secondary_KO_Goujon'] = pd.read_excel('../../../Data/Processed/GEO_submission_v2/SecondaryLibrary/Calu3_SecondaryLibraryKO_Goujon.xlsx')
Calu3_Act_dict['secondary_Act_Goujon'] = pd.read_excel('../../../Data/Processed/GEO_submission_v2/SecondaryLibrary/Calu3_SecondaryLibraryAct_Goujon.xlsx')<jupyter_output><empty_output><jupyter_text>Assign hits and ranks<jupyter_code># Rename columns with senior authors

A549_dict = rename_zscore_cols(A549_dict)

Huh7_5_dict = rename_zscore_cols(Huh7_5_dict)

Caco2_dict = rename_zscore_cols(Caco2_dict)

Calu3_KO_dict = rename_zscore_cols(Calu3_KO_dict)
Calu3_Act_dict = rename_zscore_cols(Calu3_Act_dict)

# Merge dfs for each cell line into one df
cell_line_dict = {}

cell_line_dict['A549'] = fns.merge_dict_dfs(A549_dict)

cell_line_dict['Huh7_5'] = fns.merge_dict_dfs(Huh7_5_dict)

cell_line_dict['Caco2'] = fns.merge_dict_dfs(Caco2_dict)

cell_line_dict['Calu3_KO'] = fns.merge_dict_dfs(Calu3_KO_dict)
cell_line_dict['Calu3_Act'] = fns.merge_dict_dfs(Calu3_Act_dict)

# Add bool col assigning 1 to resistance hits (score > 3)

for key, df in cell_line_dict.items():
    if 'Act' in key:
        df = resistant_hit_col(df, greater_than=False)
    else:
        df = resistant_hit_col(df)
    cell_line_dict[key] = df

# A549_df = resistant_hit_col(A549_df)

# Huh7_5_df = resistant_hit_col(Huh7_5_df)

# Caco2_df = resistant_hit_col(Caco2_df)

# Calu3_KO_df = resistant_hit_col(Calu3_KO_df)
# Calu3_Act_df = resistant_hit_col(Calu3_Act_df)

# run_cumulative_dist(A549_df, 'A549')
for key, df in cell_line_dict.items():
    if 'Act' in key:
        run_cumulative_dist(df, key, ascending=True)
    else:
        run_cumulative_dist(df, key)
#     break
# Res_Wilen_rank, Res_Wilen_auc = cumulative_dist(df=Vero_zscores, annot_col = 'Gene Symbol', rank_col = 'Rank_residual_zscore_avg_Wilen', bool_col = 'Goujon_resistance_hit', condition = 'Resistance')
# Sen_Wilen_rank, Sen_Wilen_auc = cumulative_dist(df=Vero_zscores_sensitization_Wilen_ranked, annot_col = 'Gene Symbol', rank_col = 'Rank_residual_zscore_avg_Wilen_sen', bool_col = 'Goujon_sensitization_hit', condition = 'Sensitization')

# Wilen_rank = pd.concat([Res_Wilen_rank, Sen_Wilen_rank])

primary_rank_cumulative_dist_dict = {key: value for key, value in cumulative_dist_dict.items() if 'primary_rank' in key}
secondary_rank_cumulative_dist_dict = {key: value for key, value in cumulative_dist_dict.items() if 'secondary_rank' in key}

# fig, ax = plt.subplots(figsize=(2,2))
# # Concatenate dfs in dict
# secondary_rank_cumulative_dist_df = pd.concat(secondary_rank_cumulative_dist_dict.values())

# s = sns.lineplot(data = secondary_rank_cumulative_dist_df, x = 'Fractional_rank', y = 'Cumulative_freq', ci=None, hue='Screen')
# plt.legend(prop={'size':7}, bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0.)
# plt.title('Ranked by secondary screens', fontsize=7)
# plt.xlabel('Cumulative frequency', fontsize=7)
# plt.ylabel('Fractional rank', fontsize=7)
# ax.tick_params(axis='both', labelsize=7)
# sns.despine()
        
# fig.savefig('../../../Figures/Cumulative_dist_Goujon_secondary_rank_primary_hit.png', bbox_inches='tight', dpi=300)
# gpp.savefig('../../../Figures/Cumulative_dist_Goujon_secondary_rank_primary_hit.pdf', bbox_inches='tight', dpi=300)

fig, ax = plt.subplots(figsize=(2,2))
# Concatenate dfs in dict
primary_rank_cumulative_dist_df = pd.concat(primary_rank_cumulative_dist_dict.values())

s = sns.lineplot(data = primary_rank_cumulative_dist_df, x = 'Fractional_rank', y = 'Cumulative_freq', ci=None, hue='Screen')
plt.legend(prop={'size':7}, bbox_to_anchor=(0, -0.3), loc=2, borderaxespad=0.)
plt.title('Ranked by primary screens', fontsize=7)
plt.xlabel('Cumulative frequency', fontsize=7)
plt.ylabel('Fractional rank', fontsize=7)
ax.tick_params(axis='both', labelsize=7)
sns.despine()
        
fig.savefig('../../../Figures/Cumulative_dist_primary_rank_secondary_hit.png', bbox_inches='tight', dpi=300)
gpp.savefig('../../../Figures/Cumulative_dist_primary_rank_secondary_hit.pdf', bbox_inches='tight', dpi=300)<jupyter_output><empty_output><jupyter_text>Secondary screen Heatmaps  KO<jupyter_code>cell_line_dicts = {'A549':A549_dict, 'Huh7_5': Huh7_5_dict, 'Caco2': Caco2_dict, 'Calu3': Calu3_KO_dict}
secondary_KO_dict = {}

for cell_line, dictionary in cell_line_dicts.items():
    secondary_key = [key for key in dictionary.keys() if 'secondary' in key][0]
    secondary_df = dictionary[secondary_key]
    for col in secondary_df.columns:
        if 'zscore' in col:
            new_col_name = col + '_' + cell_line
            secondary_df = secondary_df.rename(columns={col:new_col_name})
    secondary_dict_key = cell_line + '_' + secondary_key
    secondary_KO_dict[cell_line] = secondary_df

secondary_KO_df = fns.merge_dict_dfs(secondary_KO_dict)
rank_cols = [col for col in secondary_KO_df.columns if 'Rank' in col]
secondary_KO_df['Avg_Rank'] = secondary_KO_df[rank_cols].mean(axis=1)

secondary_KO_heatmap_res_df = secondary_KO_df.copy().drop(rank_cols, axis=1)

zscore_cols = [col for col in secondary_KO_heatmap_res_df.columns if 'zscore' in col and 'Rank' not in col]
# Sort by average rank
secondary_KO_heatmap_res_rank_df = select_top_ranks(secondary_KO_heatmap_res_df, cols_to_rank=zscore_cols, rank=7)#.set_index('Gene Symbol').sort_values('Avg_Rank')

mentioned_KO_genes = ['VPS29', 'ATP8B1', 'HSPA5']

# for gene in mentioned_KO_genes:
mentioned_KO_df = secondary_KO_heatmap_res_df[secondary_KO_heatmap_res_df['Gene Symbol'].isin(mentioned_KO_genes)]

secondary_KO_heatmap_res_df = pd.concat([secondary_KO_heatmap_res_rank_df, mentioned_KO_df])

secondary_KO_heatmap_res_df = secondary_KO_heatmap_res_df.set_index('Gene Symbol').drop_duplicates().sort_values('Avg_Rank')

secondary_KO_heatmap_res_df = secondary_KO_heatmap_res_df.drop('Avg_Rank', axis=1)

ylabels = ['A549', 'Huh7.5.1', 'Caco-2', 'Calu-3']

g = sns.heatmap(secondary_KO_heatmap_res_df.T, mask = secondary_KO_heatmap_res_df.T.isnull(), cmap = gpp.diverging_cmap(), square=True, yticklabels=ylabels,xticklabels=True,#yticklabels=ylabels,
                center=0, annot=False, cbar_kws={'orientation':'horizontal','shrink':0.5,'extend':'both', 'label':'z-score', 'pad':0.25}, linecolor='white', linewidths=0.5, vmin = -6, vmax = 6);#, 'orientation': orientation});#, vmin = vmin, vmax = vmax, fmt='.2f')

plt.title('Secondary KO Gene Hits (Resistance)', fontsize=7)
plt.yticks(rotation = 0, fontsize=7)
plt.xticks(fontsize=7)
plt.xlabel('Gene Symbol',fontsize=7);

fig.savefig('../../../Figures/Heatmaps/SecondaryKOHeatmapComparison_res.png', bbox_inches='tight', dpi=300)
gpp.savefig('../../../Figures/Heatmaps/SecondaryKOHeatmapComparison_res.pdf', bbox_inches='tight', dpi=300)


cell_line_dicts = {'A549':A549_dict, 'Huh7_5': Huh7_5_dict, 'Caco2': Caco2_dict, 'Calu3': Calu3_KO_dict}
secondary_KO_dict = {}

for cell_line, dictionary in cell_line_dicts.items():
    secondary_key = [key for key in dictionary.keys() if 'secondary' in key][0]
    secondary_df = dictionary[secondary_key]
    for col in secondary_df.columns:
        if 'zscore' in col:
            new_col_name = col + '_' + cell_line
            secondary_df = secondary_df.rename(columns={col:new_col_name})
    secondary_dict_key = cell_line + '_' + secondary_key
    secondary_KO_dict[cell_line] = secondary_df

secondary_KO_df = fns.merge_dict_dfs(secondary_KO_dict)
rank_cols = [col for col in secondary_KO_df.columns if 'Rank' in col]
secondary_KO_df['Avg_Rank'] = secondary_KO_df[rank_cols].mean(axis=1)

secondary_KO_heatmap_sen_df = secondary_KO_df.copy().drop(rank_cols, axis=1)

zscore_cols = [col for col in secondary_KO_heatmap_sen_df.columns if 'zscore' in col and 'Rank' not in col]
# Sort by average rank
secondary_KO_heatmap_sen_df = select_top_ranks(secondary_KO_heatmap_sen_df, cols_to_rank=zscore_cols, rank=7, largest=False).set_index('Gene Symbol').sort_values('Avg_Rank')


secondary_KO_heatmap_sen_df = secondary_KO_heatmap_sen_df.drop('Avg_Rank', axis=1)

ylabels = ['A549', 'Huh7.5.1', 'Caco-2', 'Calu-3']

g = sns.heatmap(secondary_KO_heatmap_sen_df.T, mask = secondary_KO_heatmap_sen_df.T.isnull(), cmap = gpp.diverging_cmap(), square=True, yticklabels=ylabels,xticklabels=True,#yticklabels=ylabels,
                center=0, annot=False, cbar_kws={'orientation':'horizontal','shrink':0.5,'extend':'both', 'label':'z-score', 'pad':0.35}, linecolor='white', linewidths=0.5, vmin = -6, vmax = 6);#, 'orientation': orientation});#, vmin = vmin, vmax = vmax, fmt='.2f')

plt.title('Secondary KO Gene Hits (Sensitization)', fontsize=7)
plt.yticks(rotation = 0, fontsize=7)
plt.xticks(fontsize=7)
plt.xlabel('Gene Symbol',fontsize=7);

fig.savefig('../../../Figures/Heatmaps/SecondaryKOHeatmapComparison_sen.png', bbox_inches='tight', dpi=300)
gpp.savefig('../../../Figures/Heatmaps/SecondaryKOHeatmapComparison_sen.pdf', bbox_inches='tight', dpi=300)


rank_cols = [col for col in secondary_KO_df.columns if 'Rank' in col]
secondary_KO_corr_df = secondary_KO_df.drop(rank_cols, axis=1)[1:]

for col in secondary_KO_corr_df.columns:
    if 'Huh' in col:
        new_col = 'Huh7.5.1'
    else:
        new_col = col.split('_')[-1]
    secondary_KO_corr_df = secondary_KO_corr_df.rename(columns={col:new_col})
# fig, ax = plt.subplots()

sns.heatmap(secondary_KO_corr_df.corr(), cmap = gpp.diverging_cmap(), center=0, annot=True)
plt.title('Secondary KO Cell Line Correlations');
fig = plt.gcf()

fig.savefig('../../../Figures/SecondaryKOCellLineCorrelations.png', bbox_inches = 'tight', dpi=300)<jupyter_output><empty_output><jupyter_text>Activation<jupyter_code>secondary_Act_dict = {}

secondary_Act_dict['A549'] = pd.read_excel('../../../Data/Processed/GEO_submission_v2/SecondaryLibrary/A549_SecondaryLibraryAct_Goujon.xlsx')
secondary_Act_dict['Huh7_5'] = pd.read_excel('../../../Data/Processed/GEO_submission_v2/SecondaryLibrary/Huh751_SecondaryLibraryAct_Goujon.xlsx')
secondary_Act_dict['Caco2'] = pd.read_excel('../../../Data/Processed/GEO_submission_v2/SecondaryLibrary/Caco2_SecondaryLibraryAct_Goujon.xlsx')
secondary_Act_dict['Calu3'] = Calu3_Act_dict['secondary_Act_Goujon']

for cell_line, df in secondary_Act_dict.items():
    for col in df.columns:
        if 'zscore' in col:
            new_col_name = col + '_secondary_Act_' + cell_line
            df = df.copy().rename(columns={col:new_col_name})
    secondary_Act_dict[cell_line] = df


secondary_Act_df = fns.merge_dict_dfs(secondary_Act_dict)
rank_cols = [col for col in secondary_Act_df.columns if 'Rank' in col]
secondary_Act_df['Avg_Rank'] = secondary_Act_df[rank_cols].mean(axis=1)

secondary_Act_heatmap_res_df = secondary_Act_df.copy().drop(rank_cols, axis=1)

zscore_cols = [col for col in secondary_Act_heatmap_res_df.columns if 'zscore' in col and 'Rank' not in col]


# Sort by average rank
secondary_Act_heatmap_res_df = secondary_Act_heatmap_res_df[secondary_Act_heatmap_res_df['Gene Symbol']!='URGCP-MRPS24']

secondary_Act_heatmap_res_df = select_top_ranks(secondary_Act_heatmap_res_df, cols_to_rank=zscore_cols, rank=7, largest=False).set_index('Gene Symbol').sort_values('Avg_Rank')


secondary_Act_heatmap_res_df = secondary_Act_heatmap_res_df.drop('Avg_Rank', axis=1)

ylabels = ['A549', 'Huh7.5.1', 'Caco-2', 'Calu-3']

g = sns.heatmap(secondary_Act_heatmap_res_df.T, mask = secondary_Act_heatmap_res_df.T.isnull(), cmap = gpp.diverging_cmap(), square=True, yticklabels=ylabels,xticklabels=True,#yticklabels=ylabels,
                center=0, annot=False, cbar_kws={'orientation':'horizontal','shrink':0.5,'extend':'both', 'label':'z-score', 'pad':0.4}, linecolor='white', linewidths=0.5, vmin = -6, vmax = 6);#, 'orientation': orientation});#, vmin = vmin, vmax = vmax, fmt='.2f')

plt.title('Secondary Activation Gene Hits (Resistance)', fontsize=7)
plt.yticks(rotation = 0, fontsize=7)
plt.xticks(fontsize=7)
plt.xlabel('Gene Symbol',fontsize=7);

fig.savefig('../../../Figures/Heatmaps/SecondaryActHeatmapComparison_res.png', bbox_inches='tight', dpi=300)
gpp.savefig('../../../Figures/Heatmaps/SecondaryActHeatmapComparison_res.pdf', bbox_inches='tight', dpi=300)





secondary_Act_df = fns.merge_dict_dfs(secondary_Act_dict)
rank_cols = [col for col in secondary_Act_df.columns if 'Rank' in col]
secondary_Act_df['Avg_Rank'] = secondary_Act_df[rank_cols].mean(axis=1)

secondary_Act_heatmap_df = secondary_Act_df.copy().drop(rank_cols, axis=1)

zscore_cols = [col for col in secondary_Act_heatmap_df.columns if 'zscore' in col and 'Rank' not in col]
# Sort by average rank
secondary_Act_heatmap_df = select_top_ranks(secondary_Act_heatmap_df, cols_to_rank=zscore_cols, rank=7).set_index('Gene Symbol').sort_values('Avg_Rank')


secondary_Act_heatmap_df = secondary_Act_heatmap_df.drop('Avg_Rank', axis=1)

ylabels = ['A549', 'Huh7.5.1', 'Caco-2', 'Calu-3']

g = sns.heatmap(secondary_Act_heatmap_df.T, mask = secondary_Act_heatmap_df.T.isnull(), cmap = gpp.diverging_cmap(), square=True, yticklabels=ylabels,xticklabels=True,#yticklabels=ylabels,
                center=0, annot=False, cbar_kws={'orientation':'horizontal','shrink':0.5,'extend':'both', 'label':'z-score', 'pad':0.4}, linecolor='white', linewidths=0.5, vmin = -6, vmax = 6);#, 'orientation': orientation});#, vmin = vmin, vmax = vmax, fmt='.2f')

plt.title('Secondary Activation Gene Hits (Sensitization)', fontsize=7)
plt.yticks(rotation = 0, fontsize=7)
plt.xticks(fontsize=7)
plt.xlabel('Gene Symbol',fontsize=7);

fig.savefig('../../../Figures/Heatmaps/SecondaryActHeatmapComparison_sen.png', bbox_inches='tight', dpi=300)
gpp.savefig('../../../Figures/Heatmaps/SecondaryActHeatmapComparison_sen.pdf', bbox_inches='tight', dpi=300)<jupyter_output><empty_output><jupyter_text>Secondary Screen data compilation  KO<jupyter_code>secondary_Cas9KO_annotation_df = pd.read_csv('../../../Data/Interim/Goujon/Secondary_Library/CP1658_GRCh38_NCBI_strict_gene_20210604.chip', sep='\t')
secondary_Cas9KO_annotation_df


secondary_Cas12aKO_annotation_df = pd.read_csv('../../../Data/Interim/Goujon/Secondary_Library/CP1660_sars_Cas12a_KO_secondary_library.csv', header=None)
secondary_Cas12aKO_annotation_df.columns = ['Construct Barcode', 'Gene_mapping']

for i in range(len(secondary_Cas12aKO_annotation_df)):
    secondary_Cas12aKO_annotation_df.loc[i, 'Gene Symbol'] = secondary_Cas12aKO_annotation_df.loc[i, 'Gene_mapping'].split(';')[0].split(':')[0]
secondary_Cas12aKO_annotation_df
# Rename Calu-3 key to specify Calu-3 Cas9 
if 'Calu3' in secondary_KO_dict.keys():
    secondary_KO_dict['Calu3_Cas9'] = secondary_KO_dict['Calu3']
    secondary_KO_dict.pop('Calu3')

# Add Cas12a data
secondary_KO_dict['Calu3_Cas12a'] = pd.read_excel('../../../Data/Processed/GEO_submission_v2/SecondaryLibrary/Calu3_Cas12a_SecondaryLibraryKO_Goujon.xlsx')

# Add column that flags controls
secondary_KO_control_dict = {}
secondary_KO_control_dict['SecondaryCas9KOLibraryMapping'] = secondary_Cas9KO_annotation_df
secondary_KO_control_dict['SecondaryCas12aKOLibraryMapping'] = secondary_Cas12aKO_annotation_df
for key,df in secondary_KO_dict.items():
    if key == 'Huh7_5':
        key = '<KEY>'
    if 'Cas' not in key:
        new_key = key + '_Cas9'
    else:
        new_key = key
    secondary_KO_control_dict[new_key] = add_control_col(df, ['ONE_INTERGENIC_SITE'])

secondary_KO_control_dict

with pd.ExcelWriter('../../../Data/Processed/GEO_Submission_v2/SecondaryLibrary/SecondaryKOscreens.xlsx') as writer: 
    for key, df in secondary_KO_control_dict.items():
        df.to_excel(writer, sheet_name=key, index =False)<jupyter_output><empty_output><jupyter_text>Activation<jupyter_code>secondary_Act_annotation_df = pd.read_csv('../../../Data/Interim/Goujon/Secondary_Library/CP1663_GRCh38_NCBI_strict_gene_20210707.chip', sep='\t')
secondary_Act_annotation_df

# Add column that flags controls
secondary_Act_control_dict = {}
secondary_Act_control_dict['Secondary Act Library Mapping'] = secondary_Act_annotation_df
for key,df in secondary_Act_dict.items():
    secondary_Act_control_dict[key] = add_control_col(df, ['ONE_INTERGENIC_SITE'])

secondary_Act_control_dict
with pd.ExcelWriter('../../../Data/Processed/GEO_Submission_v2/SecondaryLibrary/SecondaryActivationScreens.xlsx') as writer: 
    for key, df in secondary_Act_control_dict.items():
        df.to_excel(writer, sheet_name=key, index =False)<jupyter_output><empty_output><jupyter_text>Secondary KO vs Act Scatterplots<jupyter_code>for cell_line, ko_df in secondary_KO_dict.items():
    ko_zscore_col = [col for col in ko_df.columns if 'zscore' in col and 'Rank' not in col][0]
    act_df = secondary_Act_dict[cell_line]
    act_zscore_col = [col for col in act_df.columns if 'zscore' in col and 'Rank' not in col][0]
    actvsko_df = pd.merge(ko_df, act_df, on = 'Gene Symbol', how = 'inner')
    print(len(actvsko_df))
    
    fig, ax = plt.subplots(figsize=(2,2))
    ax = gpp.point_densityplot(actvsko_df, ko_zscore_col, act_zscore_col, s=6)
    ax = gpp.add_correlation(actvsko_df, ko_zscore_col, act_zscore_col, fontsize=7)
    
    # Annotate
    top_ranked_ko_df = actvsko_df.nlargest(3, ko_zscore_col)
    bottom_ranked_ko_df = actvsko_df.nsmallest(3, ko_zscore_col)
    top_ranked_act_df = actvsko_df.nlargest(3, act_zscore_col)
    bottom_ranked_act_df = actvsko_df.nsmallest(3, act_zscore_col)
    
    ranked_ko_df = pd.concat([top_ranked_ko_df, bottom_ranked_ko_df])
    ranked_act_df = pd.concat([top_ranked_act_df, bottom_ranked_act_df])
    annot_df = pd.concat([ranked_ko_df, ranked_act_df])
    
    sns.scatterplot(data=annot_df, x=ko_zscore_col, y=act_zscore_col, color = sns.color_palette('Set2')[0], edgecolor=None, s=6)
    texts= []
    for j, row in annot_df.iterrows():
        texts.append(ax.text(row[ko_zscore_col]+0.25, row[act_zscore_col], row['Gene Symbol'], fontsize=7,
                                      color = 'black'))
    sns.despine()
    plt.title(cell_line+ ' CRISPRa vs KO', fontsize=7)
    plt.xlabel('KO (Mean z-score)', fontsize=7)
    plt.ylabel('CRISPRa (Mean z-score)', fontsize=7)
    
    gpp.savefig('../../../Figures/Scatterplots/'+cell_line+'SecondaryActvsKOscatterplot.pdf', dpi=300)
    
    
    
#     print(actvsko_df)<jupyter_output>179
179
179
179<jupyter_text>Replicate correlations sample sizes<jupyter_code>screen_level_KO_dict = {}
screen_level_KO_dict['A549'] = pd.read_excel('../../../Data/Processed/Individual_screens_v2/A549_Cas9SecondaryLibraryKO_Goujon_indiv_screens.xlsx')
screen_level_KO_dict['Calu3'] = pd.read_excel('../../../Data/Processed/Individual_screens_v2/SecondaryLibraryIndivScreens/Calu3_SecondaryLibraryKO_Goujon_indiv_screens.xlsx')
screen_level_KO_dict['Caco2'] = pd.read_excel('../../../Data/Processed/Individual_screens_v2/Caco2_Cas9SecondaryLibraryKO_Goujon_indiv_screens.xlsx')
screen_level_KO_dict['Huh7_5'] = pd.read_excel('../../../Data/Processed/Individual_screens_v2/Huh751_Cas9SecondaryLibraryKO_Goujon_indiv_screens.xlsx')


screen_level_Act_dict = {}
screen_level_Act_dict['A549'] = pd.read_excel('../../../Data/Processed/Individual_screens_v2/SecondaryLibraryIndivScreens/A549_SecondaryLibraryAct_Goujon.xlsx')
screen_level_Act_dict['Calu3'] = pd.read_excel('../../../Data/Processed/Individual_screens_v2/SecondaryLibraryIndivScreens/Calu3_SecondaryLibraryAct_Goujon_indiv_screens.xlsx')
screen_level_Act_dict['Caco2'] = pd.read_excel('../../../Data/Processed/Individual_screens_v2/Caco2_SecondaryLibraryAct_Goujon_indiv_screens.xlsx')
screen_level_Act_dict['Huh7_5'] = pd.read_excel('../../../Data/Processed/Individual_screens_v2/SecondaryLibraryIndivScreens/Huh751_SecondaryLibraryAct_Goujon.xlsx')


for key, df in screen_level_KO_dict.items():
    print(key)
#     ko_df_1 = df[df['condition'].str.contains('#1')]
#     ko_df_2 = df[df['condition'].str.contains('#2')]
#     ko_z_df = pd.merge(ko_df_1[['Gene Symbol', 'residual_zscore']], ko_df_2[['Gene Symbol', 'residual_zscore']], on = 'Gene Symbol', how = 'outer', suffixes = ['_screen#1', '_screen#2'])
    ko_df = df
    
    act_df = screen_level_Act_dict[key]
#     act_df_1 = act_df[act_df['condition'].str.contains('#1')]
#     act_df_2 = act_df[act_df['condition'].str.contains('#2')]
#     act_z_df = pd.merge(act_df_1[['Gene Symbol', 'residual_zscore']], act_df_2[['Gene Symbol', 'residual_zscore']], on = 'Gene Symbol', how = 'outer', suffixes = ['_screen#1', '_screen#2'])
    
    
#     act_df = screen_level_Act_dict[key]
    print(key, 'KO', len(ko_df.dropna().drop_duplicates()))
    print(key, 'Act', len(act_df.dropna().drop_duplicates()))<jupyter_output>A549
A549 KO 677
A549 Act 1640
Calu3
Calu3 KO 677
Calu3 Act 820
Caco2
Caco2 KO 677
Caco2 Act 820
Huh7_5
Huh7_5 KO 677
Huh7_5 Act 1640
{'fraction_non_alphanumeric': 0.1410149932246361, 'fraction_numerical': 0.02736372776150719, 'mean_word_length': 5.868207745421795, 'pattern_counts': {'":': 0, '<': 36, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '652306', 'license': 'MIT', 'n_tokens_mistral': 9498, 'n_tokens_neox': 8765, 'n_words': 1240, 'path': 'SecondaryScreens/Resubmission_Figures.ipynb', 'repo_name': 'PriyankaRoy5/SARS-CoV-2-meta-analysis', 'size': '22880'}