Step 3: Post-Processing

Tyler J Burns

October 2, 2017

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.12 seconds (sparsity = 0.126072)!
## Learning embedding...
## Iteration 50: error is 66.749586 (50 iterations in 0.22 seconds)
## Iteration 100: error is 60.351769 (50 iterations in 0.17 seconds)
## Iteration 150: error is 59.909140 (50 iterations in 0.17 seconds)
## Iteration 200: error is 59.751714 (50 iterations in 0.17 seconds)
## Iteration 250: error is 59.668149 (50 iterations in 0.17 seconds)
## Iteration 300: error is 1.340393 (50 iterations in 0.14 seconds)
## Iteration 350: error is 1.227500 (50 iterations in 0.13 seconds)
## Iteration 400: error is 1.194481 (50 iterations in 0.13 seconds)
## Iteration 450: error is 1.180986 (50 iterations in 0.13 seconds)
## Iteration 500: error is 1.171291 (50 iterations in 0.13 seconds)
## Iteration 550: error is 1.164326 (50 iterations in 0.13 seconds)
## Iteration 600: error is 1.159510 (50 iterations in 0.13 seconds)
## Iteration 650: error is 1.155436 (50 iterations in 0.13 seconds)
## Iteration 700: error is 1.151983 (50 iterations in 0.13 seconds)
## Iteration 750: error is 1.147558 (50 iterations in 0.13 seconds)
## Iteration 800: error is 1.144999 (50 iterations in 0.13 seconds)
## Iteration 850: error is 1.142922 (50 iterations in 0.13 seconds)
## Iteration 900: error is 1.141579 (50 iterations in 0.12 seconds)
## Iteration 950: error is 1.139750 (50 iterations in 0.12 seconds)
## Iteration 1000: error is 1.138867 (50 iterations in 0.13 seconds)
## Fitting performed in 2.84 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.147          1.04           1.60                      0.733
##  2        -0.0893        -0.0653        -0.0490                   -0.135
##  3        -0.0612        -0.199         -0.499                    -0.615
##  4        -0.171          0.0286        -0.508                    -0.823
##  5        -0.123         -0.217         -0.179                    -0.509
##  6        -0.938         -0.799         -1.62                     -0.386
##  7        -0.320         -0.238         -0.350                     0.997
##  8         0.795         -0.185         -0.520                    -1.23 
##  9         0.701          1.14          -0.359                    -1.50 
## 10         0.137          1.13          -0.628                    -0.560
## # ℹ 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.939                      0.994                  0.931
##  2                       0.971                      0.951                  0.941
##  3                       0.964                      0.994                  0.980
##  4                       0.998                      0.951                  0.931
##  5                       0.939                      0.994                  0.921
##  6                       0.971                      0.994                  1    
##  7                       0.998                      1                      1    
##  8                       0.909                      0.951                  0.956
##  9                       0.971                      0.994                  0.947
## 10                       0.971                      0.994                  0.975
## # ℹ 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.147          1.04           1.60                      0.733
##  2        -0.0893        -0.0653        -0.0490                   -0.135
##  3        -0.0612        -0.199         -0.499                    -0.615
##  4        -0.171          0.0286        -0.508                    -0.823
##  5        -0.123         -0.217         -0.179                    -0.509
##  6        -0.938         -0.799         -1.62                     -0.386
##  7        -0.320         -0.238         -0.350                     0.997
##  8         0.795         -0.185         -0.520                    -1.23 
##  9         0.701          1.14          -0.359                    -1.50 
## 10         0.137          1.13          -0.628                    -0.560
## # ℹ 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.05 seconds (sparsity = 0.236792)!
## Learning embedding...
## Iteration 50: error is 54.796720 (50 iterations in 0.10 seconds)
## Iteration 100: error is 53.259699 (50 iterations in 0.09 seconds)
## Iteration 150: error is 53.026423 (50 iterations in 0.09 seconds)
## Iteration 200: error is 52.967829 (50 iterations in 0.09 seconds)
## Iteration 250: error is 52.911913 (50 iterations in 0.09 seconds)
## Iteration 300: error is 0.876003 (50 iterations in 0.07 seconds)
## Iteration 350: error is 0.820287 (50 iterations in 0.06 seconds)
## Iteration 400: error is 0.795572 (50 iterations in 0.06 seconds)
## Iteration 450: error is 0.784075 (50 iterations in 0.06 seconds)
## Iteration 500: error is 0.776871 (50 iterations in 0.06 seconds)
## Iteration 550: error is 0.772717 (50 iterations in 0.06 seconds)
## Iteration 600: error is 0.770714 (50 iterations in 0.06 seconds)
## Iteration 650: error is 0.768412 (50 iterations in 0.06 seconds)
## Iteration 700: error is 0.767592 (50 iterations in 0.06 seconds)
## Iteration 750: error is 0.767353 (50 iterations in 0.06 seconds)
## Iteration 800: error is 0.766684 (50 iterations in 0.06 seconds)
## Iteration 850: error is 0.766001 (50 iterations in 0.06 seconds)
## Iteration 900: error is 0.764352 (50 iterations in 0.06 seconds)
## Iteration 950: error is 0.762961 (50 iterations in 0.06 seconds)
## Iteration 1000: error is 0.762597 (50 iterations in 0.06 seconds)
## Fitting performed in 1.40 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.140         -0.0921        -1.49                     -2.01 
##  2        -0.126         -0.500         -0.828                     0.623
##  3        -0.0951         0.290         -0.0805                    0.143
##  4        -0.0271         0.711          0.544                     0.904
##  5        -0.218         -0.0921        -0.259                    -0.359
##  6        -0.0795         0.325          1.25                     -0.256
##  7         0.148          0.864          1.10                      0.596
##  8         0.198         -0.172          0.464                    -0.774
##  9        -0.251         -0.128         -0.262                    -0.467
## 10        -0.0189        -0.237          0.439                    -0.237
## # ℹ 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>, …