{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Author Search Demo\n", "\n", "![pdbj](https://pdbj.org/content/default.svg)\n", "\n", "AuthorSearch shows how to query PDB structures by metadata. This example queries the name fields in the audit_author and citation_author categories.\n", "\n", "\n", "## References\n", "\n", "Each category represents a table and fields represent database columns, see:\n", "[Available tables and columns](https://pdbj.org/mine-rdb-docs)\n", "\n", "Data are provided through: \n", "[Mine 2 SQL](https://pdbj.org/help/mine2-sql)\n", "\n", "Queries can be designed with the interactive\n", "[PDBj Mine 2 query service](https://pdbj.org/mine/sql)\n", "\n", "\n", "\n", "## Imports" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "from pyspark import SparkConf, SparkContext\n", "from mmtfPyspark.webfilters import PdbjMineSearch\n", "from mmtfPyspark.io import mmtfReader" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Configure Spark Context" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "conf = SparkConf().setMaster(\"local[*]\") \\\n", " .setAppName(\"AuthorSearchDemo\")\n", "sc = SparkContext(conf = conf)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Query to find PDB structures for Doudna, J.A. as a deposition (audit) author or as an author in the primary PDB citation" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "sqlQuery = \"SELECT pdbid from audit_author \" \\\n", " + \"WHERE name LIKE 'Doudna%J.A.%' \" \\\n", " + \"UNION \" \\\n", " + \"SELECT pdbid from citation_author \" \\\n", " + \"WHERE citation_id = 'primary' AND name LIKE 'Doudna%J.A.%'\"" ] }, { "cell_type": "markdown", "metadata": { "collapsed": true }, "source": [ "## Read PDB and filter by author" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Number of entries matching query: 90\n" ] } ], "source": [ "path = \"../../resources/mmtf_reduced_sample/\"\n", "\n", "pdb = mmtfReader.read_sequence_file(path, sc) \\\n", " .filter(PdbjMineSearch(sqlQuery))\n", "\n", "print(f\"Number of entries matching query: {pdb.count()}\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Terminate Spark Context" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [], "source": [ "sc.stop()" ] } ], "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.6.0" } }, "nbformat": 4, "nbformat_minor": 2 }