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.25 seconds (sparsity = 0.126030)!
## Learning embedding...
## Iteration 50: error is 66.662802 (50 iterations in 0.33 seconds)
## Iteration 100: error is 60.607086 (50 iterations in 0.21 seconds)
## Iteration 150: error is 60.277841 (50 iterations in 0.18 seconds)
## Iteration 200: error is 60.157066 (50 iterations in 0.23 seconds)
## Iteration 250: error is 60.083467 (50 iterations in 0.27 seconds)
## Iteration 300: error is 1.343804 (50 iterations in 0.29 seconds)
## Iteration 350: error is 1.241598 (50 iterations in 0.24 seconds)
## Iteration 400: error is 1.209767 (50 iterations in 0.22 seconds)
## Iteration 450: error is 1.194549 (50 iterations in 0.23 seconds)
## Iteration 500: error is 1.188408 (50 iterations in 0.23 seconds)
## Iteration 550: error is 1.182729 (50 iterations in 0.24 seconds)
## Iteration 600: error is 1.178086 (50 iterations in 0.24 seconds)
## Iteration 650: error is 1.175829 (50 iterations in 0.24 seconds)
## Iteration 700: error is 1.173771 (50 iterations in 0.24 seconds)
## Iteration 750: error is 1.171058 (50 iterations in 0.24 seconds)
## Iteration 800: error is 1.168963 (50 iterations in 0.24 seconds)
## Iteration 850: error is 1.167232 (50 iterations in 0.25 seconds)
## Iteration 900: error is 1.165034 (50 iterations in 0.19 seconds)
## Iteration 950: error is 1.162121 (50 iterations in 0.23 seconds)
## Iteration 1000: error is 1.159812 (50 iterations in 0.22 seconds)
## Fitting performed in 4.76 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        -1.13          -0.446         -2.12             -1.59         -0.860 
##  2        -0.150         -0.0612        -0.156            -2.15         -0.660 
##  3        -0.0614         0.446          0.616            -0.254        -0.296 
##  4        -0.124         -0.370         -0.210            -0.860        -0.0543
##  5        -0.112          0.538         -0.0787           -1.47         -0.265 
##  6        -0.115         -0.172         -0.158            -1.99         -0.125 
##  7        -0.173         -0.127         -0.149            -0.246        -0.175 
##  8        -0.328          0.477          1.52             -0.312        -0.0437
##  9        -0.0340        -0.0610        -0.211             0.249         0.776 
## 10        -0.207         -0.184         -0.562            -2.39         -0.323 
## # … 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.891                1            0.994            0.979
##  2            0.997                1            0.691            0.905
##  3            0.567                1            0.781            1    
##  4            0.966                1            0.853            0.979
##  5            0.891                1            0.707            0.904
##  6            0.418                1            1                0.997
##  7            0.969                1            0.873            0.979
##  8            0.756                1            0.691            0.997
##  9            0.916                1            0.619            0.979
## 10            0.567                1            0.594            0.906
## # … 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        -1.13          -0.446         -2.12             -1.59         -0.860 
##  2        -0.150         -0.0612        -0.156            -2.15         -0.660 
##  3        -0.0614         0.446          0.616            -0.254        -0.296 
##  4        -0.124         -0.370         -0.210            -0.860        -0.0543
##  5        -0.112          0.538         -0.0787           -1.47         -0.265 
##  6        -0.115         -0.172         -0.158            -1.99         -0.125 
##  7        -0.173         -0.127         -0.149            -0.246        -0.175 
##  8        -0.328          0.477          1.52             -0.312        -0.0437
##  9        -0.0340        -0.0610        -0.211             0.249         0.776 
## 10        -0.207         -0.184         -0.562            -2.39         -0.323 
## # … 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.10 seconds (sparsity = 0.235928)!
## Learning embedding...
## Iteration 50: error is 54.804151 (50 iterations in 0.15 seconds)
## Iteration 100: error is 53.395181 (50 iterations in 0.12 seconds)
## Iteration 150: error is 53.213419 (50 iterations in 0.11 seconds)
## Iteration 200: error is 53.096505 (50 iterations in 0.08 seconds)
## Iteration 250: error is 53.054509 (50 iterations in 0.12 seconds)
## Iteration 300: error is 0.846852 (50 iterations in 0.07 seconds)
## Iteration 350: error is 0.798612 (50 iterations in 0.07 seconds)
## Iteration 400: error is 0.785154 (50 iterations in 0.06 seconds)
## Iteration 450: error is 0.778727 (50 iterations in 0.07 seconds)
## Iteration 500: error is 0.772712 (50 iterations in 0.07 seconds)
## Iteration 550: error is 0.769331 (50 iterations in 0.07 seconds)
## Iteration 600: error is 0.766527 (50 iterations in 0.07 seconds)
## Iteration 650: error is 0.762870 (50 iterations in 0.10 seconds)
## Iteration 700: error is 0.762955 (50 iterations in 0.10 seconds)
## Iteration 750: error is 0.761149 (50 iterations in 0.10 seconds)
## Iteration 800: error is 0.761141 (50 iterations in 0.10 seconds)
## Iteration 850: error is 0.760954 (50 iterations in 0.07 seconds)
## Iteration 900: error is 0.758727 (50 iterations in 0.06 seconds)
## Iteration 950: error is 0.757899 (50 iterations in 0.08 seconds)
## Iteration 1000: error is 0.756262 (50 iterations in 0.08 seconds)
## Fitting performed in 1.76 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.0951         0.290         -0.0805           0.143          -0.172
##  2        -0.168         -0.357         -0.0829           0.939          -0.384
##  3         0.767          1.96           2.25            -2.47            1.22 
##  4        -0.251         -0.109         -0.0732          -0.277          -0.102
##  5        -0.715          1.82           2.10            -0.0199          1.69 
##  6        -0.243         -0.0594        -0.402           -1.19           -0.225
##  7        -0.173         -0.0759         1.28            -0.0842         -0.265
##  8        -0.110         -0.223         -0.0472           0.240          -0.248
##  9        -0.365         -0.565          0.383           -2.30            0.333
## 10        -0.643         -0.195         -0.297            0.284           0.443
## # … 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...70` <dbl>,
## #   `bh-SNE2...71` <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-SNE1...88` <dbl>,
## #   `bh-SNE2...89` <dbl>