binding_affinity / deepcoy_combine.py
jglaser's picture
update predictions for D-COID and deepcoy/DEKOIS
c066e7c
import dask.dataframe as dd
import pandas as pd
import sys
import os
import numpy as np
from Bio.PDB import PDBList
from Bio import SeqIO
from rdkit import Chem
import warnings
def get_sequence(pdb_id):
try:
pdbfile = PDBList().retrieve_pdb_file(pdb_id.upper(),file_format='pdb',pdir='/tmp')
seq = str(next(SeqIO.parse(pdbfile, "pdb-seqres")).seq)
os.unlink(pdbfile)
return seq
except Exception as e:
print(e)
pass
def make_canonical(smi):
return Chem.MolToSmiles(Chem.MolFromSmiles(smi))
if __name__ == '__main__':
import glob
filenames = glob.glob(sys.argv[3])
seqs = []
smiles = []
active = []
targets = pd.read_csv(sys.argv[1],sep=' ',keep_default_na=False)
for fn in filenames:
df = pd.read_csv(fn,header=None,sep=' ')
df[0] = df[0].apply(make_canonical)
df[1] = df[1].apply(make_canonical)
actives = df[0].unique()
decoys = df[1].unique()
smiles += actives.tolist()+decoys.tolist()
active += [True]*len(actives) + [False]*len(decoys)
split = os.path.basename(fn).split('-')
target = split[2].upper()
if len(split) > 5:
target += '-'+split[3].upper()
print(target)
seq = get_sequence(targets[targets.name.str.upper()==target].pdb.values[0])
seqs += [seq]*(len(actives)+len(decoys))
ddf = dd.from_pandas(pd.DataFrame({'seq': seqs, 'smiles': smiles, 'active': active}),npartitions=1)
ddf = ddf.repartition(partition_size='1M')
ddf.to_parquet(sys.argv[2])