parse contact matrices from PDBbind and store in chunks
Browse files- pdbbind.py +82 -9
- pdbbind.slurm +3 -3
- pdbbind_contacts.npy +0 -0
pdbbind.py
CHANGED
@@ -1,26 +1,96 @@
|
|
1 |
from mpi4py import MPI
|
2 |
from mpi4py.futures import MPICommExecutor
|
3 |
|
4 |
-
|
5 |
-
from Bio import
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
import os
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
def parse_complex(fn):
|
9 |
try:
|
10 |
name = os.path.basename(fn)
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
return None
|
17 |
|
18 |
|
19 |
if __name__ == '__main__':
|
20 |
import glob
|
21 |
|
22 |
-
filenames = glob.glob('pdbbind/
|
23 |
-
filenames.extend(glob.glob('pdbbind/
|
24 |
comm = MPI.COMM_WORLD
|
25 |
with MPICommExecutor(comm, root=0) as executor:
|
26 |
if executor is not None:
|
@@ -29,7 +99,10 @@ if __name__ == '__main__':
|
|
29 |
names = [r[0] for r in result if r is not None]
|
30 |
seqs = [r[1] for r in result if r is not None]
|
31 |
all_smiles = [r[2] for r in result if r is not None]
|
|
|
32 |
|
33 |
import pandas as pd
|
34 |
df = pd.DataFrame({'name': names, 'seq': seqs, 'smiles': all_smiles})
|
|
|
|
|
35 |
df.to_parquet('data/pdbbind_complex.parquet')
|
|
|
1 |
from mpi4py import MPI
|
2 |
from mpi4py.futures import MPICommExecutor
|
3 |
|
4 |
+
import warnings
|
5 |
+
from Bio.PDB import PDBParser, PPBuilder, CaPPBuilder
|
6 |
+
from Bio.PDB.NeighborSearch import NeighborSearch
|
7 |
+
from Bio.PDB.Selection import unfold_entities
|
8 |
+
|
9 |
+
import numpy as np
|
10 |
+
import dask.array as da
|
11 |
+
|
12 |
+
from rdkit import Chem
|
13 |
|
14 |
import os
|
15 |
+
import re
|
16 |
+
|
17 |
+
# all punctuation
|
18 |
+
punctuation_regex = r"""(\(|\)|\.|=|#|-|\+|\\|\/|:|~|@|\?|>>?|\*|\$|\%[0-9]{2}|[0-9])"""
|
19 |
+
|
20 |
+
# tokenization regex (Schwaller)
|
21 |
+
molecule_regex = r"""(\[[^\]]+]|Br?|Cl?|N|O|S|P|F|I|b|c|n|o|s|p|\(|\)|\.|=|#|-|\+|\\|\/|:|~|@|\?|>>?|\*|\$|\%[0-9]{2}|[0-9])"""
|
22 |
+
|
23 |
+
cutoff = 5
|
24 |
+
max_seq = 2048
|
25 |
+
max_smiles = 512
|
26 |
+
chunk_size = '1G'
|
27 |
+
|
28 |
def parse_complex(fn):
|
29 |
try:
|
30 |
name = os.path.basename(fn)
|
31 |
+
|
32 |
+
# parse protein sequence and coordinates
|
33 |
+
parser = PDBParser()
|
34 |
+
with warnings.catch_warnings():
|
35 |
+
warnings.simplefilter("ignore")
|
36 |
+
structure = parser.get_structure('protein',fn+'/'+name+'_protein.pdb')
|
37 |
+
|
38 |
+
# ppb = PPBuilder()
|
39 |
+
ppb = CaPPBuilder()
|
40 |
+
seq = []
|
41 |
+
for pp in ppb.build_peptides(structure):
|
42 |
+
seq.append(str(pp.get_sequence()))
|
43 |
+
seq = ''.join(seq)
|
44 |
+
|
45 |
+
# parse ligand, convert to SMILES and map atoms
|
46 |
+
suppl = Chem.SDMolSupplier(fn+'/'+name+'_ligand.sdf')
|
47 |
+
mol = next(suppl)
|
48 |
+
smi = Chem.MolToSmiles(mol)
|
49 |
+
|
50 |
+
# position of atoms in SMILES (not counting punctuation)
|
51 |
+
atom_order = mol.GetProp("_smilesAtomOutputOrder")
|
52 |
+
atom_order = [int(s) for s in list(filter(None,re.sub(r'[\[\]]','',mol.GetProp("_smilesAtomOutputOrder")).split(',')))]
|
53 |
+
|
54 |
+
# tokenize the SMILES
|
55 |
+
tokens = list(filter(None, re.split(molecule_regex, smi)))
|
56 |
+
|
57 |
+
# remove punctuation
|
58 |
+
masked_tokens = [re.sub(punctuation_regex,'',s) for s in tokens]
|
59 |
+
|
60 |
+
k = 0
|
61 |
+
token_pos = []
|
62 |
+
token_id = []
|
63 |
+
for i,token in enumerate(masked_tokens):
|
64 |
+
if token != '':
|
65 |
+
token_pos.append(tuple(mol.GetConformer().GetAtomPosition(atom_order[k])))
|
66 |
+
token_id.append(i)
|
67 |
+
k += 1
|
68 |
+
|
69 |
+
# query protein for ligand contacts
|
70 |
+
atoms = unfold_entities(structure, 'A')
|
71 |
+
neighbor_search = NeighborSearch(atoms)
|
72 |
+
|
73 |
+
close_residues = [neighbor_search.search(center=t, level='R', radius=cutoff) for t in token_pos]
|
74 |
+
residue_id = [[c.get_id()[1]-1 for c in query] for query in close_residues] # zero-based
|
75 |
+
|
76 |
+
# contact map
|
77 |
+
contact_map = np.zeros((max_seq, max_smiles),dtype=np.float32)
|
78 |
+
|
79 |
+
for query,t in zip(residue_id,token_id):
|
80 |
+
for r in query:
|
81 |
+
contact_map[r,t] = 1
|
82 |
+
|
83 |
+
return name, seq, smi, contact_map
|
84 |
+
except Exception as e:
|
85 |
+
print(e)
|
86 |
return None
|
87 |
|
88 |
|
89 |
if __name__ == '__main__':
|
90 |
import glob
|
91 |
|
92 |
+
filenames = glob.glob('data/pdbbind/v2020-other-PL/*')
|
93 |
+
filenames.extend(glob.glob('data/pdbbind/refined-set/*'))
|
94 |
comm = MPI.COMM_WORLD
|
95 |
with MPICommExecutor(comm, root=0) as executor:
|
96 |
if executor is not None:
|
|
|
99 |
names = [r[0] for r in result if r is not None]
|
100 |
seqs = [r[1] for r in result if r is not None]
|
101 |
all_smiles = [r[2] for r in result if r is not None]
|
102 |
+
all_contacts = [r[3] for r in result if r is not None]
|
103 |
|
104 |
import pandas as pd
|
105 |
df = pd.DataFrame({'name': names, 'seq': seqs, 'smiles': all_smiles})
|
106 |
+
all_contacts = da.from_array(all_contacts, chunks=chunk_size)
|
107 |
+
da.to_npy_stack('data/pdbbind_contacts/', all_contacts)
|
108 |
df.to_parquet('data/pdbbind_complex.parquet')
|
pdbbind.slurm
CHANGED
@@ -1,9 +1,9 @@
|
|
1 |
#!/bin/bash
|
2 |
#SBATCH -J preprocess_pdbbind
|
3 |
-
#SBATCH -p
|
4 |
#SBATCH -A STF006
|
5 |
#SBATCH -t 3:00:00
|
6 |
-
#SBATCH -N
|
7 |
-
#SBATCH --ntasks-per-node=
|
8 |
|
9 |
srun python pdbbind.py
|
|
|
1 |
#!/bin/bash
|
2 |
#SBATCH -J preprocess_pdbbind
|
3 |
+
#SBATCH -p gpu
|
4 |
#SBATCH -A STF006
|
5 |
#SBATCH -t 3:00:00
|
6 |
+
#SBATCH -N 2
|
7 |
+
#SBATCH --ntasks-per-node=16
|
8 |
|
9 |
srun python pdbbind.py
|
pdbbind_contacts.npy
ADDED
File without changes
|