DillonHammill / CytoExploreR

Interactive Cytometry Data Analysis
60 stars 13 forks source link

Found channel inconsistency across samples. 'Time' is missing from ... #167

Closed th-of closed 1 year ago

th-of commented 1 year ago

Anyone know how I can load an fcs file with the Time channel missing together with others file (where it's not missing)?

I have tried restrict = "Time and exclude = "Time" but it does not work.

Will this be very difficult? I don't care about the time data.

DillonHammill commented 1 year ago

This should do the trick. path is the name of the folder containing the FCS files. We add a dummy Time channel to FCS files which don't contain that parameter:

library(CytoExploreR)
library(flowWorkspace)

# FILE PATHS
path = "FCS files"
files <- list.files(path, full.names = TRUE, pattern = ".fcs")

# CYTOSET
cs <- cytoset(
  structure(
    lapply(
      files,
      function(z) {
        cf <- cyto_load(z)[[1]]
        if(!"Time" %in% cyto_channels(cf)) {
          cf_append_cols(
            cf,
            cols = matrix(,
              seq_len(nrow(cf)),
              nrow = nrow(cf),
              ncol = 1,
              dimnames = list(
                NULL,
                "Time"
              )
            )
          )
        }
        return(cf)
      }
    ),
    names = files
  )
)

# CYTOSET -> GATINGSET
gs <- GatingSet(cs)
th-of commented 1 year ago

Thank you for your reply and input, unfortunately I was not able to get rid of the error. It looks like the cyto_load in the function also require the Time channel. I was able to solve it using read.flowSet with column.pattern = "*-A" which reads only the channels with an area component.

DillonHammill commented 1 year ago

FYI, you can pass that argument to cyto_load() or cyto_setup() directly:

gs = cyto_setup(
  path,
  column.pattern = "\\-H|W|A$"
)

The above regex will pull in the height and width parameters too.