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 parameterfs
.- 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 functioncheckRepairFcsFiles
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.
Value
(Invisible) NULL. Is called for its side effects: the specified single fcs file gets written to disc with its new sample ID.
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.
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
#> Reading in all fcs files in the folder `fcsF_E_vol_sid`... ok.
#> Re-writing volume data of 2 FCS files, using `1234567` to replace missing values.
#> .. ok.
# 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
#> volume btim
#> N_na_GNeg_T4_th1_b4.fcs 45500 14:19:30
#> N_na_GNeg_T5_th3_b3.fcs 1234567 14:34:13
#> N_na_GPos_T5_th1_b1.fcs 1234567 14:43:57
#> N_na_GPos_T5_th1_b3.fcs 46000 14:47:13
#> sampleId
#> N_na_GNeg_T4_th1_b4.fcs tr: GNeg; Td: 4; wt: nativ; ap: no; th: th1; ha: ha1; bk: b4
#> N_na_GNeg_T5_th3_b3.fcs tr: GNeg; Td: 5; wt: nativ; ap: no; th: th3; ha: ha2; bk: b3
#> N_na_GPos_T5_th1_b1.fcs tr: GPos; Td: 5; wt: nativ; ap: no; th: th1; ha: ha1; bk: b1
#> N_na_GPos_T5_th1_b3.fcs blablabla very bad sample ID
#> name
#> N_na_GNeg_T4_th1_b4.fcs N_na_GNeg_T4_th1_b4.fcs
#> N_na_GNeg_T5_th3_b3.fcs N_na_GNeg_T5_th3_b3.fcs
#> N_na_GPos_T5_th1_b1.fcs N_na_GPos_T5_th1_b1.fcs
#> N_na_GPos_T5_th1_b3.fcs N_na_GPos_T5_th1_b3.fcs
# 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)
#> `N_na_GPos_T5_th1_b3.fcs` has been rewritten with the modified sample ID.
#
# and check again:
flowset <- repairSID(fn = fon)
flowset@phenoData@data # all is good
#> volume btim
#> N_na_GNeg_T4_th1_b4.fcs 45500 14:19:30
#> N_na_GNeg_T5_th3_b3.fcs 1234567 14:34:13
#> N_na_GPos_T5_th1_b1.fcs 1234567 14:43:57
#> N_na_GPos_T5_th1_b3.fcs 46000 14:47:13
#> sampleId
#> N_na_GNeg_T4_th1_b4.fcs tr: GNeg; Td: 4; wt: nativ; ap: no; th: th1; ha: ha1; bk: b4
#> N_na_GNeg_T5_th3_b3.fcs tr: GNeg; Td: 5; wt: nativ; ap: no; th: th3; ha: ha2; bk: b3
#> N_na_GPos_T5_th1_b1.fcs tr: GPos; Td: 5; wt: nativ; ap: no; th: th1; ha: ha1; bk: b1
#> N_na_GPos_T5_th1_b3.fcs tr: GPos; Td: 5; wt: nativ; ap: no; th: th1; ha: ha1; bk: b3
#> name
#> N_na_GNeg_T4_th1_b4.fcs N_na_GNeg_T4_th1_b4.fcs
#> N_na_GNeg_T5_th3_b3.fcs N_na_GNeg_T5_th3_b3.fcs
#> N_na_GPos_T5_th1_b1.fcs N_na_GPos_T5_th1_b1.fcs
#> N_na_GPos_T5_th1_b3.fcs N_na_GPos_T5_th1_b3.fcs
#
setwd(old_wd)