File size: 87,704 Bytes
8efb4bd | 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 | {
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"provenance": [],
"include_colab_link": true
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"language_info": {
"name": "python"
}
},
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "view-in-github",
"colab_type": "text"
},
"source": [
"<a href=\"https://colab.research.google.com/github/dina-lab3D/CombFold/blob/master/CombFold_Crosslinks.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
"cell_type": "markdown",
"source": [
"\n"
],
"metadata": {
"id": "MbEK2RpZcVCU"
}
},
{
"cell_type": "markdown",
"source": [
"This notebook runs the CombFold assembly algorithm, with optional crosslinks between subunits. The algorithm assembles large protein complexes, by combining PDB files of possible subcomplexes. \"Possible subcomplexes\" are structure models of different combinations of subunits from the target complex.\n",
"\n",
"By default, the notebook runs on an example ([PDB: 7ZKQ](https://www.rcsb.org/structure/7ZKQ)), but by uploading your own PDB files to Google Drive (and creating a subunits.json) you can assemble your complex by changing the path in the \"Run\" cell, as instructed in the cell.\n",
"\n",
"\n",
"**The inputs** are\n",
"1. subunits.json - a json describing all the subunits (sequences) in the complex.\n",
"2. pdbs folder - a folder with AlphaFold-Multimer models (PDB files) of different combinations of these subunits.\n",
"3. crosslinks.txt - a txt file that can be provided optionally defininig crosslinks between subunits.\n",
"\n",
"**The output** consists of several .PDB files which are models of the assembled complex structure.\n",
"more information is available on https://github.com/dina-lab3D/CombFold.\n"
],
"metadata": {
"id": "ZbAj512vF4eK"
}
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "yPmEy4fH4CT8",
"cellView": "form"
},
"outputs": [],
"source": [
"#@title Install CombFold (~2 min)\n",
"\n",
"!pip -q install biopython\n",
"!pip -q install py3Dmol\n",
"!echo Installed python dependencies\n",
"\n",
"!wget -qnc -O CombFold-master.zip wget https://github.com/dina-lab3D/CombFold/archive/refs/heads/master.zip\n",
"!unzip -q CombFold-master.zip\n",
"!echo Downloaded CombFold, Installing\n",
"!cd CombFold-master/CombinatorialAssembler && make --silent\n",
"!echo CombFold Installed!\n",
"\n",
"import py3Dmol\n",
"import os\n",
"\n",
"def view_pdb_color_by_chain(pdb_path: str):\n",
" pdb_content = open(pdb_path, \"r\").read()\n",
" view = py3Dmol.view(width=400, height=300)\n",
" view.addModelsAsFrames(pdb_content)\n",
"\n",
" # Get the list of chains in the protein\n",
" chains = {i[21] for i in pdb_content.split(\"\\n\") if len(i) > 21}\n",
"\n",
" # Assign a color to each chain\n",
" colors = [\"red\", \"blue\", \"green\", \"orange\", \"purple\", \"yellow\", \"pink\", \"brown\", \"black\", \"gray\", \"cyan\", \"magenta\", \"olive\", \"maroon\", \"navy\", \"teal\", \"gold\", \"silver\", \"crimson\"]\n",
" colors = 10 * colors\n",
"\n",
" # Set the style for each chain\n",
" for i, chain in enumerate(chains):\n",
" view.setStyle({'chain': chain}, {'cartoon': {'color': colors[i]}})\n",
"\n",
" view.zoomTo()\n",
" view.show()\n"
]
},
{
"cell_type": "code",
"source": [
"#@title View example elements {run: \"auto\"}\n",
"\n",
"#@markdown Here we demonstrate the input used to create a model of [PDB: 7ZKQ](https://www.rcsb.org/structure/7ZKQ). This complex have a total of 5 chains, each represents a single subuit.\n",
"\n",
"#@markdown - subunits.json - Defines five subunits (named: 2,A,C,T,b)\n",
"\n",
"#@markdown - pdb files - Structure models predicted by AlphaFold-Multimer of different pairings of the subunits. Each pair have multiple models, as many different pairwise interactions can be considered during assembly\n",
"\n",
"#@markdown - crosslinks.txt - Defines crosslinks, each line represents a single crosslink. the format of each line is <br>\\<res1\\> \\<chain_ids1\\> \\<res2\\> \\<chain_ids2\\> \\<minimal_distance\\> \\<maximal_distance\\> \\<crosslink_confidence\\>\n",
"\n",
"#@markdown You can view elements in the input by choosing them and running the cell.\n",
"\n",
"element_to_view = 'subunits.json' #@param [\"subunits.json\", \"crosslinks.txt\", \"pdbs/AFM_2_A_rank_001.pdb\", \"pdbs/AFM_2_A_rank_002.pdb\", \"pdbs/AFM_2_C_rank_001.pdb\", \"pdbs/AFM_2_C_rank_002.pdb\", \"pdbs/AFM_2_T_rank_001.pdb\", \"pdbs/AFM_2_T_rank_002.pdb\", \"pdbs/AFM_2_b_rank_001.pdb\", \"pdbs/AFM_2_b_rank_002.pdb\", \"pdbs/AFM_A_C_rank_001.pdb\", \"pdbs/AFM_A_C_rank_002.pdb\", \"pdbs/AFM_A_T_rank_001.pdb\", \"pdbs/AFM_A_T_rank_002.pdb\", \"pdbs/AFM_A_b_rank_001.pdb\", \"pdbs/AFM_A_b_rank_002.pdb\", \"pdbs/AFM_C_T_rank_001.pdb\", \"pdbs/AFM_C_T_rank_002.pdb\", \"pdbs/AFM_C_b_rank_001.pdb\", \"pdbs/AFM_C_b_rank_002.pdb\", \"pdbs/AFM_T_b_rank_001.pdb\", \"pdbs/AFM_T_b_rank_002.pdb\"]\n",
"example_path = \"/content/CombFold-master/example/example_xlinks\"\n",
"\n",
"subunits_path = os.path.join(example_path, \"subunits.json\")\n",
"crosslinks_path = os.path.join(example_path, \"crosslinks.txt\")\n",
"\n",
"if element_to_view == 'subunits.json':\n",
" print(open(subunits_path, \"r\").read())\n",
"elif element_to_view == 'crosslinks.txt':\n",
" print(open(crosslinks_path, \"r\").read())\n",
"else:\n",
" view_pdb_color_by_chain(os.path.join(example_path, element_to_view))\n"
],
"metadata": {
"id": "vAk-cPl4p2Jg",
"cellView": "form"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"#@title Run (~2 min on example)\n",
"import os\n",
"#@markdown The folder path on drive should have\n",
"#@markdown (1) a file named \"subunits.json\" with a description of the subunits\n",
"#@markdown and (2) a folder in it named \"pdbs\" containing all pdbs created by AFM.\n",
"#@markdown If you wish to include crosslinks - tick the enable_crosslinks box and include a crosslinks.txt\n",
"\n",
"#@markdown The results will be saved to a new folder named \"assembled\", under the path_on_drive .\n",
"\n",
"#@markdown The path should start with /content/drive/MyDrive/ and can be copied by selecting it from the files sidebar with Right-Click->Copy Path.\n",
"path_on_drive = '/content/CombFold-master/example/example_xlinks' #@param {type:\"string\"}\n",
"max_results_number = \"5\" #@param [1, 5, 10, 20]\n",
"enable_crosslinks = True #@param {type:\"boolean\"}\n",
"create_cif_instead_of_pdb = False #@param {type:\"boolean\"}\n",
"\n",
"subunits_path = os.path.join(path_on_drive, \"subunits.json\")\n",
"crosslinks_path = os.path.join(path_on_drive, \"crosslinks.txt\")\n",
"pdbs_folder = os.path.join(path_on_drive, \"pdbs\")\n",
"assembled_folder = os.path.join(path_on_drive, \"assembled\")\n",
"tmp_assembled_folder = \"/content/tmp_assembled\"\n",
"\n",
"if not (enable_crosslinks and os.path.exists(crosslinks_path)):\n",
" crosslinks_path = None\n",
"\n",
"if os.path.exists(assembled_folder):\n",
" answer = input(f\"{assembled_folder} already exists, Should delete? (y/n)\")\n",
" if answer in (\"y\", \"Y\"):\n",
" print(\"Deleteing\")\n",
" shutil.rmtree(assembled_folder)\n",
" else:\n",
" print(\"Stopping\")\n",
" exit()\n",
"\n",
"if os.path.exists(tmp_assembled_folder):\n",
" shutil.rmtree(tmp_assembled_folder)\n",
"\n",
"import subprocess\n",
"import sys\n",
"import shutil\n",
"sys.path.append(\"/content/CombFold-master/scripts/\")\n",
"import run_on_pdbs\n",
"run_on_pdbs.run_on_pdbs_folder(subunits_path, pdbs_folder, tmp_assembled_folder,\n",
" crosslinks_path=crosslinks_path,\n",
" output_cif=create_cif_instead_of_pdb,\n",
" max_results_number=int(max_results_number))\n",
"\n",
"shutil.copytree(os.path.join(tmp_assembled_folder, \"assembled_results\"),\n",
" assembled_folder)\n",
"\n",
"print(\"Results saved to\", assembled_folder)"
],
"metadata": {
"id": "OgnoSp2WNMPr",
"cellView": "form"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"#@title Display Assemled 3D structure models {run: \"auto\"}\n",
"model_num = \"0\" #@param [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n",
"model_num = int(model_num)\n",
"\n",
"output_filenames = [i for i in os.listdir(assembled_folder) if i.endswith(\".pdb\") or i.endswith(\".cif\")]\n",
"output_filenames.sort()\n",
"assert model_num < len(output_filenames), f\"Only have {len(output_filenames)} models\"\n",
"output_path = os.path.join(assembled_folder, output_filenames[model_num])\n",
"\n",
"view_pdb_color_by_chain(output_path)\n"
],
"metadata": {
"id": "WwqShmF0_YCY",
"cellView": "form"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"#@title Download results\n",
"from google.colab import files\n",
"\n",
"results_zip_path = \"/content/tmp_assembled/results.zip\"\n",
"os.system(f\"zip -r {results_zip_path} {assembled_folder}\")\n",
"files.download(results_zip_path)\n"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 17
},
"cellView": "form",
"id": "ZRNIIGP9FOsa",
"outputId": "ed721f78-a9d4-4719-f608-583ac202ffae"
},
"execution_count": 16,
"outputs": [
{
"output_type": "display_data",
"data": {
"text/plain": [
"<IPython.core.display.Javascript object>"
],
"application/javascript": [
"\n",
" async function download(id, filename, size) {\n",
" if (!google.colab.kernel.accessAllowed) {\n",
" return;\n",
" }\n",
" const div = document.createElement('div');\n",
" const label = document.createElement('label');\n",
" label.textContent = `Downloading \"${filename}\": `;\n",
" div.appendChild(label);\n",
" const progress = document.createElement('progress');\n",
" progress.max = size;\n",
" div.appendChild(progress);\n",
" document.body.appendChild(div);\n",
"\n",
" const buffers = [];\n",
" let downloaded = 0;\n",
"\n",
" const channel = await google.colab.kernel.comms.open(id);\n",
" // Send a message to notify the kernel that we're ready.\n",
" channel.send({})\n",
"\n",
" for await (const message of channel.messages) {\n",
" // Send a message to notify the kernel that we're ready.\n",
" channel.send({})\n",
" if (message.buffers) {\n",
" for (const buffer of message.buffers) {\n",
" buffers.push(buffer);\n",
" downloaded += buffer.byteLength;\n",
" progress.value = downloaded;\n",
" }\n",
" }\n",
" }\n",
" const blob = new Blob(buffers, {type: 'application/binary'});\n",
" const a = document.createElement('a');\n",
" a.href = window.URL.createObjectURL(blob);\n",
" a.download = filename;\n",
" div.appendChild(a);\n",
" a.click();\n",
" div.remove();\n",
" }\n",
" "
]
},
"metadata": {}
},
{
"output_type": "display_data",
"data": {
"text/plain": [
"<IPython.core.display.Javascript object>"
],
"application/javascript": [
"download(\"download_20623bbe-19a7-462a-9778-96d4ed3cd0a5\", \"results.zip\", 1491275)"
]
},
"metadata": {}
}
]
}
]
}
|