Skip to contents

Calculate the relative flow rates of different timepoints throughout a flow or mass cytometry run.

Usage

tof_calculate_flow_rate(
  tof_tibble,
  time_col,
  num_timesteps = nrow(tof_tibble)/1000
)

Arguments

tof_tibble

A `tof_tbl` or `tibble`.

time_col

An unquoted column name indicating which column in `tof_tibble` contains the time at which each cell was collected.

num_timesteps

The number of bins into which `time_col` should be split. to define "timesteps" of the data collection process. The number of cells analyzed by the cytometer will be counted in each bin separately and will represent the relative average flow rate for that timestep in data collection.

Value

A tibble with 3 columns and num_timesteps rows. Each row will represent a single timestep (and an error will be thrown if `num_timesteps` is larger than the number of rows in `tof_tibble`). The three columns are as follows: "timestep", a numeric vector indicating which timestep is represented by a given row; "time_window", a factor showing the interval in `time_col` over which "timestep" is defined; and "num_cells", the number of cells that were collected during each timestep.

Examples


# simulate some data
sim_data <-
    data.frame(
        cd4 = rnorm(n = 100, mean = 5, sd = 0.5),
        cd8 = rnorm(n = 100, mean = 0, sd = 0.1),
        cd33 = rnorm(n = 100, mean = 10, sd = 0.1),
        time = sample(1:300, size = 100)
    )

tof_calculate_flow_rate(tof_tibble = sim_data, time_col = time, num_timesteps = 20L)
#>    timestep time_window num_cells
#> 1         1 (6.71,21.6]         4
#> 2         2 (21.6,36.2]         6
#> 3         3 (36.2,50.8]         7
#> 4         4 (50.8,65.4]         7
#> 5         5   (65.4,80]         5
#> 6         6   (80,94.6]         4
#> 7         7  (94.6,109]         5
#> 8         8   (109,124]         4
#> 9         9   (124,138]         1
#> 10       10   (138,153]         7
#> 11       11   (153,168]         5
#> 12       12   (168,182]         2
#> 13       13   (182,197]         7
#> 14       14   (197,211]         7
#> 15       15   (211,226]         5
#> 16       16   (226,241]         2
#> 17       17   (241,255]         4
#> 18       18   (255,270]         5
#> 19       19   (270,284]         7
#> 20       20   (284,299]         6