File size: 1,585 Bytes
fe94b5c
 
 
 
 
 
 
 
 
c066e7c
 
fe94b5c
 
 
 
 
 
 
 
 
 
 
 
 
c066e7c
 
 
fe94b5c
 
 
 
 
 
 
 
 
 
 
 
c066e7c
 
fe94b5c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
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])