{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Secondary Structure Element Demo\n", "\n", "This demo shows how to get a dataset of secondary structure elements\n", "\n", "## Imports" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [], "source": [ "from pyspark import SparkConf, SparkContext\n", "from mmtfPyspark.io import mmtfReader\n", "from mmtfPyspark.mappers import StructureToPolymerChains\n", "from mmtfPyspark.filters import ContainsLProteinChain\n", "from mmtfPyspark.datasets import secondaryStructureElementExtractor" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Configure Spark" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [], "source": [ "conf = SparkConf().setMaster(\"local[*]\") \\\n", " .setAppName(\"secondaryStructureElementDemo\")\n", "sc = SparkContext(conf = conf)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Download protein (1STP)\n", "\n", "### Note: Need to use SparkContext as parameter to download Mmtf files" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [], "source": [ "pdb = mmtfReader.download_mmtf_files(['1STP'], sc).cache()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Map protein to polymer chains and apply LProteinChain filter" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [], "source": [ "pdb = pdb.flatMap(StructureToPolymerChains()) \\\n", " .filter(ContainsLProteinChain())" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Extract secondary structure element 'E'" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "+-------------+-----+\n", "|sequence |label|\n", "+-------------+-----+\n", "|TFIVTA |E |\n", "|ALTGTYE |E |\n", "|VLTGRY |E |\n", "|TALGWTVAWK |E |\n", "|NAHSATTWSGQYV|E |\n", "|INTQWLLTS |E |\n", "|TLVGHDTFT |E |\n", "+-------------+-----+\n", "\n" ] } ], "source": [ "ds = secondaryStructureElementExtractor.get_dataset(pdb, 'E', 6)\n", "\n", "ds.show(50, False)" ] }, { "cell_type": "markdown", "metadata": { "collapsed": true }, "source": [ "## Terminate Spark" ] }, { "cell_type": "code", "execution_count": 15, "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 }