In this script, we will go through the necessary steps to apply, in order to make sure that the data is cleaned, and that further analyses will reflect biological processes rather than technical artefacts.

Setup

We load some previously installed libraries, which offer specific functionalities for flow cytometry data analysis. You can have a look at http://bioconductor.org/packages/release/BiocViews.html#___FlowCytometry to see more packages which might be of interest.

library(flowCore) # For general fcs file handling
library(flowDensity) # For flow data plotting
library(flowWorkspace) # For loading a flowjo workspace
library(flowAI) # For quality control of fcs files
library(FlowSOM) # For the FlowSOM algorithm
library(FlowSOMworkshop) # Additional functions for this workshop

We point to where the FlowJo workspace and the fcs file are saved on our computer, and we parse the fcs file:

wsp_file <- "../inst/extdata/manualGating.wsp"
fcs_file <- "../inst/extdata/21-10-15_Tube_013.fcs"
tube_13 <- parse_flowjo(fcs_file, wsp_file)

We put the flowFrame containing the expression values from the tube 13 in a variable called "ff_13".

ff_13 <- tube_13$flowFrame

Exercises:

1) Generate a "tube_11" object, containing the flowjo result that corresponds to the cells of the tube 11:

fcs_file_11 <- "../inst/extdata/21-10-15_Tube_011.fcs"
tube_11 <- parse_flowjo(fcs_file_11, wsp_file)

2) Generate a "ff_11" object, containing the flowFrame that corresponds to the cells of the tube 11:

ff_11 <- tube_11$flowFrame
ff_11

Control of the time effects:

We will use the FlowAI function "flow_auto_qc" to assess the quality of the flowframe we loaded. We also provide to the function the path of the folder in which we want the results to be plotted.

resQC <- flow_auto_qc(ff_13, folder_results = "../QC/")

Now, we will assess the quality of all 6 fcs files that we have available.
We begin by listing all these fcs files using the list.files function.
This function lists all files in a given directory. A pattern can be specified so only the files containing this pattern are selected. If you are interested in defining very detailed patterns, google "R regular expressions".

fcs_files <- list.files("../inst/extdata/", pattern = ".fcs")
fcs_files

We then parse all these fcs files with the information contained in the workspace:

tubes <- parse_flowjo(fcs_files, wsp_file)

The tubes object now contains: - a flowSet, which contains one flowframe per fcs file we loaded - the information corresponding to the manual gating

We will only need the flowframes for quality control with flowAI:

flowset <- tubes$flowSet
flowset

Each flowframe in the flowSet can be accessed by its filename:

flowset$`21-10-15_Tube_028.fcs`

Or by index:

flowset[[1]]

Exercises:

3) How many cells are there in the second flowframe of the flowset object?

nrow(flowset[[2]])

4) In which channels were CD3 and CD19 measured?

get_channels(flowset[[1]], c("CD3", "CD19"))

To use flowAI, the "flow_auto_qc" accepts flowsets as well as flowframes as input, so we can use it directly on the flowset that we generated:

resQC <- flow_auto_qc(flowset, folder_results = "../QC/")

A QC report is generated for each file in the specified folder. Have a look at these to see if the measurements were consistent over time. If not, you could add a manual time-gate in flowjo or you could use some additional functionality of the FlowAI package to generate cleaned up fcs files.

Control of differences between files:

It can be interesting to look at the main differences between files, to compare:

To do so, we can use the plot_aggregate function:

We first select the live cells only:

data_live <- gating_subset(tubes, "Live")

And then plot these live cells, for each of the files we have. We can also add a labels argument, which contains one value for every flowframe, indicating to which group it belongs. This value will be used for coloring.

plot_aggregate(input = data_live$flowSet, 
               labels = c("1","1","1","2","2","2"),
               output_image = "aggregate.png")


saeyslab/FlowSOM_workshop documentation built on Sept. 3, 2021, 9:21 a.m.