<jupyter_start><jupyter_text>Load the data<jupyter_code>data = pd.read_csv("../data/skcm_vaf.csv").drop(['Unnamed: 0', 'Tumor_Sample_Barcode'], axis=1)
data.fillna(0, inplace=True)
data.head()<jupyter_output><empty_output><jupyter_text>Filter out passenger genes<jupyter_code>driver = 'BRAF NRAS TP53 CDKN2A PTEN IDH1 MAP2K1 NF1 ARID2 RAC1 CTNNB1 CDK4 PPP6C KIT DDX3X RB1 GNA11 KRAS HRAS'.split()
data = data[driver]<jupyter_output><empty_output><jupyter_text>Parameters<jupyter_code>n_bootstrap = 100
lambda1 = 0.002
alpha = 0.05
pos_threshold = 0.09
neg_threshold = -0.01<jupyter_output><empty_output><jupyter_text>Bootstrap<jupyter_code>Ws = []
for i in tqdm(range(n_bootstrap)):
    np.random.seed(42 + i)
    bootstrap_indices = np.random.choice(data.index, size=data.shape[0], replace=True)
    bootstrap_data = data.loc[bootstrap_indices]
    W = notears_linear(bootstrap_data.values, lambda1=lambda1, loss_type='l2', w_threshold=0.0, max_iter=300)
    Ws.append(W.T)
Ws = np.array(Ws)<jupyter_output>100%|██████████| 100/100 [01:00<00:00,  1.41it/s]<jupyter_text>Remove non-significant edges<jupyter_code>t_pos, p_pos = stats.ttest_1samp(Ws, pos_threshold, axis=0)
t_pos = pd.DataFrame(t_pos, columns=data.columns, index=data.columns)
p_pos = pd.DataFrame(p_pos, columns=data.columns, index=data.columns)

t_neg, p_neg = stats.ttest_1samp(Ws, neg_threshold, axis=0)
t_neg = pd.DataFrame(t_neg, columns=data.columns, index=data.columns)
p_neg = pd.DataFrame(p_neg, columns=data.columns, index=data.columns)

W = Ws.mean(axis=0)
W_pos = ((t_pos > 0) & (p_pos < alpha)) * W
W_neg = ((t_neg < 0) & (p_neg < alpha)) * W
W = W_pos + W_neg
G1 = nx.from_pandas_adjacency(W[W > 0].fillna(0), create_using=nx.DiGraph)
G2 = nx.from_pandas_adjacency(W[W < 0].fillna(0), create_using=nx.DiGraph)
plot_graph(G1, G2)

plt.figure(figsize=(15, 5));
plt.subplot(1, 2, 1);
sns.heatmap(W_pos != 0);
plt.title('Positive Edges');
plt.subplot(1, 2, 2);
sns.heatmap(W_neg != 0);
plt.title('Negative Edges');
plt.figure(figsize=(10, 6));
sns.heatmap(W, cmap='RdBu_r', vmin=-np.max([W.max(), W.min()]), vmax=np.max([W.max(), W.min()]), annot=True, fmt='.2f', mask=np.isclose(W, 0));
plt.title('Adjacency Matrix');<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1748314606741573, 'fraction_numerical': 0.04404494382022472, 'mean_word_length': 6.783216783216783, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 22, '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': '226801', 'license': 'MIT', 'n_tokens_mistral': 1042, 'n_tokens_neox': 955, 'n_words': 151, 'path': 'notebooks/Experiment.ipynb', 'repo_name': 'alirezaomidi/cancerdag', 'size': '2225'}