<jupyter_start><jupyter_text>Secondary Structure Property Encoder DemoThis demo creates a dataset of sequence segments dericed from a non-redundant set. The dataset contains the sequence segment, the DSSP Q8 and DSSP Q3 code of the center residue in a seuqnce segment, and a property encoding of the sequence segment. Imports<jupyter_code>from pyspark import SparkConf, SparkContext, SQLContext
from mmtfPyspark.ml import ProteinSequenceEncoder
from mmtfPyspark.mappers import StructureToPolymerChains
from mmtfPyspark.filters import ContainsLProteinChain
from mmtfPyspark.datasets import secondaryStructureSegmentExtractor
from mmtfPyspark.webfilters import Pisces
from mmtfPyspark.io import mmtfReader<jupyter_output><empty_output><jupyter_text>Configure Spark Context<jupyter_code>conf = SparkConf() \
            .setMaster("local[*]") \
            .setAppName("SecondaryStructurePropertyEncoderDemo")

sc = SparkContext(conf = conf)<jupyter_output><empty_output><jupyter_text>Read MMTF Hadoop sequence file and   Create a non-redundant set(<=20% seq. identity) of L-protein chains<jupyter_code>path = "../../resources/mmtf_reduced_sample/"
sequenceIdentity = 20
resolution = 2.0
fraction = 0.1
seed = 123

pdb = mmtfReader \
        .read_sequence_file(path, sc) \
        .flatMap(StructureToPolymerChains()) \
        .filter(Pisces(sequenceIdentity, resolution)) \
        .filter(ContainsLProteinChain()) \
        .sample(False, fraction, seed)<jupyter_output><empty_output><jupyter_text>Get content<jupyter_code>segmentLength = 11
data = secondaryStructureSegmentExtractor.get_dataset(pdb, segmentLength).cache()
print(f"original data   : {data.count()}")<jupyter_output>original data   : 2149<jupyter_text>Drop Q3 and sequence duplicates<jupyter_code>data = data.dropDuplicates(["labelQ3", "sequence"]).cache()
print(f"- duplicate Q3/seq  : {data.count()}")<jupyter_output>- duplicate Q3/seq  : 2149<jupyter_text>Drop sequence duplicates<jupyter_code>data = data.dropDuplicates(["sequence"])
print(f"- duplicate seq  : {data.count()}")<jupyter_output>- duplicate seq  : 2149<jupyter_text>Property Encoding<jupyter_code>encoder = ProteinSequenceEncoder(data)
data = encoder.property_encode()

data.printSchema()
data.show(5, False)<jupyter_output>root
 |-- structureChainId: string (nullable = true)
 |-- sequence: string (nullable = false)
 |-- labelQ8: string (nullable = true)
 |-- labelQ3: string (nullable = true)
 |-- features: vector (nullable = true)

+----------------+-----------+-------+-------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|structureChainId|sequence   |labelQ8|labelQ3|features                                                                                                                                                                                                                                                                                                                [...]<jupyter_text>Terminate Spark Context<jupyter_code>sc.stop()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.21138938580799047, 'fraction_numerical': 0.01073345259391771, 'mean_word_length': 2.0527752502274796, 'pattern_counts': {'":': 0, '<': 30, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 14, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '45634', 'license': 'Apache-2.0', 'n_tokens_mistral': 899, 'n_tokens_neox': 841, 'n_words': 183, 'path': 'docs/_static/demos/ml/SecondaryStructurePropertyEncoderDemo.ipynb', 'repo_name': 'sbliven/mmtf-pyspark', 'size': '3354'}