-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathflowWorkspace.Rmd
126 lines (102 loc) · 3.16 KB
/
flowWorkspace.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
---
title: "flowWorkspace and ggcyto"
author: "Jordi Camps"
date: "2018 31 05"
output: html_document
---
```{r message=TRUE}
library(flowWorkspace)
library(ggplot2)
library(ggcyto)
```
This workflow uses several packages to analyze flow data in R. It starts from your raw .fcs files and a .wsp file where you already compensated and analyzed your data. This makes it very handy to plot your data in R. You can also compensate and gate your data yourself but this is not covered in this workflow.
# Before starting
Make sure you have your *.fcs* files and you already analyzed your data with flow and saved it to a *.wsp* file.
You put all these files in the **data** folder.
# Load FlowJo workspace
Load the workspace in the R session.
```{r}
(ws <- openWorkspace("data/31-May-2018 TY8-12.wsp"))
```
Access list of samples.
```{r}
getSamples(ws)
```
Acces groups.
```{r}
getSampleGroups(ws)
```
```{r eval=FALSE, include=FALSE}
sn <- "data/EXAMPLE_FCS_FILE.fcs"
getKeywords(ws, sn)
```
# Parsing the workspace
In order to get more from the gating tree we need to parse the XML workspace into R data structures to represent the information therein.
The **name** variable has to be the name or number of the designated group that you want to analyze. If you didn't make any groups just leave it as 1.
```{r message=FALSE}
(gs <- parseWorkspace(ws, name = 1))
```
Print your samples names.
```{r}
sampleNames(gs)
```
## Basics on GatingSet
plot gating tree.
```{r}
plot(gs)
```
Retrieve population statistics.
```{r}
getPopStats(gs)
```
Plot individual gates
```{r}
plotGate(gs, "Lin-7AAD-")
```
Retrieve underlying flow data. This gives you a ncdfFlow object, from this object you can get to the data and do furter analysis.
```{r}
fs <- getData(gs)
class(fs)
```
# Plotting gated data
The plotting function of flowworkspace is not the best, that's why we use ggcyto from this moment on. This plots nice ggplot objects which you can also stack with different layers (check ggplot2 package).
## Plot gating tree
```{r}
plot(gs)
plot(gs, "Single Cells")
plot(gs, "Lin-7AAD-")
```
## Plot with ggcyto
Plot with ggplot not recommended
```{r}
fs <- getData(gs, "Lin-7AAD-")
ggplot(fs, aes(y = `Lin PE`, x = `7AAD`)) +
geom_hex(bins = 128) +
axis_x_inverse_trans() +
axis_y_inverse_trans() #+
#geom_gate("Lin-Live")
```
Data are stored transformed. When plotting, axes are scales to show raw values. The latest patch on RGlab/ggcyto lets you pass axis_inverse_trans=FALSE to autoplot to show raw values (otherwise you need to build up the plot with ggcyto and pass it in there).
```{r fig.height=10, fig.width=10}
ggcyto(gs, aes(y = `Comp-BV421-A`, x = `Comp-FITC-A`)) +
geom_hex(bins = 128) +
geom_gate(c("Alpl+Sca1-", "Alpl+Sca1+", "Alpl-Sca1+")) +
geom_stats() +
axis_x_inverse_trans() +
axis_y_inverse_trans() +
labs_cyto("marker")
```
```{r}
autoplot(fs, "Lin PE", "7AAD", bins = 64)
```
Most reccomended and easiest way of plotting. Make sure that you fill in the markers on the cytometer to make sure that you are able to plot your data in this way!
```{r}
#fs <- getData(gs, "Cd34+Sca1+")
autoplot(gs[[7]], "Cd34+Sca1+Alpl+", bins = 64)
```
```{r}
closeWorkspace(ws)
```
```{r}
sessionInfo()
```