Datasets:
File size: 27,222 Bytes
24fff69 | 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 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 | {
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "63b89129-eb15-489c-acae-c6255df4d9f0",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/home/ubuntu/.local/lib/python3.8/site-packages/pandas/core/computation/expressions.py:20: UserWarning: Pandas requires version '2.7.3' or newer of 'numexpr' (version '2.7.1' currently installed).\n",
" from pandas.core.computation.check import NUMEXPR_INSTALLED\n",
"/home/ubuntu/.local/lib/python3.8/site-packages/Bio/pairwise2.py:278: BiopythonDeprecationWarning: Bio.pairwise2 has been deprecated, and we intend to remove it in a future release of Biopython. As an alternative, please consider using Bio.Align.PairwiseAligner as a replacement, and contact the Biopython developers if you still need the Bio.pairwise2 module.\n",
" warnings.warn(\n"
]
}
],
"source": [
"# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n",
"# SPDX-License-Identifier: MIT-0\n",
"\n",
"\"\"\"\n",
"Parse PDB files to extract the coordinates of the 4 key atoms from AAs to\n",
"generate json records compatible to the LM-GVP model.\n",
"\n",
"This script is intended for Fluorescence and Protease datasets from TAPE.\n",
"\"\"\"\n",
"\n",
"import json\n",
"import os\n",
"import argparse\n",
"from collections import defaultdict\n",
"import pandas as pd\n",
"import numpy as np\n",
"\n",
"from tqdm import tqdm\n",
"from joblib import Parallel, delayed\n",
"from Bio.PDB import PDBParser\n",
"from Bio.PDB.Polypeptide import three_to_one\n",
"\n",
"import xpdb\n",
"from contact_map_utils import parse_pdb_structure\n",
"\n",
"\n",
"def parse_args():\n",
" \"\"\"Prepare argument parser.\n",
"\n",
" Args:\n",
"\n",
" Return:\n",
"\n",
" \"\"\"\n",
" parser = argparse.ArgumentParser(\n",
" description=\"Generate GVP ProteinGraph datasets representing protein\"\n",
" + \"structures.\"\n",
" )\n",
" parser.add_argument(\n",
" \"--data-file\",\n",
" help=\"Path to protein data frame, including sequences, paths to\"\n",
" + \" structure files and labels\",\n",
" required=True,\n",
" )\n",
" parser.add_argument(\n",
" \"-t\",\n",
" \"--target-variable\",\n",
" help=\"target variable in the protein data frame\",\n",
" required=True,\n",
" )\n",
" parser.add_argument(\"-o\", \"--output\", help=\"output dir for graphs\")\n",
"\n",
" args = parser.parse_args()\n",
" return args\n",
"\n",
"\n",
"def get_atom_coords(residue, target_atoms=[\"N\", \"CA\", \"C\", \"O\"]):\n",
" \"\"\"Extract the coordinates of the target_atoms from an AA residue.\n",
"\n",
" Args:\n",
" residue: a Bio.PDB.Residue object representing the residue.\n",
" target_atoms: Target atoms which residues will be returned.\n",
"\n",
" Retruns:\n",
" Array of residue's target atoms (in the same order as target atoms).\n",
" \"\"\"\n",
" return np.asarray([residue[atom].coord for atom in target_atoms])\n",
"\n",
"\n",
"def structure_to_coords(struct, target_atoms=[\"N\", \"CA\", \"C\", \"O\"], name=\"\"):\n",
" \"\"\"Convert a PDB structure in to coordinates of target atoms from all AAs\n",
"\n",
" Args:\n",
" struct: a Bio.PDB.Structure object representing the protein structure\n",
" target_atoms: Target atoms which residues will be returned.\n",
" name: String. Name of the structure\n",
"\n",
" Return:\n",
" Dictionary with the pdb sequence, atom 3D coordinates and name.\n",
" \"\"\"\n",
" output = {}\n",
" # get AA sequence in the pdb structure\n",
" pdb_seq = \"\".join(\n",
" [three_to_one(res.get_resname()) for res in struct.get_residues()]\n",
" )\n",
" output[\"seq\"] = pdb_seq\n",
" # get the atom coords\n",
" coords = np.asarray(\n",
" [\n",
" get_atom_coords(res, target_atoms=target_atoms)\n",
" for res in struct.get_residues()\n",
" ]\n",
" )\n",
" output[\"coords\"] = coords.tolist()\n",
" output[\"name\"] = name\n",
" return output\n",
"\n",
"\n",
"def parse_pdb_gz_to_json_record(parser, sequence, pdb_file_path, name=\"\"):\n",
" \"\"\"\n",
" Reads and reformats a pdb strcuture into a dictionary.\n",
"\n",
" Args:\n",
" parser: a Bio.PDB.PDBParser or Bio.PDB.MMCIFParser instance.\n",
" sequence: String. Sequence of the structure.\n",
" pdb_file_path: String. Path to the pdb file.\n",
" name: String. Name of the protein.\n",
"\n",
" Return:\n",
" Dictionary with the pdb sequence, atom 3D coordinates and name.\n",
" \"\"\"\n",
" struct = parse_pdb_structure(parser, sequence, pdb_file_path)\n",
" record = structure_to_coords(struct, name=name)\n",
" return record"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "402ad072-edd1-4c04-a4c0-93390862770b",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 11,
"id": "72469cb0-878a-478b-849d-ee88774f3708",
"metadata": {
"collapsed": true,
"jupyter": {
"outputs_hidden": true
}
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"\n",
" 0%| | 0/23197 [00:00<?, ?it/s]\u001b[A\n",
" 0%| | 30/23197 [00:00<05:33, 69.52it/s]\u001b[A\n",
" 0%| | 60/23197 [00:00<03:52, 99.48it/s]\u001b[A\n",
" 0%| | 90/23197 [00:01<04:16, 90.06it/s]\u001b[A\n",
" 1%| | 150/23197 [00:01<02:19, 164.87it/s]\u001b[A\n",
" 1%| | 210/23197 [00:01<01:34, 243.85it/s]\u001b[A\n",
" 0%| | 0/2320 [08:17<?, ?it/s] 436.75it/s]\u001b[A\n",
"\n",
" 2%|▏ | 393/23197 [00:02<02:12, 171.72it/s]\u001b[A\n",
" 2%|▏ | 510/23197 [00:02<01:23, 272.13it/s]\u001b[A\n",
" 3%|▎ | 630/23197 [00:02<01:06, 339.34it/s]\u001b[A\n",
" 3%|▎ | 750/23197 [00:02<00:56, 399.22it/s]\u001b[A\n",
" 4%|▍ | 870/23197 [00:03<00:50, 439.06it/s]\u001b[A\n",
" 4%|▍ | 990/23197 [00:03<00:47, 464.22it/s]\u001b[A\n",
" 5%|▍ | 1110/23197 [00:04<01:36, 227.71it/s]\u001b[A\n",
" 5%|▌ | 1230/23197 [00:04<01:16, 288.41it/s]\u001b[A\n",
" 6%|▌ | 1350/23197 [00:04<01:05, 332.80it/s]\u001b[A\n",
" 6%|▋ | 1470/23197 [00:04<00:57, 380.43it/s]\u001b[A\n",
" 7%|▋ | 1590/23197 [00:05<00:52, 412.55it/s]\u001b[A\n",
" 7%|▋ | 1710/23197 [00:05<00:46, 457.87it/s]\u001b[A\n",
" 8%|▊ | 1830/23197 [00:05<00:45, 471.04it/s]\u001b[A\n",
" 8%|▊ | 1950/23197 [00:06<01:42, 207.42it/s]\u001b[A\n",
" 9%|▉ | 2070/23197 [00:07<01:19, 265.95it/s]\u001b[A\n",
" 9%|▉ | 2190/23197 [00:07<01:05, 321.43it/s]\u001b[A\n",
" 10%|▉ | 2310/23197 [00:07<00:54, 381.64it/s]\u001b[A\n",
" 10%|█ | 2430/23197 [00:07<00:49, 418.37it/s]\u001b[A\n",
" 11%|█ | 2550/23197 [00:07<00:45, 454.37it/s]\u001b[A\n",
" 12%|█▏ | 2670/23197 [00:08<00:43, 474.03it/s]\u001b[A\n",
" 12%|█▏ | 2790/23197 [00:08<00:40, 498.03it/s]\u001b[A\n",
" 13%|█▎ | 2910/23197 [00:08<00:36, 562.53it/s]\u001b[A\n",
" 13%|█▎ | 3030/23197 [00:08<00:39, 511.14it/s]\u001b[A\n",
" 14%|█▎ | 3150/23197 [00:10<01:47, 185.83it/s]\u001b[A\n",
" 14%|█▍ | 3270/23197 [00:10<01:23, 238.75it/s]\u001b[A\n",
" 15%|█▍ | 3390/23197 [00:10<01:07, 295.04it/s]\u001b[A\n",
" 15%|█▌ | 3510/23197 [00:10<00:59, 331.53it/s]\u001b[A\n",
" 16%|█▌ | 3630/23197 [00:11<00:51, 379.40it/s]\u001b[A\n",
" 16%|█▌ | 3750/23197 [00:11<00:45, 432.09it/s]\u001b[A\n",
" 17%|█▋ | 3870/23197 [00:11<00:41, 468.00it/s]\u001b[A\n",
" 17%|█▋ | 3990/23197 [00:11<00:40, 470.86it/s]\u001b[A\n",
" 18%|█▊ | 4110/23197 [00:12<00:39, 481.31it/s]\u001b[A\n",
" 18%|█▊ | 4230/23197 [00:12<00:39, 485.39it/s]\u001b[A\n",
" 19%|█▉ | 4350/23197 [00:14<01:58, 158.62it/s]\u001b[A\n",
" 19%|█▉ | 4470/23197 [00:14<01:31, 204.84it/s]\u001b[A\n",
" 19%|█▉ | 4517/23197 [00:14<01:32, 201.93it/s]\u001b[A\n",
" 20%|█▉ | 4555/23197 [00:14<01:27, 212.57it/s]\u001b[A\n",
" 20%|█▉ | 4620/23197 [00:14<01:14, 250.91it/s]\u001b[A\n",
" 21%|██ | 4779/23197 [00:15<00:44, 417.69it/s]\u001b[A\n",
" 21%|██ | 4881/23197 [00:15<00:36, 508.67it/s]\u001b[A\n",
" 21%|██▏ | 4965/23197 [00:15<00:36, 497.82it/s]\u001b[A\n",
" 22%|██▏ | 5040/23197 [00:15<00:40, 450.07it/s]\u001b[A\n",
" 22%|██▏ | 5160/23197 [00:15<00:38, 468.90it/s]\u001b[A\n",
" 23%|██▎ | 5280/23197 [00:16<00:36, 497.42it/s]\u001b[A\n",
" 23%|██▎ | 5400/23197 [00:16<00:32, 543.94it/s]\u001b[A\n",
" 24%|██▍ | 5520/23197 [00:16<00:32, 545.80it/s]\u001b[A\n",
" 24%|██▍ | 5640/23197 [00:16<00:31, 555.94it/s]\u001b[A\n",
" 25%|██▍ | 5760/23197 [00:16<00:31, 545.56it/s]\u001b[A\n",
" 25%|██▌ | 5880/23197 [00:17<00:30, 561.35it/s]\u001b[A\n",
" 26%|██▌ | 6000/23197 [00:19<02:05, 136.68it/s]\u001b[A\n",
" 26%|██▌ | 6042/23197 [00:19<01:57, 145.48it/s]\u001b[A\n",
" 26%|██▌ | 6079/23197 [00:19<01:49, 156.87it/s]\u001b[A\n",
" 26%|██▋ | 6120/23197 [00:19<01:36, 176.68it/s]\u001b[A\n",
" 27%|██▋ | 6234/23197 [00:19<01:01, 274.74it/s]\u001b[A\n",
" 27%|██▋ | 6300/23197 [00:20<00:52, 321.50it/s]\u001b[A\n",
" 28%|██▊ | 6420/23197 [00:20<00:40, 413.74it/s]\u001b[A\n",
" 28%|██▊ | 6540/23197 [00:20<00:36, 453.33it/s]\u001b[A\n",
" 29%|██▊ | 6660/23197 [00:20<00:34, 478.46it/s]\u001b[A\n",
" 29%|██▉ | 6780/23197 [00:20<00:30, 532.01it/s]\u001b[A\n",
" 30%|██▉ | 6900/23197 [00:20<00:28, 573.82it/s]\u001b[A\n",
" 30%|███ | 7020/23197 [00:21<00:29, 554.08it/s]\u001b[A\n",
" 31%|███ | 7140/23197 [00:21<00:28, 562.69it/s]\u001b[A\n",
" 31%|███▏ | 7260/23197 [00:21<00:28, 555.14it/s]\u001b[A\n",
" 32%|███▏ | 7380/23197 [00:21<00:28, 551.73it/s]\u001b[A\n",
" 32%|███▏ | 7500/23197 [00:22<00:28, 556.21it/s]\u001b[A\n",
" 33%|███▎ | 7620/23197 [00:22<00:27, 574.53it/s]\u001b[A\n",
" 33%|███▎ | 7740/23197 [00:22<00:27, 572.23it/s]\u001b[A\n",
" 34%|███▍ | 7860/23197 [00:22<00:26, 580.83it/s]\u001b[A\n",
" 34%|███▍ | 7980/23197 [00:25<02:11, 116.07it/s]\u001b[A\n",
" 35%|███▍ | 8100/23197 [00:25<01:35, 158.64it/s]\u001b[A\n",
" 35%|███▌ | 8163/23197 [00:26<01:34, 159.20it/s]\u001b[A\n",
" 36%|███▌ | 8250/23197 [00:26<01:16, 195.64it/s]\u001b[A\n",
" 36%|███▌ | 8351/23197 [00:26<00:57, 259.76it/s]\u001b[A\n",
" 36%|███▋ | 8430/23197 [00:26<00:49, 298.77it/s]\u001b[A\n",
" 37%|███▋ | 8550/23197 [00:26<00:38, 376.68it/s]\u001b[A\n",
" 37%|███▋ | 8670/23197 [00:26<00:35, 413.07it/s]\u001b[A\n",
" 38%|███▊ | 8790/23197 [00:27<00:31, 460.38it/s]\u001b[A\n",
" 38%|███▊ | 8910/23197 [00:27<00:31, 453.23it/s]\u001b[A\n",
" 39%|███▉ | 9030/23197 [00:27<00:26, 531.89it/s]\u001b[A\n",
" 39%|███▉ | 9150/23197 [00:27<00:24, 573.90it/s]\u001b[A\n",
" 40%|███▉ | 9270/23197 [00:27<00:24, 557.27it/s]\u001b[A\n",
" 40%|████ | 9390/23197 [00:28<00:23, 595.00it/s]\u001b[A\n",
" 41%|████ | 9510/23197 [00:28<00:24, 561.83it/s]\u001b[A\n",
" 42%|████▏ | 9630/23197 [00:28<00:23, 585.56it/s]\u001b[A\n",
" 42%|████▏ | 9750/23197 [00:28<00:24, 559.54it/s]\u001b[A\n",
" 43%|████▎ | 9870/23197 [00:29<00:24, 544.38it/s]\u001b[A\n",
" 43%|████▎ | 9990/23197 [00:29<00:26, 491.72it/s]\u001b[A\n",
" 44%|████▎ | 10110/23197 [00:29<00:25, 511.47it/s]\u001b[A\n",
" 44%|████▍ | 10230/23197 [00:29<00:24, 530.12it/s]\u001b[A\n",
" 45%|████▍ | 10350/23197 [00:29<00:24, 525.07it/s]\u001b[A\n",
" 45%|████▌ | 10470/23197 [00:33<02:11, 96.94it/s] \u001b[A\n",
" 45%|████▌ | 10509/23197 [00:33<02:01, 104.64it/s]\u001b[A\n",
" 46%|████▌ | 10576/23197 [00:33<01:37, 129.95it/s]\u001b[A\n",
" 46%|████▌ | 10650/23197 [00:34<01:17, 161.65it/s]\u001b[A\n",
" 46%|████▋ | 10772/23197 [00:34<00:51, 243.02it/s]\u001b[A\n",
" 47%|████▋ | 10890/23197 [00:34<00:38, 317.92it/s]\u001b[A\n",
" 47%|████▋ | 11010/23197 [00:34<00:33, 368.02it/s]\u001b[A\n",
" 48%|████▊ | 11130/23197 [00:34<00:30, 400.26it/s]\u001b[A\n",
" 48%|████▊ | 11250/23197 [00:34<00:26, 447.80it/s]\u001b[A\n",
" 49%|████▉ | 11370/23197 [00:35<00:24, 484.29it/s]\u001b[A\n",
" 50%|████▉ | 11490/23197 [00:35<00:21, 541.63it/s]\u001b[A\n",
" 50%|█████ | 11610/23197 [00:35<00:20, 562.89it/s]\u001b[A\n",
" 51%|█████ | 11730/23197 [00:35<00:19, 573.70it/s]\u001b[A\n",
" 51%|█████ | 11850/23197 [00:35<00:19, 588.09it/s]\u001b[A\n",
" 52%|█████▏ | 11970/23197 [00:36<00:19, 586.69it/s]\u001b[A\n",
" 52%|█████▏ | 12090/23197 [00:36<00:20, 538.58it/s]\u001b[A\n",
" 53%|█████▎ | 12210/23197 [00:36<00:20, 546.82it/s]\u001b[A\n",
" 53%|█████▎ | 12330/23197 [00:36<00:18, 572.09it/s]\u001b[A\n",
" 54%|█████▎ | 12450/23197 [00:36<00:18, 588.52it/s]\u001b[A\n",
" 54%|█████▍ | 12570/23197 [00:37<00:19, 551.50it/s]\u001b[A\n",
" 55%|█████▍ | 12690/23197 [00:37<00:19, 545.71it/s]\u001b[A\n",
" 55%|█████▌ | 12810/23197 [00:37<00:17, 589.86it/s]\u001b[A\n",
" 56%|█████▌ | 12930/23197 [00:37<00:18, 552.70it/s]\u001b[A\n",
" 56%|█████▋ | 13050/23197 [00:38<00:17, 565.60it/s]\u001b[A\n",
" 57%|█████▋ | 13170/23197 [00:38<00:19, 504.44it/s]\u001b[A\n",
" 57%|█████▋ | 13290/23197 [00:38<00:18, 521.65it/s]\u001b[A\n",
" 58%|█████▊ | 13410/23197 [00:38<00:17, 569.59it/s]\u001b[A\n",
" 58%|█████▊ | 13530/23197 [00:38<00:16, 591.79it/s]\u001b[A\n",
" 59%|█████▉ | 13650/23197 [00:39<00:15, 608.51it/s]\u001b[A\n",
" 59%|█████▉ | 13770/23197 [00:43<01:54, 82.57it/s] \u001b[A\n",
" 60%|█████▉ | 13815/23197 [00:43<01:43, 90.83it/s]\u001b[A\n",
" 60%|█████▉ | 13854/23197 [00:43<01:32, 100.74it/s]\u001b[A\n",
" 60%|█████▉ | 13890/23197 [00:44<01:27, 106.30it/s]\u001b[A\n",
" 60%|██████ | 13920/23197 [00:44<01:18, 118.00it/s]\u001b[A\n",
" 60%|██████ | 14010/23197 [00:44<00:50, 180.32it/s]\u001b[A\n",
" 61%|██████ | 14159/23197 [00:44<00:28, 317.51it/s]\u001b[A\n",
" 61%|██████▏ | 14234/23197 [00:44<00:24, 370.77it/s]\u001b[A\n",
" 62%|██████▏ | 14310/23197 [00:44<00:22, 395.36it/s]\u001b[A\n",
" 62%|██████▏ | 14430/23197 [00:44<00:19, 457.24it/s]\u001b[A\n",
" 63%|██████▎ | 14550/23197 [00:44<00:16, 530.91it/s]\u001b[A\n",
" 63%|██████▎ | 14670/23197 [00:45<00:15, 558.90it/s]\u001b[A\n",
" 64%|██████▍ | 14790/23197 [00:45<00:13, 601.73it/s]\u001b[A\n",
" 64%|██████▍ | 14910/23197 [00:45<00:12, 659.58it/s]\u001b[A\n",
" 65%|██████▍ | 15030/23197 [00:45<00:12, 677.29it/s]\u001b[A\n",
" 65%|██████▌ | 15150/23197 [00:45<00:12, 650.98it/s]\u001b[A\n",
" 66%|██████▌ | 15270/23197 [00:45<00:11, 692.94it/s]\u001b[A\n",
" 66%|██████▋ | 15390/23197 [00:46<00:11, 666.52it/s]\u001b[A\n",
" 67%|██████▋ | 15510/23197 [00:46<00:11, 683.07it/s]\u001b[A\n",
" 67%|██████▋ | 15630/23197 [00:46<00:11, 687.59it/s]\u001b[A\n",
" 68%|██████▊ | 15750/23197 [00:46<00:11, 676.43it/s]\u001b[A\n",
" 68%|██████▊ | 15870/23197 [00:46<00:10, 672.69it/s]\u001b[A\n",
" 69%|██████▉ | 15990/23197 [00:47<00:11, 641.36it/s]\u001b[A\n",
" 69%|██████▉ | 16110/23197 [00:47<00:10, 650.64it/s]\u001b[A\n",
" 70%|██████▉ | 16230/23197 [00:47<00:11, 599.16it/s]\u001b[A\n",
" 70%|███████ | 16350/23197 [00:47<00:11, 603.14it/s]\u001b[A\n",
" 71%|███████ | 16470/23197 [00:47<00:10, 649.41it/s]\u001b[A\n",
" 72%|███████▏ | 16590/23197 [00:48<00:09, 698.82it/s]\u001b[A\n",
" 72%|███████▏ | 16710/23197 [00:48<00:09, 658.98it/s]\u001b[A\n",
" 73%|███████▎ | 16830/23197 [00:48<00:10, 610.98it/s]\u001b[A\n",
" 73%|███████▎ | 16950/23197 [00:48<00:10, 582.14it/s]\u001b[A\n",
" 74%|███████▎ | 17070/23197 [00:48<00:10, 557.19it/s]\u001b[A\n",
" 74%|███████▍ | 17190/23197 [00:49<00:10, 559.83it/s]\u001b[A\n",
" 75%|███████▍ | 17310/23197 [00:49<00:11, 532.98it/s]\u001b[A\n",
" 75%|███████▌ | 17430/23197 [00:49<00:09, 578.49it/s]\u001b[A\n",
" 76%|███████▌ | 17550/23197 [00:49<00:09, 611.19it/s]\u001b[A\n",
" 76%|███████▌ | 17670/23197 [00:49<00:09, 574.97it/s]\u001b[A\n",
" 77%|███████▋ | 17790/23197 [00:50<00:09, 546.17it/s]\u001b[A\n",
" 77%|███████▋ | 17910/23197 [00:55<01:18, 67.25it/s] \u001b[A\n",
" 77%|███████▋ | 17950/23197 [00:55<01:11, 73.56it/s]\u001b[A\n",
" 78%|███████▊ | 18030/23197 [00:55<00:54, 95.36it/s]\u001b[A\n",
" 78%|███████▊ | 18178/23197 [00:56<00:32, 154.75it/s]\u001b[A\n",
" 79%|███████▉ | 18323/23197 [00:56<00:21, 229.51it/s]\u001b[A\n",
" 79%|███████▉ | 18418/23197 [00:56<00:17, 267.38it/s]\u001b[A\n",
" 80%|███████▉ | 18500/23197 [00:56<00:15, 298.46it/s]\u001b[A\n",
" 80%|████████ | 18572/23197 [00:56<00:14, 310.68it/s]\u001b[A\n",
" 81%|████████ | 18690/23197 [00:56<00:12, 370.83it/s]\u001b[A\n",
" 81%|████████ | 18810/23197 [00:57<00:10, 408.45it/s]\u001b[A\n",
" 82%|████████▏ | 18930/23197 [00:57<00:08, 483.96it/s]\u001b[A\n",
" 82%|████████▏ | 19050/23197 [00:57<00:08, 491.89it/s]\u001b[A\n",
" 83%|████████▎ | 19170/23197 [00:57<00:07, 517.65it/s]\u001b[A\n",
" 83%|████████▎ | 19290/23197 [00:57<00:07, 529.76it/s]\u001b[A\n",
" 84%|████████▎ | 19410/23197 [00:58<00:06, 591.14it/s]\u001b[A\n",
" 84%|████████▍ | 19530/23197 [00:58<00:06, 562.74it/s]\u001b[A\n",
" 85%|████████▍ | 19650/23197 [00:58<00:06, 563.73it/s]\u001b[A\n",
" 85%|████████▌ | 19770/23197 [00:58<00:05, 576.34it/s]\u001b[A\n",
" 86%|████████▌ | 19890/23197 [00:59<00:06, 498.76it/s]\u001b[A\n",
" 86%|████████▋ | 20010/23197 [00:59<00:06, 519.95it/s]\u001b[A\n",
" 87%|████████▋ | 20130/23197 [00:59<00:05, 514.41it/s]\u001b[A\n",
" 87%|████████▋ | 20250/23197 [00:59<00:05, 516.80it/s]\u001b[A\n",
" 88%|████████▊ | 20370/23197 [01:00<00:05, 474.45it/s]\u001b[A\n",
" 88%|████████▊ | 20490/23197 [01:00<00:05, 472.73it/s]\u001b[A\n",
" 89%|████████▉ | 20610/23197 [01:00<00:05, 486.93it/s]\u001b[A\n",
" 89%|████████▉ | 20730/23197 [01:00<00:05, 463.81it/s]\u001b[A\n",
" 90%|████████▉ | 20850/23197 [01:01<00:05, 450.18it/s]\u001b[A\n",
" 90%|█████████ | 20970/23197 [01:01<00:05, 436.39it/s]\u001b[A\n",
" 91%|█████████ | 21090/23197 [01:01<00:05, 396.26it/s]\u001b[A\n",
" 91%|█████████▏| 21210/23197 [01:02<00:04, 422.49it/s]\u001b[A\n",
" 92%|█████████▏| 21330/23197 [01:02<00:04, 460.05it/s]\u001b[A\n",
" 92%|█████████▏| 21450/23197 [01:02<00:03, 481.24it/s]\u001b[A\n",
" 93%|█████████▎| 21570/23197 [01:02<00:03, 492.61it/s]\u001b[A\n",
" 94%|█████████▎| 21690/23197 [01:02<00:02, 518.25it/s]\u001b[A\n",
" 94%|█████████▍| 21810/23197 [01:03<00:02, 539.52it/s]\u001b[A\n",
" 95%|█████████▍| 21930/23197 [01:03<00:02, 558.66it/s]\u001b[A\n",
" 95%|█████████▌| 22050/23197 [01:03<00:02, 477.28it/s]\u001b[A\n",
" 96%|█████████▌| 22170/23197 [01:03<00:01, 540.81it/s]\u001b[A\n",
" 96%|█████████▌| 22290/23197 [01:04<00:01, 497.30it/s]\u001b[A\n",
" 97%|█████████▋| 22410/23197 [01:10<00:14, 54.55it/s] \u001b[A\n",
" 97%|█████████▋| 22449/23197 [01:11<00:12, 59.72it/s]\u001b[A\n",
" 97%|█████████▋| 22482/23197 [01:11<00:10, 65.92it/s]\u001b[A\n",
" 97%|█████████▋| 22512/23197 [01:11<00:09, 73.94it/s]\u001b[A\n",
" 97%|█████████▋| 22590/23197 [01:11<00:05, 107.42it/s]\u001b[A\n",
" 98%|█████████▊| 22701/23197 [01:11<00:02, 171.55it/s]\u001b[A\n",
" 98%|█████████▊| 22770/23197 [01:11<00:02, 213.01it/s]\u001b[A\n",
" 99%|█████████▊| 22890/23197 [01:11<00:01, 288.99it/s]\u001b[A\n",
" 99%|█████████▉| 23010/23197 [01:12<00:00, 349.43it/s]\u001b[A\n",
"100%|██████████| 23197/23197 [01:12<00:00, 321.23it/s]\u001b[A\n"
]
}
],
"source": [
"df = pd.read_csv('../../../data/processed/merged/kcat_max_wt_singleSeqs_wpdbs.csv')\n",
"\n",
"# PDB parser\n",
"sloppyparser = PDBParser(\n",
" QUIET=True,\n",
" PERMISSIVE=True,\n",
" structure_builder=xpdb.SloppyStructureBuilder(),\n",
")\n",
"\n",
"additional_path_pdb = '../../../'\n",
"# 2. Parallel parsing structures and converting to protein records\n",
"records = Parallel(n_jobs=-1)(\n",
" delayed(parse_pdb_gz_to_json_record)(\n",
" sloppyparser,\n",
" df.iloc[i][\"sequence\"],\n",
" additional_path_pdb+df.iloc[i][\"pdbpath\"],\n",
" df.iloc[i][\"pdbpath\"].split(\"/\")[-1],\n",
" )\n",
" for i in tqdm(range(df.shape[0]))\n",
")"
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "0add270e-bf61-4513-acb6-3ace461fdaa3",
"metadata": {},
"outputs": [],
"source": [
"target_col = 'log10kcat_max'\n",
"smiles_col = 'reactant_smiles'"
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "50e0b9ac-dcfd-4a43-88b4-d7ae36338644",
"metadata": {},
"outputs": [],
"source": [
"outprefix = '../../../data/processed/merged/kcat_max_wt_singleSeqs_wpdbs'"
]
},
{
"cell_type": "code",
"execution_count": 14,
"id": "bb37b182-aa17-41d5-a7ba-5066248804ef",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"number of records: 23197\n"
]
}
],
"source": [
"# 3. Segregate records by splits\n",
"for i, rec in enumerate(records):\n",
" row = df.iloc[i]\n",
" target = row[target_col]\n",
" smiles = row[smiles_col]\n",
" rec[\"target\"] = target\n",
" rec[\"ec\"] = row[\"ec\"]\n",
" rec[\"taxonomy_id\"] = row[\"taxonomy_id\"]\n",
" \n",
"# 4. write to disk\n",
"print(\"number of records:\", len(records))\n",
"outfile = os.path.join(f\"{outprefix}_pdbrecords.json\")\n",
"json.dump(records, open(outfile, \"w\"))"
]
},
{
"cell_type": "code",
"execution_count": 16,
"id": "62b95f57-9214-4649-879b-c63f60e72726",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"dict_keys(['seq', 'coords', 'name', 'target', 'ec', 'taxonomy_id'])"
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"records[0].keys()"
]
},
{
"cell_type": "code",
"execution_count": 18,
"id": "5cf2060a-b444-4e7b-88d5-5987d9553507",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'AF-U3KRF2-F1-model_v4.pdb'"
]
},
"execution_count": 18,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"records[0]['name']"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "4857a4ed-7ae7-4603-8baf-df113f2b7fa4",
"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.8.10"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
|