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.21 seconds (sparsity = 0.126572)!
## Learning embedding...
## Iteration 50: error is 68.344727 (50 iterations in 0.32 seconds)
## Iteration 100: error is 60.947927 (50 iterations in 0.28 seconds)
## Iteration 150: error is 60.446804 (50 iterations in 0.21 seconds)
## Iteration 200: error is 60.302919 (50 iterations in 0.21 seconds)
## Iteration 250: error is 60.220655 (50 iterations in 0.22 seconds)
## Iteration 300: error is 1.355294 (50 iterations in 0.16 seconds)
## Iteration 350: error is 1.248940 (50 iterations in 0.15 seconds)
## Iteration 400: error is 1.220622 (50 iterations in 0.14 seconds)
## Iteration 450: error is 1.210678 (50 iterations in 0.14 seconds)
## Iteration 500: error is 1.202956 (50 iterations in 0.13 seconds)
## Iteration 550: error is 1.198463 (50 iterations in 0.14 seconds)
## Iteration 600: error is 1.195021 (50 iterations in 0.14 seconds)
## Iteration 650: error is 1.190829 (50 iterations in 0.17 seconds)
## Iteration 700: error is 1.188770 (50 iterations in 0.20 seconds)
## Iteration 750: error is 1.187067 (50 iterations in 0.15 seconds)
## Iteration 800: error is 1.184462 (50 iterations in 0.15 seconds)
## Iteration 850: error is 1.182413 (50 iterations in 0.14 seconds)
## Iteration 900: error is 1.180632 (50 iterations in 0.15 seconds)
## Iteration 950: error is 1.178888 (50 iterations in 0.15 seconds)
## Iteration 1000: error is 1.176895 (50 iterations in 0.15 seconds)
## Fitting performed in 3.49 seconds.
wand.combined # input data
## # A tibble: 1,000 x 51
##    `CD3(Cd110)Di` `CD3(Cd111)Di` `CD3(Cd112)Di` `CD235-61-7-15(… `CD3(Cd114)Di`
##             <dbl>          <dbl>          <dbl>            <dbl>          <dbl>
##  1         0.254        -0.0428          1.51              0.571        -0.866 
##  2        -0.0980       -0.00653        -0.116            -0.826        -0.133 
##  3        -0.200         0.0834         -0.187             0.644         0.235 
##  4         0.445         0.0987         -0.146            -0.958        -0.694 
##  5        -0.0657       -0.243          -0.0264           -0.319        -0.187 
##  6         0.124        -0.486          -0.944            -1.23          0.0795
##  7        -0.157        -0.262          -0.0956           -0.293        -0.0566
##  8        -0.174        -0.245          -0.200            -0.434        -0.0253
##  9        -0.638        -0.222          -0.382            -1.62          0.677 
## 10        -0.159         0.00610         1.08             -0.932         0.657 
## # … with 990 more rows, and 46 more variables: `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>,
## #   `PreBCR(Ho165)Di` <dbl>, `CD43(Er167)Di` <dbl>, `CD38(Er168)Di` <dbl>,
## #   `CD40(Er170)Di` <dbl>, `CD33(Yb173)Di` <dbl>, `HLA-DR(Yb174)Di` <dbl>,
## #   Time <dbl>, Cell_length <dbl>, `cPARP(La139)Di` <dbl>,
## #   `pPLCg2(Pr141)Di` <dbl>, `pSrc(Nd144)Di` <dbl>, `pSTAT5(Nd150)Di` <dbl>,
## #   `Ki67(Sm152)Di` <dbl>, `pErk12(Gd155)Di` <dbl>, `pSTAT3(Gd158)Di` <dbl>,
## #   `pAKT(Tb159)Di` <dbl>, `pBLNK(Gd160)Di` <dbl>, `pSyk(Dy162)Di` <dbl>,
## #   `tIkBa(Er166)Di` <dbl>, `pP38(Tm169)Di` <dbl>, `pBTK(Yb171)Di` <dbl>,
## #   `pS6(Yb172)Di` <dbl>, `pCrkL(Lu175)Di` <dbl>, `pCREB(Yb176)Di` <dbl>,
## #   `DNA1(Ir191)Di` <dbl>, `DNA2(Ir193)Di` <dbl>, `Viability1(Pt195)Di` <dbl>,
## #   `Viability2(Pt196)Di` <dbl>, wanderlust <dbl>, condition <chr>
wand.scone # scone-generated data
## # A tibble: 1,000 x 34
##    `pCrkL(Lu175)Di… `pCREB(Yb176)Di… `pBTK(Yb171)Di.… `pS6(Yb172)Di.I…
##               <dbl>            <dbl>            <dbl>            <dbl>
##  1            0.994            0.954            0.942            1    
##  2            0.974            0.623            0.861            0.989
##  3            1                0.980            0.981            0.997
##  4            0.987            0.980            0.661            1    
##  5            0.974            0.615            0.379            1    
##  6            1                0.984            0.968            0.997
##  7            0.994            0.701            0.481            0.989
##  8            0.987            0.984            0.602            1    
##  9            1                1                0.795            0.957
## 10            0.974            0.971            0.994            1    
## # … with 990 more rows, and 30 more variables:
## #   `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>,
## #   `pAKT(Tb159)Di.IL7.qvalue` <dbl>, `pBLNK(Gd160)Di.IL7.qvalue` <dbl>,
## #   `pP38(Tm169)Di.IL7.qvalue` <dbl>, `pSTAT5(Nd150)Di.IL7.qvalue` <dbl>,
## #   `pSyk(Dy162)Di.IL7.qvalue` <dbl>, `tIkBa(Er166)Di.IL7.qvalue` <dbl>,
## #   `pCrkL(Lu175)Di.IL7.change` <dbl>, `pCREB(Yb176)Di.IL7.change` <dbl>,
## #   `pBTK(Yb171)Di.IL7.change` <dbl>, `pS6(Yb172)Di.IL7.change` <dbl>,
## #   `cPARP(La139)Di.IL7.change` <dbl>, `pPLCg2(Pr141)Di.IL7.change` <dbl>,
## #   `pSrc(Nd144)Di.IL7.change` <dbl>, `Ki67(Sm152)Di.IL7.change` <dbl>,
## #   `pErk12(Gd155)Di.IL7.change` <dbl>, `pSTAT3(Gd158)Di.IL7.change` <dbl>,
## #   `pAKT(Tb159)Di.IL7.change` <dbl>, `pBLNK(Gd160)Di.IL7.change` <dbl>,
## #   `pP38(Tm169)Di.IL7.change` <dbl>, `pSTAT5(Nd150)Di.IL7.change` <dbl>,
## #   `pSyk(Dy162)Di.IL7.change` <dbl>, `tIkBa(Er166)Di.IL7.change` <dbl>,
## #   IL7.fraction.cond.2 <dbl>, density <dbl>
wand.final # the data after post-processing
## # A tibble: 1,000 x 87
##    `CD3(Cd110)Di` `CD3(Cd111)Di` `CD3(Cd112)Di` `CD235-61-7-15(… `CD3(Cd114)Di`
##             <dbl>          <dbl>          <dbl>            <dbl>          <dbl>
##  1         0.254        -0.0428          1.51              0.571        -0.866 
##  2        -0.0980       -0.00653        -0.116            -0.826        -0.133 
##  3        -0.200         0.0834         -0.187             0.644         0.235 
##  4         0.445         0.0987         -0.146            -0.958        -0.694 
##  5        -0.0657       -0.243          -0.0264           -0.319        -0.187 
##  6         0.124        -0.486          -0.944            -1.23          0.0795
##  7        -0.157        -0.262          -0.0956           -0.293        -0.0566
##  8        -0.174        -0.245          -0.200            -0.434        -0.0253
##  9        -0.638        -0.222          -0.382            -1.62          0.677 
## 10        -0.159         0.00610         1.08             -0.932         0.657 
## # … with 990 more rows, and 82 more variables: `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>,
## #   `PreBCR(Ho165)Di` <dbl>, `CD43(Er167)Di` <dbl>, `CD38(Er168)Di` <dbl>,
## #   `CD40(Er170)Di` <dbl>, `CD33(Yb173)Di` <dbl>, `HLA-DR(Yb174)Di` <dbl>,
## #   Time <dbl>, Cell_length <dbl>, `cPARP(La139)Di` <dbl>,
## #   `pPLCg2(Pr141)Di` <dbl>, `pSrc(Nd144)Di` <dbl>, `pSTAT5(Nd150)Di` <dbl>,
## #   `Ki67(Sm152)Di` <dbl>, `pErk12(Gd155)Di` <dbl>, `pSTAT3(Gd158)Di` <dbl>,
## #   `pAKT(Tb159)Di` <dbl>, `pBLNK(Gd160)Di` <dbl>, `pSyk(Dy162)Di` <dbl>,
## #   `tIkBa(Er166)Di` <dbl>, `pP38(Tm169)Di` <dbl>, `pBTK(Yb171)Di` <dbl>,
## #   `pS6(Yb172)Di` <dbl>, `pCrkL(Lu175)Di` <dbl>, `pCREB(Yb176)Di` <dbl>,
## #   `DNA1(Ir191)Di` <dbl>, `DNA2(Ir193)Di` <dbl>, `Viability1(Pt195)Di` <dbl>,
## #   `Viability2(Pt196)Di` <dbl>, wanderlust <dbl>, condition <dbl>,
## #   `pCrkL(Lu175)Di.IL7.change` <dbl>, `pCREB(Yb176)Di.IL7.change` <dbl>,
## #   `pBTK(Yb171)Di.IL7.change` <dbl>, `pS6(Yb172)Di.IL7.change` <dbl>,
## #   `cPARP(La139)Di.IL7.change` <dbl>, `pPLCg2(Pr141)Di.IL7.change` <dbl>,
## #   `pSrc(Nd144)Di.IL7.change` <dbl>, `Ki67(Sm152)Di.IL7.change` <dbl>,
## #   `pErk12(Gd155)Di.IL7.change` <dbl>, `pSTAT3(Gd158)Di.IL7.change` <dbl>,
## #   `pAKT(Tb159)Di.IL7.change` <dbl>, `pBLNK(Gd160)Di.IL7.change` <dbl>,
## #   `pP38(Tm169)Di.IL7.change` <dbl>, `pSTAT5(Nd150)Di.IL7.change` <dbl>,
## #   `pSyk(Dy162)Di.IL7.change` <dbl>, `tIkBa(Er166)Di.IL7.change` <dbl>,
## #   IL7.fraction.cond.2 <dbl>, density <dbl>, `bh-SNE1` <dbl>, `bh-SNE2` <dbl>,
## #   `pCrkL(Lu175)Di.IL7.qvalue` <dbl>, `pCREB(Yb176)Di.IL7.qvalue` <dbl>,
## #   `pBTK(Yb171)Di.IL7.qvalue` <dbl>, `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>,
## #   `pAKT(Tb159)Di.IL7.qvalue` <dbl>, `pBLNK(Gd160)Di.IL7.qvalue` <dbl>,
## #   `pP38(Tm169)Di.IL7.qvalue` <dbl>, `pSTAT5(Nd150)Di.IL7.qvalue` <dbl>,
## #   `pSyk(Dy162)Di.IL7.qvalue` <dbl>, `tIkBa(Er166)Di.IL7.qvalue` <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.06 seconds (sparsity = 0.236664)!
## Learning embedding...
## Iteration 50: error is 54.818451 (50 iterations in 0.14 seconds)
## Iteration 100: error is 53.071158 (50 iterations in 0.11 seconds)
## Iteration 150: error is 52.799962 (50 iterations in 0.09 seconds)
## Iteration 200: error is 52.679573 (50 iterations in 0.09 seconds)
## Iteration 250: error is 52.620328 (50 iterations in 0.09 seconds)
## Iteration 300: error is 0.868993 (50 iterations in 0.07 seconds)
## Iteration 350: error is 0.802765 (50 iterations in 0.07 seconds)
## Iteration 400: error is 0.787957 (50 iterations in 0.06 seconds)
## Iteration 450: error is 0.782697 (50 iterations in 0.06 seconds)
## Iteration 500: error is 0.779622 (50 iterations in 0.06 seconds)
## Iteration 550: error is 0.777329 (50 iterations in 0.06 seconds)
## Iteration 600: error is 0.775944 (50 iterations in 0.06 seconds)
## Iteration 650: error is 0.774514 (50 iterations in 0.07 seconds)
## Iteration 700: error is 0.772357 (50 iterations in 0.07 seconds)
## Iteration 750: error is 0.770153 (50 iterations in 0.09 seconds)
## Iteration 800: error is 0.769393 (50 iterations in 0.09 seconds)
## Iteration 850: error is 0.768051 (50 iterations in 0.09 seconds)
## Iteration 900: error is 0.767404 (50 iterations in 0.09 seconds)
## Iteration 950: error is 0.766734 (50 iterations in 0.07 seconds)
## Iteration 1000: error is 0.766429 (50 iterations in 0.06 seconds)
## Fitting performed in 1.60 seconds.
wand.final.sub
## # A tibble: 500 x 89
##    `CD3(Cd110)Di` `CD3(Cd111)Di` `CD3(Cd112)Di` `CD235-61-7-15(… `CD3(Cd114)Di`
##             <dbl>          <dbl>          <dbl>            <dbl>          <dbl>
##  1        -0.500         -0.350         -0.181           -0.0530        -0.188 
##  2         0.445          0.990          0.535            0.795          1.17  
##  3        -0.377         -0.0500        -0.820           -1.30           0.213 
##  4        -0.0834        -0.0638         0.0345          -0.608         -0.434 
##  5        -0.366         -0.391         -0.561            0.316         -0.959 
##  6        -0.147         -0.0909         0.554            0.0533         0.601 
##  7         0.148          0.707          1.02             0.548         -0.148 
##  8        -0.213         -0.201         -0.132           -0.684         -0.0903
##  9        -1.08          -0.915         -1.30            -2.13          -1.87  
## 10        -0.303         -0.461          0.423            0.509          2.11  
## # … with 490 more rows, and 84 more variables: `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>,
## #   `PreBCR(Ho165)Di` <dbl>, `CD43(Er167)Di` <dbl>, `CD38(Er168)Di` <dbl>,
## #   `CD40(Er170)Di` <dbl>, `CD33(Yb173)Di` <dbl>, `HLA-DR(Yb174)Di` <dbl>,
## #   Time <dbl>, Cell_length <dbl>, `cPARP(La139)Di` <dbl>,
## #   `pPLCg2(Pr141)Di` <dbl>, `pSrc(Nd144)Di` <dbl>, `pSTAT5(Nd150)Di` <dbl>,
## #   `Ki67(Sm152)Di` <dbl>, `pErk12(Gd155)Di` <dbl>, `pSTAT3(Gd158)Di` <dbl>,
## #   `pAKT(Tb159)Di` <dbl>, `pBLNK(Gd160)Di` <dbl>, `pSyk(Dy162)Di` <dbl>,
## #   `tIkBa(Er166)Di` <dbl>, `pP38(Tm169)Di` <dbl>, `pBTK(Yb171)Di` <dbl>,
## #   `pS6(Yb172)Di` <dbl>, `pCrkL(Lu175)Di` <dbl>, `pCREB(Yb176)Di` <dbl>,
## #   `DNA1(Ir191)Di` <dbl>, `DNA2(Ir193)Di` <dbl>, `Viability1(Pt195)Di` <dbl>,
## #   `Viability2(Pt196)Di` <dbl>, wanderlust <dbl>, condition <dbl>,
## #   `pCrkL(Lu175)Di.IL7.change` <dbl>, `pCREB(Yb176)Di.IL7.change` <dbl>,
## #   `pBTK(Yb171)Di.IL7.change` <dbl>, `pS6(Yb172)Di.IL7.change` <dbl>,
## #   `cPARP(La139)Di.IL7.change` <dbl>, `pPLCg2(Pr141)Di.IL7.change` <dbl>,
## #   `pSrc(Nd144)Di.IL7.change` <dbl>, `Ki67(Sm152)Di.IL7.change` <dbl>,
## #   `pErk12(Gd155)Di.IL7.change` <dbl>, `pSTAT3(Gd158)Di.IL7.change` <dbl>,
## #   `pAKT(Tb159)Di.IL7.change` <dbl>, `pBLNK(Gd160)Di.IL7.change` <dbl>,
## #   `pP38(Tm169)Di.IL7.change` <dbl>, `pSTAT5(Nd150)Di.IL7.change` <dbl>,
## #   `pSyk(Dy162)Di.IL7.change` <dbl>, `tIkBa(Er166)Di.IL7.change` <dbl>,
## #   IL7.fraction.cond.2 <dbl>, density <dbl>, `bh-SNE1` <dbl>, `bh-SNE2` <dbl>,
## #   `pCrkL(Lu175)Di.IL7.qvalue` <dbl>, `pCREB(Yb176)Di.IL7.qvalue` <dbl>,
## #   `pBTK(Yb171)Di.IL7.qvalue` <dbl>, `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>,
## #   `pAKT(Tb159)Di.IL7.qvalue` <dbl>, `pBLNK(Gd160)Di.IL7.qvalue` <dbl>,
## #   `pP38(Tm169)Di.IL7.qvalue` <dbl>, `pSTAT5(Nd150)Di.IL7.qvalue` <dbl>,
## #   `pSyk(Dy162)Di.IL7.qvalue` <dbl>, `tIkBa(Er166)Di.IL7.qvalue` <dbl>,
## #   `bh-SNE11` <dbl>, `bh-SNE21` <dbl>