Skip to content

Commit fbdb7a6

Browse files
committed
Add get_X_cibersort function and update deconvolve_cellularity for improved reference handling
- Introduced get_X_cibersort function to load and return the Cibersort reference matrix for cell type deconvolution. - Updated deconvolve_cellularity to utilize get_X_cibersort for default reference handling, enhancing flexibility. - Revised documentation for both functions to clarify usage and examples. - Adjusted NAMESPACE to export the new function and removed obsolete imports.
1 parent 2fea371 commit fbdb7a6

File tree

7 files changed

+68
-16
lines changed

7 files changed

+68
-16
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ RdMacros:
9595
Biarch: true
9696
biocViews: AssayDomain, Infrastructure, RNASeq, DifferentialExpression, GeneExpression, Normalization, Clustering, QualityControl, Sequencing, Transcription, Transcriptomics
9797
Encoding: UTF-8
98-
LazyData: false
98+
LazyData: true
9999
RoxygenNote: 7.3.2
100100
LazyDataCompression: xz
101101
URL: https://github.com/stemangiola/tidybulk

NAMESPACE

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export(cluster_elements)
1212
export(deconvolve_cellularity)
1313
export(describe_transcript)
1414
export(fill_missing_abundance)
15+
export(get_X_cibersort)
1516
export(get_bibliography)
1617
export(identify_abundant)
1718
export(impute_missing_abundance)
@@ -37,7 +38,6 @@ export(test_gene_rank)
3738
exportMethods(as_SummarizedExperiment)
3839
import(lifecycle)
3940
import(tibble)
40-
import(ttservice)
4141
importFrom(GenomicRanges,makeGRangesListFromDataFrame)
4242
importFrom(Matrix,colSums)
4343
importFrom(Matrix,rowMeans)
@@ -86,7 +86,6 @@ importFrom(dplyr,rename)
8686
importFrom(dplyr,rowwise)
8787
importFrom(dplyr,select)
8888
importFrom(dplyr,select_if)
89-
importFrom(dplyr,where)
9089
importFrom(dplyr,setdiff)
9190
importFrom(dplyr,slice)
9291
importFrom(dplyr,starts_with)

R/data.R

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,20 @@
22
#'
33
#' @references Newman, A. M., Liu, C. L., Green, M. R., Gentles, A. J., Feng, W., Xu, Y., Hoang, C. D., Diehn, M., & Alizadeh, A. A. (2015). Robust enumeration of cell subsets from tissue expression profiles. Nature Methods, 12(5), 453–457. https://doi.org/10.1038/nmeth.3337
44
#'
5-
#'
65
"X_cibersort"
76

87
#' Needed for vignette vignette_manuscript_signature_tsne
98
#'
10-
#'
119
"vignette_manuscript_signature_tsne"
1210

1311
#' Needed for vignette vignette_manuscript_signature_boxplot
1412
#'
15-
#'
1613
"vignette_manuscript_signature_boxplot"
1714

1815
#' Needed for vignette vignette_manuscript_signature_tsne2
1916
#'
20-
#'
2117
"vignette_manuscript_signature_tsne2"
2218

2319
#' Needed for tests tximeta_summarizeToGene_object, It is SummarizedExperiment from tximeta
2420
#'
25-
#'
2621
"tximeta_summarizeToGene_object"

R/deconvolve_cellularity.R

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,26 @@
1+
#' Get Cibersort reference data
2+
#'
3+
#' @description This function loads and returns the X_cibersort reference matrix used for
4+
#' cell type deconvolution with the Cibersort and LLSR methods. The reference matrix
5+
#' contains gene expression signatures for 22 immune cell types.
6+
#'
7+
#' @return The X_cibersort reference matrix with genes as rows and cell types as columns
8+
#' @export
9+
#'
10+
#' @examples
11+
#' # Get the default Cibersort reference matrix
12+
#' ref_matrix <- get_X_cibersort()
13+
#'
14+
#' # Use with deconvolve_cellularity
15+
#' # se |> deconvolve_cellularity(reference = get_X_cibersort(), method = "cibersort")
16+
#'
17+
#' @references Newman, A. M., Liu, C. L., Green, M. R., Gentles, A. J., Feng, W., Xu, Y., Hoang, C. D., Diehn, M., & Alizadeh, A. A. (2015). Robust enumeration of cell subsets from tissue expression profiles. Nature Methods, 12(5), 453-457. doi:10.1038/nmeth.3337
18+
get_X_cibersort <- function() {
19+
# Load the data object
20+
data(X_cibersort, envir = environment())
21+
return(X_cibersort)
22+
}
23+
124
#' Get cell type proportions from samples
225
#'
326
#' `r lifecycle::badge("maturing")`
@@ -15,7 +38,7 @@
1538
#'
1639
#' @param .data A `tbl` (with at least three columns for sample, feature and transcript abundance) or `SummarizedExperiment` (more convenient if abstracted to tibble with library(tidySummarizedExperiment))
1740
#' @param .abundance The name of the transcript/gene abundance column
18-
#' @param reference A data frame. The methods cibersort and llsr can accept a custom rectangular dataframe with genes as rows names, cell types as column names and gene-transcript abundance as values. For exampler tidybulk::X_cibersort. The transcript/cell_type data frame of integer transcript abundance. If NULL, the default reference for each algorithm will be used. For llsr will be LM22.
41+
#' @param reference A data frame. The methods cibersort and llsr can accept a custom rectangular dataframe with genes as rows names, cell types as column names and gene-transcript abundance as values. If NULL, the default reference for each algorithm will be used. For cibersort and llsr, the default is obtained via `get_X_cibersort()`. For llsr will be LM22.
1942
#' @param method A character string. The method to be used. Available methods: "cibersort", "llsr", "epic", "mcp_counter", "quantiseq", "xcell". If a vector is provided, an error will be thrown. Default is all available methods.
2043
#' @param prefix A character string. The prefix you would like to add to the result columns. It is useful if you want to reshape data.
2144
#' @param feature_column A character string. The name of a column in rowData to use as feature names instead of rownames. If NULL (default), rownames are used.
@@ -66,6 +89,10 @@
6689
#' # rowData(se_with_features)$gene_symbol <- rownames(se_with_features)
6790
#' # se_with_features |> deconvolve_cellularity(feature_column = 'gene_symbol', cores = 1)
6891
#'
92+
#' # Using a custom reference matrix
93+
#' # custom_ref <- get_X_cibersort() # Get the default Cibersort reference
94+
#' # se_with_features |> deconvolve_cellularity(reference = custom_ref, feature_column = 'gene_symbol', cores = 1)
95+
#'
6996
#' @references
7097
#' Mangiola, S., Molania, R., Dong, R., Doyle, M. A., & Papenfuss, A. T. (2021). tidybulk: an R tidy framework for modular transcriptomic data analysis. Genome Biology, 22(1), 42. doi:10.1186/s13059-020-02233-7
7198
#'
@@ -118,7 +145,6 @@ setGeneric("deconvolve_cellularity", function(.data,
118145
#'
119146
#' @family deconvolution helpers
120147
#'
121-
122148
#' @importFrom purrr map
123149
#' @importFrom rlang quo_is_symbolic quo_name
124150
#' @importFrom tibble as_tibble
@@ -128,7 +154,7 @@ setGeneric("deconvolve_cellularity", function(.data,
128154
#' @keywords internal
129155
#' @noRd
130156
.deconvolve_cellularity_se = function(.data,
131-
reference = X_cibersort,
157+
reference = NULL,
132158
method = c("cibersort", "llsr", "epic", "mcp_counter", "quantiseq", "xcell"),
133159
prefix = "",
134160
feature_column = NULL,
@@ -186,8 +212,8 @@ setGeneric("deconvolve_cellularity", function(.data,
186212
# Check if package is installed, otherwise install
187213
check_and_install_packages(c("class", "e1071", "preprocessCore"))
188214

189-
# Choose reference
190-
reference = if (is.null(reference)) X_cibersort else reference
215+
# Use provided reference or default to get_X_cibersort()
216+
reference = if (is.null(reference)) get_X_cibersort() else reference
191217

192218
# Validate reference
193219
validate_signature_SE(my_assay, reference)
@@ -198,8 +224,8 @@ setGeneric("deconvolve_cellularity", function(.data,
198224
select(-`P-value`,-Correlation,-RMSE)
199225
} else if (method |> tolower() |> equals("llsr")) {
200226

201-
# Choose reference
202-
reference = if (is.null(reference)) X_cibersort else reference
227+
# Use provided reference or default to get_X_cibersort()
228+
reference = if (is.null(reference)) get_X_cibersort() else reference
203229

204230
# Validate reference
205231
validate_signature_SE(my_assay, reference)

man/deconvolve_cellularity-methods.Rd

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

man/get_X_cibersort.Rd

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

tests/testthat/test-cellularity-analysis.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ airway_mini <- airway[1:100, 1:5]
66

77
library(dplyr)
88
library(SummarizedExperiment)
9+
library(tidybulk)
910

1011
# Test deconvolve_cellularity function
1112

0 commit comments

Comments
 (0)