<jupyter_start><jupyter_text>KLIFS structures with mutated pocketsExplore KLIFS structures with mutations in their pocket:- Number of structures with mutations- Distribution of number of mutations per structure- Number of mutations per KLIFS pocket position- Type of mutations- Type of mutations per KLIFS position<jupyter_code>import pandas as pd
from opencadd.databases.klifs import setup_remote
klifs_session = setup_remote()<jupyter_output><empty_output><jupyter_text>Structures<jupyter_code>structures = klifs_session.structures.all_structures()
structures.shape<jupyter_output><empty_output><jupyter_text>Kinases<jupyter_code>kinases_short = klifs_session.kinases.all_kinases()
kinases = klifs_session.kinases.by_kinase_klifs_id(kinases_short["kinase.klifs_id"].to_list())<jupyter_output><empty_output><jupyter_text>Structure and kinase pocket sequence<jupyter_code>structure_kinase_sequence = pd.merge(
    structures[["structure.klifs_id", "kinase.klifs_id", "kinase.klifs_name", "structure.pocket"]],
    kinases[["kinase.klifs_id", "kinase.pocket"]],
)<jupyter_output><empty_output><jupyter_text>Mutations in pockets<jupyter_code>def get_mutations(structure_seq, kinase_seq):

    sequences = pd.DataFrame(
        [list(structure_seq), list(kinase_seq)], index=["structure", "kinase"]
    ).transpose()
    sequences.index = sequences.index + 1
    sequences = sequences[sequences.apply(lambda x: x["structure"] != "_", axis=1)]
    sequences = sequences[sequences.apply(lambda x: x["kinase"] != "-", axis=1)]

    mutations = sequences[sequences.apply(lambda x: x["structure"] != x["kinase"], axis=1)]
    return mutations
%%time

print(f"Number of structures to iterate over: {structure_kinase_sequence.shape[0]}")
mutated_residues = []
for structure_klifs_id, structure in structure_kinase_sequence.set_index(
    "structure.klifs_id"
).iterrows():
    mutations = get_mutations(structure["structure.pocket"], structure["kinase.pocket"])
    mutations["structure_klifs_id"] = structure_klifs_id
    if mutations.shape[0] > 0:
        mutated_residues.append(mutations)

mutated_residues = pd.concat(mutated_residues)
mutated_residues.index.name = "residue_klifs_id"
mutated_residues = mutated_residues.reset_index()
mutated_residues = mutated_residues.set_index(["structure_klifs_id", "residue_klifs_id"])
mutated_residues<jupyter_output>Number of structures to iterate over: 12572
CPU times: user 59.2 s, sys: 2.14 ms, total: 59.2 s
Wall time: 59.1 s<jupyter_text>Number of structures with mutations<jupyter_code>structure_klifs_ids_with_mutation = mutated_residues.index.get_level_values(0).unique()
print(f"Number of structures with mutations: {len(structure_klifs_ids_with_mutation)}")<jupyter_output>Number of structures with mutations: 1843<jupyter_text>Distribution of number of mutations per structure<jupyter_code>n_mutations_per_structure = mutated_residues.groupby("structure_klifs_id").size()
n_structures_mutations = n_mutations_per_structure.value_counts()
n_structures_mutations.name = "n_structures"
n_structures_mutations.index.name = "n_mutations"
n_structures_mutations = n_structures_mutations.sort_index().squeeze()

n_structures_mutations.plot(kind="bar");<jupyter_output><empty_output><jupyter_text>Number of mutations per KLIFS pocket position<jupyter_code>n_mutations_per_residue = mutated_residues.reset_index()["residue_klifs_id"].value_counts()
n_mutations_per_residue.name = "n_structures"
n_mutations_per_residue.index.name = "residue_klifs_id"
n_mutations_per_residue = n_mutations_per_residue.sort_index().squeeze()

n_mutations_per_residue.plot(kind="bar", figsize=(15, 5));<jupyter_output><empty_output><jupyter_text>Type of mutations<jupyter_code>mutated_residues.groupby(["structure", "kinase"]).size().sort_values(ascending=False).head(30)<jupyter_output><empty_output><jupyter_text>Type of mutations per KLIFS position<jupyter_code>mutated_residues.reset_index().groupby(
    ["residue_klifs_id", "structure", "kinase"]
).size().sort_values(ascending=False).head(30)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11388339920948616, 'fraction_numerical': 0.008893280632411068, 'mean_word_length': 9.022277227722773, 'pattern_counts': {'":': 0, '<': 39, '<?xml version=': 0, '>': 40, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '10', 'dir': 'jupyter-structured-clean-dedup', 'id': '587141', 'license': 'MIT', 'n_tokens_mistral': 1462, 'n_tokens_neox': 1362, 'n_words': 214, 'path': 'notebooks/002_structures/004_mutated_structures.ipynb', 'repo_name': 'volkamerlab/kissim_app', 'size': '4048'}