<jupyter_start><jupyter_text>PDB Drug Bank MappingJoin PDB, Drug Bank and PDBjMine dataset together   Imports and variables<jupyter_code>from pyspark.sql import SparkSession
from mmtfPyspark.datasets import customReportService, drugBankDataset, pdbjMineDataset
from mmtfPyspark import structureViewer<jupyter_output><empty_output><jupyter_text>Configure Spark<jupyter_code>spark = SparkSession.builder.appName("PdbDrugBankMapping").getOrCreate()<jupyter_output><empty_output><jupyter_text>Download open DrugBank dataset<jupyter_code>path = "../../resources/mmtf_full_sample/"
drugBank = drugBankDataset.get_open_drug_links().cache()
drugBank.toPandas().head(10)<jupyter_output><empty_output><jupyter_text>Filter out DrugBank entries without StandardInChIKey<jupyter_code>drugBank = drugBank.filter(drugBank.StandardInChIKey.isNotNull())
drugBank.toPandas().head(5)<jupyter_output><empty_output><jupyter_text>Get PDB ligand annotations<jupyter_code>ligands = customReportService.get_dataset(["ligandId","ligandMolecularWeight","ligandFormula","ligandSmiles","InChIKey"]).cache()
ligands.toPandas().head(10)<jupyter_output><empty_output><jupyter_text>Filter out DrugBank entries without InChIKey<jupyter_code>ligands = ligands.filter(ligands.InChIKey.isNotNull())
ligands.toPandas().head(5)<jupyter_output><empty_output><jupyter_text>Join ligand dataset with DrugBank info by InChIKey<jupyter_code>ligands = ligands.join(drugBank, ligands.InChIKey == drugBank.StandardInChIKey)
ligands.toPandas().head(10)<jupyter_output><empty_output><jupyter_text>Show one example per drug molecule<jupyter_code>ligands = ligands.dropDuplicates(["Commonname"])
ligands = ligands.select("structureChainId", "ligandId", "DrugBankID", "Commonname", "ligandMolecularWeight","ligandFormula", "InChIKey", "ligandSmiles")
ligands.sort("Commonname").toPandas().head(10)<jupyter_output><empty_output><jupyter_text>Query structures with 2.7.11.1 EC number using PDBjMine<jupyter_code>enzymeQuery = "SELECT * FROM sifts.pdb_chain_enzyme WHERE ec_number = '2.7.11.1'"
enzyme = pdbjMineDataset.get_dataset(enzymeQuery)

print(f"First 10 results for query: {enzymeQuery}")
enzyme.show(10)<jupyter_output>First 10 results for query: SELECT * FROM sifts.pdb_chain_enzyme WHERE ec_number = '2.7.11.1'
+-----+-----+---------+---------+----------------+
|pdbid|chain|accession|ec_number|structureChainId|
+-----+-----+---------+---------+----------------+
| 1AUE|    A|   P42345| 2.7.11.1|          1AUE.A|
| 1AUE|    B|   P42345| 2.7.11.1|          1AUE.B|
| 1BPV|    A|   Q8WZ42| 2.7.11.1|          1BPV.A|
| 1C1Y|    B|   P04049| 2.7.11.1|          1C1Y.B|
| 1CF4|    B|   Q07912| 2.7.11.1|          1CF4.B|
| 1CJA|    A|   P80197| 2.7.11.1|          1CJA.A|
| 1CJA|    B|   P80197| 2.7.11.1|          1CJA.B|
| 1CKI|    A|   Q06486| 2.7.11.1|          1CKI.A|
| 1CKI|    B|   Q06486| 2.7.11.1|          1CKI.B|
| 1CKJ|    A|   Q06486| 2.7.11.1|          1CKJ.A|
+-----+-----+---------+---------+----------------+
only showing top 10 rows<jupyter_text>Join ligand dataset with PDBjMine dataset with structureChainId<jupyter_code>ligands = ligands.join(enzyme, ligands.structureChainId == enzyme.structureChainId)
print(f"Total number of structures: {ligands.count()}")

df = ligands.toPandas()
df.head()<jupyter_output>Total number of structures: 175<jupyter_text>Visualize protein kinase interaction<jupyter_code>structureViewer.view_binding_site(df.pdbid, df.ligandId, df.chain, 4.0);<jupyter_output><empty_output><jupyter_text>Terminate Spark<jupyter_code>spark.stop()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.163957399103139, 'fraction_numerical': 0.04484304932735426, 'mean_word_length': 4.8316993464052285, 'pattern_counts': {'":': 0, '<': 47, '<?xml version=': 0, '>': 47, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 13, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '12', 'dir': 'jupyter-structured-clean-dedup', 'id': '320638', 'license': 'Apache-2.0', 'n_tokens_mistral': 1464, 'n_tokens_neox': 1337, 'n_words': 198, 'path': 'demos/applications/PdbDrugBankMapping.ipynb', 'repo_name': 'sbliven/mmtf-pyspark', 'size': '3568'}