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.126728)!
## Learning embedding...
## Iteration 50: error is 68.134966 (50 iterations in 0.13 seconds)
## Iteration 100: error is 60.667908 (50 iterations in 0.11 seconds)
## Iteration 150: error is 60.153333 (50 iterations in 0.10 seconds)
## Iteration 200: error is 59.986454 (50 iterations in 0.10 seconds)
## Iteration 250: error is 59.901834 (50 iterations in 0.10 seconds)
## Iteration 300: error is 1.361603 (50 iterations in 0.09 seconds)
## Iteration 350: error is 1.242843 (50 iterations in 0.08 seconds)
## Iteration 400: error is 1.208222 (50 iterations in 0.08 seconds)
## Iteration 450: error is 1.189969 (50 iterations in 0.08 seconds)
## Iteration 500: error is 1.182064 (50 iterations in 0.08 seconds)
## Iteration 550: error is 1.174317 (50 iterations in 0.08 seconds)
## Iteration 600: error is 1.168902 (50 iterations in 0.08 seconds)
## Iteration 650: error is 1.165021 (50 iterations in 0.08 seconds)
## Iteration 700: error is 1.161875 (50 iterations in 0.08 seconds)
## Iteration 750: error is 1.159120 (50 iterations in 0.08 seconds)
## Iteration 800: error is 1.157053 (50 iterations in 0.08 seconds)
## Iteration 850: error is 1.155282 (50 iterations in 0.08 seconds)
## Iteration 900: error is 1.154546 (50 iterations in 0.08 seconds)
## Iteration 950: error is 1.153023 (50 iterations in 0.08 seconds)
## Iteration 1000: error is 1.150731 (50 iterations in 0.08 seconds)
## Fitting performed in 1.76 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.0698        -0.164         -0.0780                  -0.688 
##  2        -0.597         -0.242         -0.106                   -0.624 
##  3        -0.157          0.342          1.03                     0.402 
##  4        -0.158         -0.0951        -0.235                   -0.369 
##  5        -0.251         -0.298         -0.229                   -0.167 
##  6        -0.308         -0.503         -0.592                    0.431 
##  7        -0.326         -0.0343         1.04                     0.157 
##  8        -0.0268         0.781          1.29                     0.0662
##  9         0.395         -0.120          0.634                    0.989 
## 10        -0.238         -0.0382         0.347                    0.898 
## # ℹ 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                       1                          0.966                  0.924
##  2                       0.989                      0.930                  0.962
##  3                       0.989                      0.962                  0.870
##  4                       0.989                      0.996                  0.870
##  5                       0.989                      0.969                  0.962
##  6                       0.989                      0.965                  0.962
##  7                       1                          0.992                  0.891
##  8                       0.989                      0.992                  0.870
##  9                       1                          0.962                  0.958
## 10                       0.989                      0.965                  0.924
## # ℹ 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.0698        -0.164         -0.0780                  -0.688 
##  2        -0.597         -0.242         -0.106                   -0.624 
##  3        -0.157          0.342          1.03                     0.402 
##  4        -0.158         -0.0951        -0.235                   -0.369 
##  5        -0.251         -0.298         -0.229                   -0.167 
##  6        -0.308         -0.503         -0.592                    0.431 
##  7        -0.326         -0.0343         1.04                     0.157 
##  8        -0.0268         0.781          1.29                     0.0662
##  9         0.395         -0.120          0.634                    0.989 
## 10        -0.238         -0.0382         0.347                    0.898 
## # ℹ 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.236256)!
## Learning embedding...
## Iteration 50: error is 54.728269 (50 iterations in 0.06 seconds)
## Iteration 100: error is 53.512426 (50 iterations in 0.05 seconds)
## Iteration 150: error is 53.304690 (50 iterations in 0.05 seconds)
## Iteration 200: error is 53.216404 (50 iterations in 0.05 seconds)
## Iteration 250: error is 53.177967 (50 iterations in 0.05 seconds)
## Iteration 300: error is 0.864592 (50 iterations in 0.04 seconds)
## Iteration 350: error is 0.818150 (50 iterations in 0.04 seconds)
## Iteration 400: error is 0.807113 (50 iterations in 0.04 seconds)
## Iteration 450: error is 0.800146 (50 iterations in 0.04 seconds)
## Iteration 500: error is 0.795486 (50 iterations in 0.04 seconds)
## Iteration 550: error is 0.791192 (50 iterations in 0.04 seconds)
## Iteration 600: error is 0.788714 (50 iterations in 0.04 seconds)
## Iteration 650: error is 0.786955 (50 iterations in 0.04 seconds)
## Iteration 700: error is 0.785138 (50 iterations in 0.04 seconds)
## Iteration 750: error is 0.784207 (50 iterations in 0.04 seconds)
## Iteration 800: error is 0.782000 (50 iterations in 0.04 seconds)
## Iteration 850: error is 0.781900 (50 iterations in 0.04 seconds)
## Iteration 900: error is 0.781312 (50 iterations in 0.04 seconds)
## Iteration 950: error is 0.780614 (50 iterations in 0.04 seconds)
## Iteration 1000: error is 0.780258 (50 iterations in 0.04 seconds)
## Fitting performed in 0.81 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.210          -0.249        -0.126                     0.868 
##  2       -0.138          -0.318        -0.309                     0.852 
##  3       -0.186          -0.150        -0.104                    -1.84  
##  4       -0.0915         -0.179        -0.00690                   0.558 
##  5       -0.489          -0.489        -0.817                     0.900 
##  6       -0.00750        -0.589        -0.810                     0.738 
##  7       -0.189          -0.707        -0.479                     0.0466
##  8       -0.260          -0.249        -0.0120                   -1.23  
##  9       -0.163          -0.145        -0.441                    -0.0194
## 10        0.146           0.0425        0.0244                   -0.244 
## # ℹ 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>, …