{ "cells": [ { "cell_type": "code", "execution_count": 14, "id": "c47a32d8-c857-41de-a70a-cec48046df12", "metadata": {}, "outputs": [], "source": [ "import pandas as pd" ] }, { "cell_type": "code", "execution_count": 24, "id": "e0c6bd53-3417-44bd-b1b4-81802b37fbfc", "metadata": {}, "outputs": [], "source": [ "df = pd.read_csv('binding_moad/every.csv',header=None,skiprows=2)\n", "df = df.rename(columns={2:'pdb',3: 'ligand_name', 4: 'ligand_valid', 5: 'affinity_quantity',\n", " 7: 'affinity_val', 8: 'affinity_unit', 9:'smiles'})\n", "#df = df[df['ligand_valid']!='invalid'].copy()" ] }, { "cell_type": "code", "execution_count": 25, "id": "e40b1ddc-9a98-4a3b-b8a6-45e3940a3ea2", "metadata": {}, "outputs": [], "source": [ "df['is_sep'] = df[1] == 'Family. Representative Entry is '" ] }, { "cell_type": "code", "execution_count": 26, "id": "4f00a0d1-78db-4f32-9d12-5e035b70ef98", "metadata": {}, "outputs": [], "source": [ "df['cum_sum'] = df['is_sep'].cumsum()" ] }, { "cell_type": "code", "execution_count": 27, "id": "ebaeb749-656e-4b92-8dbd-2e29eefdcad5", "metadata": {}, "outputs": [], "source": [ "quantities = ['ki','kd','ka','k1/2','kb']" ] }, { "cell_type": "code", "execution_count": 28, "id": "52c0c66c-1eb0-415b-b019-bc77419ccbd7", "metadata": {}, "outputs": [], "source": [ "from pint import UnitRegistry\n", "ureg = UnitRegistry()\n", "\n", "def to_uM(affinity_unit):\n", " try:\n", " val = ureg(str(affinity_unit[0])+str(affinity_unit[1]))\n", " return val.m_as(ureg.uM)\n", " except Exception:\n", " pass\n", " \n", " try:\n", " val = ureg(str(affinity_unit[0])+str(affinity_unit[1]))\n", " return 1/val.m_as(1/ureg.uM)\n", " except Exception:\n", " pass" ] }, { "cell_type": "code", "execution_count": 29, "id": "e5b4dd41-1389-408d-bee6-6dbeefc1d5c7", "metadata": {}, "outputs": [], "source": [ "groupby = df.groupby('cum_sum')" ] }, { "cell_type": "code", "execution_count": 30, "id": "61b8276c-54fe-4989-af5f-723994e1df7e", "metadata": {}, "outputs": [], "source": [ "def group(df):\n", " pdb = df[df['is_sep']]['pdb'].values\n", " if len(pdb) > 0:\n", " pdb = pdb[0]\n", " df['pdb_ref'] = pdb\n", " return df[df['ligand_valid']=='valid']\n", "df_expand = groupby.apply(group).reset_index(drop=True)" ] }, { "cell_type": "code", "execution_count": 31, "id": "342c8ef3-6808-471b-baa4-f9bdc7f6e8d6", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "88806" ] }, "execution_count": 31, "metadata": {}, "output_type": "execute_result" } ], "source": [ "len(df_expand)" ] }, { "cell_type": "code", "execution_count": 34, "id": "8bb2dfac-5f11-455c-9dee-3607b47b4232", "metadata": {}, "outputs": [], "source": [ "df_expand['affinity_uM'] = df_expand[['affinity_val','affinity_unit']].apply(to_uM,axis=1)" ] }, { "cell_type": "code", "execution_count": 35, "id": "b5c0fa42-b595-4b96-b2d5-57f0031427dc", "metadata": {}, "outputs": [], "source": [ "df_filter = df_expand[df_expand['affinity_quantity'].str.lower().isin(quantities)]" ] }, { "cell_type": "code", "execution_count": 38, "id": "27c4865b-5337-48e0-9be7-a913b31cfae1", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "88806" ] }, "execution_count": 38, "metadata": {}, "output_type": "execute_result" } ], "source": [ "len(df_expand)" ] }, { "cell_type": "code", "execution_count": 37, "id": "f3daf4ad-0205-48c0-8c38-36aa4eb561e0", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "17724" ] }, "execution_count": 37, "metadata": {}, "output_type": "execute_result" } ], "source": [ "len(df_filter)" ] }, { "cell_type": "code", "execution_count": 47, "id": "0dc39f62-5b18-4a86-9a44-17d1925da2ad", "metadata": {}, "outputs": [], "source": [ "df_complex = pd.read_parquet('data/moad_complex.parquet')\n", "df_complex['name'] = df_complex['name'].str.upper()" ] }, { "cell_type": "code", "execution_count": 48, "id": "6d158a41-64c6-4fa2-92d5-562aa11e8924", "metadata": {}, "outputs": [], "source": [ "df_all = df_filter.merge(df_complex,left_on='pdb_ref',right_on='name')" ] }, { "cell_type": "code", "execution_count": 49, "id": "901fe6c6-dc8c-4ce4-82c6-1fb0b718287a", "metadata": {}, "outputs": [], "source": [ "df_all = df_all[~df_all['affinity_val'].isnull()]" ] }, { "cell_type": "code", "execution_count": 50, "id": "383f9a1c-ffc6-43da-ac5a-5bcb815be28b", "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", " \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", " \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", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
01pdbligand_nameligand_validaffinity_quantity6affinity_valaffinity_unitsmiles10is_sepcum_sumpdb_refaffinity_uMnameseq
0NaNNaNNaN2PA:C:613validKi=0.62nMNP(=O)(N)ONaNFalse16H8J0.0006206H8JNYIVPGEYRVAEGEIEINAGREKTTIRVSNTGDRPIQVGSHIHFVE...
1NaNNaNNaNHAE:C:800validKi=2.60uMCC(=O)NONaNFalse16H8J2.6000006H8JNYIVPGEYRVAEGEIEINAGREKTTIRVSNTGDRPIQVGSHIHFVE...
2NaNNaNNaNADN:A:901validKd=15.00uMc1nc(c2c(n1)n(cn2)[C@H]3[C@@H]([C@@H]([C@H](O3...NaNFalse52GL015.0000002GL0MTDMSIKFELIDVPIPQGTNVIIGQAHFIKTVEDLYEALVTSVPGV...
3NaNNaNNaNADN:B:902validKd=15.00uMc1nc(c2c(n1)n(cn2)[C@H]3[C@@H]([C@@H]([C@H](O3...NaNFalse52GL015.0000002GL0MTDMSIKFELIDVPIPQGTNVIIGQAHFIKTVEDLYEALVTSVPGV...
4NaNNaNNaNADN:C:903validKd=15.00uMc1nc(c2c(n1)n(cn2)[C@H]3[C@@H]([C@@H]([C@H](O3...NaNFalse52GL015.0000002GL0MTDMSIKFELIDVPIPQGTNVIIGQAHFIKTVEDLYEALVTSVPGV...
......................................................
17682NaNNaNNaNMAN NAG:G:1validKa=7860.00M^-1NaNNaNFalse104992WDB127.2264632WDBMGSSHHHHHHSSGLVPRGSHMASNPSLIRSESWQVYEGNEANLLDG...
17683NaNNaNNaNMAN NAG:F:1validKa=7860.00M^-1NaNNaNFalse104992WDB127.2264632WDBMGSSHHHHHHSSGLVPRGSHMASNPSLIRSESWQVYEGNEANLLDG...
17684NaNNaNNaNNGA NAG:F:1validKa=5910.00M^-1NaNNaNFalse104992WDB169.2047382WDBMGSSHHHHHHSSGLVPRGSHMASNPSLIRSESWQVYEGNEANLLDG...
17685NaNNaNNaNNGA NAG:E:1validKa=5910.00M^-1NaNNaNFalse104992WDB169.2047382WDBMGSSHHHHHHSSGLVPRGSHMASNPSLIRSESWQVYEGNEANLLDG...
17686NaNNaNNaNNGA NAG:H:1validKa=5910.00M^-1NaNNaNFalse104992WDB169.2047382WDBMGSSHHHHHHSSGLVPRGSHMASNPSLIRSESWQVYEGNEANLLDG...
\n", "

17687 rows × 17 columns

\n", "
" ], "text/plain": [ " 0 1 pdb ligand_name ligand_valid affinity_quantity 6 \\\n", "0 NaN NaN NaN 2PA:C:613 valid Ki = \n", "1 NaN NaN NaN HAE:C:800 valid Ki = \n", "2 NaN NaN NaN ADN:A:901 valid Kd = \n", "3 NaN NaN NaN ADN:B:902 valid Kd = \n", "4 NaN NaN NaN ADN:C:903 valid Kd = \n", "... ... ... ... ... ... ... .. \n", "17682 NaN NaN NaN MAN NAG:G:1 valid Ka = \n", "17683 NaN NaN NaN MAN NAG:F:1 valid Ka = \n", "17684 NaN NaN NaN NGA NAG:F:1 valid Ka = \n", "17685 NaN NaN NaN NGA NAG:E:1 valid Ka = \n", "17686 NaN NaN NaN NGA NAG:H:1 valid Ka = \n", "\n", " affinity_val affinity_unit \\\n", "0 0.62 nM \n", "1 2.60 uM \n", "2 15.00 uM \n", "3 15.00 uM \n", "4 15.00 uM \n", "... ... ... \n", "17682 7860.00 M^-1 \n", "17683 7860.00 M^-1 \n", "17684 5910.00 M^-1 \n", "17685 5910.00 M^-1 \n", "17686 5910.00 M^-1 \n", "\n", " smiles 10 is_sep cum_sum \\\n", "0 NP(=O)(N)O NaN False 1 \n", "1 CC(=O)NO NaN False 1 \n", "2 c1nc(c2c(n1)n(cn2)[C@H]3[C@@H]([C@@H]([C@H](O3... NaN False 5 \n", "3 c1nc(c2c(n1)n(cn2)[C@H]3[C@@H]([C@@H]([C@H](O3... NaN False 5 \n", "4 c1nc(c2c(n1)n(cn2)[C@H]3[C@@H]([C@@H]([C@H](O3... NaN False 5 \n", "... ... .. ... ... \n", "17682 NaN NaN False 10499 \n", "17683 NaN NaN False 10499 \n", "17684 NaN NaN False 10499 \n", "17685 NaN NaN False 10499 \n", "17686 NaN NaN False 10499 \n", "\n", " pdb_ref affinity_uM name \\\n", "0 6H8J 0.000620 6H8J \n", "1 6H8J 2.600000 6H8J \n", "2 2GL0 15.000000 2GL0 \n", "3 2GL0 15.000000 2GL0 \n", "4 2GL0 15.000000 2GL0 \n", "... ... ... ... \n", "17682 2WDB 127.226463 2WDB \n", "17683 2WDB 127.226463 2WDB \n", "17684 2WDB 169.204738 2WDB \n", "17685 2WDB 169.204738 2WDB \n", "17686 2WDB 169.204738 2WDB \n", "\n", " seq \n", "0 NYIVPGEYRVAEGEIEINAGREKTTIRVSNTGDRPIQVGSHIHFVE... \n", "1 NYIVPGEYRVAEGEIEINAGREKTTIRVSNTGDRPIQVGSHIHFVE... \n", "2 MTDMSIKFELIDVPIPQGTNVIIGQAHFIKTVEDLYEALVTSVPGV... \n", "3 MTDMSIKFELIDVPIPQGTNVIIGQAHFIKTVEDLYEALVTSVPGV... \n", "4 MTDMSIKFELIDVPIPQGTNVIIGQAHFIKTVEDLYEALVTSVPGV... \n", "... ... \n", "17682 MGSSHHHHHHSSGLVPRGSHMASNPSLIRSESWQVYEGNEANLLDG... \n", "17683 MGSSHHHHHHSSGLVPRGSHMASNPSLIRSESWQVYEGNEANLLDG... \n", "17684 MGSSHHHHHHSSGLVPRGSHMASNPSLIRSESWQVYEGNEANLLDG... \n", "17685 MGSSHHHHHHSSGLVPRGSHMASNPSLIRSESWQVYEGNEANLLDG... \n", "17686 MGSSHHHHHHSSGLVPRGSHMASNPSLIRSESWQVYEGNEANLLDG... \n", "\n", "[17687 rows x 17 columns]" ] }, "execution_count": 50, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df_all" ] }, { "cell_type": "code", "execution_count": 51, "id": "bebc962b-10f7-478c-8e23-e2d3722e875c", "metadata": {}, "outputs": [], "source": [ "df_all[['pdb','ligand_name','smiles','name','affinity_uM','seq']].to_parquet('data/moad.parquet')" ] }, { "cell_type": "code", "execution_count": null, "id": "49a160d6-4599-488a-ba02-a65a79535f38", "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 }