repairSID: Repair a Single Sample ID

View source: R/gen-functions.R

repairSIDR Documentation

Repair a Single Sample ID

Description

Replace a faulty sample ID with a new one and write the single fcs file back to disc.

Usage

repairSID(
  fs = NULL,
  name = NULL,
  newSID = NULL,
  patt = NULL,
  fn = ".",
  confirm = TRUE,
  fcsRepair = FALSE
)

Arguments

fs

The object returned by this function if parameter fs is left at its default NULL, what then can be used as input for the parameter fs.

name

Character length one. The name of the fcs file within the flowSet that should get a new sample ID.

newSID

Character length one. The new Sample ID.

patt

A regular expression defining a possible subset of FCS files residing in the directory specified by fn to read in. Only matching patterns will be included.

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.

confirm

Logical. If the user should be asked for additional confirmation before the rewriting of the fcs file is performed. Defaults to TRUE.

fcsRepair

Logical. If set to TRUE, fcs-files in the folder specified at argument 'fn' will be checked for multiplied entries in the keywords, as after some testing the author came to the humble conclusion that these multiplied keywords can be the reason for the error message:
"The HEADER and the TEXT segment define different starting point ... to read the data".
If 'fcsRepair' is set to TRUE, all except the last of each multiplied keyword will be removed and the fcs file will be saved to disc, overwriting the original fcs file without further warning.
Use the function checkRepairFcsFiles which does offer more options to manually check and repair afflicted fcs files. There, it is possible to display multiplied keywords and to select which one to keep.

Details

To first obtain the flowSet, leave the parameter 'fs'at its default NULL. By providing a pattern to 'patt', subgroups of fcs files can be read in. Provide the so obtained flowSet to the parameter 'fs', and specify the name and the new sample ID in order to re-write the specified file with its new Sample ID. 'object@phenoData@data' can be used to inspect and verify names of FCS files and the sample IDs therein – see examples.

Value

(Invisible) NULL. Is called for its side effects: the specified single fcs file gets written to disc with its new sample ID.

Note

A correct sample ID is of importance when using the 'dictionary' to expand the abbreviations in the sample ID - see https://bpollner.github.io/flowdex/articles/acquire_data.html.

See Also

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

Other Repair functions: checkRepairFcsFiles(), 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_vol_sid"
repairVolumes(vol=1234567, fn=fon, confirm = FALSE) # because these files are also used 
# to demonstrate function 'repairVolumes'. We need to repair the volumes there first
flowset <- repairSID(fn = fon)
flowset@phenoData@data # very bad sample ID in the fourth sample
# view the correct sample IDs of the other samples
# copy one of those correct sample IDs
# paste and modify it - it should be beaker #3:
nsid <- "tr: GPos; Td: 5; wt: nativ; ap: no; th: th1; ha: ha1; bk: b3"
# also copy and paste the sample name
sana <- "N_na_GPos_T5_th1_b3.fcs" # the  name of the sample having the faulty sample ID
# now put all together and write fcs file with correct sample ID back to disk
repairSID(fs=flowset, fn = fon, name = sana, newSID = nsid, confirm = FALSE)
#
# and check again:
flowset <- repairSID(fn = fon)
flowset@phenoData@data # all is good 
#
setwd(old_wd)

bpollner/flowdex documentation built on March 31, 2022, 3:21 a.m.