Skip to content

Commit bb40824

Browse files
Merge pull request #40 from lorenzobonaguro/dev_lb
Push changes for version 0.3.1 to Dev
2 parents 4b45355 + d9dd595 commit bb40824

109 files changed

Lines changed: 863 additions & 342 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

DESCRIPTION

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: cyCONDOR
22
Type: Package
33
Title: Flow Cytometry data analysis toolbox
4-
Version: 0.3.0
4+
Version: 0.3.1
55
Authors@R: c(
66
person(given = "Lorenzo", family = "Bonaguro", email = "lorenzo.bonaguro@dzne.de", role = c("aut", "cre")),
77
person(given = "Charlotte", family = "Kroeger", email = "charlotte.kroeger@dzne.de", role = "aut"),
@@ -13,7 +13,8 @@ Authors@R: c(
1313
)
1414
Description: Flow cytometry analysis workflow. The aim of this project is to
1515
provide an intuitive workflow for the analysis of high-dimensionality cytometry data in R.
16-
URL: https://lorenzobonaguro.github.io/cyCONDOR
16+
URL: https://lorenzobonaguro.github.io/cyCONDOR, https://github.com/lorenzobonaguro/cyCONDOR
17+
template:
1718
License: GPL-3 + file LICENSE
1819
Encoding: UTF-8
1920
biocViews:

NEWS.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
# cyCONDOR 0.3.1
2+
* Added function `condor_info` to easily explore the content of a condor object.
3+
* Solved Issue #31, color pallette is reversed in `plot_marker_ridgeplot()` function.
4+
* Solved Issue #30, the pseudotime function can now use a `prefix` argument.
5+
* Improved documentation regarding the use of different co-factors when using the archsin data transformation.
6+
* Solved Issue #33, the `plot_marker_dotplot` function have now an `alpha` argument to control the transparency of the dots.
7+
* Solved Issue #34, the `plot_marker_ridgeplot` now have a `title` argument.
8+
* Solved Issue #19, if an empty `fcs` or `csv` file is provided the `prep_fcd` function will stop and point to the corrupted file.
9+
* Added function `order_param` to allow manual ordering of an annotation or clustering variable.
10+
* Added `prefix` argument to `astir` functions.
11+
112
# cyCONDOR 0.3.0
213
* Bug fix with data projection where specific parameters were removed in UMAP calculation
314
* Updated official Docker image to the latest Bioconductor version (Bioconductor 3.20, R 4.4.2)

R/astir.R

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ runAstir_celltype <- function(fcd,
2222
manifest_name,
2323
max_epochs,
2424
learning_rate,
25-
initial_epochs) {
25+
initial_epochs,
26+
prefix = "") {
2627

2728
# Save the expression matrix as csv
2829
write.csv(x = fcd$expr[[data_slot]], file = paste0(analysis_path, "expr.csv"))
@@ -67,7 +68,7 @@ runAstir_celltype <- function(fcd,
6768
"Learning_Rate_", learning_rate,
6869
"_Initial_Epochs_", initial_epochs))
6970

70-
fcd[["astir"]][[paste0("Astir_cell_type_", data_slot)]] <- df
71+
fcd[["astir"]][[paste(prefix, "Astir_cell_type", data_slot, sep = "_")]] <- df
7172

7273
return(fcd)
7374

@@ -96,7 +97,8 @@ runAstir_cellstates <- function(fcd,
9697
manifest_name,
9798
max_epochs,
9899
learning_rate,
99-
initial_epochs) {
100+
initial_epochs,
101+
prefix = "") {
100102

101103
# Save the expression matrix as csv
102104
write.csv(x = fcd$expr[[data_slot]], file = paste0(analysis_path, "expr.csv"))
@@ -136,7 +138,7 @@ runAstir_cellstates <- function(fcd,
136138
"Learning_Rate_", learning_rate,
137139
"_Initial_Epochs_", initial_epochs))
138140

139-
fcd[["astir"]][[paste0("Astir_cell_state_", data_slot)]] <- df
141+
fcd[["astir"]][[paste(prefix, "Astir_cell_state", data_slot, sep = "_")]] <- df
140142

141143
return(fcd)
142144

R/data_load_and_transform.R

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,12 @@ read_data <- function(data_path,
7979

8080
single_file_red <- exprs(flow_frame_single)
8181

82+
if (dim(single_file_red)[1] == 0) {
83+
84+
stop(paste0("File: ", data_files[FileNum], " contains no valid event"))
85+
86+
}
87+
8288
## Downsample if needed
8389
if (nrow(single_file_red) <= max_cells) {
8490
single_file_red <- single_file_red
@@ -133,6 +139,12 @@ read_data <- function(data_path,
133139

134140
single_file_red <- read.delim(paste0(data_path,"/",data_files[FileNum]), check.names = F, sep = separator)
135141

142+
if (dim(single_file_red)[1] == 0) {
143+
144+
stop(paste0("File: ", data_files[FileNum], " contains no valid event"))
145+
146+
}
147+
136148
## Downsample if needed
137149
if (nrow(single_file_red) <= max_cells){
138150
single_file_red <- single_file_red

R/data_visualization.R

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,8 @@ plot_dim_red <- function(fcd,
258258
cluster_slot = NULL,
259259
add_pseudotime = FALSE,
260260
pseudotime_slot,
261+
add_astir = FALSE,
262+
astir_slot,
261263
param,
262264
order = FALSE,
263265
title = "Dimensionality Reduction Plot",
@@ -327,6 +329,12 @@ plot_dim_red <- function(fcd,
327329

328330
}
329331

332+
if (isTRUE(add_astir)) {
333+
334+
data <- cbind(data, fcd$astir[[astir_slot]])
335+
336+
}
337+
330338
# Check if `param` exist
331339
if(!param %in% colnames(data)){
332340
stop('column "',param,'" is not available in the provided data')
@@ -1523,6 +1531,7 @@ plot_marker_boxplot<- function(fcd,
15231531
#' @param seed a seed is set for reproducibility of the plotting result.
15241532
#' @param color_palette vector of colors that should be used to color dots.
15251533
#' @param dot_size numeric indicating the size of the dots.
1534+
#' @param alpha transparency of the dots.
15261535
#' @param title Title of the plot.
15271536
#' @import ggplot2
15281537
#' @return The function returns a scatter plot of two features available in the expression matrix. By default, dots are colored by cell population label provided in cluster_var. If coloring by a metadata is wanted instead, a group_var can be defined. Further, if only a selection of levels available in cluster_var should be included in plotting, a vector of labels of interest can be provided to cluster_to_show argument.
@@ -1540,7 +1549,8 @@ plot_marker_dotplot <- function(fcd,
15401549
order = F,
15411550
seed = 91,
15421551
color_palette = cluster_palette,
1543-
dot_size=2,
1552+
dot_size = 2,
1553+
alpha = 1,
15441554
title ="") {
15451555

15461556
#### check slots, cellIDs und varibles
@@ -1623,7 +1633,7 @@ plot_marker_dotplot <- function(fcd,
16231633
}
16241634

16251635
p <- ggplot(data, aes(x = X, y = Y)) +
1626-
geom_point(aes(color = group_var), size = dot_size) +
1636+
geom_point(aes(color = group_var), size = dot_size, alpha = alpha) +
16271637
theme_bw()+
16281638
theme(aspect.ratio = 1, panel.grid = element_blank())+
16291639
ggtitle(title) +
@@ -1645,7 +1655,7 @@ plot_marker_dotplot <- function(fcd,
16451655
}
16461656

16471657
p <- ggplot(data, aes(x = X, y = Y)) +
1648-
geom_point(aes(color = cluster), size = dot_size) +
1658+
geom_point(aes(color = cluster), size = dot_size, alpha = alpha) +
16491659
theme_bw()+
16501660
theme(aspect.ratio = 1, panel.grid = element_blank())+
16511661
ggtitle(title) +
@@ -1815,6 +1825,7 @@ plot_marker_density <- function(fcd,
18151825
#' @param cluster_to_show (optional) vector of strings indicating levels in cluster_var that should be included for plotting.
18161826
#' @param color_palette vector of colors to be used to fill density distributions.
18171827
#' @param alpha numeric, adjust alpha to be used on fill color of density distributions.
1828+
#' @param title Title of the plot.
18181829
#' @import ggridges
18191830
#' @returns \code{plot_marker_ridgeplot()} returns either one plot in case only one marker is provided via \code{marker} argument or a list of plots, if several markers are requested.
18201831
#' @details The ridgeline plots are plotted with default parameters of ggridges's \code{\link[ggridges]{geom_density_ridges}}
@@ -1826,8 +1837,9 @@ plot_marker_ridgeplot<- function(fcd,
18261837
cluster_slot,
18271838
cluster_var,
18281839
cluster_to_show = NULL,
1829-
color_palette = cluster_palette,
1830-
alpha = 1){
1840+
color_palette = rev(cluster_palette),
1841+
alpha = 1,
1842+
title = ""){
18311843

18321844
#### check slots, cellIDs und varibles
18331845
checkInput(fcd = fcd,
@@ -1900,6 +1912,7 @@ plot_marker_ridgeplot<- function(fcd,
19001912
scale_y_discrete(expand = expand_scale(mult = c(0.01, 0.2))) +
19011913
scale_fill_manual(values = color_palette) +
19021914
theme(legend.position = "none") +
1915+
ggtitle(title) +
19031916
xlab("expression") + ylab(cluster_var) + ggtitle(i)
19041917

19051918
plot.list[[i]] <- p

R/misc.R

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -563,3 +563,127 @@ condor_session_info <- function(fcd = condor) {
563563
return(tmp)
564564
}
565565

566+
#' condor_info
567+
#'
568+
#' @title condor_info
569+
#' @description This function prints an overview of the details of the condor object
570+
#' @param fcd flow cytometry dataset
571+
#'
572+
#' @returns Prints to the console the detail of the condor object
573+
#'
574+
#' @export
575+
576+
condor_info <- function(fcd = condor) {
577+
578+
if (!class(fcd) == "flow_cytometry_dataframe") {
579+
580+
stop("The provided fcd is not a condor object")
581+
582+
}
583+
584+
writeLines(paste0("condor object with: ",
585+
dim(fcd$expr$orig)[1],
586+
" cells ",
587+
dim(fcd$expr$orig)[2],
588+
" parameters across ",
589+
length(unique(fcd$anno$cell_anno$expfcs_filename)), " samples", "\n"))
590+
591+
writeLines("Available Data Slots:\n")
592+
593+
writeLines(names(fcd$expr))
594+
595+
writeLines("\nAvailable Dimensionality Reductions:\n")
596+
597+
available_dim_red <- names(fcd)[names(fcd) %in% c("pca", "umap", "tSNE")]
598+
599+
if (length(available_dim_red) == 0) {
600+
601+
writeLines("none")
602+
603+
} else {
604+
605+
for (dr in available_dim_red) {
606+
607+
writeLines(paste0(dr,": ", names(fcd[[dr]])))
608+
609+
}
610+
}
611+
612+
writeLines("\nAvailable Clustering:\n")
613+
614+
if (length(names(fcd$clustering)) == 0) {
615+
616+
writeLines("none")
617+
618+
} else {
619+
620+
writeLines(names(fcd$clustering))
621+
622+
}
623+
624+
}
625+
626+
#' order_param
627+
#'
628+
#' @title order_param
629+
#' @description This function helps to re-oder the levels of a variable to allow a personalized order for plotting.
630+
#' @param fcd flow cytometry dataset.
631+
#' @param type This function can be used to re-order either a metadata annotation or a clustering label (metacluster).
632+
#' @param cluster_slot string specifying which clustering slot to use to find variable specified in param. Necessary only if type is "cluster".
633+
#' @param param Parameter to reorder.
634+
#' @param new_order A vector describing the new order asigned to the labels.
635+
#' @returns Returns a condor object with a reordered variable
636+
#'
637+
#' @export
638+
639+
order_param <- function(fcd,
640+
type,
641+
cluster_slot,
642+
param,
643+
new_order) {
644+
645+
#First check if the fcd is a valid condor object
646+
if (class(fcd) != "flow_cytometry_dataframe") {
647+
648+
stop("The provided object is not a valid condor object")
649+
650+
}
651+
652+
#Decide which variable need to be adjusted
653+
if (type == "anno") {
654+
655+
# Check if the provided order covers all of the selected variable
656+
if (setequal(unique(fcd$anno$cell_anno[[param]]), new_order)) {
657+
658+
# If the check is passed the factor is reordered
659+
fcd$anno$cell_anno[[param]] <- factor(fcd$anno$cell_anno[[param]], levels = new_order)
660+
661+
message("The variable was reordered successfully")
662+
663+
}
664+
665+
}
666+
667+
if (type == "cluster") {
668+
669+
# Check if the provided order covers all of the selected variable
670+
if (setequal(unique(fcd$clustering[[cluster_slot]][[param]]), new_order)) {
671+
672+
# If the check is passed the factor is reordered
673+
fcd$clustering[[cluster_slot]][[param]] <- factor(fcd$clustering[[cluster_slot]][[param]], levels = new_order)
674+
675+
message("The variable was reordered successfully")
676+
677+
}
678+
679+
}
680+
681+
if (sum(type == c("anno", "cluster")) == 0) {
682+
683+
stop("The provided 'type' valiable is not valid, please use either 'anno' or 'cluster'")
684+
685+
}
686+
687+
return(fcd)
688+
689+
}

R/pseudotime.R

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#' @param smoother choice of scatter plot smoother. Same as principal_curve, but "lowess" option is replaced with "loess" for additional flexibility.
2626
#' @param shrink.method character denoting how to determine the appropriate amount of shrinkage for a branching lineage. Accepted values are the same as for kernel in density (default is "cosine"), as well as "tricube" and "density". See 'Details' for more.
2727
#' @param allow.breaks logical, determines whether curves that branch very close to the origin should be allowed to have different starting points.
28+
#' @param prefix Optional prefix for the slot name of the output.
2829
#' @param seed A seed is set for reproducibility.
2930
#' @details `runPseudotime()` is a wrapper function around \code{\link[slingshot]{getLineages}} and \code{\link[slingshot]{getCurves}} implemented in the package *slingshot*.
3031
#' The function first calculated the linages and then the curves of the pseudotime and converts the result to a format compatible with the structure of the 'condor' object. The user can specify all the parameters available for the \code{\link[slingshot]{getLineages}} and \code{\link[slingshot]{getCurves}} functions, arguments description were copied from the documentation of the *slingshot* package.
@@ -56,6 +57,7 @@ runPseudotime <- function(fcd,
5657
smoother = "smooth.spline",
5758
shrink.method = "cosine",
5859
allow.breaks = TRUE,
60+
prefix = NULL,
5961
seed = 91) {
6062

6163

@@ -115,15 +117,15 @@ runPseudotime <- function(fcd,
115117

116118
if (is.null(start.clus)) {
117119

118-
fcd[["extras"]][[paste("slingshot", reduction_method, reduction_slot, sep = "_")]] <- pseudotime_extra
120+
fcd[["extras"]][[paste("slingshot", prefix, reduction_method, reduction_slot, sep = "_")]] <- pseudotime_extra
119121

120-
fcd[["pseudotime"]][[paste("slingshot", reduction_method, reduction_slot, sep = "_")]] <- curve
122+
fcd[["pseudotime"]][[paste("slingshot", prefix, reduction_method, reduction_slot, sep = "_")]] <- curve
121123

122124
} else {
123125

124-
fcd[["extras"]][[paste("slingshot", reduction_method, reduction_slot, start.clus, sep = "_")]] <- pseudotime_extra
126+
fcd[["extras"]][[paste("slingshot", prefix, reduction_method, reduction_slot, start.clus, sep = "_")]] <- pseudotime_extra
125127

126-
fcd[["pseudotime"]][[paste("slingshot", reduction_method, reduction_slot, start.clus, sep = "_")]] <- curve
128+
fcd[["pseudotime"]][[paste("slingshot", prefix, reduction_method, reduction_slot, start.clus, sep = "_")]] <- curve
127129

128130
}
129131

_pkgdown.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
url: https://lorenzobonaguro.github.io/cyCONDOR
1+
url: https://lorenzobonaguro.github.io/cyCONDOR, https://github.com/lorenzobonaguro/cyCONDOR
22
template:
33
bootstrap: 5
44
light-switch: true
@@ -107,6 +107,8 @@ reference:
107107

108108
articles:
109109
- title: Detailed cyCONDOR workflows
110+
desc: >
111+
cyCONDOR tutorials
110112
navbar: ~
111113
contents:
112114
- Prepare_data_for_cyCONDOR_analysis
@@ -123,3 +125,9 @@ articles:
123125
- Machine_learning_classifier
124126
- Cell_type_prediction
125127
- Other_utilities
128+
129+
- title: Other workflows
130+
desc: >
131+
Additional analytical workflows
132+
contents:
133+
- Workflow_merge_panels

0 commit comments

Comments
 (0)