{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "ecce356e-321b-441e-8a5d-a20bf72f8691", "metadata": {}, "outputs": [], "source": [ "import dask.dataframe as dd" ] }, { "cell_type": "code", "execution_count": 2, "id": "89cbcd82-4ca2-4aba-95b7-e58c0ceed770", "metadata": {}, "outputs": [], "source": [ "cols = ['Ligand SMILES', 'IC50 (nM)','KEGG ID of Ligand','Ki (nM)', 'Kd (nM)','EC50 (nM)']" ] }, { "cell_type": "code", "execution_count": 3, "id": "a870d8d7-374b-4474-b9ee-305bbf9f17a9", "metadata": {}, "outputs": [], "source": [ "import tqdm.notebook" ] }, { "cell_type": "code", "execution_count": null, "id": "e9f76b32-e8f0-47ee-b592-a91a88f4f93e", "metadata": {}, "outputs": [], "source": [ "for i in tqdm.notebook.tqdm(range(0,13)):\n", " mycol = 'BindingDB Target Chain Sequence.{}'.format(i)\n", " allseq = ['BindingDB Target Chain Sequence']+['BindingDB Target Chain Sequence.{}'.format(j) for j in range(1,13)]\n", " dtypes = {'BindingDB Target Chain Sequence.{}'.format(i): 'object' for i in range(1,13)}\n", " dtypes.update({'BindingDB Target Chain Sequence': 'object',\n", " 'IC50 (nM)': 'object',\n", " 'KEGG ID of Ligand': 'object',\n", " 'Ki (nM)': 'object',\n", " 'Kd (nM)': 'object',\n", " 'EC50 (nM)': 'object',\n", " 'koff (s-1)': 'object'})\n", " ddf = dd.read_csv('bindingdb/data/BindingDB_All.tsv',sep='\\t',error_bad_lines=False,blocksize=16*1024*1024,\n", " usecols=cols+allseq,\n", " dtype=dtypes)\n", " ddf = ddf.reset_index()\n", " ddf = ddf.rename(columns={'BindingDB Target Chain Sequence.{}'.format(j): 'seq_{}'.format(j) for j in range(1,13)})\n", " ddf = ddf.rename(columns={'BindingDB Target Chain Sequence': 'seq_0'})\n", " ddf = ddf.drop(columns={'seq_{}'.format(j) for j in range(0,13) if i != j})\n", " ddf[cols+['seq_{}'.format(i)]].to_parquet('bindingdb/parquet_data/target{}'.format(i),schema='infer')" ] }, { "cell_type": "code", "execution_count": 68, "id": "be79bbcf-0622-4d1e-8f08-a723a4167d8b", "metadata": {}, "outputs": [], "source": [ "ddfs = []\n", "for i in range(0,13):\n", " ddf = dd.read_parquet('bindingdb/parquet_data/target{}'.format(i))\n", " ddf = ddf.rename(columns={'seq_{}'.format(i): 'seq'})\n", " ddfs.append(ddf)" ] }, { "cell_type": "code", "execution_count": 69, "id": "35ca09cb-6264-4526-b504-0d29236a03c1", "metadata": {}, "outputs": [], "source": [ "ddf = dd.concat(ddfs)" ] }, { "cell_type": "code", "execution_count": 70, "id": "ba518a9a-0d15-47be-977b-e2dfe2511529", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
Ligand SMILESIC50 (nM)KEGG ID of LigandKi (nM)Kd (nM)EC50 (nM)seq
0COc1cc2c(Nc3ccc(Br)cc3F)ncnc2cc1OCC1CCN(C)CC1NoneNone0.24NoneNonePQITLWQRPLVTIKIGGQLKEALLDTGADDTVLEEMSLPGRWKPKM...
1O[C@@H]1[C@@H](O)[C@@H](Cc2ccccc2)N(C\\C=C\\c2cn...NoneNone0.25NoneNonePQITLWQRPLVTIKIGGQLKEALLDTGADDTVLEEMSLPGRWKPKM...
2O[C@@H]1[C@@H](O)[C@@H](Cc2ccccc2)N(CC2CC2)C(=...NoneNone0.41NoneNonePQITLWQRPLVTIKIGGQLKEALLDTGADDTVLEEMSLPGRWKPKM...
3OCCCCCCN1[C@H](Cc2ccccc2)[C@H](O)[C@@H](O)[C@@...NoneNone0.8NoneNonePQITLWQRPLVTIKIGGQLKEALLDTGADDTVLEEMSLPGRWKPKM...
4OCCCCCN1[C@H](Cc2ccccc2)[C@H](O)[C@@H](O)[C@@H...NoneNone0.99NoneNonePQITLWQRPLVTIKIGGQLKEALLDTGADDTVLEEMSLPGRWKPKM...
\n", "
" ], "text/plain": [ " Ligand SMILES IC50 (nM) \\\n", "0 COc1cc2c(Nc3ccc(Br)cc3F)ncnc2cc1OCC1CCN(C)CC1 None \n", "1 O[C@@H]1[C@@H](O)[C@@H](Cc2ccccc2)N(C\\C=C\\c2cn... None \n", "2 O[C@@H]1[C@@H](O)[C@@H](Cc2ccccc2)N(CC2CC2)C(=... None \n", "3 OCCCCCCN1[C@H](Cc2ccccc2)[C@H](O)[C@@H](O)[C@@... None \n", "4 OCCCCCN1[C@H](Cc2ccccc2)[C@H](O)[C@@H](O)[C@@H... None \n", "\n", " KEGG ID of Ligand Ki (nM) Kd (nM) EC50 (nM) \\\n", "0 None 0.24 None None \n", "1 None 0.25 None None \n", "2 None 0.41 None None \n", "3 None 0.8 None None \n", "4 None 0.99 None None \n", "\n", " seq \n", "0 PQITLWQRPLVTIKIGGQLKEALLDTGADDTVLEEMSLPGRWKPKM... \n", "1 PQITLWQRPLVTIKIGGQLKEALLDTGADDTVLEEMSLPGRWKPKM... \n", "2 PQITLWQRPLVTIKIGGQLKEALLDTGADDTVLEEMSLPGRWKPKM... \n", "3 PQITLWQRPLVTIKIGGQLKEALLDTGADDTVLEEMSLPGRWKPKM... \n", "4 PQITLWQRPLVTIKIGGQLKEALLDTGADDTVLEEMSLPGRWKPKM... " ] }, "execution_count": 70, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ddf.head()" ] }, { "cell_type": "code", "execution_count": 71, "id": "f504d7aa-dfc1-4346-a136-8814c4b5d979", "metadata": {}, "outputs": [], "source": [ "ddf.repartition(partition_size='25MB').to_parquet('bindingdb/parquet_data/all_targets',schema='infer')" ] }, { "cell_type": "code", "execution_count": 4, "id": "d7eafa69-4606-4b34-ae8f-8c6462dcb004", "metadata": {}, "outputs": [], "source": [ "ddf = dd.read_parquet('bindingdb/parquet_data/all_targets')" ] }, { "cell_type": "code", "execution_count": 5, "id": "b151868a-0cd6-405e-8401-f79918fb0b07", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
Dask DataFrame Structure:
\n", "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
Ligand SMILESIC50 (nM)KEGG ID of LigandKi (nM)Kd (nM)EC50 (nM)seq
npartitions=459
objectobjectobjectobjectobjectobjectobject
.....................
........................
.....................
.....................
\n", "
\n", "
Dask Name: read-parquet, 459 tasks
" ], "text/plain": [ "Dask DataFrame Structure:\n", " Ligand SMILES IC50 (nM) KEGG ID of Ligand Ki (nM) Kd (nM) EC50 (nM) seq\n", "npartitions=459 \n", " object object object object object object object\n", " ... ... ... ... ... ... ...\n", "... ... ... ... ... ... ... ...\n", " ... ... ... ... ... ... ...\n", " ... ... ... ... ... ... ...\n", "Dask Name: read-parquet, 459 tasks" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ddf" ] }, { "cell_type": "code", "execution_count": 6, "id": "c00102b8-f4be-4ebd-8d30-7a2c7fc2d05e", "metadata": {}, "outputs": [], "source": [ "ddf_nonnull = ddf[~ddf.seq.isnull()].copy()" ] }, { "cell_type": "code", "execution_count": 7, "id": "c5337e06-1e45-4180-90ed-49ac9ecdd24a", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
Ligand SMILESIC50 (nM)KEGG ID of LigandKi (nM)Kd (nM)EC50 (nM)seq
4453CC(C)C[C@H](NC(=O)N1CCC(CC1)C(=O)Nc1ccc(cc1)-c...9.4NoneNoneNoneNoneMSYDRAITVFSPDGHLFQVEYAQEAVKKGSTAVGVRGRDIVVLGVE...
4454CC(C)C[C@H](NC(=O)[C@H](Cc1ccccc1)NC(=O)c1cncc...11NoneNoneNoneNoneMSYDRAITVFSPDGHLFQVEYAQEAVKKGSTAVGVRGRDIVVLGVE...
4455CC(C)C[C@H](NC(=O)N1CCCC(C1)C(=O)Nc1cnccn1)C(=...355NoneNoneNoneNoneMSYDRAITVFSPDGHLFQVEYAQEAVKKGSTAVGVRGRDIVVLGVE...
4456COc1ccc(NC(=O)N2CCC(CC2)C(=O)N[C@@H](CC(C)C)C(...17NoneNoneNoneNoneMSYDRAITVFSPDGHLFQVEYAQEAVKKGSTAVGVRGRDIVVLGVE...
4457CC(C)C[C@H](NC(=O)C1CCN(CC1)C(=O)Nc1cnccn1)C(=...76NoneNoneNoneNoneMSYDRAITVFSPDGHLFQVEYAQEAVKKGSTAVGVRGRDIVVLGVE...
\n", "
" ], "text/plain": [ " Ligand SMILES IC50 (nM) \\\n", "4453 CC(C)C[C@H](NC(=O)N1CCC(CC1)C(=O)Nc1ccc(cc1)-c... 9.4 \n", "4454 CC(C)C[C@H](NC(=O)[C@H](Cc1ccccc1)NC(=O)c1cncc... 11 \n", "4455 CC(C)C[C@H](NC(=O)N1CCCC(C1)C(=O)Nc1cnccn1)C(=... 355 \n", "4456 COc1ccc(NC(=O)N2CCC(CC2)C(=O)N[C@@H](CC(C)C)C(... 17 \n", "4457 CC(C)C[C@H](NC(=O)C1CCN(CC1)C(=O)Nc1cnccn1)C(=... 76 \n", "\n", " KEGG ID of Ligand Ki (nM) Kd (nM) EC50 (nM) \\\n", "4453 None None None None \n", "4454 None None None None \n", "4455 None None None None \n", "4456 None None None None \n", "4457 None None None None \n", "\n", " seq \n", "4453 MSYDRAITVFSPDGHLFQVEYAQEAVKKGSTAVGVRGRDIVVLGVE... \n", "4454 MSYDRAITVFSPDGHLFQVEYAQEAVKKGSTAVGVRGRDIVVLGVE... \n", "4455 MSYDRAITVFSPDGHLFQVEYAQEAVKKGSTAVGVRGRDIVVLGVE... \n", "4456 MSYDRAITVFSPDGHLFQVEYAQEAVKKGSTAVGVRGRDIVVLGVE... \n", "4457 MSYDRAITVFSPDGHLFQVEYAQEAVKKGSTAVGVRGRDIVVLGVE... " ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ddf_nonnull.tail()" ] }, { "cell_type": "code", "execution_count": 8, "id": "872edb84-3459-43d9-8e0e-e2a6b5d281eb", "metadata": {}, "outputs": [], "source": [ "from pint import UnitRegistry\n", "import numpy as np\n", "import re\n", "ureg = UnitRegistry()\n", "\n", "def to_uM(affinities):\n", " ic50, Ki, Kd, ec50 = affinities\n", "\n", " vals = []\n", " try:\n", " ic50 = ureg(str(ic50)+'nM').m_as(ureg.uM)\n", " vals.append(ic50)\n", " except:\n", " pass\n", "\n", " try:\n", " Ki = ureg(str(Ki)+'nM').m_as(ureg.uM)\n", " vals.append(Ki)\n", " except:\n", " pass\n", "\n", " try:\n", " Kd = ureg(str(Kd)+'nM').m_as(ureg.uM)\n", " vals.append(Kd)\n", " except:\n", " pass\n", "\n", " try:\n", " ec50 = ureg(str(ec50)+'nM').m_as(ureg.uM)\n", " vals.append(ec50)\n", " except:\n", " pass\n", "\n", " if len(vals) > 0:\n", " vals = np.array(vals)\n", " return np.mean(vals[~np.isnan(vals)])\n", " \n", " return None" ] }, { "cell_type": "code", "execution_count": 9, "id": "b3cff13c-19b2-4413-a84b-d99062f516a7", "metadata": {}, "outputs": [], "source": [ "df_nonnull = ddf_nonnull.compute()" ] }, { "cell_type": "code", "execution_count": 10, "id": "f11834ef-2b8f-4123-816c-5e54ca92a07a", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Collecting pandarallel\n", " Using cached pandarallel-1.5.2.tar.gz (16 kB)\n", "Collecting dill\n", " Using cached dill-0.3.3-py2.py3-none-any.whl (81 kB)\n", "Building wheels for collected packages: pandarallel\n", " Building wheel for pandarallel (setup.py) ... \u001b[?25ldone\n", "\u001b[?25h Created wheel for pandarallel: filename=pandarallel-1.5.2-py3-none-any.whl size=18384 sha256=d611c0def59d5c3b807ccd787aeba685a821000f283d6082fce6b37d77b4d542\n", " Stored in directory: /autofs/nccs-svm1_home1/glaser/.cache/pip/wheels/6e/10/a9/c46b278fe836832830eb22a6a781a8379262d9a82ae87009c1\n", "Successfully built pandarallel\n", "Installing collected packages: dill, pandarallel\n", "Successfully installed dill-0.3.3 pandarallel-1.5.2\n" ] } ], "source": [ "!pip install pandarallel" ] }, { "cell_type": "code", "execution_count": 12, "id": "ca9795de-e821-4dc3-a7bf-70ade9e4c7f0", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "INFO: Pandarallel will run on 32 workers.\n", "INFO: Pandarallel will use Memory file system to transfer data between the main process and workers.\n" ] } ], "source": [ "from pandarallel import pandarallel\n", "pandarallel.initialize()\n" ] }, { "cell_type": "code", "execution_count": 13, "id": "4356a3e2-fede-48e7-a486-343661fe0a0a", "metadata": {}, "outputs": [], "source": [ "df_affinity = df_nonnull.copy()\n", "df_affinity['affinity_uM'] = df_affinity[['IC50 (nM)', 'Ki (nM)', 'Kd (nM)','EC50 (nM)']].parallel_apply(to_uM,axis=1)" ] }, { "cell_type": "code", "execution_count": 15, "id": "e91c3af8-84a5-42a2-9e25-49cb2f320b0b", "metadata": {}, "outputs": [], "source": [ "df_affinity[~df_affinity['affinity_uM'].isnull()].to_parquet('data/bindingdb.parquet')" ] }, { "cell_type": "code", "execution_count": 18, "id": "27194288-cf3e-4c30-ad55-3b0998fdf939", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
Ligand SMILESIC50 (nM)KEGG ID of LigandKi (nM)Kd (nM)EC50 (nM)seqaffinity_uM
0COc1cc2c(Nc3ccc(Br)cc3F)ncnc2cc1OCC1CCN(C)CC1NoneNone0.24NoneNonePQITLWQRPLVTIKIGGQLKEALLDTGADDTVLEEMSLPGRWKPKM...0.00024
1O[C@@H]1[C@@H](O)[C@@H](Cc2ccccc2)N(C\\C=C\\c2cn...NoneNone0.25NoneNonePQITLWQRPLVTIKIGGQLKEALLDTGADDTVLEEMSLPGRWKPKM...0.00025
2O[C@@H]1[C@@H](O)[C@@H](Cc2ccccc2)N(CC2CC2)C(=...NoneNone0.41NoneNonePQITLWQRPLVTIKIGGQLKEALLDTGADDTVLEEMSLPGRWKPKM...0.00041
3OCCCCCCN1[C@H](Cc2ccccc2)[C@H](O)[C@@H](O)[C@@...NoneNone0.8NoneNonePQITLWQRPLVTIKIGGQLKEALLDTGADDTVLEEMSLPGRWKPKM...0.00080
4OCCCCCN1[C@H](Cc2ccccc2)[C@H](O)[C@@H](O)[C@@H...NoneNone0.99NoneNonePQITLWQRPLVTIKIGGQLKEALLDTGADDTVLEEMSLPGRWKPKM...0.00099
\n", "
" ], "text/plain": [ " Ligand SMILES IC50 (nM) \\\n", "0 COc1cc2c(Nc3ccc(Br)cc3F)ncnc2cc1OCC1CCN(C)CC1 None \n", "1 O[C@@H]1[C@@H](O)[C@@H](Cc2ccccc2)N(C\\C=C\\c2cn... None \n", "2 O[C@@H]1[C@@H](O)[C@@H](Cc2ccccc2)N(CC2CC2)C(=... None \n", "3 OCCCCCCN1[C@H](Cc2ccccc2)[C@H](O)[C@@H](O)[C@@... None \n", "4 OCCCCCN1[C@H](Cc2ccccc2)[C@H](O)[C@@H](O)[C@@H... None \n", "\n", " KEGG ID of Ligand Ki (nM) Kd (nM) EC50 (nM) \\\n", "0 None 0.24 None None \n", "1 None 0.25 None None \n", "2 None 0.41 None None \n", "3 None 0.8 None None \n", "4 None 0.99 None None \n", "\n", " seq affinity_uM \n", "0 PQITLWQRPLVTIKIGGQLKEALLDTGADDTVLEEMSLPGRWKPKM... 0.00024 \n", "1 PQITLWQRPLVTIKIGGQLKEALLDTGADDTVLEEMSLPGRWKPKM... 0.00025 \n", "2 PQITLWQRPLVTIKIGGQLKEALLDTGADDTVLEEMSLPGRWKPKM... 0.00041 \n", "3 PQITLWQRPLVTIKIGGQLKEALLDTGADDTVLEEMSLPGRWKPKM... 0.00080 \n", "4 PQITLWQRPLVTIKIGGQLKEALLDTGADDTVLEEMSLPGRWKPKM... 0.00099 " ] }, "execution_count": 18, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df_affinity.head()" ] }, { "cell_type": "code", "execution_count": 17, "id": "603fd298-0aa6-4097-b298-c55db013548c", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "2391969" ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "len(df_affinity)" ] }, { "cell_type": "code", "execution_count": null, "id": "c6ea5a79-facf-4a50-9d7c-2e1864ebad3d", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.4" } }, "nbformat": 4, "nbformat_minor": 5 }