Skip to contents

Downsample a gs based on subset

Usage

Utility_Downsample(
  x,
  sample.name,
  removestrings,
  subsets,
  subsample = NULL,
  inverse.transform = FALSE,
  internal = FALSE,
  export = FALSE,
  outpath = NULL
)

Arguments

x

A gating set object

sample.name

Keyword specifying sample name

removestrings

Value to be removed from sample name

subsets

The gating hierarchy subset you want to include

subsample

Total number of events to sub-sample from each specimen

inverse.transform

Whether to reverse the GatingSet Transform on the data, default is set to FALSE.

internal

Whether to return as a data.frame (vs. a flow frame or .fcs file)

export

Default is set to FALSE, when TRUE (and internal = FALSE) returns a .fcs file to outpath.

outpath

When export is true, the file.path to where you want the .fcs file stored.

Value

Either a data.frame, a flow.frame or an .fcs file depending on your selected options

Examples


library(BiocGenerics)
library(flowCore)
library(flowWorkspace)
library(openCyto)
library(data.table)

File_Location <- system.file("extdata", package = "Luciernaga")
FCS_Files <- list.files(path = File_Location, pattern = ".fcs",
  full.names = TRUE)
Unmixed_FullStained <- FCS_Files[grep("Unmixed", FCS_Files)]
UnmixedFCSFiles <- Unmixed_FullStained[1:2]
UnmixedCytoSet <- load_cytoset_from_fcs(UnmixedFCSFiles[1:2],
  truncate_max_range = FALSE,transformation = FALSE)
UnmixedGatingSet <- GatingSet(UnmixedCytoSet)
Markers <- colnames(UnmixedCytoSet)
KeptMarkers <- Markers[-grep("Time|FS|SC|SS|Original|-W$|-H$|AF", Markers)]
MyBiexponentialTransform <- flowjo_biexp_trans(channelRange = 256,
  maxValue = 1000000,pos = 4.5, neg = 0, widthBasis = -1000)
TransformList <- transformerList(KeptMarkers, MyBiexponentialTransform)
UnmixedGatingSet <- flowWorkspace::transform(UnmixedGatingSet, TransformList)
FileLocation <- system.file("extdata", package = "Luciernaga")
UnmixedGates <- fread(file.path(path = FileLocation, pattern = 'GatesUnmixed.csv'))
UnmixedGating <- gatingTemplate(UnmixedGates)
#> Adding population:singletsFSC
#> Adding population:singletsSSC
#> Adding population:singletsSSCB
#> Adding population:nonDebris
#> Adding population:lymphocytes
#> Adding population:live
gt_gating(UnmixedGating, UnmixedGatingSet)
#> Gating for 'singletsFSC'
#> done!
#> done.
#> Gating for 'singletsSSC'
#> done!
#> done.
#> Gating for 'singletsSSCB'
#> done!
#> done.
#> Gating for 'nonDebris'
#> done!
#> done.
#> Gating for 'lymphocytes'
#> The prior specification has no effect when usePrior=no
#> Using the serial version of flowClust
#> The prior specification has no effect when usePrior=no
#> Using the serial version of flowClust
#> done!
#> done.
#> Gating for 'live'
#> done!
#> done.
#> finished.

removestrings <- c("DTR_2023_ILT_15_Tetramers-","-Ctrl_Tetramer_Unmixed", ".fcs")
StorageLocation <- file.path("C:", "Users", "JohnDoe", "Desktop")

CountData <- gs_pop_get_count_fast(UnmixedGatingSet)
Counts_Specimen <- CountData %>%
 filter(Population %in% "/singletsFSC/singletsSSC/singletsSSCB/nonDebris/lymphocytes/live") %>%
 select(name, Count)

SingleSample <- Utility_Downsample(UnmixedGatingSet[1],
 sample.name = "GROUPNAME", removestrings=removestrings,
 subsets = "live", subsample = 2500, internal = FALSE, export = FALSE)