image_output_2.png image_output_1.png
import matplotlib.pyplot as plt

import numpy as np # linear algebra

import numpy as np # linear algebra

import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

import seaborn as sns

fig = plt.figure(figsize = (20,8))
col_x = 'CD53'
x_loc = df[col_x]
c = 0
for col in ['CD45RA','CD45RO', 'PTPRC']:
    if col in df_Y.columns:
        y_loc = df_Y[col]
    else:
        y_loc = df[col]

        
    c+=1; fig.add_subplot(1,3,c)
    sns.scatterplot(x=x_loc, y=y_loc)
    plt.xlabel(col_x)
    plt.ylabel(col)
    print( np.corrcoef(x_loc, y_loc)[0,1], 'correlation ', col_x, col)
    m = (x_loc !=0 ) &( y_loc != 0 )
    cc = np.corrcoef(x_loc[m], y_loc[m])[0,1]
    print(cc  , 'correlation excluding zeros ', col_x, col)
    if np.abs(cc) > 0.5: print('WOW it is big ! ')
        
plt.show()

display( df_Y[['CD45RA','CD45RO', ]].corr() )

y_loc = df_Y['CD45RO']
x_loc = df_Y['CD45RA']
fig = plt.figure(figsize = (10,10))
#     fig.add_subplot(1,2,1)
sns.scatterplot(x=x_loc, y=y_loc)
#     fig.add_subplot(1,2,2)
#     x_loc = df_Y['CD45RO']
#     sns.scatterplot(x=x_loc, y=y_loc)
plt.show()

if 'PTPRC' in df.columns: # 'PTPRC' is name for CD45 gene 
    y_loc = df['PTPRC']
    x_loc = df_Y['CD45RA']
    fig = plt.figure(figsize = (20,10))
    fig.add_subplot(1,2,1)
    sns.scatterplot(x=x_loc, y=y_loc)
    fig.add_subplot(1,2,2)
    x_loc = df_Y['CD45RO']
    sns.scatterplot(x=x_loc, y=y_loc)
    plt.show()
    
    print('Pearson correlations CD45RA, CD45RO:')
    print(np.corrcoef(df['PTPRC'], df_Y['CD45RA'])[1,0],     np.corrcoef(df['PTPRC'], df_Y['CD45RO'])[1,0],  )  
    
    print('Pearson correlations excluding zero rna values CD45RA, CD45RO:')
    mask = df['PTPRC'] != 0
    print(np.corrcoef(df['PTPRC'][mask], df_Y['CD45RA'][mask])[1,0],     np.corrcoef(df['PTPRC'][mask], df_Y['CD45RO'][mask])[1,0],  )  
    

for col in ['CD45RA', 'CD45RO']:
    n_bins = 50
    fig = plt.figure(figsize = (20,4))
    fig.add_subplot(1,2,1)
    mask = df['PTPRC'] == 0
    plt.hist(np.clip(df_Y[col][mask],0,2.5), bins = n_bins) 
    plt.title('ZERO RNA condition ' + col)
    fig.add_subplot(1,2,2)
    mask = df['PTPRC'] != 0
    plt.hist(np.clip(df_Y[col][mask],0,2.5), bins = n_bins) 
    plt.title('NON-ZERO RNA condition ' + col)
    plt.show()
    # print(np.corrcoef(df['PTPRC'][mask], df_Y['CD45RA'][mask])[1,0],     np.corrcoef(df['PTPRC'][mask], df_Y['CD45RO'][mask])[1,0],  )  

d2 = pd.DataFrame()
for c in ['CD45RA', 'CD45RO', 'MALAT1', 'NEAT1', 'CD45', 'SNRPD2', 'SNRPE', 'SRSF1', 'SRSF5', 'PTPRC']:
    if c in df.columns:
        d2[c] = df[c]
    elif c in df_Y.columns:
        d2[c] = df_Y[c]
d2.corr()

sns.clustermap(d2.corr().round(2), annot=True)

l = ['CD45RA', 'CD45RO', 'CD45', 'PTPRC', 'CD53', 'CD4', 'CD28', 'CD37', 'CD81', 'APC', 'SP1', 'CD151', 'MUC1', 'SDS', 'CD69', 'PTPRC', 'CD9', 'LCK', 'CD44', 'UCHL1', 'CD5', 'CD55', 'BCR', 'NHS', 'STAR', 'ZAP70']
d2 = pd.DataFrame()
for c in l:
    if c in df.columns:
        d2[c] = df[c]
    elif c in df_Y.columns:
        d2[c] = df_Y[c]
d2.corr()

sns.clustermap(d2.corr().round(2), annot=True)
plt.show()