<jupyter_start><jupyter_text>Mutual Exclusivity: BRCA<jupyter_code>import os
import os.path as op

os.chdir('../')

# os.listdir()
# SNV_PATHS
SNV_COMMON_PATH = "C:/Users/ibrah/Desktop/SNV_data/SNV_datasets/"
BRCA_SNV_PATH = op.join(SNV_COMMON_PATH, "SNV_BRCA_hg38_2021-09-22.csv")

BRCA_PRELIMINARY_DATA_PATH = r"../data/predictions_datasets/brca_prediction_2021-11-17/558297b6/brca_preliminary_data_cgc_2021-11-17.xlsx"

# PATIENT INTERACTION DATA PATHS
BRCA_PATIENT_INTERACTION_DATA_PATH = "../data/patient_interaction_datasets/BRCA_patient_interactions_analysis_table_2021-11-17.xlsx"

# Reflect changes in the modules immediately.
%load_ext autoreload
%autoreload 2
from helpers.helpers_analysis.mutual_exclusivity import MutualExclusivity
from helpers.helpers_analysis.protein_id_retrieval import ProteinIDFetcher
brca_mutex = MutualExclusivity(
    tcga="BRCA", 
    tcga_snv_path=BRCA_SNV_PATH, 
    patient_interaction_data_path=BRCA_PATIENT_INTERACTION_DATA_PATH
)
len(brca_mutex.patients)
len(brca_mutex.get_patients_with("P04637", identifier_type="protein"))
len(brca_mutex.get_patients_with("P04626", identifier_type="protein"))
ProteinIDFetcher().fetch("ERBB2")
len(brca_mutex.get_patients_with("P04626", identifier_type="protein"))
len(brca_mutex.get_patients_with("J3QLU9", identifier_type="protein"))
import pandas as pd
brca_preliminary_data = pd.read_excel(BRCA_PRELIMINARY_DATA_PATH)
brca_preliminary_data.head(3)
def apply_filtering_conditions(data):
    data_filtered = data[
        (data["NUM_ELASPIC_INTERFACE_ENTRIES"] >= 10) &
        (data["PATIENT_INTERFACE_COUNT"] > 5)
    ]
    
    protein_gene_pairs = list(zip(data_filtered["PROTEIN"], data_filtered["GENE"]))
    return protein_gene_pairs
protein_gene_list = apply_filtering_conditions(brca_preliminary_data)
protein_gene_list
for protein_gene in protein_gene_list:
    protein, gene = protein_gene
    print(f"PROTEIN_GENE: {protein}_{gene}")
    brca_mutex.export_disruptive_mutual_exclusivity_data("dev\mutex_testing", protein)<jupyter_output>PROTEIN_GENE: O75582_RPS6KA5
2021-11-20 01:52:33 |[32m INFO     [0m| helpers.helpers_analysis.mutual_exclusivity | Calculating Mutual Exclusivity over O75582's interactors ..
2021-11-20 01:52:33 |[36m DEBUG    [0m| helpers.helpers_analysis.mutual_exclusivity | O75582 have 6 interactors:
['Q15759:MAPK11', 'Q15418:RPS6KA1', 'Q16539:MAPK14', 'L7RSM2:MAPK14', 'Q9UK32:RPS6KA6', 'P67870:CSNK2B']
2021-11-20 01:52:33 |[36m DEBUG    [0m| helpers.helpers_analysis.mutual_exclusivity | Exporting Mutual Exclusivity BRCA O75582 ..
2021-11-20 01:52:33 |[33m WARNING  [0m| helpers.helpers_analysis.mutual_exclusivity | File dev\mutex_testing\BRCA_O75582_RPS6KA5_2021-11-20.csv is already exist.
To overwrite existing file, use `overwrite=True`.
PROTEIN_GENE: P04626_ERBB2
2021-11-20 01:52:33 |[32m INFO     [0m| helpers.helpers_analysis.mutual_exclusivity | Calculating Mutual Exclusivity over P04626's interactors ..
2021-11-20 01:52:33 |[36m DEBUG    [0m| helpers.helpers_analysis.mutual_exclusiv[...]<jupyter_text>RPS6KA5<jupyter_code>ProteinIDFetcher().fetch("RPS6KA5")
brca_mutex.get_disruptive_mutual_exclusivity_data("P04637")
brca_mutex.get_disruptive_mutual_exclusivity_proba_data("P04637")
brca_mutex.export_disruptive_mutual_exclusivity_data("dev/mutex", "P04626")
brca_mutex.export_disruptive_mutual_exclusivity_data("dev/mutex", "P04626", prob=True)<jupyter_output>2021-11-20 02:42:39 |[32m INFO     [0m| helpers.helpers_analysis.mutual_exclusivity | Calculating Mutual Exclusivity over P04626's interactors ..
2021-11-20 02:42:39 |[36m DEBUG    [0m| helpers.helpers_analysis.mutual_exclusivity | P04626 have 15 interactors:
{'O60674:JAK2': 0.63, 'P00533:EGFR': 1.49, 'P06241:FYN': 1.3, 'P08069:IGF1R': 1.82, 'P15153:RAC2': 0.75, 'P16591:FER': 1.52, 'P21860:ERBB3': 0.84, 'P23458:JAK1': 0.66, 'P42680:TEC': 1.4, 'P51813:BMX': 1.38, 'Q13153:PAK1': 1.4, 'Q14289:PTK2B': 1.62, 'Q92625:ANKS1A': 0.55, 'Q96SB4:SRPK1': 4.79, 'Q9UJM3:ERRFI1': 0.8}
2021-11-20 02:42:40 |[36m DEBUG    [0m| helpers.helpers_analysis.mutual_exclusivity | Exporting Mutual Exclusivity BRCA P04626 ..<jupyter_text>---<jupyter_code>ProteinIDFetcher().fetch("PIK3CA")
ProteinIDFetcher().fetch("TP53")
x = brca_mutex.get_disrupted_interactors("PIK3CA", identifier_type="gene", return_counter=True)
for k, v in x.items():
    print(k, v)
brca_mutex.get_disrupted_interactors("P42336", identifier_type="protein", return_counter=True)
get_disrupted_interactors_probabilities
brca_mutex.get_disrupted_interactors_probabilities("PIK3CA", identifier_type="gene")
brca_mutex.get_disrupted_interactors("PIK3CA", identifier_type="gene", return_counter=True)
x = brca_mutex.get_disrupted_interactors_probabilities("PIK3CA", identifier_type="gene")
x
def split_prob(x):
    protein_gene, probability = x.rsplit(":", 1)
    probability = float(probability)
    return protein_gene, probability
x_list = list(x.apply(lambda x: split_prob(x)))
x_list[:3]
x_df = pd.DataFrame(x_list, columns=["PROTEIN:GENE", "PROBABILITY"])
x_df.head()
x_df.groupby("PROTEIN:GENE")["PROBABILITY"].sum()
brca_mutex.get_disrupted_interactors("PIK3CA", identifier_type="gene", return_counter=True)
brca_mutex.get_disrupted_interactors_probabilities("PIK3CA", identifier_type="gene")<jupyter_output><empty_output><jupyter_text>Örneğin ERBB2 geni için en sık disrupt olan interactor SRPK1, ERBB2 ile SRPK1 arasındaki mutual exclusivity'yi hesaplayalım. S1 ERBB'nun mutasyona uğradığı hasta seti olsun. S2 SRPK1'nın mutasyona uğradığı hasta seti olsun. P04626 - ERBBRQ96SB4 - SRPK1|S1 union S2| / |S1| + |S2| değerini hesaplayalım. mutasyona uğradığı derken direk snv datasına bakabiliriz elaspic'i karıştırmadan. Aynı hesaplamayı ERBB2'nun bütün interactorları için tekrarlayalım. SRPK1 ile olan mutual exclusivity değeri daha mı iyi görelim.Bunu analysis.docx'deki tablolarda bulunan genler için tekrarlayalım.<jupyter_code>brca_mutex.calculate_mutual_exclusivity("P04626", "Q96SB4")<jupyter_output><empty_output><jupyter_text>Patient Interaction Data<jupyter_code>brca_mutex.patient_interaction_data.head()
    SRPK1
brca_mutex.get_disrupted_interactors(
    "ERBB2", identifier_type="gene", return_counter=True
)
brca_mutex.get_disrupted_interactors("TP53", identifier_type="gene", return_counter=True)
brca_mutex.get_disrupted_interactors("TP53", identifier_type="gene", return_counter=True)
brca_mutex.get_disrupted_interactors("TP53", identifier_type="gene")
brca_mutex.get_disrupted_interactors("TP53", identifier_type="gene", return_counter=True)
brca_mutex.get_disrupted_interactors("H3C1", identifier_type="gene", return_counter=True)
brca_mutex.get_disrupted_interactors("H4C1", identifier_type="gene", return_counter=True)
brca_mutex.get_disrupted_interactors("MAP2K4", identifier_type="gene", return_counter=True)
ProteinIDFetcher().fetch("TP53")
ProteinIDFetcher().fetch("MAP2K4")
ProteinIDFetcher().fetch("ERBB2")
brca_mutex.calculate_mutual_exclusivity("Q96SB4", "P04626")
brca_mutex.calculate_mutual_exclusivity("P08069", "Q96SB4")
brca_mutex.calculate_mutual_exclusivity("P08069", "P23458")
brca_mutex.calculate_mutual_exclusivity("P23458", "P08069")<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1214146477304372, 'fraction_numerical': 0.07894736842105263, 'mean_word_length': 8.706756756756757, 'pattern_counts': {'":': 1, '<': 19, '<?xml version=': 0, '>': 21, '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': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '618405', 'license': 'MIT', 'n_tokens_mistral': 3259, 'n_tokens_neox': 2833, 'n_words': 382, 'path': 'src/dev/MutualExclusivityBRCA_updated.ipynb', 'repo_name': 'ibrahimberb/Predicting-Mutation-Effects', 'size': '7182'}