<jupyter_start><jupyter_text>Extract contact residue pairs from sift interface contacts<jupyter_code>features = np.empty((len(pdb_files),15))
for i,(ic,pdb) in enumerate(zip(ic_files,pdb_files)):
    print(ic,pdb)
    ic_features = ArpeggioFeatures(level_sift="normal")
    ic_features.parse_contactdata(icfile=ic)
    ic_features.parse_pdbdata(pdbfile=pdb)
    
    contacts = ic_features.get_features()
    
    
    features[i] = contacts
DF_contact_mut = pd.DataFrame(features, index=[pdb.name for pdb in pdb_files],columns=DF_contact_deprecated.columns[:15].str[:-2])
DF_contact_mut.to_csv("../data/DF_contact15_mut_2019.csv",)
DF_contact_mut = pd.read_csv("../data/DF_contact_mut_2019.csv",index_col=0)
#DF_contact_deprecated = pd.read_csv("../data/DF_mutated_features300.v2.csv",index_col=0)
DF_contact_mut.columns =  DF_contact_deprecated.drop("ddG(kcal/mol)",axis=1).columns
DF_contact_mut.to_csv("../data/DF_contact300_mut_2019.csv")<jupyter_output><empty_output><jupyter_text>Energetic data Mutants<jupyter_code>energetic_features = np.empty((len(pdb_files),29))

try:
    os.chdir(PDBS_MUT)
    
    for i,pdb in enumerate(pdb_files):
        partners = ab_bind_mCSM_HM["Partners(A_B)"].iloc[i]
        foldx = FoldX(verbose=False)
        result_analyse = foldx.analyse_complex(pdb_file=pdb.name, partners=partners)
        energetic_features[i] = result_analyse
finally:
    os.chdir(CWD)

DF_energetic_mut = pd.DataFrame(energetic_features,index=[pdb.name for pdb in pdb_files])
DF_energetic_mut.to_csv("../data/DF_energetic_mut.csv")<jupyter_output><empty_output><jupyter_text>Wildtype<jupyter_code>pdb_partner = (ab_bind_mCSM_HM["#PDB"]+"/"+ab_bind_mCSM_HM["Partners(A_B)"]).unique()

pdbwt_files = list(PDBS_WT.glob("*clean.pdb"))

energetic_features_wt = np.empty((len(pdbwt_files),29))

try:
    os.chdir(PDBS_WT)
    
    for i,pdb in enumerate(pdbwt_files):
        partners = pdb_partner[i].split("/")[1]
        foldx = FoldX(verbose=False)
        result_analyse = foldx.analyse_complex(pdb_file=pdb.name, partners=partners)
        energetic_features_wt[i] = result_analyse
finally:
    os.chdir(CWD)
DF_energetic_wt = pd.DataFrame(energetic_features_wt,index=[pdb.name for pdb in pdbwt_files])
DF_energetic_wt.head()
DF_energetic_wt.to_csv("../data/DF_energetic_wt.csv")<jupyter_output><empty_output><jupyter_text>Energetic features wt and mut, merge dataframes<jupyter_code>from AbPred.FoldX import names_stability_complex_mut,names_stability_complex_wt

DF_energetic_mut = pd.read_csv("../data/DF_energetic_mut.csv",index_col=0)
DF_energetic_wt = pd.read_csv("../data/DF_energetic_wt.csv",index_col=0)
DF_energetic_mut.columns = names_stability_complex_mut
DF_energetic_wt.columns = names_stability_complex_wt
pdbmut_index_code = DF_energetic_mut.index.str.split(".",expand=True).get_level_values(0)

DF_energetic_mut['codes'] = pdbmut_index_code
DF_energetic_mut.reset_index(inplace=True)
DF_energetic_mut.set_index('codes',inplace=True)
DF_energetic_wt['codes'] = DF_energetic_wt.index.str[:-17]
DF_energetic_wt.reset_index(inplace=True)
DF_energetic_wt.set_index('codes',inplace=True)
DF_energetic_wt_mut = DF_energetic_mut.merge(DF_energetic_wt,on='codes')
def convert_features_to_differences(df, keep_mut=False):
    """Convert `_wt` and `_mut` columns into `_wt` and `_change` columns.
    Create a new set of features (ending in `_change`) that describe the difference between values
    of the wildtype (features ending in `_wt`) and mutant (features ending in `_mut`) features.
    If `keep_mut` is `False`, removes all mutant features (features ending in `_mut`).
    """
    column_list = []
    for column_name, column in df.iteritems():
        if ('_mut' in column_name and column_name.replace('_mut', '_wt') in df.columns and
                df[column_name].dtype != object):
            if keep_mut:
                column_list.append(column)
            new_column = column - df[column_name.replace('_mut', '_wt')]
            if 'secondary_structure' in column_name:
                new_column = new_column.apply(lambda x: 1 if x else 0)
            new_column.name = column_name.replace('_mut', '_change')
            column_list.append(new_column)
        else:
            column_list.append(column)
    new_df = pd.concat(column_list, axis=1)
    return new_df
DF_energetic_changes =  convert_features_to_differences(DF_energetic_wt_mut,keep_mut=False)
DF_energetic_changes<jupyter_output><empty_output><jupyter_text>POPS interface asa,  mutant and wt<jupyter_code>def get_pdb_chain(pdb,partner,outdir):
    protein = prody.parsePDB(pdb,chain=partner)
    pdbwrited = prody.writePDB(str(outdir.resolve())+"/"+"%s_%s" % (pdb.name[:-4], partner), protein)
    print("writing %s_%s" % (pdb.name[:-4], partner))
    return pdbwrited
# MUtant interface sasas calculate as (TA + TB - T) / 2.0.
# When T=total sas complex, TA= total sasa partner A , TB=total sasa partner B.

outfolder = Path('popout')
if not outfolder.exists():
    outfolder.mkdir()
complexMUT_sasas = list()
partnerA_MUT_sasas = list()
partnerB_MUT_sasas = list()
for i,pdb in enumerate(pdb_files):
    
    pp = ab_bind_mCSM_HM["Partners(A_B)"].iloc[i]
    
    # Calculate sasa for complex
    asa_data = run_pops(str(pdb.resolve()), outdir=outfolder, mode='total')
    pops_complex = POPS_parse2(asa_data, mode='total') 
    complexMUT_sasas.append(list(pops_complex.values()))
    
    # Calculate sasa for partner A
    pdbA = get_pdb_chain(pdb.resolve(),partner=pp.split("_")[0],outdir=outfolder)
    asa_data = run_pops(pdbA, outdir=outfolder, mode='total')
    pops_A = POPS_parse2(asa_data, mode='total') 
    partnerA_MUT_sasas.append(list(pops_A.values()))
    
    # Calculate sasa for partner B
    pdbB = get_pdb_chain(pdb.resolve(),partner=pp.split("_")[1],outdir=outfolder)
    asa_data = run_pops(pdbB, outdir=outfolder, mode='total')
    pops_B = POPS_parse2(asa_data, mode='total') 
    partnerB_MUT_sasas.append(list(pops_B.values()))

    
    
    

complexMUT_sasas = [list(p) for p in complexMUT_sasas]
partnerA_MUT_sasas = [list(p) for p in partnerA_MUT_sasas]
partnerB_MUT_sasas = [list(p) for p in partnerB_MUT_sasas]
# To numpy arrays
complexMUT_sasas = np.asarray(complexMUT_sasas)
partnerA_MUT_sasas = np.asarray(partnerA_MUT_sasas)
partnerB_MUT_sasas = np.asarray(partnerB_MUT_sasas)
# Phil, Phob, Total , interface sasa
interface_asa_MUT = ((partnerA_MUT_sasas + partnerB_MUT_sasas) - complexMUT_sasas)/2
interface_asa_MUT.shape
# Pandas dataframe
interface_asa_MUT_df = pd.DataFrame(interface_asa_MUT,columns=["if_phil","if_phob","if_total"],index=[pdb.name for pdb in pdb_files])
interface_asa_MUT_df["sasa_phil_mut"] = complexMUT_sasas.T[0]
interface_asa_MUT_df["sasa_phob_mut"] = complexMUT_sasas.T[1]
interface_asa_MUT_df["sasa_total_mut"] = complexMUT_sasas.T[2]

interface_asa_MUT_df.to_csv("../data/sasa_mut.csv")<jupyter_output><empty_output><jupyter_text>WT asa<jupyter_code># WT sasa
pdbwt_files = list(PDBS_WT.glob("*clean.pdb"))
outfolder = Path('popout')
if not outfolder.exists():
    outfolder.mkdir()
complexWT_sasas = list()
for pdb in pdbwt_files:
        
    # Calculate sasa for complex
    asa_data = run_pops(str(pdb.resolve()), outdir=outfolder, mode='total')
    pops_complex = POPS_parse2(asa_data, mode='total') 
    complexWT_sasas.append(list(pops_complex.values()))
complexWT_sasas = np.asarray(complexWT_sasas)
asa_WT_df = pd.DataFrame(complexWT_sasas,columns=["sasa_phil_wt","sasa_phob_wt","sasa_wt"],index=[pdb.name for pdb in pdbwt_files])<jupyter_output><empty_output><jupyter_text>merge data<jupyter_code>interface_asa_MUT_df = pd.read_csv("../data/sasa_mut.csv",index_col=0)
interface_mut_index_code = interface_asa_MUT_df.index.str.split(".",expand=True).get_level_values(0)

# set new index equal to pdb code name
interface_asa_MUT_df['codes'] = interface_mut_index_code
interface_asa_MUT_df.reset_index(inplace=True)
interface_asa_MUT_df.set_index('codes',inplace=True)
# set new index equal to pdb code name
asa_WT_df['codes'] = asa_WT_df.index.str[:-17]
asa_WT_df.reset_index(inplace=True)
asa_WT_df.set_index('codes',inplace=True)
DF_sasa_wt_mut = interface_asa_MUT_df.merge(asa_WT_df,on='codes')
DF_sasa_wt_mut = DF_sasa_wt_mut.set_index("index_x").drop("index_y",axis=1)
DF_sasa_wt_mut.index.name = None
DF_sasa_wt_mut.to_csv("../data/sasa_mut_wt.csv")<jupyter_output><empty_output><jupyter_text>merge with contact energy data<jupyter_code># 15 contact data
DF_contact15energy = pd.read_csv("../data/DF_contact15_energy_2019.csv",index_col=0)
DF_contact15energy_sasa = DF_contact15energy.drop("ddG_exp",axis=1).join(DF_sasa_wt_mut).join(DF_contact15energy["ddG_exp"])
DF_contact15energy_sasa.to_csv("../data/DF_contact15_energy_sasa.csv")
DF_contact_energy_sasa = DF_tomerge.join(DF_sasa_wt_mut)
DF_contact_energy_sasa.to_csv("../data/DF_contact400_energy_sasa_2019.csv")<jupyter_output><empty_output><jupyter_text>final dataframe<jupyter_code>DF_energetic_changes.reset_index(drop=True,inplace=True)
DF_energetic_changes.drop(["index_y",'number_of_residues_y'],axis=1,inplace=True)
DF_energetic_changes.set_index('index_x',inplace=True)
DF_energetic_changes.index.name = None
DF_contact_energy = DF_contact_mut.join(DF_energetic_changes)
DF_contact15['ddG_exp'] = -ab_bind_mCSM_HM["ddG(kcal/mol)"].values.astype(float)
DF_contact_energy.to_csv("../data/DF_contact15_energy_2019.csv")
DF_contact_energy
np.corrcoef(DF_energetic_changes.dg_change,-ab_bind_mCSM_HM["ddG(kcal/mol)"])
%matplotlib inline
(-ab_bind_mCSM_HM["ddG(kcal/mol)"]).hist()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1278753659556671, 'fraction_numerical': 0.010351317440401506, 'mean_word_length': 6.329501915708812, 'pattern_counts': {'":': 0, '<': 37, '<?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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '346015', 'license': 'MIT', 'n_tokens_mistral': 3904, 'n_tokens_neox': 3800, 'n_words': 483, 'path': 'notebooks/5-Train_Data.ipynb', 'repo_name': 'victorfica/Master-thesis', 'size': '9564'}