<jupyter_start><jupyter_text>03d DPA MPP surface clusterscompare differences in proportions within MPP subtypesdone with this docker image:docker run --rm -d --name test_eva -p 8883:8888 -e JUPYTER_ENABLE_LAB=YES -v /Users/efast/Documents/:/home/jovyan/work r_scanpy:vs5<jupyter_code>import scanpy as sc
import numpy as np
import scipy as sp
import pandas as pd

import matplotlib.pyplot as plt
from matplotlib import rcParams
from matplotlib import colors
import seaborn as sns
import scipy.stats as stats
sc.settings.set_figure_params(dpi=80, dpi_save=300, vector_friendly=True)
#Data files
treatments = ['ct', 'indo', 'GCSF', 'dmPGE2', 'pIC']
cell_types = ['HSC', 'MPP1', 'MPP', 'MPP2',  'MPP3/4']
cell_type_names = ['HSC', 'MPP1', 'MPP', 'MPP2',  'MPP3']

for i in range(len(cell_types)):
    cell = cell_types[i]
    cell_name = cell_type_names[i]
    results_df = []
    results_df = pd.DataFrame()
    
    for treatment in treatments:

        path_name = './write/' + 'MPP_MPPsurf_within_leiden_' + treatment + '.csv'
        df = pd.read_csv(path_name)
        
        df = df.set_index('Unnamed: 0')
        
        row = pd.DataFrame(df.loc[cell,:]).T
        row.index = [treatment]
        
        results_df = results_df.append(row)
    
    
    save_name = './write/' + 'clusters_by_surf_' + cell_name +'.csv'
    results_df.to_csv(save_name)<jupyter_output>/opt/conda/lib/python3.7/site-packages/pandas/core/frame.py:7138: FutureWarning: Sorting because non-concatenation axis is not aligned. A future version
of pandas will change to not sort by default.

To accept the future behavior, pass 'sort=False'.

To retain the current behavior and silence the warning, pass 'sort=True'.

  sort=sort,<jupyter_text>Do DPA for subgroups<jupyter_code>import rpy2.rinterface_lib.callbacks
import logging

from rpy2.robjects import pandas2ri
import anndata2ri
# Ignore R warning messages
#Note: this can be commented out to get more verbose R output
rpy2.rinterface_lib.callbacks.logger.setLevel(logging.ERROR)

# Automatically convert rpy2 outputs to pandas dataframes
pandas2ri.activate()
anndata2ri.activate()
%load_ext rpy2.ipython

plt.rcParams['figure.figsize']=(8,8) #rescale figures
sc.settings.verbosity = 3
#sc.set_figure_params(dpi=200, dpi_save=300)
sc.logging.print_versions()
%%R
# Load libraries from correct lib Paths for my environment - ignore this!
.libPaths(.libPaths()[c(3,2,1)])

# Load all the R libraries we will be using in the notebook
library(ggplot2)
library(plyr)

source("diffprop_functions.R");<jupyter_output><empty_output><jupyter_text>Comparison MPP clusters - MPPs<jupyter_code># read csvs, rename columns, merge and transpose
MPP = pd.read_csv('./write/clusters_by_surf_MPP.csv', index_col = 0)
MPP = MPP.fillna(0)
MPP[MPP < 5] = 0
MPP
sns.set_style("white")

def_color = ['#1f77b4','#b5bd61', '#279e68', '#8c564b', 
                               '#e377c2', '#aa40fc', '#d62728', 'tab:cyan']

percent_abs_v = MPP.T.iloc[:,0:8].div(MPP.T.sum(axis=0), axis=1)
percent_abs_v = percent_abs_v.reindex(['Progenitor', 'Primed', 'Metabolism', 'Cell-cycle', 
                                       'Interferon cell-cycle', 'Interferon', 'Acute-Activation','Myeloid'])

ax = percent_abs_v.T.plot.bar(stacked=True, color = def_color, figsize=(4, 4))
handles, labels = ax.get_legend_handles_labels()
plt.legend(handles[::-1], labels[::-1], loc='center left', bbox_to_anchor=(1.0, 0.5))
plt.ylabel("proportion of cells")
#plt.grid(b=None) # turns off gridlines
plt.savefig('./figures/MPP_onlyMPP_leiden_within_treatment.pdf', bbox_inches = "tight")
%%R -i MPP
## Read in file of counts of cells in each population across conditions

obs.counts = as.matrix(MPP)
print(obs.counts)
%%R

## Run an example using error (p) of 0.05 and with 100,000 iterations
tip.exp <- generateNull(obs.counts, n=100000, p=0.1);     # Generate the null distribution based on sampling

obs.counts/apply(obs.counts, 1, sum)
%%R
### P-value tests for old vs new
print('indo')
print(two.class.test(obs.counts, tip.exp, cond.control="ct", cond.treatment="indo",to.plot=F))
print('GCSF')
print(two.class.test(obs.counts, tip.exp, cond.control="ct", cond.treatment="GCSF",to.plot=F))
print('dmPGE2')
print(two.class.test(obs.counts, tip.exp, cond.control="ct", cond.treatment="dmPGE2",to.plot=F))
print('pIC')
print(two.class.test(obs.counts, tip.exp, cond.control="ct", cond.treatment="pIC",to.plot=F))<jupyter_output>[1] "indo"
     Acute.Activation            Cell.cycle            Interferon 
              0.44227               0.33657               0.49945 
Interferon.cell.cycle            Metabolism               Myeloid 
              0.14245               0.41373                   NaN 
               Primed            Progenitor 
              0.28984               0.49820 
[1] "GCSF"
     Acute.Activation            Cell.cycle            Interferon 
              0.45774               0.46421               0.48047 
Interferon.cell.cycle            Metabolism               Myeloid 
              0.14177               0.46605                   NaN 
               Primed            Progenitor 
              0.25057               0.35493 
[1] "dmPGE2"
     Acute.Activation            Cell.cycle            Interferon 
              0.00000               0.35581               0.46062 
Interferon.cell.cycle            Metabolism               Myeloid 
              0.14148               0.34019     [...]<jupyter_text>Comparison MPP clusters - MPP1s<jupyter_code># read csvs, rename columns, merge and transpose
MPP = pd.read_csv('./write/clusters_by_surf_MPP1.csv', index_col = 0)
MPP = MPP.fillna(0)
#MPP[MPP < 5] = 0

MPP
sns.set_style("white")

def_color = ['#1f77b4','#b5bd61', '#279e68', '#8c564b', 
                               '#e377c2', '#aa40fc', '#d62728', 'tab:cyan']

percent_abs_v = MPP.T.iloc[:,0:8].div(MPP.T.sum(axis=0), axis=1)
percent_abs_v = percent_abs_v.reindex(['Progenitor', 'Primed', 'Metabolism', 'Cell-cycle', 
                                       'Interferon cell-cycle', 'Interferon', 'Acute-Activation','Myeloid'])

ax = percent_abs_v.T.plot.bar(stacked=True, color = def_color, figsize=(4, 4))
handles, labels = ax.get_legend_handles_labels()
plt.legend(handles[::-1], labels[::-1], loc='center left', bbox_to_anchor=(1.0, 0.5))
plt.ylabel("proportion of cells")
#plt.grid(b=None) # turns off gridlines
plt.savefig('./figures/MPP_onlyMPP1_leiden_within_treatment.pdf', bbox_inches = "tight")
%%R -i MPP
## Read in file of counts of cells in each population across conditions

obs.counts = as.matrix(MPP)
print(obs.counts)
%%R

## Run an example using error (p) of 0.05 and with 100,000 iterations
tip.exp <- generateNull(obs.counts, n=100000, p=0.1);     # Generate the null distribution based on sampling

obs.counts/apply(obs.counts, 1, sum)
%%R
### P-value tests for old vs new
print('indo')
print(two.class.test(obs.counts, tip.exp, cond.control="ct", cond.treatment="indo",to.plot=F))
print('GCSF')
print(two.class.test(obs.counts, tip.exp, cond.control="ct", cond.treatment="GCSF",to.plot=F))
print('dmPGE2')
print(two.class.test(obs.counts, tip.exp, cond.control="ct", cond.treatment="dmPGE2",to.plot=F))
print('pIC')
print(two.class.test(obs.counts, tip.exp, cond.control="ct", cond.treatment="pIC",to.plot=F))<jupyter_output>[1] "indo"
     Acute.Activation            Cell.cycle            Interferon 
              0.41295               0.42275               0.42211 
Interferon.cell.cycle            Metabolism               Myeloid 
              0.11245               0.38822                   NaN 
               Primed            Progenitor 
              0.31239               0.43962 
[1] "GCSF"
     Acute.Activation            Cell.cycle            Interferon 
              0.46652               0.38333               0.44124 
Interferon.cell.cycle            Metabolism               Myeloid 
              0.11354               0.47270                   NaN 
               Primed            Progenitor 
              0.35934               0.47331 
[1] "dmPGE2"
     Acute.Activation            Cell.cycle            Interferon 
              0.00482               0.43294               0.38984 
Interferon.cell.cycle            Metabolism               Myeloid 
              0.11337               0.39884     [...]<jupyter_text>Comparison MPP clusters - MPP2s<jupyter_code># read csvs, rename columns, merge and transpose
MPP = pd.read_csv('./write/clusters_by_surf_MPP2.csv', index_col = 0)
MPP = MPP.fillna(0)
#MPP[MPP < 5] = 0

MPP
sns.set_style("white")

def_color = ['#1f77b4','#b5bd61', '#279e68', '#8c564b', 
                               '#e377c2', '#aa40fc', '#d62728', 'tab:cyan']

percent_abs_v = MPP.T.iloc[:,0:8].div(MPP.T.sum(axis=0), axis=1)
percent_abs_v = percent_abs_v.reindex(['Progenitor', 'Primed', 'Metabolism', 'Cell-cycle', 
                                       'Interferon cell-cycle', 'Interferon', 'Acute-Activation','Myeloid'])

ax = percent_abs_v.T.plot.bar(stacked=True, color = def_color, figsize=(4, 4))
handles, labels = ax.get_legend_handles_labels()
plt.legend(handles[::-1], labels[::-1], loc='center left', bbox_to_anchor=(1.0, 0.5))
plt.ylabel("proportion of cells")
#plt.grid(b=None) # turns off gridlines
plt.savefig('./figures/MPP_onlyMPP2_leiden_within_treatment.pdf', bbox_inches = "tight")
%%R -i MPP
## Read in file of counts of cells in each population across conditions

obs.counts = as.matrix(MPP)
print(obs.counts)
%%R

## Run an example using error (p) of 0.05 and with 100,000 iterations
tip.exp <- generateNull(obs.counts, n=100000, p=0.1);     # Generate the null distribution based on sampling

obs.counts/apply(obs.counts, 1, sum)
%%R
### P-value tests for old vs new
print('indo')
print(two.class.test(obs.counts, tip.exp, cond.control="ct", cond.treatment="indo",to.plot=F))
print('GCSF')
print(two.class.test(obs.counts, tip.exp, cond.control="ct", cond.treatment="GCSF",to.plot=F))
print('dmPGE2')
print(two.class.test(obs.counts, tip.exp, cond.control="ct", cond.treatment="dmPGE2",to.plot=F))
print('pIC')
print(two.class.test(obs.counts, tip.exp, cond.control="ct", cond.treatment="pIC",to.plot=F))<jupyter_output>[1] "indo"
     Acute.Activation            Cell.cycle            Interferon 
              0.19961               0.41163               0.17410 
Interferon.cell.cycle            Metabolism               Myeloid 
              0.06916               0.32360               0.22138 
               Primed            Progenitor 
              0.27695               0.23484 
[1] "GCSF"
     Acute.Activation            Cell.cycle            Interferon 
              0.20456               0.41813               0.17779 
Interferon.cell.cycle            Metabolism               Myeloid 
              0.06932               0.38631               0.21735 
               Primed            Progenitor 
              0.28692               0.32627 
[1] "dmPGE2"
     Acute.Activation            Cell.cycle            Interferon 
              0.04610               0.33822               0.17701 
Interferon.cell.cycle            Metabolism               Myeloid 
              0.06928               0.43420     [...]<jupyter_text>Comparison MPP clusters - MPP3/4s<jupyter_code># read csvs, rename columns, merge and transpose
MPP = pd.read_csv('./write/clusters_by_surf_MPP3.csv', index_col = 0)
MPP = MPP.fillna(0)
#MPP[MPP < 5] = 0

MPP
sns.set_style("white")

def_color = ['#1f77b4','#b5bd61', '#279e68', '#8c564b', 
                               '#e377c2', '#aa40fc', '#d62728', 'tab:cyan']

percent_abs_v = MPP.T.iloc[:,0:8].div(MPP.T.sum(axis=0), axis=1)
percent_abs_v = percent_abs_v.reindex(['Progenitor', 'Primed', 'Metabolism', 'Cell-cycle', 
                                       'Interferon cell-cycle', 'Interferon', 'Acute-Activation','Myeloid'])

ax = percent_abs_v.T.plot.bar(stacked=True, color = def_color, figsize=(4, 4))
handles, labels = ax.get_legend_handles_labels()
plt.legend(handles[::-1], labels[::-1], loc='center left', bbox_to_anchor=(1.0, 0.5))
plt.ylabel("proportion of cells")
#plt.grid(b=None) # turns off gridlines
plt.savefig('./figures/MPP_onlyMPP3_leiden_within_treatment.pdf', bbox_inches = "tight")
%%R -i MPP
## Read in file of counts of cells in each population across conditions

obs.counts = as.matrix(MPP)
print(obs.counts)
%%R

## Run an example using error (p) of 0.05 and with 100,000 iterations
tip.exp <- generateNull(obs.counts, n=100000, p=0.1);     # Generate the null distribution based on sampling

obs.counts/apply(obs.counts, 1, sum)
%%R
### P-value tests for old vs new
print('indo')
print(two.class.test(obs.counts, tip.exp, cond.control="ct", cond.treatment="indo",to.plot=F))
print('GCSF')
print(two.class.test(obs.counts, tip.exp, cond.control="ct", cond.treatment="GCSF",to.plot=F))
print('dmPGE2')
print(two.class.test(obs.counts, tip.exp, cond.control="ct", cond.treatment="dmPGE2",to.plot=F))
print('pIC')
print(two.class.test(obs.counts, tip.exp, cond.control="ct", cond.treatment="pIC",to.plot=F))<jupyter_output>[1] "indo"
     Acute.Activation            Cell.cycle            Interferon 
              0.48601               0.45973               0.46272 
Interferon.cell.cycle            Metabolism               Myeloid 
              0.47350               0.48095               0.39233 
               Primed            Progenitor 
              0.49050               0.37014 
[1] "GCSF"
     Acute.Activation            Cell.cycle            Interferon 
              0.47631               0.33849               0.48084 
Interferon.cell.cycle            Metabolism               Myeloid 
              0.45213               0.49669               0.31971 
               Primed            Progenitor 
              0.42332               0.45563 
[1] "dmPGE2"
     Acute.Activation            Cell.cycle            Interferon 
              0.00000               0.45018               0.46001 
Interferon.cell.cycle            Metabolism               Myeloid 
              0.45927               0.08391     [...]<jupyter_text>Comparison treatment shift surface MPPs<jupyter_code># read csvs, rename columns, merge and transpose
MPP = pd.read_csv('./write/MPP_MPPsurf_treatment_shift.csv', index_col = 0)
MPP = MPP.fillna(0)
#MPP[MPP < 5] = 0

MPP = MPP.T
%%R -i MPP
## Read in file of counts of cells in each population across conditions

obs.counts = as.matrix(MPP)
print(obs.counts)
%%R

## Run an example using error (p) of 0.05 and with 100,000 iterations
tip.exp <- generateNull(obs.counts, n=100000, p=0.1);     # Generate the null distribution based on sampling

print(obs.counts/apply(obs.counts, 1, sum))
%%R
### P-value tests for old vs new
print('Acute-Activation')
print(two.class.test(obs.counts, tip.exp, cond.control="dmPGE2", cond.treatment="Acute-Activation",to.plot=F))
print('Interferon')
print(two.class.test(obs.counts, tip.exp, cond.control="pIC", cond.treatment="Interferon",to.plot=F))
print('Interferon cell-cycle')
print(two.class.test(obs.counts, tip.exp, cond.control="pIC", cond.treatment="Interferon cell-cycle",to.plot=F))
print('Interferon cell-cycle vs Interferon')
print(two.class.test(obs.counts, tip.exp, cond.control="Interferon", cond.treatment="Interferon cell-cycle",to.plot=F))<jupyter_output>[1] "Acute-Activation"
    HSC     MPP    MPP1    MPP2  MPP3.4 
0.28537 0.11602 0.29030 0.27296 0.32965 
[1] "Interferon"
    HSC     MPP    MPP1    MPP2  MPP3.4 
0.47174 0.15512 0.44841 0.36290 0.19084 
[1] "Interferon cell-cycle"
    HSC     MPP    MPP1    MPP2  MPP3.4 
0.16258 0.09271 0.35480 0.46305 0.07589 
[1] "Interferon cell-cycle vs Interferon"
    HSC     MPP    MPP1    MPP2  MPP3.4 
0.17293 0.03129 0.33463 0.39078 0.03385<jupyter_text>Comparison surface receptors treatment<jupyter_code># read csvs, rename columns, merge and transpose
# since I didn't know the exact cell numbers assumed 5000 LT-HSCs in control and adjusted everything accordingly,
# total number is the same for all conditions
MPP = pd.read_csv('./raw_data/cell_numbers_dpa.csv', index_col = 0)
MPP = MPP.fillna(0)
MPP = MPP.T
MPP = round(MPP/50)
MPP
%%R -i MPP
## Read in file of counts of cells in each population across conditions

obs.counts = as.matrix(MPP)
print(obs.counts)
%%R

## Run an example using error (p) of 0.05 and with 100,000 iterations
tip.exp <- generateNull(obs.counts, n=100000, p=0.1);     # Generate the null distribution based on sampling

print(obs.counts/apply(obs.counts, 1, sum))
%%R
### P-value tests for old vs new
print('indo')
print(two.class.test(obs.counts, tip.exp, cond.control="ct", cond.treatment="indo",to.plot=F))
print('GCSF')
print(two.class.test(obs.counts, tip.exp, cond.control="ct", cond.treatment="GCSF",to.plot=F))
print('dmPGE2')
print(two.class.test(obs.counts, tip.exp, cond.control="ct", cond.treatment="dmPGE2",to.plot=F))
print('pIC')
print(two.class.test(obs.counts, tip.exp, cond.control="ct", cond.treatment="pIC",to.plot=F))
# read csvs, rename columns, merge and transpose
# since I didn't know the exact cell numbers assumed 5000 LT-HSCs in control and adjusted everything accordingly,
# total number is the same for all conditions
MPP = pd.read_csv('./raw_data/cell_numbers_dpa.csv', index_col = 0)
MPP = MPP.fillna(0)
MPP = MPP.T
MPP = round(MPP/5)
MPP
%%R -i MPP
## Read in file of counts of cells in each population across conditions

obs.counts = as.matrix(MPP)
print(obs.counts)
%%R

## Run an example using error (p) of 0.05 and with 100,000 iterations
tip.exp <- generateNull(obs.counts, n=100000, p=0.1);     # Generate the null distribution based on sampling

print(obs.counts/apply(obs.counts, 1, sum))
%%R
### P-value tests for old vs new
print('indo')
print(two.class.test(obs.counts, tip.exp, cond.control="ct", cond.treatment="indo",to.plot=F))
print('GCSF')
print(two.class.test(obs.counts, tip.exp, cond.control="ct", cond.treatment="GCSF",to.plot=F))
print('dmPGE2')
print(two.class.test(obs.counts, tip.exp, cond.control="ct", cond.treatment="dmPGE2",to.plot=F))
print('pIC')
print(two.class.test(obs.counts, tip.exp, cond.control="ct", cond.treatment="pIC",to.plot=F))<jupyter_output>[1] "indo"
 MPP3.4    MPP2     MPP    MPP1     HSC 
0.27585 0.48074 0.45818 0.23440 0.41343 
[1] "GCSF"
 MPP3.4    MPP2     MPP    MPP1     HSC 
0.41014 0.09545 0.12391 0.33785 0.41657 
[1] "dmPGE2"
 MPP3.4    MPP2     MPP    MPP1     HSC 
0.38358 0.08238 0.00692 0.00000 0.00089 
[1] "pIC"
 MPP3.4    MPP2     MPP    MPP1     HSC 
0.00366 0.04882 0.00001 0.21029 0.39128<jupyter_text>Compare treatment within Leiden LT<jupyter_code># read csvs, rename columns, merge and transpose
LT = pd.read_csv('./write/LT_treatment_within_leiden.csv', index_col = 0)
LT = LT.fillna(0)
#LT.insert( 0, 'baseline', 200) # insert baseline column
LT
div = LT.shape[1]
LT['baseline']= round(LT.sum(axis=1)/div)
LT = LT.T
%%R -i LT
## Read in file of counts of cells in each population across conditions

obs.counts = as.matrix(LT)
print(obs.counts)
%%R

## Run an example using error (p) of 0.05 and with 100,000 iterations
tip.exp <- generateNull(obs.counts, n=100000, p=0.1);     # Generate the null distribution based on sampling

print(obs.counts/apply(obs.counts, 1, sum))
%%R
### P-value tests for old vs new
print('Acute-Activation')
print(two.class.test(obs.counts, tip.exp, cond.control="baseline", cond.treatment="Acute-Activation",to.plot=F))
print('Interferon')
print(two.class.test(obs.counts, tip.exp, cond.control="baseline", cond.treatment="Interferon",to.plot=F))
print('Quiescent')
print(two.class.test(obs.counts, tip.exp, cond.control="baseline", cond.treatment="Quiescent",to.plot=F))
print('Metabolism')
print(two.class.test(obs.counts, tip.exp, cond.control="baseline", cond.treatment="Metabolism",to.plot=F))
print('Activated')
print(two.class.test(obs.counts, tip.exp, cond.control="baseline", cond.treatment="Activated",to.plot=F))
print('Cell-cycle')
print(two.class.test(obs.counts, tip.exp, cond.control="baseline", cond.treatment="Cell-cycle",to.plot=F))<jupyter_output>[1] "Acute-Activation"
   GCSF      ct  dmPGE2    indo     pIC 
0.00819 0.00031 0.00000 0.00038 0.13520 
[1] "Interferon"
   GCSF      ct  dmPGE2    indo     pIC 
0.02795 0.00273 0.14495 0.01038 0.00000 
[1] "Quiescent"
   GCSF      ct  dmPGE2    indo     pIC 
0.45733 0.20897 0.06315 0.49431 0.29586 
[1] "Metabolism"
   GCSF      ct  dmPGE2    indo     pIC 
0.15457 0.44856 0.18933 0.32818 0.28732 
[1] "Activated"
   GCSF      ct  dmPGE2    indo     pIC 
0.32750 0.42484 0.35413 0.08817 0.04971 
[1] "Cell-cycle"
   GCSF      ct  dmPGE2    indo     pIC 
0.34967 0.26410 0.26596 0.28524 0.27545<jupyter_text>Compare treatment within Leiden MPP<jupyter_code># read csvs, rename columns, merge and transpose
MPP = pd.read_csv('./write/MPP_treatment_within_leiden.csv', index_col = 0)
MPP = MPP.fillna(0)
#MPP.insert( 0, 'baseline', 200) # insert baseline column
MPP
div = MPP.shape[1]
MPP['baseline']= round(MPP.sum(axis=1)/div)
MPP = MPP.T
%%R -i MPP
## Read in file of counts of cells in each population across conditions

obs.counts = as.matrix(MPP)
print(obs.counts)
%%R

## Run an example using error (p) of 0.05 and with 100,000 iterations
tip.exp <- generateNull(obs.counts, n=100000, p=0.1);     # Generate the null distribution based on sampling

print(obs.counts/apply(obs.counts, 1, sum))
%%R
### P-value tests for old vs new
print('Acute-Activation')
print(two.class.test(obs.counts, tip.exp, cond.control="baseline", cond.treatment="Acute-Activation",to.plot=F))
print('Interferon')
print(two.class.test(obs.counts, tip.exp, cond.control="baseline", cond.treatment="Interferon",to.plot=F))
print('Interferon cell-cycle')
print(two.class.test(obs.counts, tip.exp, cond.control="baseline", cond.treatment="Interferon cell-cycle",to.plot=F))
print('Primed')
print(two.class.test(obs.counts, tip.exp, cond.control="baseline", cond.treatment="Primed",to.plot=F))
print('Metabolism')
print(two.class.test(obs.counts, tip.exp, cond.control="baseline", cond.treatment="Metabolism",to.plot=F))
print('Progenitor')
print(two.class.test(obs.counts, tip.exp, cond.control="baseline", cond.treatment="Progenitor",to.plot=F))
print('Myeloid')
print(two.class.test(obs.counts, tip.exp, cond.control="baseline", cond.treatment="Myeloid",to.plot=F))
print('Cell-cycle')
print(two.class.test(obs.counts, tip.exp, cond.control="baseline", cond.treatment="Cell-cycle",to.plot=F))<jupyter_output>[1] "Acute-Activation"
     ct    indo    GCSF  dmPGE2     pIC 
0.02968 0.00313 0.00212 0.00000 0.00025 
[1] "Interferon"
     ct    indo    GCSF  dmPGE2     pIC 
0.03236 0.01155 0.00341 0.00106 0.00000 
[1] "Interferon cell-cycle"
     ct    indo    GCSF  dmPGE2     pIC 
0.08312 0.03922 0.02737 0.01454 0.00000 
[1] "Primed"
     ct    indo    GCSF  dmPGE2     pIC 
0.24828 0.10795 0.06212 0.00051 0.46250 
[1] "Metabolism"
     ct    indo    GCSF  dmPGE2     pIC 
0.32552 0.26406 0.20337 0.25330 0.14852 
[1] "Progenitor"
     ct    indo    GCSF  dmPGE2     pIC 
0.14654 0.10224 0.12378 0.02324 0.11966 
[1] "Myeloid"
     ct    indo    GCSF  dmPGE2     pIC 
0.28059 0.23130 0.32498 0.12620 0.48108 
[1] "Cell-cycle"
     ct    indo    GCSF  dmPGE2     pIC 
0.38746 0.43056 0.48631 0.21797 0.13226<jupyter_text>Compare myeloid proportion within Surface of all<jupyter_code># read csvs, rename columns, merge and transpose
MPP = pd.read_csv('./write/MPP_leiden_within_MPPsurf_all.csv', index_col = 0)
MPP = MPP.fillna(0)
#MPP.insert( 0, 'baseline', 200) # insert baseline column
MPP = MPP.T
MPP
%%R -i MPP
## Read in file of counts of cells in each population across conditions

obs.counts = as.matrix(MPP)
print(obs.counts)
%%R

## Run an example using error (p) of 0.05 and with 100,000 iterations
tip.exp <- generateNull(obs.counts, n=100000, p=0.1);     # Generate the null distribution based on sampling

print(obs.counts/apply(obs.counts, 1, sum))
%%R
### P-value test MPP2 vs rest
print('HSC')
print(two.class.test(obs.counts, tip.exp, cond.control="MPP2", cond.treatment="HSC",to.plot=F))
print('MPP')
print(two.class.test(obs.counts, tip.exp, cond.control="MPP2", cond.treatment="MPP",to.plot=F))
print('MPP1')
print(two.class.test(obs.counts, tip.exp, cond.control="MPP2", cond.treatment="MPP1",to.plot=F))
print('MPP3/4')
print(two.class.test(obs.counts, tip.exp, cond.control="MPP2", cond.treatment="MPP3/4",to.plot=F))
%%R
### P-value test MPP vs rest
print('HSC')
print(two.class.test(obs.counts, tip.exp, cond.control="MPP", cond.treatment="HSC",to.plot=F))
print('MPP2')
print(two.class.test(obs.counts, tip.exp, cond.control="MPP", cond.treatment="MPP2",to.plot=F))
print('MPP1')
print(two.class.test(obs.counts, tip.exp, cond.control="MPP", cond.treatment="MPP1",to.plot=F))
print('MPP3/4')
print(two.class.test(obs.counts, tip.exp, cond.control="MPP", cond.treatment="MPP3/4",to.plot=F))<jupyter_output>[1] "HSC"
               Primed            Metabolism            Progenitor 
              0.14435               0.31825               0.02233 
           Cell.cycle      Acute.Activation            Interferon 
              0.33921               0.02463               0.45841 
Interferon.cell.cycle               Myeloid 
              0.28885               0.12072 
[1] "MPP2"
               Primed            Metabolism            Progenitor 
              0.24846               0.01026               0.00041 
           Cell.cycle      Acute.Activation            Interferon 
              0.06899               0.15071               0.28111 
Interferon.cell.cycle               Myeloid 
              0.29043               0.03159 
[1] "MPP1"
               Primed            Metabolism            Progenitor 
              0.04572               0.16946               0.23857 
           Cell.cycle      Acute.Activation            Interferon 
              0.27398               0.21942        [...]<jupyter_text>Compare MPP2 within the myeloid cluster<jupyter_code># read csvs, rename columns, merge and transpose
MPP = pd.read_csv('./write/MPP_MPPsurf_within_leiden_all.csv', index_col = 0)
MPP = MPP.fillna(0)
#MPP.insert( 0, 'baseline', 200) # insert baseline column
MPP = MPP.T
MPP
%%R -i MPP
## Read in file of counts of cells in each population across conditions

obs.counts = as.matrix(MPP)
print(obs.counts)
%%R

## Run an example using error (p) of 0.05 and with 100,000 iterations
tip.exp <- generateNull(obs.counts, n=100000, p=0.1);     # Generate the null distribution based on sampling

print(obs.counts/apply(obs.counts, 1, sum))
%%R
### P-value tests for old vs new
print('Acute-Activation')
print(two.class.test(obs.counts, tip.exp, cond.control="Myeloid", cond.treatment="Acute-Activation",to.plot=F))
print('Interferon')
print(two.class.test(obs.counts, tip.exp, cond.control="Myeloid", cond.treatment="Interferon",to.plot=F))
print('Interferon cell-cycle')
print(two.class.test(obs.counts, tip.exp, cond.control="Myeloid", cond.treatment="Interferon cell-cycle",to.plot=F))
print('Primed')
print(two.class.test(obs.counts, tip.exp, cond.control="Myeloid", cond.treatment="Primed",to.plot=F))
print('Metabolism')
print(two.class.test(obs.counts, tip.exp, cond.control="Myeloid", cond.treatment="Metabolism",to.plot=F))
print('Progenitor')
print(two.class.test(obs.counts, tip.exp, cond.control="Myeloid", cond.treatment="Progenitor",to.plot=F))
print('Cell-cycle')
print(two.class.test(obs.counts, tip.exp, cond.control="Myeloid", cond.treatment="Cell-cycle",to.plot=F))
%%R
### compare Progenitor cluster against everything else
print('Acute-Activation')
print(two.class.test(obs.counts, tip.exp, cond.control="Progenitor", cond.treatment="Acute-Activation",to.plot=F))
print('Interferon')
print(two.class.test(obs.counts, tip.exp, cond.control="Progenitor", cond.treatment="Interferon",to.plot=F))
print('Interferon cell-cycle')
print(two.class.test(obs.counts, tip.exp, cond.control="Progenitor", cond.treatment="Interferon cell-cycle",to.plot=F))
print('Primed')
print(two.class.test(obs.counts, tip.exp, cond.control="Progenitor", cond.treatment="Primed",to.plot=F))
print('Metabolism')
print(two.class.test(obs.counts, tip.exp, cond.control="Progenitor", cond.treatment="Metabolism",to.plot=F))
print('Myeloid')
print(two.class.test(obs.counts, tip.exp, cond.control="Progenitor", cond.treatment="Myeloid",to.plot=F))
print('Cell-cycle')
print(two.class.test(obs.counts, tip.exp, cond.control="Progenitor", cond.treatment="Cell-cycle",to.plot=F))
%%R

sessionInfo()
!pip list
sc.logging.print_versions()
pd.show_versions()<jupyter_output>scanpy==1.4.5.1 anndata==0.7.1 umap==0.3.10 numpy==1.17.3 scipy==1.3.0 pandas==0.25.3 scikit-learn==0.22.2.post1 statsmodels==0.10.0 python-igraph==0.7.1 louvain==0.6.1

INSTALLED VERSIONS
------------------
commit           : None
python           : 3.7.3.final.0
python-bits      : 64
OS               : Linux
OS-release       : 4.19.76-linuxkit
machine          : x86_64
processor        : x86_64
byteorder        : little
LC_ALL           : en_US.UTF-8
LANG             : en_US.UTF-8
LOCALE           : en_US.UTF-8

pandas           : 0.25.3
numpy            : 1.17.3
pytz             : 2019.3
dateutil         : 2.8.1
pip              : 19.3.1
setuptools       : 41.6.0.post20191101
Cython           : None
pytest           : 5.3.5
hypothesis       : None
sphinx           : None
blosc            : None
feather          : None
xlsxwriter       : None
lxml.etree       : None
html5lib         : None
pymysql          : None
psycopg2         : None
jinja2           : 2.10.3
IPython          : 7.[...]
{'fraction_non_alphanumeric': 0.14064778701034425, 'fraction_numerical': 0.06684754960149228, 'mean_word_length': 2.9090547527508948, 'pattern_counts': {'":': 0, '<': 54, '<?xml version=': 0, '>': 38, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 1}, 'pii_count': 1, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '12', 'dir': 'jupyter-structured-clean-dedup', 'id': '610750', 'license': 'MIT', 'n_tokens_mistral': 12118, 'n_tokens_neox': 10548, 'n_words': 2234, 'path': '03d_DPA_MPP_surface_clusters.ipynb', 'repo_name': 'evafast/scrnaseq_paper', 'size': '29485'}