{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Read List Of Entries From Local Hadoop Sequence File\n", "\n", "Simple example reading a list of PDB entries from local Hadoop Sequence Files\n", "\n", "## Imports" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "from pyspark import SparkConf, SparkContext\n", "from mmtfPyspark.io import mmtfReader\n", "from mmtfPyspark.structureViewer import view_structure" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Configure Spark" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "conf = SparkConf().setMaster(\"local[*]\") \\\n", " .setAppName(\"ReadListFromLocal\")\n", "sc = SparkContext(conf = conf)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Read in local Hadoop Sequence Files and count number of entries" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "number of pdb entries read : 3\n" ] } ], "source": [ "path = \"../../resources/mmtf_full_sample/\"\n", "pdbIds = [\"1M4L\", \"1LXJ\", \"4XPX\"]\n", "\n", "pdb = mmtfReader.read_sequence_file(path, sc, pdbId = pdbIds,)\n", "\n", "count = pdb.count()\n", "\n", "print(f'number of pdb entries read : {count}')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Visualize Structures" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "55343eb0124b446b849084eb7408e9d1", "version_major": 2, "version_minor": 0 }, "text/plain": [ "interactive(children=(IntSlider(value=0, continuous_update=False, description='Structure', max=2), Output()), …" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/plain": [ ".view3d(i=0)>" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "structures = pdb.keys().collect()\n", "view_structure(structures)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Terminate Spark" ] }, { "cell_type": "code", "execution_count": 5, "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 }