Benchmark AF Assignment Accuracy Against Spectral Panel Size
Source:R/benchmark_af_spectra.R
benchmark.af.spectra.RdRepeatedly subsamples the fluorophore spectra matrix to a range of panel
sizes, runs test.af.accuracy for each subsample, and
summarises how cosine similarity between raw detector signals and the
assigned AF spectra changes with the number of fluorophores. Results are
saved as a line-plot PDF and returned as a list.
Usage
benchmark.af.spectra(
unstained.fcs,
spectra,
af.spectra,
asp,
functions = c("assign.af.joint.cov", "assign.af.fluorophores", "assign.af.residuals"),
n.fluors = c(5, 10, 15, 20, 25, 30, 35, 40),
n.draws = 5L,
seed = 42L,
n.downsample = 1000L,
plot.dir = "figure_af_accuracy",
filename = "af_accuracy_spectra_benchmark"
)Arguments
- unstained.fcs
Character scalar. Path to the unstained FCS file passed through to
test.af.accuracy.- spectra
Numeric matrix of fluorophore spectra (fluorophores x detectors). Row names must be fluorophore names; column names must match the detector channels in the FCS file. Any row named
"AF"is removed automatically before processing. Column names must match those ofspectra.- af.spectra
Numeric matrix of AF spectra (AF variants x detectors). The first row is treated as the mean AF spectrum and is used for the baseline comparison. Column names must match those of
spectra.- asp
Aspect-ratio value passed through to
test.af.accuracy.- functions
Character vector of AF-function names to benchmark. See
test.af.accuracyfor the required calling conventions.- n.fluors
Integer vector of panel sizes (number of fluorophores) to evaluate. Values outside
[1, nrow(spectra)]are silently dropped. Default:c(5, 10, 15, 20, 25, 30, 35, 40).- n.draws
Integer scalar. Number of random draws (unique fluorophore subsets) per panel size. A unique seed is derived for each
(n.fluors, draw)combination fromseed, so results are fully reproducible. Default:5L.- seed
Integer scalar. Base seed for reproducible subsampling. Default:
42L.- n.downsample
Integer scalar. Maximum number of events passed to each
test.af.accuracycall. A random subsample is drawn when the FCS file contains more events. Set toInfto use all events. Default:1000L.- plot.dir
Character scalar. Directory for output files. Created recursively if it does not exist. Default:
"figure_af_accuracy".- filename
Character scalar. Stem used to name the summary PDF (the file will be
<plot.dir>/<filename>.pdf). Default:"af_accuracy_spectra_benchmark".
Value
A named list with three elements:
rawData frame of per-draw results with columns
n.fluors,draw,method,Mean_Sim, andSD_Sim.summaryData frame summarising
rawacross draws for each(n.fluors, method)combination, with columnsn.fluors,method,mean_Mean_Sim,sd_Mean_Sim(variability across draws), andmean_SD_Sim(average within-draw spread).plotThe
ggplot2object for the summary line plot.