{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Poly-peptide Chain Statistics Example\n", "\n", "Example demonstrating how to extract protein cahins from PDB entries. This example uses a flatMap function to transform a structure to its polymer chains.\n", "\n", "## Imports" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "from pyspark import SparkConf, SparkContext\n", "from mmtfPyspark.filters import PolymerComposition\n", "from mmtfPyspark.io import mmtfReader\n", "from mmtfPyspark.mappers import StructureToPolymerChains" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Configure Spark" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "conf = SparkConf().setMaster(\"local[*]\") \\\n", " .setAppName(\"polypeptideCahinStats\")\n", "sc = SparkContext(conf = conf)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Read in mmtf files, flatMap to polymer chains, filter by polymer composition, and get number of groups" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "path = \"../../resources/mmtf_full_sample/\"\n", "\n", "chainLengths = mmtfReader.read_sequence_file(path, sc) \\\n", " .flatMap(StructureToPolymerChains(False, True)) \\\n", " .filter(PolymerComposition(PolymerComposition.AMINO_ACIDS_20)) \\\n", " .map(lambda t: t[1].num_groups) \\\n", " .cache()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Print out poly-peptide chain statistics" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Total number of chains: 7489\n", "Total number of groups: 1655462\n", "Min chain length: 3\n", "Mean chain length: 221.05247696621703\n", "Max chain length: 1231\n" ] } ], "source": [ "print(f\"Total number of chains: {chainLengths.count()}\")\n", "print(f\"Total number of groups: {chainLengths.sum()}\")\n", "print(f\"Min chain length: {chainLengths.min()}\")\n", "print(f\"Mean chain length: {chainLengths.mean()}\")\n", "print(f\"Max chain length: {chainLengths.max()}\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Terminate Spark" ] }, { "cell_type": "code", "execution_count": 6, "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 }