{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Simple Query Demo\n", "\n", "![pdbj](https://pdbj.org/content/default.svg)\n", "\n", "PDBj Mine 2 RDB keyword search query and MMTF filtering using pdbid.\n", "\n", "[PDBj Mine Search Website](https://pdbj.org/mine)\n", "\n", "## Imports" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [], "source": [ "from pyspark import SparkConf, SparkContext\n", "from mmtfPyspark.webfilters import PdbjMineSearch\n", "from mmtfPyspark.datasets import pdbjMineDataset\n", "from mmtfPyspark.io import mmtfReader" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Configure Spark Context" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [], "source": [ "conf = SparkConf().setMaster(\"local[*]\") \\\n", " .setAppName(\"SimpleQuerySearch\")\n", " \n", "sc = SparkContext(conf = conf)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Read in MMTF files from local directory" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [], "source": [ "path = \"../../resources/mmtf_full_sample/\"\n", "\n", "pdb = mmtfReader.read_sequence_file(path, sc)" ] }, { "cell_type": "markdown", "metadata": { "collapsed": true }, "source": [ "## Apply a SQL search on PDBj using a filter\n", "\n", "Very simple query; this gets the pdbids for all entries modified since 2016-06-28 with a resulution better than 1.5 A" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Number of entries using sql to filter: 11\n" ] } ], "source": [ "sql = \"select pdbid from brief_summary where modification_date >= '2016-06-28' and resolution < 1.5\"\n", "\n", "search = PdbjMineSearch(sql)\n", "count = pdb.filter(search).keys().count()\n", "print(f\"Number of entries using sql to filter: {count}\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Apply a SQL search on PDBj and get a dataset" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "+-----------+\n", "|structureId|\n", "+-----------+\n", "| 5U8P|\n", "| 5U8U|\n", "| 5U8V|\n", "| 5U9D|\n", "| 5UAM|\n", "+-----------+\n", "only showing top 5 rows\n", "\n" ] } ], "source": [ "dataset = pdbjMineDataset.get_dataset(sql)\n", "dataset.show(5)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Terminate Spark Context" ] }, { "cell_type": "code", "execution_count": 13, "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 }