Skip to content

Commit 0b9cb7d

Browse files
Merge pull request #41 from lorenzobonaguro/dev
GitHub update to Version 0.3.1
2 parents 1d7705b + 507bab6 commit 0b9cb7d

116 files changed

Lines changed: 987 additions & 182 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: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ Imports:
6262
rstatix,
6363
tidyr,
6464
CytoNorm,
65-
corrplot
65+
corrplot,
66+
S4Vectors
6667
Remotes:
6768
JinmiaoChenLab/Rphenograph,
6869
stuchly/Rphenoannoy,

NAMESPACE

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@ export(change_param_name)
66
export(checkInput)
77
export(check_IDs)
88
export(clr)
9+
export(condor_info)
910
export(condor_session_info)
1011
export(confusionMatrix)
1112
export(corr_plot_comparison)
1213
export(create_metaclustering_script)
1314
export(df_frequency)
15+
export(export_sce)
1416
export(filter_fcd)
1517
export(frequency_anova_test)
1618
export(frequency_friedman_test)
@@ -25,6 +27,7 @@ export(marker_wilcox_test)
2527
export(measured_markers)
2628
export(merge_condor)
2729
export(metaclustering)
30+
export(order_param)
2831
export(plot_confusion_HM)
2932
export(plot_counts_barplot)
3033
export(plot_dim_density)
@@ -109,6 +112,10 @@ import(umap)
109112
import(uwot)
110113
importFrom(Biobase,AnnotatedDataFrame)
111114
importFrom(Matrix,sparseMatrix)
115+
importFrom(S4Vectors,metadata)
116+
importFrom(SingleCellExperiment,SingleCellExperiment)
117+
importFrom(SingleCellExperiment,reducedDim)
118+
importFrom(SummarizedExperiment,colData)
112119
importFrom(grDevices,recordPlot)
113120
importFrom(igraph,membership)
114121
importFrom(utils,packageDescription)

R/astir.R

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#' @param max_epochs Maximum number of epochs, for details see `Astir` documentation.
1111
#' @param learning_rate Learning Rate.
1212
#' @param initial_epochs initial epochs, for details see `Astir` documentation.
13+
#' @param prefix Optional prefix for the slot name of the output.
1314
#' @details Predict cell types using 'Astir'. This package requires the python library `astir` and `reticulate`. This function is still experimental and was not extensively tested in cyCONDOR. In one of the next release we will document it's usage in more details on a dedicated vignette.
1415
#' For the moment if you want to know more feel free to reach out on our `Slack` channel. For more details on the different parameters refer to `Astir` documentation.
1516
#' @import reticulate
@@ -23,7 +24,7 @@ runAstir_celltype <- function(fcd,
2324
max_epochs,
2425
learning_rate,
2526
initial_epochs,
26-
prefix = "") {
27+
prefix = NULL) {
2728

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

71-
fcd[["astir"]][[paste(prefix, "Astir_cell_type", data_slot, sep = "_")]] <- df
72+
fcd[["astir"]][[paste("Astir_cell_type", sub("^_", "", paste(prefix, data_slot, sep = "_")), sep = "_")]] <- df
7273

7374
return(fcd)
7475

@@ -86,6 +87,7 @@ runAstir_celltype <- function(fcd,
8687
#' @param max_epochs Maximum number of epochs.
8788
#' @param learning_rate Learning Rate.
8889
#' @param initial_epochs Initial Epochs.
90+
#' @param prefix Optional prefix for the slot name of the output.
8991
#' @import reticulate
9092
#' @importFrom utils write.csv
9193
#' @return runAstir_cellstates
@@ -98,7 +100,7 @@ runAstir_cellstates <- function(fcd,
98100
max_epochs,
99101
learning_rate,
100102
initial_epochs,
101-
prefix = "") {
103+
prefix = NULL) {
102104

103105
# Save the expression matrix as csv
104106
write.csv(x = fcd$expr[[data_slot]], file = paste0(analysis_path, "expr.csv"))
@@ -138,7 +140,7 @@ runAstir_cellstates <- function(fcd,
138140
"Learning_Rate_", learning_rate,
139141
"_Initial_Epochs_", initial_epochs))
140142

141-
fcd[["astir"]][[paste(prefix, "Astir_cell_state", data_slot, sep = "_")]] <- df
143+
fcd[["astir"]][[paste("Astir_cell_state", sub("^_", "", paste(prefix, data_slot, sep = "_")), sep = "_")]] <- df
142144

143145
return(fcd)
144146

R/data_load_and_transform.R

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -656,3 +656,80 @@ write_fcs <- function(fcd = condor,
656656
message("File was saved to ", dir, filename, ".fcs")
657657
}
658658
}
659+
660+
#' Save the results from cyCONDOR as a Single Cell Experiment Class as RDS file
661+
#'
662+
#' @title Export Flow Cytometry Dataset as SCE.
663+
#' @description This function creates an object of the class Single Cell Experiment (SCE) based on the data of the flow cytometry dataset (fcd).
664+
#' @param fcd flow cytometry data set
665+
#' @param expr_slot expr_slot from which to take marker expression values, default is "orig".
666+
#' @param reduction_method string specifying which dimensionality reduction method to use.
667+
#' @param reduction_slot string specifying reduction name in reduction_method to use for visualization, e.g. "pca_orig".
668+
#' @param cluster_slot string specifying which clustering slot to use to find variable specified in cluster_var.
669+
#' @param cluster_var string specifying variable name in cluster_slot that identifies cell population labels to be used (e.g. clusters, metaclusters or predicted labels). Must be numeric in this function - factors are converted automatically.
670+
#' @param save boolean indicating if the sce should be saved as RDS file.
671+
#' @param dir string specifying the directory where the RDS file is saved. Current working directory by default.
672+
#' @param filename string specifying the filename for the RDS file.
673+
#' @importFrom SingleCellExperiment SingleCellExperiment reducedDim
674+
#' @importFrom SummarizedExperiment colData
675+
#' @importFrom S4Vectors metadata
676+
#' @returns The SCE plus a short message if the RDS file was saved successfully.
677+
#'
678+
#' @export
679+
export_sce <- function(fcd = condor,
680+
expr_slot = "orig",
681+
reduction_method = NULL,
682+
reduction_slot = NULL,
683+
cluster_slot = NULL,
684+
cluster_var = NULL,
685+
save = TRUE,
686+
dir = paste0(getwd(), "/"),
687+
filename = "") {
688+
689+
message("This function is still experimental, if you run into any issue please let us know!")
690+
691+
# Extracting the expression data
692+
exp <- as.matrix(t(fcd[["expr"]][[expr_slot]]))
693+
694+
# Extracting the annotation data
695+
anno <- fcd[["anno"]][["cell_anno"]]
696+
names(anno)[names(anno) == "sample_ID"] <- "sample_id" # required for CATALYST - .check_sce() checks if 'sample_id' (case sensitive!) is present in the SCE.
697+
names(anno)[names(anno) == "group"] <- "condition" # also required naming for CATALYST
698+
699+
# Check if the colnames of exp and the rownames of anno match
700+
if(!identical(colnames(exp), rownames(anno))){
701+
stop("Column names of the expression matrix and rownames of the annotation matrix do not match.")
702+
}
703+
704+
# Create the SCE
705+
sce <- SingleCellExperiment::SingleCellExperiment(assays = list(assays = exp),
706+
colData = anno)
707+
708+
# Extract and add dimensional reduction data
709+
if(!is.null(reduction_method)){
710+
red <- fcd[[reduction_method]][[reduction_slot]]
711+
SingleCellExperiment::reducedDim(sce, reduction_method) <- red
712+
}
713+
714+
# Extract and add clustering information
715+
if(!is.null(cluster_slot)){
716+
clust <- fcd[["clustering"]][[cluster_slot]][[cluster_var]]
717+
SummarizedExperiment::colData(sce)[[cluster_slot]] <- clust
718+
SummarizedExperiment::colData(sce)[["cluster_id"]] <- clust # also required for downstream application in CATALYST
719+
}
720+
721+
# Extract and save experiment_info as metadata
722+
ei <- unique(as.data.frame(colData(sce)[, c("sample_id", "condition")]))
723+
rownames(ei) <- ei$sample_id # Set rownames = sample IDs
724+
S4Vectors::metadata(sce)$experiment_info <- ei
725+
726+
# Save the SCE
727+
## as .rds for standard usage in R
728+
if(save == TRUE) {
729+
saveRDS(sce,
730+
file = paste0(dir, filename, ".rds"))
731+
message("SCE has been saved to ", dir, filename, ".rds")
732+
}
733+
734+
return(sce)
735+
}

R/data_visualization.R

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,8 @@ confusionMatrix <- function (i = NULL, j = NULL)
225225
#' @param cluster_slot string specifying which clustering slot to use to find variable specified in cluster_var.
226226
#' @param add_pseudotime Logical, if plot should be colored by pseudotime.
227227
#' @param pseudotime_slot string specifying pseudotime name to use for visualization.
228+
#' @param add_astir Logical, if plot should be colored by Astir prediction.
229+
#' @param astir_slot string specifying astir description name to use for visualization.
228230
#' @param param parameter to visualize in the plot, this can be either a continuous variable or a categorical one, the function will react differently accordingly.
229231
#' @param order logical if you want to order the dots in the plot, by expression for example. This can help to find small populations of positive cells. If set to FALSE, the plotting order of the cells is randomized.
230232
#' @param title title of the plot.

_pkgdown.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@ reference:
104104
- condor_session_info
105105
- corr_plot_comparison
106106
- write_fcs
107+
- condor_info
108+
- export_sce
109+
- order_param
107110

108111
articles:
109112
- title: Detailed cyCONDOR workflows
@@ -129,5 +132,5 @@ articles:
129132
- title: Other workflows
130133
desc: >
131134
Additional analytical workflows
132-
contents:
135+
contents:
133136
- Workflow_merge_panels

docs/404.html

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/LICENSE-text.html

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/articles/Batch_correction.html

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)