## Warning: replacing previous import 'ncdfFlow::filter' by 'dplyr::filter' when
## loading 'flowWorkspace'
parse the workspace into gs
ws <- open_flowjo_xml("~/rglab/workspace/CytoML/wsTestSuite/allstats.wsp")
gs <- flowjo_to_gatingset(ws, name = 1, path = "~/rglab/workspace/CytoML/wsTestSuite/Cytotrol/NHLBI/Tcell/")
gs_get_pop_paths(gs, path = "auto")
## [1] "root" "Lymphocytes" "CD3" "cd4" "HLA"
## [6] "cd8"
list all the available stats for the entire gating tree
gh <- gs[[1]]
gh_pop_stats_ls(gh)
## [1] "Count" "SD" "Robust CV" "Mode"
## [5] "Median Abs Dev" "40% Percentile" "Median" "Robust SD"
## [9] "Mean" "Geometric Mean" "Freqoftotal" "Freqofgranparent"
## [13] "CV" "Freqof" "Freqofparent"
list all the available stats for the individual pops
gh_pop_stats_ls(gh, "CD3")
## [1] "Count"
print the stats
default is count
gs_pop_stats_print(gs)
## sample pop value
## 1: CytoTrol_CytoTrol_1.fcs_119531 root 119531
## 2: CytoTrol_CytoTrol_1.fcs_119531 Lymphocytes 67633
## 3: CytoTrol_CytoTrol_1.fcs_119531 CD3 51450
## 4: CytoTrol_CytoTrol_1.fcs_119531 cd4 31640
## 5: CytoTrol_CytoTrol_1.fcs_119531 HLA 30036
## 6: CytoTrol_CytoTrol_1.fcs_119531 cd8 14934
gs_pop_stats_print(gs, "cd4")
## sample pop value
## 1: CytoTrol_CytoTrol_1.fcs_119531 cd4 31640
select different stats, default is cytolib value
gs_pop_stats_print(gh, type = "Freqofparent")
## sample pop value
## 1: CytoTrol_CytoTrol_1.fcs_119531 HLA 0.9493047
the columns are stats specific
gs_pop_stats_print(gh, type = "Freqof")
## sample ancestor pop value
## 1: CytoTrol_CytoTrol_1.fcs_119531 Lymphocytes HLA 0.4441027
channel-specific stats are not computed by default
gs_pop_stats_print(gs, "HLA", type = "Median")
## sample channel pop value
## 1: CytoTrol_CytoTrol_1.fcs_119531 Comp-B710-A HLA NaN
gs_pop_stats_print(gs, "HLA", type = "Median", xml = T)
## sample channel pop value
## 1: CytoTrol_CytoTrol_1.fcs_119531 Comp-B710-A HLA 17778.66
to invoke the stats computing
gs_pop_stats_compute(gs)
gs_pop_stats_print(gs, "HLA", type = "Median")
## sample channel pop value
## 1: CytoTrol_CytoTrol_1.fcs_119531 Comp-B710-A HLA 17809.85
compare stats
gh_pop_stats_compare(gs, "HLA", type = "Median")
## type channel cytolib xml node
## 1: Median Comp-B710-A 17809.85 17778.66 HLA
gh_pop_stats_compare(gh)
## type cytolib xml node
## 1: Count 119531 119531 root
## 2: Count 67633 67633 Lymphocytes
## 3: Count 51450 51450 CD3
## 4: Count 31640 31640 cd4
## 5: Count 30036 30036 HLA
## 6: Count 14934 14934 cd8
% is currently concatenated to the type (otherwise we need to append extra column for all the rest stats)
gh_pop_stats_compare(gh, type = "40% Percentile")
## type channel cytolib xml node
## 1: 40% Percentile Comp-B710-A 16643.83 16612.87 HLA
Add stats
prevent invalid stats to be added
stat <- list("new_stats")
gs_pop_stats_add(gs, "cd4", stat)
## Error in gs_pop_stats_add(gs, "cd4", stat): stat must be a valid 'cyto_stats' object generated by 'cyto_stats()' constuctor
cyto_stats()
validity checks of constructor
stats <- cyto_stats(type = "Freqof", channel = c("Comp-V450-A"))
## Error in .cyto_stats(tp, ch, an, pc): channel argument is not applicable for Freqof
stats <- cyto_stats(type = "Median")
## Error in .cyto_stats(tp, ch, an, pc): channels argument is required for Median
construct multi-stats within one call
stats <- cyto_stats(type = c("CV", "Median"), channel = c("Comp-V450-A", "Comp-G560-A"))
stats
## [[1]]
## cyto_stats
## type: CV
## attr: Comp-V450-A
##
## [[2]]
## cyto_stats
## type: CV
## attr: Comp-G560-A
##
## [[3]]
## cyto_stats
## type: Median
## attr: Comp-V450-A
##
## [[4]]
## cyto_stats
## type: Median
## attr: Comp-G560-A
add stats
gh_pop_stats_ls(gh, "cd4")
## [1] "Count"
gs_pop_stats_add(gs, "cd4", stats)
gh_pop_stats_ls(gh, "cd4")
## [1] "Median" "CV" "Count"
gs_pop_stats_compute(gs, "cd4")
gh_pop_stats_compare(gh, "cd4", type = c("CV", "Median"))
## Warning in if (type == "Freqof") col.attr <- "ancestor" else col.attr <-
## "channel": the condition has length > 1 and only the first element will be used
## type channel cytolib xml node
## 1: CV Comp-V450-A 38.62045 NaN cd4
## 2: Median Comp-V450-A 6426.73584 NaN cd4
## 3: CV Comp-G560-A 91.61989 NaN cd4
## 4: Median Comp-G560-A 1870.52136 NaN cd4
remove stats
# gs_pop_stats_remove(gs, "cd4", type = "CV")
#gh_pop_stats_ls(gh, "cd4")