You will use GetMarkerNames() to obtain properly named markers as a column in a csv saved to your computer. In this csv, you will make two columns, one for markers you want as input for knn, and one for markers you want to make your scone comparisons on. You will read this back into R to access these markers as vectors of strings. You’ll then run ProcessMultipleFiles() to get your subsampled, concatenated matrix ready for KNN computation.
Fluorescence and mass cytometry data are routinely processed by an increasing array of software platforms. Many of these contain graphical user interfaces, and many of these are R packages. However, no two analyses are the same, and many cases may involve direct processing of files in R. The Sconify package provides a suite of functions to make this process simpler and more user-friendly, prior to the knn-centric analysis occurring downstream. In essence, these functions convert fcs files into data matrices, process these matrices, and can output said matrices into fcs files readable by additional software. Although the primary intent of these functions is to pre-process fcs files for use of k-nearest neighbor statistics and visualizations in the remainder of this package, they are intended also to be general use functions.
We will be using the Wanderlust dataset through this series of vignettes. (paper: https://www.ncbi.nlm.nih.gov/pubmed/24766814, dataset: https://www.c2b2.columbia.edu/danapeerlab/html/wanderlust-data.html). We show a particular donor (labeled Sample C), with B cell precursors at the basal state, and stimulated with IL-7. In the paper, this reveals a small subset of precursors elevating its levels of pSTAT5 in relation to the rest of the cells.
For general comparisons, your files need to take on the structure “name_condition.fcs.” If you are comparing multiple donors, then your files need to take on the structure "name__donorID_condition.fcs."
I provide the function GetMarkerNames() to get the names of your parameters out of your data and modify them accordingly. This saves a list of marker names to a csv, as a single named column. Open this up in excel and delete the parameters you don’t want. Then, make two named columns. One contains static markers to be used for KNN (typically surface markers). The second contains the markers to be used in the comparisons. Name these two columns what you like. You’ll read in this csv and get these columns out as a vector of strings.
library(Sconify)
# Example fcs file
basal <- system.file('extdata',
'Bendall_et_al_Cell_Sample_C_basal.fcs',
package = "Sconify")
# Run this, and check your directory for "markers.csv"
markers <- GetMarkerNames(basal)
markers
## [1] "Time" "Cell_length" "CD3(Cd110)Di"
## [4] "CD3(Cd111)Di" "CD3(Cd112)Di" "CD235-61-7-15(In113)Di"
## [7] "CD3(Cd114)Di" "CD45(In115)Di" "cPARP(La139)Di"
## [10] "pPLCg2(Pr141)Di" "CD19(Nd142)Di" "CD22(Nd143)Di"
## [13] "pSrc(Nd144)Di" "IgD(Nd145)Di" "CD79b(Nd146)Di"
## [16] "CD20(Sm147)Di" "CD34(Nd148)Di" "CD179a(Sm149)Di"
## [19] "pSTAT5(Nd150)Di" "CD72(Eu151)Di" "Ki67(Sm152)Di"
## [22] "IgM(Eu153)Di" "Kappa(Sm154)Di" "pErk12(Gd155)Di"
## [25] "CD10(Gd156)Di" "Lambda(Gd157)Di" "pSTAT3(Gd158)Di"
## [28] "pAKT(Tb159)Di" "pBLNK(Gd160)Di" "CD24(Dy161)Di"
## [31] "pSyk(Dy162)Di" "TdT(Dy163)Di" "Rag1(Dy164)Di"
## [34] "PreBCR(Ho165)Di" "tIkBa(Er166)Di" "CD43(Er167)Di"
## [37] "CD38(Er168)Di" "pP38(Tm169)Di" "CD40(Er170)Di"
## [40] "pBTK(Yb171)Di" "pS6(Yb172)Di" "CD33(Yb173)Di"
## [43] "HLA-DR(Yb174)Di" "pCrkL(Lu175)Di" "pCREB(Yb176)Di"
## [46] "DNA1(Ir191)Di" "DNA2(Ir193)Di" "Viability1(Pt195)Di"
## [49] "Viability2(Pt196)Di" "wanderlust"
# Turn this into two columns, one for surface markers, and one for phosphos
# Label the two columns accoridngly. Save to csv. You'll read this modified
# file in the ProcessMultipleFiles() function.
write.csv(markers, "markers.csv", row.names = FALSE)
The markers.csv file, when opened in excel, looks like this (first 20 rows):
You modify it by hand. In the case of this dataset, it looks like this (first 20 rows):
Skip to “processing multiple files” section for the function that directly produces the data matrix for SCONE. Here, I provide here a general function that takes a single fcs file as input, performs an asinh transformation with a scale argument of 5 (for CyTOF) if instructed to, and converts the final output into a tibble. For SCONE, you’ll use ProcessMultipleFiles(), which has this function embedded inside it. I provide it as well for any instance where you simply want to read a fcs file into R.
# FCS file provided in the package
basal <- system.file('extdata',
'Bendall_et_al_Cell_Sample_C_basal.fcs',
package = "Sconify")
# Example of data with no transformation
basal.raw <- FcsToTibble(basal, transform = "none")
basal.raw
## # A tibble: 1,000 × 50
## Time Cell_…¹ CD3(C…² CD3(C…³ CD3(C…⁴ CD235…⁵ CD3(C…⁶ CD45(…⁷ cPARP…⁸ pPLCg…⁹
## <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 635 31 -3.54 1.82 -0.417 -1.54 -1.39 34.4 5.54 -1.19
## 2 1737 25 -0.639 -0.644 -0.758 -3.68 -0.351 11.4 -1.08 -0.140
## 3 2253 27 -1.64 2.78 -4.20 1.89 6.23 2.40 -0.932 0.639
## 4 3138 31 -0.250 -0.304 11.9 0.466 -0.511 20.3 -0.325 -0.892
## 5 4330 24 2.23 3.76 4.45 -2.34 -0.738 53.0 0.480 -0.709
## 6 4645 26 -0.795 -0.476 -1.19 -1.89 -1.24 42.6 -1.11 1.07
## 7 4760 26 -1.24 -0.648 1.23 0.930 -0.219 58.6 4.48 1.32
## 8 4771 24 -0.109 -3.62 -4.50 3.62 -0.799 17.1 -0.373 -0.539
## 9 4937 29 -0.302 4.43 2.38 -7.68 -3.75 42.4 -0.950 -0.218
## 10 4968 22 -4.85 -1.52 -2.15 -0.970 -2.08 22.2 0.470 -1.01
## # … with 990 more rows, 40 more variables: `CD19(Nd142)Di` <dbl>,
## # `CD22(Nd143)Di` <dbl>, `pSrc(Nd144)Di` <dbl>, `IgD(Nd145)Di` <dbl>,
## # `CD79b(Nd146)Di` <dbl>, `CD20(Sm147)Di` <dbl>, `CD34(Nd148)Di` <dbl>,
## # `CD179a(Sm149)Di` <dbl>, `pSTAT5(Nd150)Di` <dbl>, `CD72(Eu151)Di` <dbl>,
## # `Ki67(Sm152)Di` <dbl>, `IgM(Eu153)Di` <dbl>, `Kappa(Sm154)Di` <dbl>,
## # `pErk12(Gd155)Di` <dbl>, `CD10(Gd156)Di` <dbl>, `Lambda(Gd157)Di` <dbl>,
## # `pSTAT3(Gd158)Di` <dbl>, `pAKT(Tb159)Di` <dbl>, `pBLNK(Gd160)Di` <dbl>, …
# Asinh transformation with a scale argument of 5
basal.asinh <- FcsToTibble(basal, transform = "asinh")
basal.asinh
## # A tibble: 1,000 × 50
## Time Cell_…¹ CD3(C…² CD3(C…³ CD3(C…⁴ CD235…⁵ CD3(C…⁶ CD45(…⁷ cPARP…⁸ pPLCg…⁹
## <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 5.54 2.52 -0.659 0.357 -0.0833 -0.303 -0.274 2.63 0.955 -0.236
## 2 6.54 2.31 -0.128 -0.128 -0.151 -0.682 -0.0701 1.56 -0.213 -0.0281
## 3 6.80 2.39 -0.322 0.531 -0.763 0.370 1.04 0.463 -0.185 0.127
## 4 7.14 2.52 -0.0500 -0.0608 1.60 0.0931 -0.102 2.11 -0.0649 -0.177
## 5 7.46 2.27 0.432 0.694 0.801 -0.453 -0.147 3.06 0.0959 -0.141
## 6 7.53 2.35 -0.158 -0.0951 -0.235 -0.369 -0.246 2.84 -0.220 0.212
## 7 7.55 2.35 -0.245 -0.129 0.244 0.185 -0.0438 3.16 0.806 0.261
## 8 7.55 2.27 -0.0218 -0.672 -0.809 0.673 -0.159 1.95 -0.0745 -0.108
## 9 7.59 2.46 -0.0603 0.798 0.460 -1.21 -0.694 2.84 -0.189 -0.0436
## 10 7.59 2.19 -0.860 -0.300 -0.417 -0.193 -0.405 2.19 0.0940 -0.200
## # … with 990 more rows, 40 more variables: `CD19(Nd142)Di` <dbl>,
## # `CD22(Nd143)Di` <dbl>, `pSrc(Nd144)Di` <dbl>, `IgD(Nd145)Di` <dbl>,
## # `CD79b(Nd146)Di` <dbl>, `CD20(Sm147)Di` <dbl>, `CD34(Nd148)Di` <dbl>,
## # `CD179a(Sm149)Di` <dbl>, `pSTAT5(Nd150)Di` <dbl>, `CD72(Eu151)Di` <dbl>,
## # `Ki67(Sm152)Di` <dbl>, `IgM(Eu153)Di` <dbl>, `Kappa(Sm154)Di` <dbl>,
## # `pErk12(Gd155)Di` <dbl>, `CD10(Gd156)Di` <dbl>, `Lambda(Gd157)Di` <dbl>,
## # `pSTAT3(Gd158)Di` <dbl>, `pAKT(Tb159)Di` <dbl>, `pBLNK(Gd160)Di` <dbl>, …
This is the function that will be used as input for the rest of the SCONE pipeline. If multiple files are used, the data will be conatenated into a single labeled tibble with an additional column containing “condition” information for each cell (which file it came from). If multiple donors as used, an additional column can be added with this information as well (see MultipleDonorScone.Rmd). Per marker, the files can be quantile normalized (across files), or z score transformed. The files are downsampled evenly to the number specified by the user. We recommend 20,000.
# The FCS files (THEY NEED TO BE IN THE "....._condidtion.fcs" format")
basal <- system.file('extdata',
'Bendall_et_al_Cell_Sample_C_basal.fcs',
package = "Sconify")
il7 <- system.file('extdata',
'Bendall_et_al_Cell_Sample_C_IL7.fcs',
package = "Sconify")
# The markers (after they were modified by hand as instructed above)
markers <- system.file('extdata',
'markers.csv',
package = "Sconify")
markers <- ParseMarkers(markers)
surface <- markers[[1]]
surface
## [1] "CD3(Cd110)Di" "CD3(Cd111)Di" "CD3(Cd112)Di"
## [4] "CD235-61-7-15(In113)Di" "CD3(Cd114)Di" "CD45(In115)Di"
## [7] "CD19(Nd142)Di" "CD22(Nd143)Di" "IgD(Nd145)Di"
## [10] "CD79b(Nd146)Di" "CD20(Sm147)Di" "CD34(Nd148)Di"
## [13] "CD179a(Sm149)Di" "CD72(Eu151)Di" "IgM(Eu153)Di"
## [16] "Kappa(Sm154)Di" "CD10(Gd156)Di" "Lambda(Gd157)Di"
## [19] "CD24(Dy161)Di" "TdT(Dy163)Di" "Rag1(Dy164)Di"
## [22] "PreBCR(Ho165)Di" "CD43(Er167)Di" "CD38(Er168)Di"
## [25] "CD40(Er170)Di" "CD33(Yb173)Di" "HLA-DR(Yb174)Di"
# Combining these. Note that default is sub-sampling to 10,000 cells.
# Here, we subsample to 1000 cells to minimize processing time for the vignettes.
# not normalizing, and not scaling.
wand.combined <- ProcessMultipleFiles(files = c(basal, il7),
input = surface,
numcells = 1000)
wand.combined
## # A tibble: 1,000 × 51
## CD3(Cd110)D…¹ CD3(C…² CD3(C…³ CD235…⁴ CD3(C…⁵ CD45(…⁶ CD19(…⁷ CD22(…⁸ IgD(N…⁹
## <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 -0.249 -0.105 0.988 -0.718 1.09 2.01 1.95 -0.253 -0.0921
## 2 -0.161 -0.241 -0.232 -1.92 -0.436 2.52 2.43 1.68 -0.157
## 3 -0.983 -1.42 -2.20 -1.20 -1.72 -2.22 0.718 -0.479 -0.525
## 4 0.130 -0.167 1.26 0.959 -0.228 0.850 -0.217 -0.217 1.76
## 5 -0.0527 0.330 0.262 -0.0624 -0.386 2.50 2.75 -0.166 1.77
## 6 -0.154 0.535 0.0881 -1.33 1.76 0.758 1.34 -0.231 0.889
## 7 -0.171 0.0286 -0.508 -0.823 -0.234 3.75 2.84 1.92 0.399
## 8 -0.914 -0.996 -0.512 0.304 -0.420 3.00 2.84 0.440 -0.0654
## 9 -0.592 -0.433 -0.360 -0.0968 1.44 2.15 -0.0166 -0.329 0.582
## 10 0.356 -0.131 -0.431 -0.859 -0.746 3.94 2.16 0.663 1.59
## # … with 990 more rows, 42 more variables: `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>, …
## [1] "basal" "IL7"
# Limit your matrix to surface markers, if just using those downstream
wand.combined.input <- wand.combined[,surface]
wand.combined.input
## # A tibble: 1,000 × 27
## CD3(Cd110)D…¹ CD3(C…² CD3(C…³ CD235…⁴ CD3(C…⁵ CD45(…⁶ CD19(…⁷ CD22(…⁸ IgD(N…⁹
## <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 -0.249 -0.105 0.988 -0.718 1.09 2.01 1.95 -0.253 -0.0921
## 2 -0.161 -0.241 -0.232 -1.92 -0.436 2.52 2.43 1.68 -0.157
## 3 -0.983 -1.42 -2.20 -1.20 -1.72 -2.22 0.718 -0.479 -0.525
## 4 0.130 -0.167 1.26 0.959 -0.228 0.850 -0.217 -0.217 1.76
## 5 -0.0527 0.330 0.262 -0.0624 -0.386 2.50 2.75 -0.166 1.77
## 6 -0.154 0.535 0.0881 -1.33 1.76 0.758 1.34 -0.231 0.889
## 7 -0.171 0.0286 -0.508 -0.823 -0.234 3.75 2.84 1.92 0.399
## 8 -0.914 -0.996 -0.512 0.304 -0.420 3.00 2.84 0.440 -0.0654
## 9 -0.592 -0.433 -0.360 -0.0968 1.44 2.15 -0.0166 -0.329 0.582
## 10 0.356 -0.131 -0.431 -0.859 -0.746 3.94 2.16 0.663 1.59
## # … with 990 more rows, 18 more variables: `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>, and abbreviated variable …
# We can do this on a single file as well.
wand.basal <- ProcessMultipleFiles(files = basal,
numcells = 1000,
scale = TRUE,
input = surface)
wand.basal
## # A tibble: 1,000 × 51
## CD3(Cd110)D…¹ CD3(C…² CD3(C…³ CD235…⁴ CD3(C…⁵ CD45(…⁶ CD19(…⁷ CD22(…⁸ IgD(N…⁹
## <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 -1.14 0.650 -0.133 0.155 -0.326 0.170 -0.337 -0.350 2.01
## 2 0.0690 -0.144 -0.216 -0.278 -0.0849 -0.727 -1.07 -0.741 -0.618
## 3 -0.374 0.935 -0.967 0.923 1.23 -1.65 -1.24 0.655 1.15
## 4 0.246 -0.0332 1.93 0.607 -0.122 -0.266 0.711 0.320 -0.596
## 5 1.35 1.20 0.952 -0.0163 -0.176 0.533 0.980 0.310 -0.390
## 6 -0.000929 -0.0893 -0.319 0.0802 -0.292 0.350 -0.0783 -0.907 -0.727
## 7 -0.198 -0.145 0.269 0.712 -0.0540 0.616 -1.11 -0.621 -0.886
## 8 0.310 -1.03 -1.02 1.27 -0.190 -0.403 0.683 -0.555 -0.557
## 9 0.222 1.37 0.533 -0.885 -0.820 0.346 1.12 -0.668 0.902
## 10 -1.60 -0.425 -0.543 0.281 -0.480 -0.194 1.78 0.836 -0.0706
## # … with 990 more rows, 42 more variables: `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>, …
## [1] "basal"
For the type of condition versus basal analysis shown above, it may behoove the user to have a control containing two basal files being compared to each other (eg. with phospho-protein shifts across clusters). To this end, I developed a function called splitFile() that takes in a single file as input and splits it into two sub-matricies such that one group of cells can be the “treated” condition.
# Using the aforementioned basal fcs file
markers <- system.file('extdata',
'markers.csv',
package = "Sconify")
# The markers
markers <- read.csv(markers, stringsAsFactors = FALSE)
surface <- markers$surface
# The function
split.data <- SplitFile(file = basal,
input.markers = surface,
numcells = 1000)
split.data
## # A tibble: 1,000 × 51
## CD3(Cd110)…¹ CD3(C…² CD3(Cd…³ CD235…⁴ CD3(C…⁵ CD45(…⁶ CD19(…⁷ CD22(…⁸ IgD(N…⁹
## <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 -0.398 -0.252 -0.830 -0.816 -0.492 3.06 1.97 1.36 -0.369
## 2 -0.404 -0.440 -0.357 -0.738 -0.962 3.12 2.26 0.290 -0.134
## 3 -0.00781 -0.132 -0.00909 0.694 0.216 2.41 1.28 -0.0973 -0.376
## 4 -0.113 -0.0204 -0.118 -0.894 -0.141 4.10 1.32 1.57 1.59
## 5 0.312 1.10 0.906 0.572 0.393 2.33 -0.239 1.27 -0.0836
## 6 -0.360 -0.205 0.691 -0.609 -0.447 1.38 2.18 0.646 -0.306
## 7 -0.291 -0.0899 -0.355 -0.511 -0.159 3.16 1.30 -0.135 1.60
## 8 -0.251 -0.128 -0.262 -0.467 0.124 1.40 -0.168 -0.165 0.291
## 9 -0.0906 -0.236 -0.242 0.282 -0.353 2.27 2.00 -0.140 -0.0237
## 10 -0.193 -0.130 -0.0941 -0.683 -0.290 4.02 2.15 0.345 -0.141
## # … with 990 more rows, 42 more variables: `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>, …
## [1] "Split.1" "Split.2"