Diversity_rf: Diversity_rf function for FCM data

Description Usage Arguments Examples

View source: R/Diversity_rf.R

Description

This function calculates Hill diversity metrics from FCM data. This function differs from the Diversity() function in that it resamples (with replacement) all individual samples and averages out the diversity over all subsamples. This function is recommended in case there are differences in sample size (nr. of cells). Analysis time is approximately 10s/resample run (R) on default settings for the flowData example.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
Diversity_rf(
  x,
  d = 4,
  R = 100,
  R.b = 100,
  bw = 0.01,
  nbin = 128,
  param,
  cleanFCS = FALSE,
  ncores = 1,
  parallel = FALSE,
  timesplit = 0.1,
  TimeChannel = "Time"
)

Arguments

x

flowSet containing the samples to analyse.

d

Rounding factor for density values. Defaults to 4.

R

Number of resampling runs to conduct on individual samples. Defaults to 100

R.b

Number of bootstraps to conduct on the fingerprint (requires less). Defaults to 100

bw

Bandwidth used in the kernel density estimation. Defaults to 0.01 which is ideal for normalized FCM data (i.e., all parameter values are within [0,1]).

nbin

Resolution of the binning grid. Defaults to 128 bins which corresponds to a 128x128 binning grid.

param

Parameter vector indicating on which parameters the diversity should be estimated. An example input would be: c("FL1-H", "FL3-H", "SSC-H", "FSC-H"). In addition the first parameter in this vector will be used to normalize the data. Please make sure this is the primary fluorescence channel if available. For example FL1-H for SYBR Green stained bacterial cells measured on an Accuri C6.

cleanFCS

Indicate whether outlier removal should be conducted prior to diversity assessment (flowAI package). Defaults to FALSE. I would recommend to make sure samples have > 500 cells. Will denoise based on the parameters specified in 'param'.

ncores

How many cores should be used in case of parallel computation? Defaults to 1.

parallel

Should the calculation be parallelized? Defaults to FALSE

timesplit

Fraction of timestep used in flowAI for denoising. Please consult the 'flowAI::flow_auto_qc' function for more information.

TimeChannel

Name of time channel in the FCS files. This can differ between flow cytometers. Defaults to "Time". You can check this by: colnames(flowSet).

Examples

 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
# Full data processing example

# Load raw data (imported using flowCore)
data(flowData)

# Take subsample
flowData <- flowData[1:5]

# Asinh transform and select parameters of interest (cells were stained with Sybr Green I).
flowData_transformed <- flowCore::transform(flowData,`FL1-H`=asinh(`FL1-H`),
       `SSC-H`=asinh(`SSC-H`),
       `FL3-H`=asinh(`FL3-H`),
       `FSC-H`=asinh(`FSC-H`))
param=c('FL1-H', 'FL3-H','SSC-H','FSC-H')

# Create a PolygonGate for denoising the dataset
# Define coordinates for gate in sqrcut1 in format: c(x,x,x,x,y,y,y,y)
sqrcut1 <- matrix(c(8.75,8.75,14,14,3,7.5,14,3),ncol=2, nrow=4)
colnames(sqrcut1) <- c('FL1-H','FL3-H')
polyGate1 <- flowCore::polygonGate(.gate=sqrcut1, filterId = 'Total Cells')

# Gating quality check
flowViz::xyplot(`FL3-H` ~ `FL1-H`, data=flowData_transformed[1], filter=polyGate1,
       scales=list(y=list(limits=c(0,14)),
       x=list(limits=c(6,16))),
       axis = lattice::axis.default, nbin=125,
       par.strip.text=list(col='white', font=2, cex=2), smooth=FALSE)

# Isolate only the cellular information based on the polyGate1
flowData_transformed <- flowCore::Subset(flowData_transformed, polyGate1)

# Calculate diversity for first 5 samples without cleaning data
Diversity_rf(flowData_transformed[1:5], param = param, R = 3, R.b = 3,
             cleanFCS = FALSE)

rprops/Phenoflow_package documentation built on Sept. 22, 2020, 5:43 p.m.