Created
November 7, 2021 02:36
-
-
Save ljmartin/643c9f78f49ee7f3ec321ada393ffa51 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "cells": [ | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "id": "a4226b9e-f975-4a5b-b716-7cc0bd2843a9", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "['10GS',\n", | |
| " '13GS',\n", | |
| " '16PK',\n", | |
| " '181L',\n", | |
| " '182L',\n", | |
| " '183L',\n", | |
| " '184L',\n", | |
| " '185L',\n", | |
| " '186L',\n", | |
| " '187L']" | |
| ] | |
| }, | |
| "execution_count": 1, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "import json\n", | |
| "import requests \n", | |
| "import urllib\n", | |
| "from urllib.request import urlopen\n", | |
| "\n", | |
| "\n", | |
| "def get_all_entries():\n", | |
| " base_url = 'https://search.rcsb.org/rcsbsearch/v1/query'\n", | |
| " json_query_string = \"\"\"\n", | |
| " {\n", | |
| " \"query\": {\n", | |
| " \"type\": \"terminal\",\n", | |
| " \"service\": \"text\",\n", | |
| " \"parameters\": {\n", | |
| " \"attribute\": \"rcsb_binding_affinity.value\",\n", | |
| " \"operator\": \"exists\"\n", | |
| " }\n", | |
| " },\n", | |
| " \"request_options\": {\n", | |
| " \"results_verbosity\": \"compact\",\n", | |
| " \"return_all_hits\": true\n", | |
| " },\n", | |
| " \"return_type\": \"entry\"\n", | |
| " } \n", | |
| " \"\"\"\n", | |
| " #formulate the query:\n", | |
| " query = urllib.parse.quote(json_query_string)\n", | |
| " req_url = base_url+'?json={request}'\n", | |
| " url_query = req_url.format(request=query)\n", | |
| " response = urlopen(url_query)\n", | |
| " #read the output into json/dict:\n", | |
| " output = json.loads(response.read())\n", | |
| " return output\n", | |
| " \n", | |
| "all_entries = get_all_entries()\n", | |
| "all_entries['result_set'][:10]" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 2, | |
| "id": "e48f6708-05c3-458f-b0c2-c5bcf2c00d6e", | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "def query_for_component_id(ids):\n", | |
| " \n", | |
| " \"\"\"\n", | |
| " Input a list of PDB codes and return all the measured affinity \n", | |
| " data.\n", | |
| " \"\"\"\n", | |
| " #base graphql query:\n", | |
| " base_url = 'https://data.rcsb.org/graphql'\n", | |
| " \n", | |
| " #all graphql queries require format: [\"id1\", \"id2\", so on...]\n", | |
| " query_fmt = '[' + ', '.join(['\"' + i + '\"' for i in ids]) + ']'\n", | |
| " \n", | |
| " #put the query together\n", | |
| " graphql_query = \"\"\"\n", | |
| " {\n", | |
| " entries(entry_ids:\"\"\" + query_fmt +\"\"\") {\n", | |
| " rcsb_binding_affinity {\n", | |
| " comp_id \n", | |
| " value\n", | |
| " type\n", | |
| " unit\n", | |
| " symbol\n", | |
| " link\n", | |
| " provenance_code\n", | |
| " \n", | |
| " }\n", | |
| " rcsb_primary_citation {\n", | |
| " pdbx_database_id_PubMed\n", | |
| " pdbx_database_id_DOI\n", | |
| " }\n", | |
| " }\n", | |
| " }\n", | |
| " \"\"\"\n", | |
| "\n", | |
| " #encode as an html request and get the json data\n", | |
| " r = requests.post(base_url, json={'query': graphql_query})\n", | |
| " output = r.json()\n", | |
| " return output\n" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "id": "a3f1a2d4-4998-47a4-ba5d-11f780ae2ce1", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "{'data': {'entries': [{'rcsb_binding_affinity': [{'comp_id': 'VWW',\n", | |
| " 'value': 400.0,\n", | |
| " 'type': 'Ki',\n", | |
| " 'unit': 'nM',\n", | |
| " 'symbol': None,\n", | |
| " 'link': 'http://www.pdbbind-cn.org/quickpdb.php?quickpdb=10gs',\n", | |
| " 'provenance_code': 'PDBBind'},\n", | |
| " {'comp_id': 'VWW',\n", | |
| " 'value': 400.0,\n", | |
| " 'type': 'Ki',\n", | |
| " 'unit': 'nM',\n", | |
| " 'symbol': None,\n", | |
| " 'link': 'http://www.bindingmoad.org/pdbrecords/index/10gs',\n", | |
| " 'provenance_code': 'Binding MOAD'}],\n", | |
| " 'rcsb_primary_citation': {'pdbx_database_id_PubMed': 9398518,\n", | |
| " 'pdbx_database_id_DOI': '10.1006/jmbi.1997.1364'}},\n", | |
| " {'rcsb_binding_affinity': [{'comp_id': 'SAS',\n", | |
| " 'value': 24000.0,\n", | |
| " 'type': 'Ki',\n", | |
| " 'unit': 'nM',\n", | |
| " 'symbol': None,\n", | |
| " 'link': 'http://www.bindingmoad.org/pdbrecords/index/13gs',\n", | |
| " 'provenance_code': 'Binding MOAD'},\n", | |
| " {'comp_id': 'SAS',\n", | |
| " 'value': 24000.0,\n", | |
| " 'type': 'Ki',\n", | |
| " 'unit': 'nM',\n", | |
| " 'symbol': None,\n", | |
| " 'link': 'http://www.pdbbind-cn.org/quickpdb.php?quickpdb=13gs',\n", | |
| " 'provenance_code': 'PDBBind'}],\n", | |
| " 'rcsb_primary_citation': {'pdbx_database_id_PubMed': 10452896,\n", | |
| " 'pdbx_database_id_DOI': '10.1006/jmbi.1999.3029'}}]}}" | |
| ] | |
| }, | |
| "execution_count": 5, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "query_for_component_id(all_entries['result_set'][0:2])" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "id": "310cf748-5bff-40b8-b969-aa0201fb0c94", | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [] | |
| } | |
| ], | |
| "metadata": { | |
| "kernelspec": { | |
| "display_name": "Python 3 (ipykernel)", | |
| "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.7" | |
| } | |
| }, | |
| "nbformat": 4, | |
| "nbformat_minor": 5 | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment