Skip to contents

Check all fcs files in a specified folder for non-unique keywords. Multiple entries in the keywords are removed, and the file is written back to disc. The original ("corrupt") fcs file will be overwritten.

Usage

checkRepairFcsFiles(
  fn = ".",
  fcsRepair = FALSE,
  confirm = TRUE,
  showMultiples = FALSE,
  keepLast = TRUE,
  verbose = TRUE
)

Arguments

fn

Character length one. The name of the folder where FCS files should be read from. If left at the default '.', the folder name as defined in the settings file (key: 'foN_fcsFiles') will be used.

fcsRepair

Logical. If defect fcs files should be attempted to repair. If left at the default FALSE, fcs files with double entries in their keywords will only be listed. If set to TRUE, the keyword doublets will be deleted and the fcs file will be saved to disc. The original fcs file will be overwritten.

confirm

Logical. If confirmation is required before overwriting the faulty fcs files with their corrected version. Defaults to TRUE. If set to FALSE. original fcs files will be overwritten without further warning.

showMultiples

Logical, If the multiplied keywords should be displayed. Defaults to FALSE.

keepLast

Logical or Numeric. If the last or the first item of a keyword multiplication should be kept. If left at the default TRUE, the last keyword of a keyword multiplication will be kept, if set to FALSE the first will be kept. Provide a numeric length one to denote the number of the multiplied keyword to keep.

verbose

Logical. If status messages should be displayed. If left at the default '.', the value as defined in the settings file (key 'dV_verbose') will be used.

Value

(Invisible) TRUE. Is used for its side effect, i.e. to repair fcs files with multiplied keywords and to write those fcs files to disc.

Details

When reading in resp. working with some fcs files it can happen that the following error message is displayed:
"The HEADER and the TEXT segment define different starting point ... to read the data"
After some testing, the author came to the conclusion that a solution to this error can be to delete multiple entries of the same keyword in the keywords of the fcs file. (As fcs files *not* displaying this error seem to have only unique keywords.)
It also appeared that always the last of the multiplied entries was the correct one, hence the default keeping of the *last* of multiple entries.
Currently, only uniformly multiplied keyword entries get remedied -- if there should be a mixture of keyword-multiplication (e.g. some are two-fold, some others are three-fold) an error message is displayed.
Other approaches to this problem via e.g. ignoring the text offset as possible in load_cytoframe_from_fcs resulted in data loss.

See also

Other Accessory functions: applyBandpass(), cutFdmatToGate(), exportFdmatData(), fd_load(), fd_save(), genfs(), repairSID(), repairVolumes()

Other Repair functions: repairSID(), repairVolumes()

Examples

td <- tempdir()
data_source <- "https://github.com/bpollner/data/raw/main/flowdex_examples/flowdex_examples.zip"
check_download_data(td, data_source)
exp_home <- paste0(td, "/flowdex_examples")
old_wd <- getwd()
setwd(exp_home)
#
assign("get_settings_from_flowdex_package_root", TRUE, pos=.GlobalEnv)
# only required to make the examples run automatically
# you should not call 'assign' if you run the examples manually
# the effect of setting 'get_settings_from_flowdex_package_root' to TRUE
# is that the file 'flowdex_settings.R' in 'root' of the installed package
# 'flowdex' will be sourced instead of the one in the user-defined location.
#
fon <- "fcsF_E_rep"
# checkRepairFcsFiles(fon)  # just to see what needs repairing
checkRepairFcsFiles(fon, TRUE, FALSE)
#> 
#> The following 2 files from the folder 'fcsF_E_rep' 
#> do have non-unique entries (all 2 fold) in their keywords:
#> N_na_GNeg_T6_th1_b2.fcs
#> N_na_GNeg_T6_th1_b3.fcs
#> 
#> All except the last of each multiplied keyword were removed, and the original fcs file were overwritten.
#> (You can use 'checkRepairFcsFiles' directly and set 'showMultiples' to TRUE to display the multiplied keywords.)
#
setwd(old_wd)