Step 3: Post-Processing

The post-processing function:

This vignette covers what takes place following the generation of SCONE output detailed in TheSconeWorkflow.Rmd. The obvious step that needs to take place is the Scone generated columns being merged into the original input data. The user gets the option of log base 10 transforming q values, which is easier to visualize. The user also gets the option to run t-SNE on the data, such that said maps can be colored by SCONE generated values. In this case, t-SNE is run utilizing the Rtsne package, using the same markers that were used as input for the KNN. generation.

library(Sconify)
wand.final <- PostProcessing(scone.output = wand.scone,
                         cell.data = wand.combined,
                         input = input.markers)
## Read the 1000 x 27 data matrix successfully!
## OpenMP is working. 1 threads.
## Using no_dims = 2, perplexity = 30.000000, and theta = 0.500000
## Computing input similarities...
## Building tree...
## Done in 0.07 seconds (sparsity = 0.126314)!
## Learning embedding...
## Iteration 50: error is 63.184969 (50 iterations in 0.13 seconds)
## Iteration 100: error is 60.032842 (50 iterations in 0.10 seconds)
## Iteration 150: error is 59.668914 (50 iterations in 0.11 seconds)
## Iteration 200: error is 59.533792 (50 iterations in 0.11 seconds)
## Iteration 250: error is 59.445533 (50 iterations in 0.11 seconds)
## Iteration 300: error is 1.356225 (50 iterations in 0.09 seconds)
## Iteration 350: error is 1.243909 (50 iterations in 0.08 seconds)
## Iteration 400: error is 1.208901 (50 iterations in 0.08 seconds)
## Iteration 450: error is 1.193915 (50 iterations in 0.08 seconds)
## Iteration 500: error is 1.185686 (50 iterations in 0.08 seconds)
## Iteration 550: error is 1.181790 (50 iterations in 0.08 seconds)
## Iteration 600: error is 1.178675 (50 iterations in 0.08 seconds)
## Iteration 650: error is 1.175919 (50 iterations in 0.08 seconds)
## Iteration 700: error is 1.173869 (50 iterations in 0.08 seconds)
## Iteration 750: error is 1.170550 (50 iterations in 0.08 seconds)
## Iteration 800: error is 1.168141 (50 iterations in 0.08 seconds)
## Iteration 850: error is 1.165933 (50 iterations in 0.08 seconds)
## Iteration 900: error is 1.163819 (50 iterations in 0.08 seconds)
## Iteration 950: error is 1.162432 (50 iterations in 0.08 seconds)
## Iteration 1000: error is 1.161351 (50 iterations in 0.08 seconds)
## Fitting performed in 1.81 seconds.
wand.combined # input data
## # A tibble: 1,000 × 51
##    `CD3(Cd110)Di` `CD3(Cd111)Di` `CD3(Cd112)Di` `CD235-61-7-15(In113)Di`
##             <dbl>          <dbl>          <dbl>                    <dbl>
##  1        -0.0453        1.06             0.663                  -1.23  
##  2         0.138         0.411            1.46                   -0.0117
##  3        -0.278        -0.00435         -0.131                  -1.06  
##  4        -0.373        -0.908           -0.133                  -0.411 
##  5         0.157        -0.814           -0.645                   0.228 
##  6        -0.637         1.92             0.912                  -0.200 
##  7        -0.223        -0.865           -1.16                   -1.42  
##  8         0.476         0.467           -0.477                  -0.0572
##  9         0.701         1.14            -0.359                  -1.50  
## 10        -0.326        -0.0343           1.04                    0.157 
## # ℹ 990 more rows
## # ℹ 47 more variables: `CD3(Cd114)Di` <dbl>, `CD45(In115)Di` <dbl>,
## #   `CD19(Nd142)Di` <dbl>, `CD22(Nd143)Di` <dbl>, `IgD(Nd145)Di` <dbl>,
## #   `CD79b(Nd146)Di` <dbl>, `CD20(Sm147)Di` <dbl>, `CD34(Nd148)Di` <dbl>,
## #   `CD179a(Sm149)Di` <dbl>, `CD72(Eu151)Di` <dbl>, `IgM(Eu153)Di` <dbl>,
## #   `Kappa(Sm154)Di` <dbl>, `CD10(Gd156)Di` <dbl>, `Lambda(Gd157)Di` <dbl>,
## #   `CD24(Dy161)Di` <dbl>, `TdT(Dy163)Di` <dbl>, `Rag1(Dy164)Di` <dbl>, …
wand.scone # scone-generated data
## # A tibble: 1,000 × 34
##    `pCrkL(Lu175)Di.IL7.qvalue` pCREB(Yb176)Di.IL7.qvalu…¹ pBTK(Yb171)Di.IL7.qv…²
##                          <dbl>                      <dbl>                  <dbl>
##  1                       0.999                      0.886                  0.827
##  2                       0.999                      0.824                  0.782
##  3                       0.999                      0.933                  0.773
##  4                       0.999                      0.824                  0.994
##  5                       0.999                      0.824                  0.973
##  6                       0.999                      0.750                  0.873
##  7                       0.999                      0.833                  0.993
##  8                       0.999                      0.961                  0.953
##  9                       0.999                      0.796                  0.994
## 10                       0.954                      0.926                  0.708
## # ℹ 990 more rows
## # ℹ abbreviated names: ¹​`pCREB(Yb176)Di.IL7.qvalue`,
## #   ²​`pBTK(Yb171)Di.IL7.qvalue`
## # ℹ 31 more variables: `pS6(Yb172)Di.IL7.qvalue` <dbl>,
## #   `cPARP(La139)Di.IL7.qvalue` <dbl>, `pPLCg2(Pr141)Di.IL7.qvalue` <dbl>,
## #   `pSrc(Nd144)Di.IL7.qvalue` <dbl>, `Ki67(Sm152)Di.IL7.qvalue` <dbl>,
## #   `pErk12(Gd155)Di.IL7.qvalue` <dbl>, `pSTAT3(Gd158)Di.IL7.qvalue` <dbl>, …
wand.final # the data after post-processing
## # A tibble: 1,000 × 87
##    `CD3(Cd110)Di` `CD3(Cd111)Di` `CD3(Cd112)Di` `CD235-61-7-15(In113)Di`
##             <dbl>          <dbl>          <dbl>                    <dbl>
##  1        -0.0453        1.06             0.663                  -1.23  
##  2         0.138         0.411            1.46                   -0.0117
##  3        -0.278        -0.00435         -0.131                  -1.06  
##  4        -0.373        -0.908           -0.133                  -0.411 
##  5         0.157        -0.814           -0.645                   0.228 
##  6        -0.637         1.92             0.912                  -0.200 
##  7        -0.223        -0.865           -1.16                   -1.42  
##  8         0.476         0.467           -0.477                  -0.0572
##  9         0.701         1.14            -0.359                  -1.50  
## 10        -0.326        -0.0343           1.04                    0.157 
## # ℹ 990 more rows
## # ℹ 83 more variables: `CD3(Cd114)Di` <dbl>, `CD45(In115)Di` <dbl>,
## #   `CD19(Nd142)Di` <dbl>, `CD22(Nd143)Di` <dbl>, `IgD(Nd145)Di` <dbl>,
## #   `CD79b(Nd146)Di` <dbl>, `CD20(Sm147)Di` <dbl>, `CD34(Nd148)Di` <dbl>,
## #   `CD179a(Sm149)Di` <dbl>, `CD72(Eu151)Di` <dbl>, `IgM(Eu153)Di` <dbl>,
## #   `Kappa(Sm154)Di` <dbl>, `CD10(Gd156)Di` <dbl>, `Lambda(Gd157)Di` <dbl>,
## #   `CD24(Dy161)Di` <dbl>, `TdT(Dy163)Di` <dbl>, `Rag1(Dy164)Di` <dbl>, …
# tSNE map shows highly responsive population of interest
TsneVis(wand.final, 
        "pSTAT5(Nd150)Di.IL7.change", 
        "IL7 -> pSTAT5 change")

# tSNE map now colored by q value
TsneVis(wand.final, 
        "pSTAT5(Nd150)Di.IL7.qvalue", 
        "IL7 -> pSTAT5 -log10(qvalue)")

# tSNE map colored by KNN density estimation
TsneVis(wand.final, "density")

Subsampling your data prior to running t-SNE:

If one has a large number of cells in the dataset (>100K), then t-SNE can become time-consuming and produce results that are less clean. As such, I provide a wrapper that allows one to subsample the final data and run t-SNE on the subsampled data, producing a new tibble that contains the subsampled data along with two t-SNE dimensions added to it. Note the two added dimensions at the end of the tibble are called “bh-SNE11” and “bh-SNE21”. This is because the dimensions “bh-SNE1” and “bh-SNE2” are already in the data, because t-SNE was run during the post processing step in this example. As I have stated, a user would realistically use this function with a much larger number of cells, in which case the user would have selected “tsne = FALSE” in the post.processing function detailed above in this vignette.

wand.final.sub <- SubsampleAndTsne(dat = wand.final, 
                                   input = input.markers, 
                                   numcells = 500)
## Read the 500 x 27 data matrix successfully!
## OpenMP is working. 1 threads.
## Using no_dims = 2, perplexity = 30.000000, and theta = 0.500000
## Computing input similarities...
## Building tree...
## Done in 0.03 seconds (sparsity = 0.239600)!
## Learning embedding...
## Iteration 50: error is 54.401587 (50 iterations in 0.06 seconds)
## Iteration 100: error is 53.102960 (50 iterations in 0.05 seconds)
## Iteration 150: error is 52.787810 (50 iterations in 0.05 seconds)
## Iteration 200: error is 52.708432 (50 iterations in 0.05 seconds)
## Iteration 250: error is 52.599268 (50 iterations in 0.05 seconds)
## Iteration 300: error is 0.840470 (50 iterations in 0.04 seconds)
## Iteration 350: error is 0.787558 (50 iterations in 0.04 seconds)
## Iteration 400: error is 0.769098 (50 iterations in 0.04 seconds)
## Iteration 450: error is 0.762597 (50 iterations in 0.04 seconds)
## Iteration 500: error is 0.757841 (50 iterations in 0.04 seconds)
## Iteration 550: error is 0.754431 (50 iterations in 0.04 seconds)
## Iteration 600: error is 0.752890 (50 iterations in 0.04 seconds)
## Iteration 650: error is 0.751321 (50 iterations in 0.04 seconds)
## Iteration 700: error is 0.749054 (50 iterations in 0.04 seconds)
## Iteration 750: error is 0.747736 (50 iterations in 0.04 seconds)
## Iteration 800: error is 0.745026 (50 iterations in 0.04 seconds)
## Iteration 850: error is 0.743631 (50 iterations in 0.04 seconds)
## Iteration 900: error is 0.742581 (50 iterations in 0.04 seconds)
## Iteration 950: error is 0.742249 (50 iterations in 0.04 seconds)
## Iteration 1000: error is 0.740522 (50 iterations in 0.04 seconds)
## Fitting performed in 0.83 seconds.
wand.final.sub
## # A tibble: 500 × 89
##    `CD3(Cd110)Di` `CD3(Cd111)Di` `CD3(Cd112)Di` `CD235-61-7-15(In113)Di`
##             <dbl>          <dbl>          <dbl>                    <dbl>
##  1        -0.908         -0.813         -0.287                   -1.83  
##  2        -0.643         -0.195         -0.297                    0.284 
##  3         0.610         -0.718          1.59                    -1.71  
##  4        -0.547         -0.356         -0.325                   -0.0631
##  5         0.747          0.799          1.86                     0.597 
##  6        -0.128         -0.128         -0.151                   -0.682 
##  7        -0.505         -0.0680         0.295                    0.257 
##  8        -0.273          0.0231        -0.810                   -1.31  
##  9        -0.0584        -0.247         -0.0507                   0.150 
## 10         0.0264         0.147          0.804                   -2.53  
## # ℹ 490 more rows
## # ℹ 85 more variables: `CD3(Cd114)Di` <dbl>, `CD45(In115)Di` <dbl>,
## #   `CD19(Nd142)Di` <dbl>, `CD22(Nd143)Di` <dbl>, `IgD(Nd145)Di` <dbl>,
## #   `CD79b(Nd146)Di` <dbl>, `CD20(Sm147)Di` <dbl>, `CD34(Nd148)Di` <dbl>,
## #   `CD179a(Sm149)Di` <dbl>, `CD72(Eu151)Di` <dbl>, `IgM(Eu153)Di` <dbl>,
## #   `Kappa(Sm154)Di` <dbl>, `CD10(Gd156)Di` <dbl>, `Lambda(Gd157)Di` <dbl>,
## #   `CD24(Dy161)Di` <dbl>, `TdT(Dy163)Di` <dbl>, `Rag1(Dy164)Di` <dbl>, …