<jupyter_start><jupyter_text>Poly-peptide Chain Statistics ExampleExample demonstrating how to extract protein cahins from PDB entries. This example uses a flatMap function to transform a structure to its polymer chains. Imports<jupyter_code>from pyspark.sql import SparkSession
from mmtfPyspark.filters import PolymerComposition
from mmtfPyspark.io import mmtfReader
from mmtfPyspark.mappers import StructureToPolymerChains<jupyter_output><empty_output><jupyter_text>Configure Spark<jupyter_code>spark = SparkSession.builder.appName("PolyPeptideChainStatisticsExample").getOrCreate()<jupyter_output><empty_output><jupyter_text>Read in mmtf files, flatMap to polymer chains, filter by polymer composition, and get number of groups<jupyter_code>path = "../../resources/mmtf_full_sample/"

chainLengths = mmtfReader.read_sequence_file(path) \
                         .flatMap(StructureToPolymerChains(False, True)) \
                         .filter(PolymerComposition(PolymerComposition.AMINO_ACIDS_20)) \
                         .map(lambda t: t[1].num_groups)<jupyter_output><empty_output><jupyter_text>Print out poly-peptide chain statistics<jupyter_code>stats = chainLengths.stats()
print(f"Total number of chains: {stats.count()}")
print(f"Total number of groups: {stats.sum()}")
print(f"Min chain length: {stats.min()}")
print(f"Mean chain length: {stats.mean()}")
print(f"Max chain length: {stats.max()}")<jupyter_output>Total number of chains: 8346
Total number of groups: 1791120.0000000005
Min chain length: 1.0
Mean chain length: 214.60819554277504
Max chain length: 1038.0<jupyter_text>Terminate Spark<jupyter_code>spark.stop()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09820359281437126, 'fraction_numerical': 0.02874251497005988, 'mean_word_length': 5.933609958506224, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 1, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '186841', 'license': 'Apache-2.0', 'n_tokens_mistral': 576, 'n_tokens_neox': 517, 'n_words': 119, 'path': 'demos/mappers/PolyPeptideChainStatisticsExample.ipynb', 'repo_name': 'sbliven/mmtf-pyspark', 'size': '1670'}