<jupyter_start><jupyter_text>Look at the genes individually<jupyter_code>source = genes_df.join(df[['Subtype','target']]).melt(id_vars=['Subtype','target'])
source.columns = ["Subtype","target","Gene","Value"]
counts = source.groupby('Subtype')['target'].count().to_frame()
counts.columns = ['Count']
source = source.set_index('Subtype').join(counts).reset_index()
# use the url approach to keep notebook smaller
url = 'Luminal_B_101_to_graph_fig1.json'
pyknowledge.plot.prepare_url(source,url)
source
# Scale Genes
import pyknowledge.transformers

genes_df_scaled = pyknowledge.transformers.standard_scale(genes_df)
# Get Distances
import pyknowledge.pathways
pathways_df = pyknowledge.pathways.get_pathway_genes('ReactomeLumB.csv')
#pathways_df = pathways_df[pathways_df['Pathway identifier'] == 'R-HSA-3700989']
Ds = pyknowledge.pathways.get_pathway_distances(pathways_df, genes_df_scaled)

Ds = pd.read_pickle(r'checkpoint.pkl')
Ds.pop('checkpoint', None)
# Stack Distances 
from scipy.stats import f_oneway

import matplotlib.pyplot as plt
fig = plt.figure(figsize=(20,20))
num = 0

variation_lumb = {}
variation_luma = {}

luma = None
lumb = None
not_luma = None
not_lumb = None


for key in Ds.keys():
    #Ds = Ds1[k]
    #cols = [i for i in D_s.keys() if int(i.split('_')[1]) in [a]]

    #Ds = { your_key: D_s[your_key] for your_key in cols }

    distances = {}
    for key in Ds.keys():
        distances[key] = pd.DataFrame(list(Ds[key]['distance']),columns=[key],index=Ds[key].index)
        
    for key in distances.keys():
        distances[key] = pyknowledge.distance.remove_self_ref(distances[key]).dropna()
    
    for key in distances.keys():
        distances[key] = pyknowledge.common.add_labels(df,distances[key])
        
    for key in distances.keys():
        t = distances[key]
    
        lumb = pd.concat([lumb,t[t['label1_label2'] == 'LumB - LumB'][key].reset_index()[key]], axis=1)
        not_lumb = pd.concat([not_lumb,t[t['label1_label2'] != 'LumB - LumB'][key].reset_index()[key]], axis=1)
        luma = pd.concat([luma,t[t['label1_label2'] == 'LumA - LumA'][key].reset_index()[key]], axis=1)
        not_luma = pd.concat([not_luma,t[t['label1_label2'] != 'LumA - LumA'][key].reset_index()[key]], axis=1)

    
    break

    lumb.to_csv('lumb.csv')
    not_lumb.to_csv('not_lumb.csv')
    luma.to_csv('luma.csv')
    not_luma.to_csv('not_luma.csv')
    
            
            
luma = pd.read_csv('luma.csv')
lumb = pd.read_csv('lumb.csv')
not_luma = pd.read_csv('not_luma.csv')
not_lumb = pd.read_csv('not_lumb.csv')
luma = luma.drop(['Unnamed: 0', 'Unnamed: 0.1', 'Unnamed: 0.1.1', 'Unnamed: 0.1.1.1',
       'Unnamed: 0.1.1.1.1', 'Unnamed: 0.1.1.1.1.1'], axis=1)
not_luma = not_luma.drop(['Unnamed: 0', 'Unnamed: 0.1', 'Unnamed: 0.1.1', 'Unnamed: 0.1.1.1',
       'Unnamed: 0.1.1.1.1', 'Unnamed: 0.1.1.1.1.1'], axis=1)
import matplotlib.pyplot as plt
import seaborn as sns
fig = plt.figure(figsize=(30, 20))
a = 1
for i in np.unique(luma.columns[0:15]):
    if ('DLSIGN' not in i):
        fig.add_subplot(2, 5, a)
        plt.title(i)
        plt.boxplot([luma[i], not_luma[i]])
        a += 1

#plt.savefig('distances_b/distances_0to4.png', bbox_inches='tight')
import matplotlib.pyplot as plt
import seaborn as sns
fig = plt.figure(figsize=(30, 20))
a = 1
for i in np.unique(luma.columns[15:30]):
    fig.add_subplot(3, 5, a)
    plt.title(i)
    plt.boxplot([luma[i], not_luma[i]])
    a += 1

!mkdir new_distances
fig = plt.figure(figsize=(30, 20))
a = 1
for i in np.unique(luma.columns[60:75]):
    if ('DLSIGN' not in i):
        fig.add_subplot(2, 5, a)
        plt.title(i)
        sns.kdeplot(luma[i])
        sns.kdeplot(not_luma[i])
        a += 1
        plt.xlim(0, 6)
        plt.ylim(0, 3)
        
plt.savefig('new_distances/distances_20to24.png', bbox_inches='tight')
fig = plt.figure(figsize=(30, 20))
a = 1
for i in np.unique(luma.columns[15:30]):
    if ('DLSIGN' not in i):
        fig.add_subplot(2, 5, a)
        plt.title(i)
        sns.kdeplot(luma[i])
        sns.kdeplot(not_luma[i])
        a += 1
        plt.xlim(0, 6)
        plt.ylim(0, 3)
        
#plt.savefig('distances_b/distances_10to14.png', bbox_inches='tight')
fig = plt.figure(figsize=(30, 20))
a = 1
for i in np.unique(lumb.columns[60:75]):
    fig.add_subplot(3, 5, a)
    plt.title(i)
    sns.kdeplot(lumb[i])
    sns.kdeplot(not_lumb[i])
    a += 1
plt.savefig('distances_b/distances_20to24.png', bbox_inches='tight')
fig = plt.figure(figsize=(30, 20))
a = 1
for i in np.unique(lumb.columns[75:90]):
    fig.add_subplot(3, 5, a)
    plt.title(i)
    sns.kdeplot(lumb[i])
    sns.kdeplot(not_lumb[i])
    a += 1
    
plt.savefig('distances_b/distances_25to26.png', bbox_inches='tight')
d = {}
for i in np.unique(luma.columns):
    d[i] =  np.abs(lumb[i].mean() - not_lumb[i].mean())
    
dict(sorted(d.items(), key=lambda item: item[1]))
4, 20, 21, 19, 10<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.17681688997157938, 'fraction_numerical': 0.036743808363784006, 'mean_word_length': 3.674573055028463, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 6, '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': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '530341', 'license': 'MIT', 'n_tokens_mistral': 2163, 'n_tokens_neox': 2047, 'n_words': 352, 'path': 'metabric/Luminal_B_101/PathwaysDistances.ipynb', 'repo_name': 'calpoly-bioinf/knowledgelib', 'size': '4926'}