├── .github
├── .gitignore
├── .DS_Store
├── ISSUE_TEMPLATE
│ ├── feature_request.md
│ └── bug_report.md
└── workflows
│ └── rworkflows.yml
├── inst
├── .DS_Store
├── hex
│ ├── hex.png
│ ├── 2BIgqrmzc0GSaaAGOqSeAu.jpg
│ └── hexSticker.Rmd
├── extdata
│ ├── tt_results.rda
│ └── bootstrap_results.rda
├── CITATION
└── cit
│ └── EWCE.bib
├── tests
├── testthat.R
└── testthat
│ ├── test-list_species.R
│ ├── test-check_percent_hits.R
│ ├── test-filter_ctd_genes.R
│ ├── test-bin_columns_into_quantiles.r
│ ├── test-ewce_plot.r
│ ├── test-generate_celltype_data.r
│ ├── test-run_DGE.R
│ ├── test-DelayedArray.R
│ └── test-get_celltype_table.r
├── R
├── cells_in_ctd.R
├── check_mtc_method.R
├── message_parallel.R
├── max_ctd_depth.R
├── is_matrix.R
├── is_32bit.R
├── messager.R
├── is_celltypedataset.R
├── is_delayed_array.R
├── myScalesComma.R
├── rNorm.R
├── check_numeric.R
├── check_nas.R
├── read_ctd.R
├── package.R
├── load_rdata.R
├── is_sparse_matrix.R
├── list_species.R
├── dt_to_df.R
├── check_group_name.R
├── is_ctd_standardised.R
├── check_annotLevels.R
├── report_dge.R
├── convert_new_ewce_to_old.r
├── get_ctd_levels.R
├── check_ewce_expression_data_args.R
├── to_delayed_array.R
├── drop_nonexpressed_genes.R
├── cell_list_dist.r
├── filter_genes_without_1to1_homolog.r
├── run_limma.r
├── get_sig_results.R
├── create_quadrants.R
├── theme_graph.R
├── to_dataframe.R
├── to_sparse_matrix.R
├── calculate_specificity_for_level.R
├── get_ctd_matrix_names.R
├── drop_nonexpressed_cells.R
├── sct_normalize.R
├── create_list_network.R
├── fix_celltype_names.R
├── fix_celltype_names_full_results.R
├── report_results.R
├── check_full_results.R
├── filter_ctd_genes.R
├── sce_merged_apply.R
├── delayedarray_normalize.R
├── sce_lists_apply.R
├── get_summed_proportions_iterate.R
├── check_species.R
├── prepare_tt.R
├── assign_cores.r
├── run_deseq2.R
├── bin_specificity_into_quantiles.r
├── calculate_meanexp_for_level.R
├── check_generate_controlled_bootstrapped_geneset.R
├── compute_gene_counts.R
├── check_bootstrap_args.R
├── convert_old_ewce_to_new.r
├── check_sce.R
├── plot_with_bootstrap_distributions.R
├── prep_dendro.r
├── bin_columns_into_quantiles.r
├── check_args_for_bootstrap_plot_generation.R
├── run_mast.r
├── filter_variance_quantiles.r
├── get_exp_data_for_bootstrapped_genes.R
├── plot_ctd.R
├── check_controlled_args.R
├── example_bootstrap_results.R
├── ctd_to_sce.R
├── example_transcriptome_results.R
└── check_percent_hits.R
├── man
├── is_32bit.Rd
├── check_nas.Rd
├── is_matrix.Rd
├── theme_graph.Rd
├── sce_merged_apply.Rd
├── dt_to_df.Rd
├── message_parallel.Rd
├── messager.Rd
├── check_sce.Rd
├── check_numeric.Rd
├── is_celltypedataset.Rd
├── is_delayed_array.Rd
├── is_sparse_matrix.Rd
├── create_list_network.Rd
├── max_ctd_depth.Rd
├── myScalesComma.Rd
├── report_results.Rd
├── to_dataframe.Rd
├── prep.dendro.Rd
├── sce_lists_apply.Rd
├── calculate_meanexp_for_level.Rd
├── check_group_name.Rd
├── list_species.Rd
├── is_ctd_standardised.Rd
├── drop_nonexpressed_genes.Rd
├── assign_cores.Rd
├── prep_dendro.Rd
├── to_sparse_matrix.Rd
├── compute_gene_counts.Rd
├── load_rdata.Rd
├── check_annotLevels.Rd
├── check_full_results.Rd
├── convert_new_ewce_to_old.Rd
├── to_delayed_array.Rd
├── drop_nonexpressed_cells.Rd
├── get_ctd_levels.Rd
├── plot_with_bootstrap_distributions.Rd
├── plot_log_bootstrap_distributions.Rd
├── bootstrap_plots_for_transcriptome.Rd
├── report_dge.Rd
├── sct_normalize.Rd
├── cell_list_dist.Rd
├── filter_ctd_genes.Rd
├── fix_celltype_names_full_results.Rd
├── get_ctd_matrix_names.Rd
├── calculate_specificity_for_level.Rd
├── ctd_to_sce.Rd
├── get_sig_results.Rd
├── convert_old_ewce_to_new.Rd
├── delayedarray_normalize.Rd
├── plot_ctd.Rd
├── filter_variance_quantiles.Rd
├── get_celltype_table.Rd
├── check_ewce_expression_data_args.Rd
├── fix_celltype_names.Rd
├── merge_sce_list.Rd
├── check_generate_controlled_bootstrap_geneset.Rd
├── get_exp_data_for_bootstrapped_genes.Rd
├── check_bootstrap_args.Rd
├── check_percent_hits.Rd
├── check_species.Rd
├── bin_specificity_into_quantiles.Rd
├── bin_columns_into_quantiles.Rd
├── compute_gene_scores.Rd
├── run_limma.Rd
├── bootstrap_plot.Rd
├── run_mast.Rd
├── generate_controlled_bootstrap_geneset.Rd
├── filter_genes_without_1to1_homolog.Rd
├── prepare_tt.Rd
├── check_controlled_args.Rd
├── example_bootstrap_results.Rd
├── run_deseq2.Rd
├── example_transcriptome_results.Rd
├── add_res_to_merging_list.Rd
├── EWCE-package.Rd
├── check_args_for_bootstrap_plot_generation.Rd
├── create_background_multilist.Rd
├── fix_bad_hgnc_symbols.Rd
├── ewce_plot.Rd
├── merged_ewce.Rd
├── merge_sce.Rd
├── merge_two_expfiles.Rd
├── prepare_genesize_control_network.Rd
├── fix_bad_mgi_symbols.Rd
└── merge_ctd.Rd
├── .Rbuildignore
├── .gitignore
└── DESCRIPTION
/.github/.gitignore:
--------------------------------------------------------------------------------
1 | *.html
2 |
--------------------------------------------------------------------------------
/inst/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NathanSkene/EWCE/HEAD/inst/.DS_Store
--------------------------------------------------------------------------------
/.github/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NathanSkene/EWCE/HEAD/.github/.DS_Store
--------------------------------------------------------------------------------
/inst/hex/hex.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NathanSkene/EWCE/HEAD/inst/hex/hex.png
--------------------------------------------------------------------------------
/tests/testthat.R:
--------------------------------------------------------------------------------
1 | library(testthat)
2 | library(EWCE)
3 |
4 | test_check("EWCE")
5 |
--------------------------------------------------------------------------------
/inst/extdata/tt_results.rda:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NathanSkene/EWCE/HEAD/inst/extdata/tt_results.rda
--------------------------------------------------------------------------------
/inst/extdata/bootstrap_results.rda:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NathanSkene/EWCE/HEAD/inst/extdata/bootstrap_results.rda
--------------------------------------------------------------------------------
/inst/hex/2BIgqrmzc0GSaaAGOqSeAu.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NathanSkene/EWCE/HEAD/inst/hex/2BIgqrmzc0GSaaAGOqSeAu.jpg
--------------------------------------------------------------------------------
/R/cells_in_ctd.R:
--------------------------------------------------------------------------------
1 | cells_in_ctd <- function(ctdIN,
2 | cells) {
3 | if (sum(!cells %in% colnames(ctdIN$specificity) == 0)) {
4 | return(1)
5 | } else {
6 | return(0)
7 | }
8 | }
--------------------------------------------------------------------------------
/tests/testthat/test-list_species.R:
--------------------------------------------------------------------------------
1 | test_that("list_species works", {
2 | if (!is_32bit()) {
3 | species <- EWCE::list_species()
4 | testthat::expect_true(methods::is(species, "data.frame"))
5 | testthat::expect_gte(nrow(species), 21)
6 | }
7 | })
8 |
--------------------------------------------------------------------------------
/R/check_mtc_method.R:
--------------------------------------------------------------------------------
1 | check_mtc_method <- function(mtc_method){
2 | err_msg <- paste0(
3 | "ERROR: Invalid mtc_method argument. Please see",
4 | " '?p.adjust' for valid methods."
5 | )
6 | if (!mtc_method %in% c(
7 | stats::p.adjust.methods
8 | )) {
9 | stop(err_msg)
10 | }
11 | }
--------------------------------------------------------------------------------
/R/message_parallel.R:
--------------------------------------------------------------------------------
1 | #' Print messages
2 | #'
3 | #' Print messages even from within parallelised functions.
4 | #'
5 | #' @param ... Message input.
6 | #'
7 | #' @return Null output.
8 | #'
9 | #' @keywords internal
10 | message_parallel <- function(...) {
11 | system(sprintf('echo "%s"', paste0(..., collapse = "")))
12 | }
13 |
--------------------------------------------------------------------------------
/R/max_ctd_depth.R:
--------------------------------------------------------------------------------
1 | #' Get max CTD depth
2 | #'
3 | #' Get the maximum level depth from a list of CellTypeDataset objects.
4 | #'
5 | #' @param CTD_list A list of CellTypeDataset objects.
6 | #'
7 | #' @return integer
8 | #'
9 | #' @keywords internal
10 | max_ctd_depth <- function(CTD_list) {
11 | max(unlist(lapply(CTD_list, length)))
12 | }
13 |
--------------------------------------------------------------------------------
/R/is_matrix.R:
--------------------------------------------------------------------------------
1 | #' Assess whether an object is a Matrix
2 | #'
3 | #' Assess whether an object is a Matrix or one of
4 | #' its derived object types.
5 | #'
6 | #' @param X Object.
7 | #'
8 | #' @return boolean
9 | #'
10 | #' @importFrom methods is
11 | is_matrix <- function(X) {
12 | methods::is(X, "Matrix") || methods::is(X, "matrix")
13 | }
14 |
--------------------------------------------------------------------------------
/R/is_32bit.R:
--------------------------------------------------------------------------------
1 | #' Checks whether OS is a 32-bit Windows
2 | #'
3 | #' Helper function to avoid duplicate test runs on Windows OS.
4 | #'
5 | #' @return Null
6 | #'
7 | #' @keywords internal
8 | is_32bit <- function() {
9 | is_32bit_windows <- .Platform$OS.type == "windows" &&
10 | .Platform$r_arch == "i386"
11 | return(is_32bit_windows)
12 | }
13 |
--------------------------------------------------------------------------------
/R/messager.R:
--------------------------------------------------------------------------------
1 | #' Print messages
2 | #'
3 | #' Print messages with option to silence.
4 | #'
5 | #' @param ... Message input.
6 | #' @param v Whether to print messages.
7 | #'
8 | #' @return Null output.
9 | #'
10 | #' @keywords internal
11 | messager <- function(..., v = TRUE) {
12 | if (v) {
13 | msg <- paste(...)
14 | message(msg)
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/man/is_32bit.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/is_32bit.R
3 | \name{is_32bit}
4 | \alias{is_32bit}
5 | \title{Checks whether OS is a 32-bit Windows}
6 | \usage{
7 | is_32bit()
8 | }
9 | \value{
10 | Null
11 | }
12 | \description{
13 | Helper function to avoid duplicate test runs on Windows OS.
14 | }
15 | \keyword{internal}
16 |
--------------------------------------------------------------------------------
/R/is_celltypedataset.R:
--------------------------------------------------------------------------------
1 | #' Check whether object is a CellTypeDataset
2 | #'
3 | #' Check whether an object is a CellTypeDataset.
4 | #'
5 | #' @param ctd Object.
6 | #'
7 | #' @return boolean
8 | #'
9 | #' @keywords internal
10 | is_celltypedataset <- function(ctd) {
11 | (!is.function(ctd)) &&
12 | all(c("annot", "mean_exp", "specificity") %in% names(ctd[[1]]))
13 | }
14 |
--------------------------------------------------------------------------------
/R/is_delayed_array.R:
--------------------------------------------------------------------------------
1 | #' Assess whether an object is a DelayedArray.
2 | #'
3 | #' Assess whether an object is a DelayedArray or one of
4 | #' its derived object types.
5 | #'
6 | #' @param X Object.
7 | #'
8 | #' @return boolean
9 | #'
10 | #' @importFrom methods is
11 | is_delayed_array <- function(X) {
12 | methods::is(X, "DelayedMatrix") |
13 | methods::is(X, "DelayedArray")
14 | }
15 |
--------------------------------------------------------------------------------
/R/myScalesComma.R:
--------------------------------------------------------------------------------
1 | #' \code{myScalesComma}
2 | #'
3 | #' Adjusts \pkg{ggplot2} label display. See \link[scales]{comma} for details.
4 | #' Support function for \link[EWCE]{plot_log_bootstrap_distributions}.
5 | #'
6 | #' @return Numeric vector
7 | #'
8 | #' @keywords internal
9 | myScalesComma <- function(x) {
10 | requireNamespace("scales")
11 | return(scales::comma(x = x, accuracy = 0.01))
12 | }
13 |
--------------------------------------------------------------------------------
/R/rNorm.R:
--------------------------------------------------------------------------------
1 | # Use the rank norm transformation on specificity
2 | rNorm <- function(ctdIN,
3 | as_sparse = TRUE,
4 | verbose = TRUE) {
5 | spec <- apply(ctdIN$specificity, 2, RNOmni::RankNorm)
6 | ctdIN$specificity <- to_sparse_matrix(
7 | exp = spec,
8 | as_sparse = as_sparse,
9 | verbose = verbose
10 | )
11 | return(ctdIN)
12 | }
13 |
--------------------------------------------------------------------------------
/man/check_nas.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/check_nas.R
3 | \name{check_nas}
4 | \alias{check_nas}
5 | \title{Check NAs}
6 | \usage{
7 | check_nas(exp)
8 | }
9 | \arguments{
10 | \item{exp}{Expression matrix.}
11 | }
12 | \value{
13 | Null output.
14 | }
15 | \description{
16 | Check for any NAs in an expression matrix.
17 | }
18 | \keyword{internal}
19 |
--------------------------------------------------------------------------------
/man/is_matrix.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/is_matrix.R
3 | \name{is_matrix}
4 | \alias{is_matrix}
5 | \title{Assess whether an object is a Matrix}
6 | \usage{
7 | is_matrix(X)
8 | }
9 | \arguments{
10 | \item{X}{Object.}
11 | }
12 | \value{
13 | boolean
14 | }
15 | \description{
16 | Assess whether an object is a Matrix or one of
17 | its derived object types.
18 | }
19 |
--------------------------------------------------------------------------------
/R/check_numeric.R:
--------------------------------------------------------------------------------
1 | #' Check numeric
2 | #'
3 | #' Ensure that a matrix is numeric. If not, it will be converted to numeric.
4 | #' @param exp Input matrix.
5 | #' @return Numeric expression matrix.
6 | #'
7 | #' @keywords internal
8 | #' @importFrom methods is
9 | check_numeric <- function(exp) {
10 | if (methods::is(exp[1, 1], "character")) {
11 | storage.mode(exp) <- "numeric"
12 | }
13 | return(exp)
14 | }
15 |
--------------------------------------------------------------------------------
/man/theme_graph.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/theme_graph.R
3 | \name{theme_graph}
4 | \alias{theme_graph}
5 | \title{Get graph theme}
6 | \usage{
7 | theme_graph()
8 | }
9 | \value{
10 | \code{ggplot2} graph theme.
11 | }
12 | \description{
13 | Get graph theme for plots created by
14 | \link[EWCE]{generate_bootstrap_plots_for_transcriptome}.
15 | }
16 | \keyword{internal}
17 |
--------------------------------------------------------------------------------
/man/sce_merged_apply.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/sce_merged_apply.R
3 | \name{sce_merged_apply}
4 | \alias{sce_merged_apply}
5 | \title{sce_merged_apply}
6 | \usage{
7 | sce_merged_apply(SCE_merged, as_sparse = TRUE, as_DelayedArray = FALSE)
8 | }
9 | \value{
10 | Merged SingleCellExperiment.
11 | }
12 | \description{
13 | Merge a list of SingleCellExperiments.
14 | }
15 | \keyword{internal}
16 |
--------------------------------------------------------------------------------
/man/dt_to_df.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/dt_to_df.R
3 | \name{dt_to_df}
4 | \alias{dt_to_df}
5 | \title{Convert a \code{data.table} to a \code{data.frame}.}
6 | \usage{
7 | dt_to_df(exp)
8 | }
9 | \value{
10 | \link[base]{data.frame}
11 | }
12 | \description{
13 | Converts a \code{data.table} to a \code{data.frame} by setting the
14 | first column as the rownames.
15 | }
16 | \keyword{internal}
17 |
--------------------------------------------------------------------------------
/man/message_parallel.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/message_parallel.R
3 | \name{message_parallel}
4 | \alias{message_parallel}
5 | \title{Print messages}
6 | \usage{
7 | message_parallel(...)
8 | }
9 | \arguments{
10 | \item{...}{Message input.}
11 | }
12 | \value{
13 | Null output.
14 | }
15 | \description{
16 | Print messages even from within parallelised functions.
17 | }
18 | \keyword{internal}
19 |
--------------------------------------------------------------------------------
/man/messager.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/messager.R
3 | \name{messager}
4 | \alias{messager}
5 | \title{Print messages}
6 | \usage{
7 | messager(..., v = TRUE)
8 | }
9 | \arguments{
10 | \item{...}{Message input.}
11 |
12 | \item{v}{Whether to print messages.}
13 | }
14 | \value{
15 | Null output.
16 | }
17 | \description{
18 | Print messages with option to silence.
19 | }
20 | \keyword{internal}
21 |
--------------------------------------------------------------------------------
/man/check_sce.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/check_sce.R
3 | \name{check_sce}
4 | \alias{check_sce}
5 | \title{Check SingleCellExperiment}
6 | \usage{
7 | check_sce(exp, verbose = TRUE)
8 | }
9 | \value{
10 | List of extracted SCE components.
11 | }
12 | \description{
13 | Check whether \code{exp} is a SingleCellExperiment (SCE) object and extract
14 | the relevant components.
15 | }
16 | \keyword{internal}
17 |
--------------------------------------------------------------------------------
/R/check_nas.R:
--------------------------------------------------------------------------------
1 | #' Check NAs
2 | #'
3 | #' Check for any NAs in an expression matrix.
4 | #'
5 | #' @param exp Expression matrix.
6 | #' @return Null output.
7 | #'
8 | #' @keywords internal
9 | check_nas <- function(exp) {
10 | err_msg <- paste0(
11 | "NA values detected in expresson matrix. All NA values",
12 | " should be removed before running EWCE."
13 | )
14 | if (sum(is.na(exp)) > 0) {
15 | stop(err_msg)
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/man/check_numeric.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/check_numeric.R
3 | \name{check_numeric}
4 | \alias{check_numeric}
5 | \title{Check numeric}
6 | \usage{
7 | check_numeric(exp)
8 | }
9 | \arguments{
10 | \item{exp}{Input matrix.}
11 | }
12 | \value{
13 | Numeric expression matrix.
14 | }
15 | \description{
16 | Ensure that a matrix is numeric. If not, it will be converted to numeric.
17 | }
18 | \keyword{internal}
19 |
--------------------------------------------------------------------------------
/man/is_celltypedataset.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/is_celltypedataset.R
3 | \name{is_celltypedataset}
4 | \alias{is_celltypedataset}
5 | \title{Check whether object is a CellTypeDataset}
6 | \usage{
7 | is_celltypedataset(ctd)
8 | }
9 | \arguments{
10 | \item{ctd}{Object.}
11 | }
12 | \value{
13 | boolean
14 | }
15 | \description{
16 | Check whether an object is a CellTypeDataset.
17 | }
18 | \keyword{internal}
19 |
--------------------------------------------------------------------------------
/man/is_delayed_array.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/is_delayed_array.R
3 | \name{is_delayed_array}
4 | \alias{is_delayed_array}
5 | \title{Assess whether an object is a DelayedArray.}
6 | \usage{
7 | is_delayed_array(X)
8 | }
9 | \arguments{
10 | \item{X}{Object.}
11 | }
12 | \value{
13 | boolean
14 | }
15 | \description{
16 | Assess whether an object is a DelayedArray or one of
17 | its derived object types.
18 | }
19 |
--------------------------------------------------------------------------------
/man/is_sparse_matrix.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/is_sparse_matrix.R
3 | \name{is_sparse_matrix}
4 | \alias{is_sparse_matrix}
5 | \title{Assess whether an object is a sparse matrix}
6 | \usage{
7 | is_sparse_matrix(X)
8 | }
9 | \arguments{
10 | \item{X}{Object.}
11 | }
12 | \value{
13 | boolean
14 | }
15 | \description{
16 | Assess whether an object is a sparse matrix or one of
17 | its derived object types.
18 | }
19 |
--------------------------------------------------------------------------------
/man/create_list_network.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/create_list_network.R
3 | \name{create_list_network}
4 | \alias{create_list_network}
5 | \title{\code{create_list_network}}
6 | \usage{
7 | create_list_network(data_byGene2, hits_NEW, reps = 10000, no_cores = 1)
8 | }
9 | \value{
10 | List network
11 | }
12 | \description{
13 | Support function for \code{prepare_genesize_control_network}.
14 | }
15 | \keyword{internal}
16 |
--------------------------------------------------------------------------------
/man/max_ctd_depth.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/max_ctd_depth.R
3 | \name{max_ctd_depth}
4 | \alias{max_ctd_depth}
5 | \title{Get max CTD depth}
6 | \usage{
7 | max_ctd_depth(CTD_list)
8 | }
9 | \arguments{
10 | \item{CTD_list}{A list of CellTypeDataset objects.}
11 | }
12 | \value{
13 | integer
14 | }
15 | \description{
16 | Get the maximum level depth from a list of CellTypeDataset objects.
17 | }
18 | \keyword{internal}
19 |
--------------------------------------------------------------------------------
/man/myScalesComma.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/myScalesComma.R
3 | \name{myScalesComma}
4 | \alias{myScalesComma}
5 | \title{\code{myScalesComma}}
6 | \usage{
7 | myScalesComma(x)
8 | }
9 | \value{
10 | Numeric vector
11 | }
12 | \description{
13 | Adjusts \pkg{ggplot2} label display. See \link[scales]{comma} for details.
14 | Support function for \link[EWCE]{plot_log_bootstrap_distributions}.
15 | }
16 | \keyword{internal}
17 |
--------------------------------------------------------------------------------
/man/report_results.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/report_results.R
3 | \name{report_results}
4 | \alias{report_results}
5 | \title{Report cell type enrichment results}
6 | \usage{
7 | report_results(results, sig_thresh = 0.05, verbose = TRUE)
8 | }
9 | \value{
10 | NULL output.
11 | }
12 | \description{
13 | Report cell type enrichment results generated by
14 | \link[EWCE]{bootstrap_enrichment_test}.
15 | }
16 | \keyword{internal}
17 |
--------------------------------------------------------------------------------
/man/to_dataframe.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/to_dataframe.R
3 | \name{to_dataframe}
4 | \alias{to_dataframe}
5 | \title{Convert object to data.frame}
6 | \usage{
7 | to_dataframe(X, verbose = TRUE)
8 | }
9 | \arguments{
10 | \item{X}{Object.}
11 |
12 | \item{verbose}{Print messages.}
13 | }
14 | \value{
15 | \link[base]{data.frame}.
16 | }
17 | \description{
18 | Convert a variety of object types to data.frame format.
19 | }
20 | \keyword{internal}
21 |
--------------------------------------------------------------------------------
/R/read_ctd.R:
--------------------------------------------------------------------------------
1 | # read_ctd <- function(CTD_meta_row){
2 | # sourceRData <- function(fileName){
3 | # repmis::source_data(fileName)
4 | # get(ls()[ls() != "fileName"])
5 | # }
6 | # ROW <- CTD_meta_row
7 | # if(endsWith(tolower(ROW$url),".rds")){
8 | # print("Reading in RDS file...")
9 | # ctd <- readRDS(url(ROW$url,"rb"))
10 | # }else {
11 | # print("Reading in RDA file...")
12 | # ctd <- sourceRData(ROW$url)
13 | # }
14 | # return(ctd)
15 | # }
16 |
--------------------------------------------------------------------------------
/man/prep.dendro.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/prep_dendro.r
3 | \name{prep.dendro}
4 | \alias{prep.dendro}
5 | \title{prep.dendro}
6 | \usage{
7 | prep.dendro(ctdIN)
8 | }
9 | \arguments{
10 | \item{ctdIN}{A single annotLevel of a ctd, i.e. ctd[[1]] (the function is
11 | intended to be used via apply).}
12 | }
13 | \value{
14 | A CellTypeDataset with dendrogram plotting info added.
15 | }
16 | \description{
17 | \code{prep_dendro} adds a dendrogram to a CellTypeDataset (CTD).
18 | }
19 |
--------------------------------------------------------------------------------
/man/sce_lists_apply.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/sce_lists_apply.R
3 | \name{sce_lists_apply}
4 | \alias{sce_lists_apply}
5 | \title{sce_lists_apply}
6 | \usage{
7 | sce_lists_apply(
8 | SCE_lists,
9 | return_genes = FALSE,
10 | level = 2,
11 | as_matrix = FALSE,
12 | as_DelayedArray = FALSE
13 | )
14 | }
15 | \value{
16 | List of \code{SingleCellExperiment}s.
17 | }
18 | \description{
19 | Support function for \code{EWCE::merge_sce_list}.
20 | }
21 | \keyword{internal}
22 |
--------------------------------------------------------------------------------
/R/package.R:
--------------------------------------------------------------------------------
1 | #' @details
2 | #' EWCE: Expression Weighted Celltype Enrichment
3 | #'
4 | #' Used to determine which cell types are enriched within gene lists.
5 | #' The package provides tools for testing enrichments within simple gene lists
6 | #' (such as human disease associated genes) and those resulting from
7 | #' differential expression studies.
8 | #'
9 | #' The package does not depend upon any particular Single Cell Transcriptome
10 | #' dataset and user defined datasets can be loaded in and used in the analyses.
11 | "_PACKAGE"
12 |
--------------------------------------------------------------------------------
/man/calculate_meanexp_for_level.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/calculate_meanexp_for_level.R
3 | \name{calculate_meanexp_for_level}
4 | \alias{calculate_meanexp_for_level}
5 | \title{calculate_meanexp_for_level}
6 | \usage{
7 | calculate_meanexp_for_level(
8 | ctd_oneLevel,
9 | expMatrix,
10 | as_sparse = TRUE,
11 | verbose = TRUE
12 | )
13 | }
14 | \value{
15 | One level of a CellTypeDataset.
16 | }
17 | \description{
18 | calculate_meanexp_for_level
19 | }
20 | \keyword{internal}
21 |
--------------------------------------------------------------------------------
/man/check_group_name.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/check_group_name.R
3 | \name{check_group_name}
4 | \alias{check_group_name}
5 | \title{Check group name}
6 | \usage{
7 | check_group_name(groupName)
8 | }
9 | \arguments{
10 | \item{groupName}{A human readable name for referring to the dataset
11 | being used.}
12 | }
13 | \value{
14 | Null output.
15 | }
16 | \description{
17 | Ensure \code{groupName} argument is provided to
18 | \link[EWCE]{generate_celltype_data}.
19 | }
20 | \keyword{internal}
21 |
--------------------------------------------------------------------------------
/R/load_rdata.R:
--------------------------------------------------------------------------------
1 | #' \code{load_rdata}
2 | #'
3 | #' Load processed data (\emph{.rda} format) using a function that assigns it
4 | #' to a specific variable
5 | #' (so you don't have to guess what the loaded variable name is).
6 | #'
7 | #' @param fileName Name of the file to load.
8 | #'
9 | #' @return Data object.
10 | #'
11 | #' @export
12 | #' @examples
13 | #' tmp <- tempfile()
14 | #' save(mtcars, file = tmp)
15 | #' mtcars2 <- load_rdata(tmp)
16 | load_rdata <- function(fileName) {
17 | load(fileName)
18 | get(ls()[ls() != "fileName"])
19 | }
20 |
--------------------------------------------------------------------------------
/man/list_species.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/list_species.R
3 | \name{list_species}
4 | \alias{list_species}
5 | \title{List all species}
6 | \usage{
7 | list_species(verbose = TRUE)
8 | }
9 | \arguments{
10 | \item{verbose}{Print messages.}
11 | }
12 | \value{
13 | List of species EWCE can input/output genes as.
14 | }
15 | \description{
16 | List all species that EWCE can convert genes from/to.
17 | Wrapper function for \link[orthogene]{map_species}.
18 | }
19 | \examples{
20 | list_species()
21 | }
22 |
--------------------------------------------------------------------------------
/R/is_sparse_matrix.R:
--------------------------------------------------------------------------------
1 | #' Assess whether an object is a sparse matrix
2 | #'
3 | #' Assess whether an object is a sparse matrix or one of
4 | #' its derived object types.
5 | #'
6 | #' @param X Object.
7 | #'
8 | #' @return boolean
9 | #'
10 | #' @importFrom methods is
11 | is_sparse_matrix <- function(X) {
12 | methods::is(X, "sparseMatrix") |
13 | methods::is(X, "dgCMatrix") |
14 | methods::is(X, "dgRMatrix") |
15 | methods::is(X, "dgTMatrix") |
16 | methods::is(X, "dgeMatrix") |
17 | methods::is(X, "lgCMatrix")
18 | }
19 |
--------------------------------------------------------------------------------
/.Rbuildignore:
--------------------------------------------------------------------------------
1 | Icon?
2 | .*\.rda
3 | BootstrapPlots
4 | .*\.csv
5 | .*\.txt
6 | .*\.log
7 | \.travis\.yml
8 | BootstrapPlots/*
9 | README_files/*
10 | vignettes/.build.timestamp
11 | vignettes/EWCE_cache/*
12 | vignettes/EWCE_files/*
13 | Dockerfile
14 | DOCKERFILE
15 | \.dockerignore
16 |
17 | ^.*\.Rproj$
18 | ^\.Rproj\.user$
19 | ^LICENSE\.md$
20 | ^\.Rproj\.user$
21 | ^README.Rmd
22 | ^\.github$
23 | ^Meta$
24 | ^codecov\.yml$
25 | ^_pkgdown\.yml$
26 | ^docs$
27 | /docs/
28 | ^doc$
29 | ^pkgdown$
30 |
31 | node_modules$
32 | package-lock\.json$
33 | package\.json$
34 |
--------------------------------------------------------------------------------
/R/list_species.R:
--------------------------------------------------------------------------------
1 | #' List all species
2 | #'
3 | #' List all species that EWCE can convert genes from/to.
4 | #' Wrapper function for \link[orthogene]{map_species}.
5 | #'
6 | #' @param verbose Print messages.
7 | #'
8 | #' @return List of species EWCE can input/output genes as.
9 | #'
10 | #' @export
11 | #' @importFrom orthogene map_species
12 | #' @examples
13 | #' list_species()
14 | list_species <- function(verbose = TRUE) {
15 | orthogene::map_species(
16 | species = NULL,
17 | method = "homologene",
18 | verbose = verbose
19 | )
20 | }
21 |
--------------------------------------------------------------------------------
/man/is_ctd_standardised.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/is_ctd_standardised.R
3 | \name{is_ctd_standardised}
4 | \alias{is_ctd_standardised}
5 | \title{Check whether a CellTypeDataset is standardised}
6 | \usage{
7 | is_ctd_standardised(ctd)
8 | }
9 | \arguments{
10 | \item{ctd}{CellTypeDataset.}
11 | }
12 | \value{
13 | Whether the \code{ctd} is standardised.
14 | }
15 | \description{
16 | Check whether a CellTypeDataset was previously standardised
17 | using \link[EWCE]{standardise_ctd}.
18 | }
19 | \keyword{internal}
20 |
--------------------------------------------------------------------------------
/R/dt_to_df.R:
--------------------------------------------------------------------------------
1 | #' Convert a \code{data.table} to a \code{data.frame}.
2 | #'
3 | #' Converts a \code{data.table} to a \code{data.frame} by setting the
4 | #' first column as the rownames.
5 | #'
6 | #' @return \link[base]{data.frame}
7 | #'
8 | #' @keywords internal
9 | dt_to_df <- function(exp) {
10 | if (methods::is(exp, "data.table")) {
11 | col1 <- colnames(exp)[1]
12 | exp <- data.frame(exp,
13 | row.names = col1,
14 | check.rows = FALSE,
15 | check.names = FALSE
16 | )
17 | }
18 | return(exp)
19 | }
20 |
--------------------------------------------------------------------------------
/man/drop_nonexpressed_genes.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/drop_nonexpressed_genes.R
3 | \name{drop_nonexpressed_genes}
4 | \alias{drop_nonexpressed_genes}
5 | \title{Drop genes with zero counts}
6 | \usage{
7 | drop_nonexpressed_genes(exp, verbose = TRUE)
8 | }
9 | \arguments{
10 | \item{exp}{Gene expression matrix.}
11 |
12 | \item{verbose}{Print messages.}
13 | }
14 | \value{
15 | List of filtered \code{exp}.
16 | }
17 | \description{
18 | Remove rows (genes) in which counts sum to zero.
19 | }
20 | \keyword{internal}
21 |
--------------------------------------------------------------------------------
/man/assign_cores.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/assign_cores.r
3 | \name{assign_cores}
4 | \alias{assign_cores}
5 | \title{Assign cores}
6 | \usage{
7 | assign_cores(worker_cores = 0.9, verbose = TRUE)
8 | }
9 | \arguments{
10 | \item{worker_cores}{Number (>1) or proportion (<1) of worker cores to use.}
11 |
12 | \item{verbose}{Print messages.}
13 | }
14 | \value{
15 | List of core allocations.
16 | }
17 | \description{
18 | Assign cores automatically for parallel processing, while reserving some.
19 | }
20 | \keyword{internal}
21 |
--------------------------------------------------------------------------------
/man/prep_dendro.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/prep_dendro.r
3 | \name{prep_dendro}
4 | \alias{prep_dendro}
5 | \title{Prepare dendrogram}
6 | \usage{
7 | prep_dendro(ctdIN, expand = c(0, 0.66))
8 | }
9 | \arguments{
10 | \item{ctdIN}{A single annotLevel of a ctd, i.e. ctd[[1]] (the function is
11 | intended to be used via apply).}
12 | }
13 | \value{
14 | A CellTypeDataset with dendrogram plotting info added.
15 | }
16 | \description{
17 | \code{prep_dendro} adds a dendrogram to a CellTypeDataset (CTD).
18 | }
19 | \keyword{internal}
20 |
--------------------------------------------------------------------------------
/man/to_sparse_matrix.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/to_sparse_matrix.R
3 | \name{to_sparse_matrix}
4 | \alias{to_sparse_matrix}
5 | \title{Convert object to sparse matrix}
6 | \usage{
7 | to_sparse_matrix(exp, as_sparse = TRUE, verbose = TRUE)
8 | }
9 | \arguments{
10 | \item{exp}{Object.}
11 |
12 | \item{as_sparse}{Whether to convert \code{exp} to sparse matrix}
13 |
14 | \item{verbose}{Print messages.}
15 | }
16 | \value{
17 | Sparse matrix.
18 | }
19 | \description{
20 | Convert a variety of object types to sparse matrix format.
21 | }
22 | \keyword{internal}
23 |
--------------------------------------------------------------------------------
/R/check_group_name.R:
--------------------------------------------------------------------------------
1 | #' Check group name
2 | #'
3 | #' Ensure \code{groupName} argument is provided to
4 | #' \link[EWCE]{generate_celltype_data}.
5 | #' @inheritParams generate_celltype_data
6 | #' @return Null output.
7 | #'
8 | #' @keywords internal
9 | check_group_name <- function(groupName) {
10 | err_msg3 <- paste0(
11 | "ERROR: groupName must be set. groupName is used to",
12 | " label the files created by this function."
13 | )
14 | if (is.null(groupName)) {
15 | stop(err_msg3)
16 | }
17 | if (is.null(groupName) || groupName == "") {
18 | stop(err_msg3)
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/man/compute_gene_counts.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/compute_gene_counts.R
3 | \name{compute_gene_counts}
4 | \alias{compute_gene_counts}
5 | \title{Compute gene counts}
6 | \usage{
7 | compute_gene_counts(bootstrap_list, verbose = TRUE)
8 | }
9 | \arguments{
10 | \item{bootstrap_list}{The output of \code{get_summed_proportions_iterate}.}
11 |
12 | \item{verbose}{Print messages.}
13 | }
14 | \value{
15 | \link[data.table]{data.table}
16 | }
17 | \description{
18 | Counts the number of times each gene appeared in
19 | the randomly sampled gene lists.
20 | }
21 | \keyword{internal}
22 |
--------------------------------------------------------------------------------
/man/load_rdata.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/load_rdata.R
3 | \name{load_rdata}
4 | \alias{load_rdata}
5 | \title{\code{load_rdata}}
6 | \usage{
7 | load_rdata(fileName)
8 | }
9 | \arguments{
10 | \item{fileName}{Name of the file to load.}
11 | }
12 | \value{
13 | Data object.
14 | }
15 | \description{
16 | Load processed data (\emph{.rda} format) using a function that assigns it
17 | to a specific variable
18 | (so you don't have to guess what the loaded variable name is).
19 | }
20 | \examples{
21 | tmp <- tempfile()
22 | save(mtcars, file = tmp)
23 | mtcars2 <- load_rdata(tmp)
24 | }
25 |
--------------------------------------------------------------------------------
/man/check_annotLevels.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/check_annotLevels.R
3 | \name{check_annotLevels}
4 | \alias{check_annotLevels}
5 | \title{check_annotLevels
6 |
7 | First, check the number of annotations equals the number of columns
8 | in the expression data.}
9 | \usage{
10 | check_annotLevels(annotLevels, exp)
11 | }
12 | \arguments{
13 | \item{exp}{exp (#fix).}
14 | }
15 | \value{
16 | Null output.
17 | }
18 | \description{
19 | check_annotLevels
20 |
21 | First, check the number of annotations equals the number of columns
22 | in the expression data.
23 | }
24 | \keyword{internal}
25 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | Icon?
2 | *.rda
3 | BootstrapPlots
4 | *.csv
5 | *.txt
6 | *.log
7 | docs
8 | /doc/
9 | doc
10 | /doc/
11 | Meta
12 | /Meta/
13 | vignettes/.build.timestamp
14 | vignettes/EWCE_cache/*
15 | vignettes/EWCE_files/*
16 | tests/testthat/Rplots.pdf
17 |
18 | *.Rproj
19 | .Rproj.user
20 | .Rhistory
21 | ./**/.Rhistory
22 | .RData
23 | .Ruserdata
24 |
25 | vignettes/*.R$
26 | vignettes/*.html$
27 |
28 | # find . -name .DS_Store -print0 | xargs -0 git rm -f --ignore-unmatch
29 | ./.DS_Store
30 | ./**/.DS_Store
31 | ./**/**/.DS_Store
32 | ./**/**/**/.DS_Store
33 | ./**/**/**/**/.DS_Store
34 | ./**/**/**/**/**/.DS_Store
35 | ./**/**/**/**/**/**/.DS_Store
36 |
--------------------------------------------------------------------------------
/man/check_full_results.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/check_full_results.R
3 | \name{check_full_results}
4 | \alias{check_full_results}
5 | \title{check_full_results}
6 | \usage{
7 | check_full_results(full_results, sct_data)
8 | }
9 | \arguments{
10 | \item{full_results}{The full output of
11 | \link[EWCE]{bootstrap_enrichment_test} for the same gene list.}
12 |
13 | \item{sct_data}{List generated using \link[EWCE]{generate_celltype_data}.}
14 | }
15 | \value{
16 | Null output.
17 | }
18 | \description{
19 | Check full results generated by \link[EWCE]{bootstrap_enrichment_test}.
20 | }
21 | \keyword{internal}
22 |
--------------------------------------------------------------------------------
/man/convert_new_ewce_to_old.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/convert_new_ewce_to_old.r
3 | \name{convert_new_ewce_to_old}
4 | \alias{convert_new_ewce_to_old}
5 | \title{convert_new_ewce_to_old}
6 | \usage{
7 | convert_new_ewce_to_old(ctd, lvl)
8 | }
9 | \arguments{
10 | \item{ctd}{A cell type data structure containing
11 | "mean_exp" and "specificity".}
12 |
13 | \item{lvl}{The annotation level to extract.}
14 | }
15 | \value{
16 | CellTypeData in the old data structure style.
17 | }
18 | \description{
19 | \code{convert_new_ewce_to_old} Used to get an old style EWCE ctd file
20 | from a new one
21 | }
22 | \keyword{internal}
23 |
--------------------------------------------------------------------------------
/R/is_ctd_standardised.R:
--------------------------------------------------------------------------------
1 | #' Check whether a CellTypeDataset is standardised
2 | #'
3 | #' Check whether a CellTypeDataset was previously standardised
4 | #' using \link[EWCE]{standardise_ctd}.
5 | #'
6 | #' @param ctd CellTypeDataset.
7 | #'
8 | #' @return Whether the \code{ctd} is standardised.
9 | #'
10 | #' @keywords internal
11 | is_ctd_standardised <- function(ctd) {
12 | std_list <- lapply(ctd, function(x) {
13 | if ("standardised" %in% names(x)) {
14 | return(x[["standardised"]])
15 | } else {
16 | return(FALSE)
17 | }
18 | })
19 | is_standardised <- all(unlist(std_list) == TRUE)
20 | return(is_standardised)
21 | }
22 |
--------------------------------------------------------------------------------
/man/to_delayed_array.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/to_delayed_array.R
3 | \name{to_delayed_array}
4 | \alias{to_delayed_array}
5 | \title{Convert object to DelayedArray}
6 | \usage{
7 | to_delayed_array(exp, as_DelayedArray = TRUE, verbose = TRUE)
8 | }
9 | \arguments{
10 | \item{exp}{Object.}
11 |
12 | \item{as_DelayedArray}{Whether to convert \code{exp} to
13 | \link[DelayedArray]{DelayedArray}.}
14 |
15 | \item{verbose}{Print messages.}
16 | }
17 | \value{
18 | \link[DelayedArray]{DelayedArray}.
19 | }
20 | \description{
21 | Convert a variety of object types to
22 | \link[DelayedArray]{DelayedArray} format.
23 | }
24 | \keyword{internal}
25 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/feature_request.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Feature request
3 | about: Suggest an idea for this project
4 | title: ''
5 | labels: ''
6 | assignees: ''
7 |
8 | ---
9 |
10 | **Is your feature request related to a problem? Please describe.**
11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
12 |
13 | **Describe the solution you'd like**
14 | A clear and concise description of what you want to happen.
15 |
16 | **Describe alternatives you've considered**
17 | A clear and concise description of any alternative solutions or features you've considered.
18 |
19 | **Additional context**
20 | Add any other context or screenshots about the feature request here.
21 |
--------------------------------------------------------------------------------
/tests/testthat/test-check_percent_hits.R:
--------------------------------------------------------------------------------
1 | test_that("check_percent_hits works", {
2 | if (!is_32bit()) {
3 | full_results <- EWCE::example_bootstrap_results()
4 | testthat::expect_true(length(full_results) %in% c(3,4) )
5 | testthat::expect_true(methods::is(full_results$results, "data.frame"))
6 |
7 | report <- EWCE::check_percent_hits(
8 | full_results = full_results,
9 | target_celltype = "microglia"
10 | )
11 | testthat::expect_true(
12 | all(c("target_hits", "percent_hits", "target_celltype")
13 | %in% names(report))
14 | )
15 | testthat::expect_equal(report$percent_hits, 14.3)
16 | }
17 | })
18 |
--------------------------------------------------------------------------------
/R/check_annotLevels.R:
--------------------------------------------------------------------------------
1 | #' check_annotLevels
2 | #'
3 | #' First, check the number of annotations equals the number of columns
4 | #' in the expression data.
5 | #'
6 | #' @param exp exp (#fix).
7 | #' @inheritParams bootstrap_enrichment_test
8 | #' @return Null output.
9 | #'
10 | #' @keywords internal
11 | check_annotLevels <- function(annotLevels,
12 | exp) {
13 | err_msg2 <- paste0(
14 | "Error: length of all annotation levels must equal",
15 | " the number of columns in exp matrix"
16 | )
17 | out <- lapply(annotLevels, test <- function(x, exp) {
18 | if (length(x) != dim(exp)[2]) {
19 | stop(err_msg2)
20 | }
21 | }, exp)
22 | }
23 |
--------------------------------------------------------------------------------
/man/drop_nonexpressed_cells.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/drop_nonexpressed_cells.R
3 | \name{drop_nonexpressed_cells}
4 | \alias{drop_nonexpressed_cells}
5 | \title{Drop cells with zero gene counts}
6 | \usage{
7 | drop_nonexpressed_cells(exp, annotLevels, verbose = TRUE)
8 | }
9 | \arguments{
10 | \item{exp}{Gene expression matrix.}
11 |
12 | \item{annotLevels}{Cell-wise annotations to be subset
13 | if some cells are dropped.}
14 |
15 | \item{verbose}{Print messages.}
16 | }
17 | \value{
18 | List of filtered \code{exp} and \code{annotLevels}.
19 | }
20 | \description{
21 | Remove columns (cells) in which (gene) counts sum to zero.
22 | }
23 | \keyword{internal}
24 |
--------------------------------------------------------------------------------
/man/get_ctd_levels.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/get_ctd_levels.R
3 | \name{get_ctd_levels}
4 | \alias{get_ctd_levels}
5 | \title{Get the names of CellTypeDataset levels}
6 | \usage{
7 | get_ctd_levels(ctd, max_only = FALSE)
8 | }
9 | \arguments{
10 | \item{ctd}{CellTypeDataset.}
11 |
12 | \item{max_only}{Only return the level with the greatest depth
13 | (e.g. \code{"level3"} in \code{c("level1","level2","level3")}).}
14 | }
15 | \value{
16 | List of levels in \code{ctd}.
17 | }
18 | \description{
19 | Returns the level names of a CellTypeDataset. If none are available,
20 | will instead return a vector of numbers (one number per level).
21 | }
22 | \keyword{internal}
23 |
--------------------------------------------------------------------------------
/R/report_dge.R:
--------------------------------------------------------------------------------
1 | #' Report DGE
2 | #'
3 | #' Report differential gene expression (DGE) results
4 | #'
5 | #' @param exp Gene expression matrix.
6 | #' @param keep_genes Genes kept after DGE.
7 | #' @inheritParams drop_uninformative_genes
8 | #'
9 | #' @return Null output.
10 | #'
11 | #' @keywords internal
12 | report_dge <- function(exp,
13 | keep_genes,
14 | adj_pval_thresh = .05,
15 | verbose = TRUE) {
16 | messager(paste(
17 | formatC(nrow(exp) - length(keep_genes), big.mark = ","),
18 | "/",
19 | formatC(nrow(exp), big.mark = ","),
20 | "genes dropped @ DGE adj_pval_thresh <", adj_pval_thresh
21 | ), v = verbose)
22 | }
23 |
--------------------------------------------------------------------------------
/man/plot_with_bootstrap_distributions.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/plot_with_bootstrap_distributions.R
3 | \name{plot_with_bootstrap_distributions}
4 | \alias{plot_with_bootstrap_distributions}
5 | \title{Plot with bootstrap distributions}
6 | \usage{
7 | plot_with_bootstrap_distributions(
8 | exp_mats,
9 | cc,
10 | hit_exp,
11 | tag,
12 | listFileName,
13 | graph_theme,
14 | save_dir = file.path(tempdir(), paste0("BootstrapPlots", "_for_transcriptome")),
15 | height = 3.5,
16 | width = 3.5
17 | )
18 | }
19 | \value{
20 | Null result.
21 | }
22 | \description{
23 | Plot results of \link[EWCE]{generate_bootstrap_plots_for_transcriptome}.
24 | }
25 | \keyword{internal}
26 |
--------------------------------------------------------------------------------
/man/plot_log_bootstrap_distributions.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/plot_log_bootstrap_distributions.R
3 | \name{plot_log_bootstrap_distributions}
4 | \alias{plot_log_bootstrap_distributions}
5 | \title{Plot log bootstrap distributions}
6 | \usage{
7 | plot_log_bootstrap_distributions(
8 | dat,
9 | exp_mats,
10 | cc,
11 | hit_exp,
12 | tag,
13 | listFileName,
14 | graph_theme,
15 | save_dir = file.path(tempdir(), paste0("BootstrapPlots", "_for_transcriptome")),
16 | height = 3.5,
17 | width = 3.5
18 | )
19 | }
20 | \value{
21 | Null result.
22 | }
23 | \description{
24 | Plot results of \link[EWCE]{generate_bootstrap_plots_for_transcriptome}.
25 | }
26 | \keyword{internal}
27 |
--------------------------------------------------------------------------------
/man/bootstrap_plots_for_transcriptome.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/bootstrap_plots_for_transcriptome.R
3 | \name{bootstrap_plots_for_transcriptome}
4 | \alias{bootstrap_plots_for_transcriptome}
5 | \title{Bootstrap plot}
6 | \usage{
7 | bootstrap_plots_for_transcriptome(
8 | dat,
9 | tag,
10 | listFileName,
11 | cc,
12 | showGNameThresh,
13 | graph_theme,
14 | maxX,
15 | save_dir = file.path(tempdir(), paste0("BootstrapPlots", "_for_transcriptome")),
16 | height = 3.5,
17 | width = 3.5,
18 | show_plot = TRUE
19 | )
20 | }
21 | \value{
22 | Null result.
23 | }
24 | \description{
25 | Plot results of \link[EWCE]{generate_bootstrap_plots_for_transcriptome}.
26 | }
27 | \keyword{internal}
28 |
--------------------------------------------------------------------------------
/man/report_dge.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/report_dge.R
3 | \name{report_dge}
4 | \alias{report_dge}
5 | \title{Report DGE}
6 | \usage{
7 | report_dge(exp, keep_genes, adj_pval_thresh = 0.05, verbose = TRUE)
8 | }
9 | \arguments{
10 | \item{exp}{Gene expression matrix.}
11 |
12 | \item{keep_genes}{Genes kept after DGE.}
13 |
14 | \item{adj_pval_thresh}{Minimum differential expression significance
15 | that a gene must demonstrate across \code{level2annot} (i.e. cell types).}
16 |
17 | \item{verbose}{Print messages.
18 | #' @inheritParams orthogene::convert_orthologs}
19 | }
20 | \value{
21 | Null output.
22 | }
23 | \description{
24 | Report differential gene expression (DGE) results
25 | }
26 | \keyword{internal}
27 |
--------------------------------------------------------------------------------
/man/sct_normalize.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/sct_normalize.R
3 | \name{sct_normalize}
4 | \alias{sct_normalize}
5 | \title{Normalize expression matrix}
6 | \usage{
7 | sct_normalize(exp, as_sparse = TRUE, verbose = TRUE)
8 | }
9 | \arguments{
10 | \item{exp}{Gene x cell expression matrix.}
11 |
12 | \item{as_sparse}{Convert \code{exp} to sparse matrix.}
13 |
14 | \item{verbose}{Print messages.}
15 | }
16 | \value{
17 | Normalised expression matrix.
18 | }
19 | \description{
20 | Normalize expression matrix by accounting for library size.
21 | Uses \pkg{sctransform}.
22 | }
23 | \examples{
24 | cortex_mrna <- ewceData::cortex_mrna()
25 | exp_sct_normed <- EWCE::sct_normalize(exp = cortex_mrna$exp[1:300, ])
26 | }
27 |
--------------------------------------------------------------------------------
/R/convert_new_ewce_to_old.r:
--------------------------------------------------------------------------------
1 | #' convert_new_ewce_to_old
2 | #'
3 | #' \code{convert_new_ewce_to_old} Used to get an old style EWCE ctd file
4 | #' from a new one
5 | #'
6 | #' @param ctd A cell type data structure containing
7 | #' "mean_exp" and "specificity".
8 | #' @param lvl The annotation level to extract.
9 | #'
10 | #' @return CellTypeData in the old data structure style.
11 | #'
12 | #' @keywords internal
13 | convert_new_ewce_to_old <- function(ctd,
14 | lvl) {
15 | celltype_data <- list()
16 | celltype_data[[1]] <- list()
17 | celltype_data[[1]]$cell_dists <- ctd[[lvl]]$specificity
18 | celltype_data[[1]]$all_scts <- ctd[[lvl]]$mean_exp
19 | celltype_data[[1]]$annot <- ctd[[lvl]]$annot
20 | return(celltype_data)
21 | }
22 |
--------------------------------------------------------------------------------
/man/cell_list_dist.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/cell_list_dist.r
3 | \name{cell_list_dist}
4 | \alias{cell_list_dist}
5 | \title{cell_list_dist}
6 | \usage{
7 | cell_list_dist(hits, sct_data, annotLevel)
8 | }
9 | \arguments{
10 | \item{hits}{List of gene symbols containing the target gene list.}
11 |
12 | \item{sct_data}{List generated using \link[EWCE]{generate_celltype_data}.}
13 |
14 | \item{annotLevel}{An integer indicating which level of \code{sct_data} to
15 | analyse (\emph{Default: 1}).}
16 | }
17 | \value{
18 | The summed specificity of each celltype
19 | across a set of \code{hits}.
20 | }
21 | \description{
22 | specificity is generated in the main_CellTypeAnalysis_Preperation.r file
23 | }
24 | \keyword{internal}
25 |
--------------------------------------------------------------------------------
/man/filter_ctd_genes.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/filter_ctd_genes.R
3 | \name{filter_ctd_genes}
4 | \alias{filter_ctd_genes}
5 | \title{Filter genes in a CellTypeDataset}
6 | \usage{
7 | filter_ctd_genes(ctd, gene_subset)
8 | }
9 | \arguments{
10 | \item{ctd}{CellTypeDataset.}
11 |
12 | \item{gene_subset}{Genes to subset to.}
13 | }
14 | \value{
15 | Filtered CellTypeDataset.
16 | }
17 | \description{
18 | Removes rows from each matrix within a CellTypeDataset (CTD) that are not
19 | within \code{gene_subset}.
20 | }
21 | \examples{
22 |
23 | ctd <- ewceData::ctd()
24 | ctd <- standardise_ctd(ctd, input_species="mouse")
25 | gene_subset <- rownames(ctd[[1]]$mean_exp)[1:100]
26 | ctd_subset <- EWCE::filter_ctd_genes(ctd = ctd, gene_subset = gene_subset)
27 | }
28 |
--------------------------------------------------------------------------------
/man/fix_celltype_names_full_results.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/fix_celltype_names_full_results.R
3 | \name{fix_celltype_names_full_results}
4 | \alias{fix_celltype_names_full_results}
5 | \title{Fix celltype name in full results}
6 | \usage{
7 | fix_celltype_names_full_results(full_results, verbose = TRUE)
8 | }
9 | \arguments{
10 | \item{full_results}{Cell-type enrichment results generated by
11 | \link[EWCE]{bootstrap_enrichment_test}.}
12 |
13 | \item{verbose}{Print messages.}
14 | }
15 | \value{
16 | Fixed full results.
17 | }
18 | \description{
19 | Aligns celltype names in full results generated by
20 | \link[EWCE]{bootstrap_enrichment_test} with the standardised
21 | CellTypeDataset (CTD) produced by \link[EWCE]{standardise_ctd}.
22 | }
23 | \keyword{internal}
24 |
--------------------------------------------------------------------------------
/man/get_ctd_matrix_names.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/get_ctd_matrix_names.R
3 | \name{get_ctd_matrix_names}
4 | \alias{get_ctd_matrix_names}
5 | \title{Get CTD matrix names}
6 | \usage{
7 | get_ctd_matrix_names(
8 | ctd = NULL,
9 | matrices = c("mean_exp", "median_exp", "specificity", "median_specificity",
10 | "specificity_quantiles"),
11 | verbose = TRUE
12 | )
13 | }
14 | \arguments{
15 | \item{ctd}{CellTypeDataset. If set to \code{NULL} (default),
16 | will simply return all possible matrix names.}
17 |
18 | \item{matrices}{Matrix names to search for.}
19 |
20 | \item{verbose}{Print messages.}
21 | }
22 | \value{
23 | List of matrix names.
24 | }
25 | \description{
26 | Find the names of all data matrices in a CellTypeDataset.
27 | }
28 | \keyword{internal}
29 |
--------------------------------------------------------------------------------
/man/calculate_specificity_for_level.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/calculate_specificity_for_level.R
3 | \name{calculate_specificity_for_level}
4 | \alias{calculate_specificity_for_level}
5 | \title{Calculate specificity for one CTD level}
6 | \usage{
7 | calculate_specificity_for_level(
8 | ctd_oneLevel,
9 | matrix_name = "mean_exp",
10 | as_sparse = TRUE,
11 | verbose = TRUE
12 | )
13 | }
14 | \arguments{
15 | \item{ctd_oneLevel}{One level from a CTD.}
16 |
17 | \item{matrix_name}{Name of the matrix to extract.}
18 |
19 | \item{as_sparse}{Whether to convert \code{exp} to sparse matrix}
20 |
21 | \item{verbose}{Print messages.}
22 | }
23 | \value{
24 | One CTD level.
25 | }
26 | \description{
27 | Calculate specificity for one CellTypeDataset (CTD) level.
28 | }
29 | \keyword{internal}
30 |
--------------------------------------------------------------------------------
/man/ctd_to_sce.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/ctd_to_sce.R
3 | \name{ctd_to_sce}
4 | \alias{ctd_to_sce}
5 | \title{CellTypeDataset to SingleCellExperiment}
6 | \usage{
7 | ctd_to_sce(object, as_sparse = TRUE, as_DelayedArray = FALSE, verbose = TRUE)
8 | }
9 | \arguments{
10 | \item{object}{CellTypeDataset object.}
11 |
12 | \item{as_sparse}{Store SingleCellExperiment matrices as sparse.}
13 |
14 | \item{as_DelayedArray}{Store SingleCellExperiment matrices as DelayedArray.}
15 |
16 | \item{verbose}{Print messages.}
17 | }
18 | \value{
19 | SingleCellExperiment
20 | }
21 | \description{
22 | Copied from \href{https://github.com/neurogenomics/scKirby}{scKirby},
23 | which is not yet on CRAN or Bioconductor.
24 | }
25 | \examples{
26 | ctd <- ewceData::ctd()
27 | sce <- EWCE::ctd_to_sce(ctd)
28 | }
29 |
--------------------------------------------------------------------------------
/inst/CITATION:
--------------------------------------------------------------------------------
1 | citHeader("To cite this package, please use:")
2 |
3 | citEntry(
4 | entry = "Article",
5 | title = "Identification of Vulnerable Cell
6 | Types in Major Brain Disorders Using Single Cell Transcriptomes
7 | and Expression Weighted Cell Type Enrichment",
8 | author = "Nathan G. Skene, Seth G. N. Grant",
9 | journal = "Frontiers in Neuroscience",
10 | year = "2016",
11 | volume = "10",
12 | number = NULL,
13 | pages = "16",
14 | url = "https://doi.org/10.3389/fnins.2016.00016",
15 | textVersion = paste("Nathan G. Skene, Seth G. N. Grant (2016) Identification of Vulnerable Cell Types in Major Brain Disorders Using Single Cell Transcriptomes and Expression Weighted Cell Type Enrichment, *Frontiers in Neuroscience*; 10, [https://doi.org/10.3389/fnins.2016.00016](https://doi.org/10.3389/fnins.2016.00016)"
16 | )
17 | )
18 |
--------------------------------------------------------------------------------
/man/get_sig_results.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/get_sig_results.R
3 | \name{get_sig_results}
4 | \alias{get_sig_results}
5 | \title{Extract significant results}
6 | \usage{
7 | get_sig_results(
8 | full_results,
9 | mtc_method = "BH",
10 | q_threshold = 0.05,
11 | verbose = TRUE
12 | )
13 | }
14 | \arguments{
15 | \item{full_results}{Output of \link[EWCE]{bootstrap_enrichment_test}.}
16 |
17 | \item{mtc_method}{Multiple-testing correction method
18 | (passed to \link[stats]{p.adjust}).}
19 |
20 | \item{q_threshold}{Maximum multiple-testing-corrected p-value to include.}
21 |
22 | \item{verbose}{Print messages.}
23 | }
24 | \value{
25 | Filtered enrichment results table.
26 | }
27 | \description{
28 | Extract significant results from output of
29 | \link[EWCE]{bootstrap_enrichment_test}.
30 | }
31 | \keyword{internal}
32 |
--------------------------------------------------------------------------------
/R/get_ctd_levels.R:
--------------------------------------------------------------------------------
1 | #' Get the names of CellTypeDataset levels
2 | #'
3 | #' Returns the level names of a CellTypeDataset. If none are available,
4 | #' will instead return a vector of numbers (one number per level).
5 | #'
6 | #' @param ctd CellTypeDataset.
7 | #' @param max_only Only return the level with the greatest depth
8 | #' (e.g. \code{"level3"} in \code{c("level1","level2","level3")}).
9 | #'
10 | #' @return List of levels in \code{ctd}.
11 | #'
12 | #' @keywords internal
13 | get_ctd_levels <- function(ctd,
14 | max_only = FALSE) {
15 | # This is necessary in case further meta-data such as $name is used
16 | if (!is.null(names(ctd))) {
17 | lvls <- names(ctd)
18 | } else {
19 | lvls <- seq(1, length(ctd))
20 | }
21 | if (max_only) {
22 | return(max(lvls))
23 | } else {
24 | return(lvls)
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/R/check_ewce_expression_data_args.R:
--------------------------------------------------------------------------------
1 | #' check_ewce_expression_data_args
2 | #'
3 | #' Check the input arguments of the
4 | #' \link[EWCE]{ewce_expression_data}.
5 | #'
6 | #' @inheritParams ewce_expression_data
7 | #' @return Null output.
8 | #'
9 | #' @keywords internal
10 | check_ewce_expression_data_args <- function(sortBy,
11 | tt,
12 | thresh){
13 | err_msg <- paste0(
14 | "ERROR: tt does not contain a column with value",
15 | " passed in sortBy argument"
16 | )
17 | # Check the arguments
18 | if (!sortBy %in% colnames(tt)) {
19 | stop(err_msg)
20 | }
21 | err_msg2 <- paste0(
22 | "ERROR: length of table is less than",
23 | " twice the size of threshold"
24 | )
25 | if (dim(tt)[1] < (thresh * 2)) {
26 | stop(err_msg2)
27 | }
28 | }
--------------------------------------------------------------------------------
/tests/testthat/test-filter_ctd_genes.R:
--------------------------------------------------------------------------------
1 | test_that("filter_ctd_genes works", {
2 |
3 | ctd <- ewceData::ctd()
4 | n_genes <- 100
5 | gene_subset <- rownames(ctd[[1]]$mean_exp)[seq_len(n_genes)]
6 |
7 | #### Works with old CTD format ####
8 | ctd_subset <- filter_ctd_genes(ctd = ctd,
9 | gene_subset = gene_subset)
10 | testthat::expect_true(
11 | all(lapply(ctd_subset, function(x)nrow(x$mean_exp))==n_genes)
12 | )
13 |
14 | #### Works with new CTD format ####
15 | ctd <- standardise_ctd(ctd, input_species="mouse")
16 | gene_subset <- rownames(ctd[[1]]$mean_exp)[seq_len(n_genes)]
17 | ctd_subset <- filter_ctd_genes(ctd = ctd,
18 | gene_subset = gene_subset)
19 | testthat::expect_true(
20 | all(lapply(ctd_subset, function(x)nrow(x$mean_exp))==n_genes)
21 | )
22 | })
23 |
--------------------------------------------------------------------------------
/R/to_delayed_array.R:
--------------------------------------------------------------------------------
1 | #' Convert object to DelayedArray
2 | #'
3 | #' Convert a variety of object types to
4 | #' \link[DelayedArray]{DelayedArray} format.
5 | #'
6 | #' @param exp Object.
7 | #' @param as_DelayedArray Whether to convert \code{exp} to
8 | #' \link[DelayedArray]{DelayedArray}.
9 | #' @param verbose Print messages.
10 | #'
11 | #' @return \link[DelayedArray]{DelayedArray}.
12 | #'
13 | #' @keywords internal
14 | #' @importFrom DelayedArray DelayedArray
15 | to_delayed_array <- function(exp,
16 | as_DelayedArray = TRUE,
17 | verbose = TRUE) {
18 | if (as_DelayedArray && (!is_delayed_array(exp))) {
19 | messager("Converting to DelayedArray.", v = verbose)
20 | if (!is_matrix(exp)) {
21 | exp <- as.matrix(exp)
22 | }
23 | exp <- DelayedArray::DelayedArray(exp)
24 | }
25 | return(exp)
26 | }
27 |
--------------------------------------------------------------------------------
/man/convert_old_ewce_to_new.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/convert_old_ewce_to_new.r
3 | \name{convert_old_ewce_to_new}
4 | \alias{convert_old_ewce_to_new}
5 | \title{convert_old_ewce_to_new}
6 | \usage{
7 | convert_old_ewce_to_new(level1 = NA, level2 = NA, celltype_data = NA)
8 | }
9 | \arguments{
10 | \item{level1}{File path to old level1 of EWCE ctd.}
11 |
12 | \item{level2}{File path to old level2 of EWCE ctd.}
13 |
14 | \item{celltype_data}{The ctd to be converted.}
15 | }
16 | \value{
17 | CellTypeData in the new data structure style.
18 | }
19 | \description{
20 | \code{convert_old_ewce_to_new} Used to get an new style EWCE ctd file
21 | (mean_exp/specificity) from old ones (all_scts).
22 | }
23 | \details{
24 | If you've already loaded it and want to pass it as a celltype_data
25 | structure, then don't set level1 or level2.
26 | }
27 | \keyword{internal}
28 |
--------------------------------------------------------------------------------
/R/drop_nonexpressed_genes.R:
--------------------------------------------------------------------------------
1 | #' Drop genes with zero counts
2 | #'
3 | #' Remove rows (genes) in which counts sum to zero.
4 | #'
5 | #' @param exp Gene expression matrix.
6 | #' @param verbose Print messages.
7 | #'
8 | #' @return List of filtered \code{exp}.
9 | #'
10 | #' @keywords internal
11 | #' @importFrom Matrix rowSums
12 | drop_nonexpressed_genes <- function(exp,
13 | verbose = TRUE) {
14 | messager("Checking for non-expressed genes.", v = verbose)
15 | orig.dims <- dim(exp)
16 | row.sums <- Matrix::rowSums(exp) # MUST be from Matrix
17 | n_zeros <- sum(row.sums <= 0, na.rm = TRUE)
18 | #### Drop genes ####
19 | if (n_zeros > 0) {
20 | exp <- exp[row.sums > 0, ]
21 | messager(nrow(exp) - orig.dims[1], "/", nrow(exp),
22 | "non-expressed genes dropped",
23 | v = verbose
24 | )
25 | }
26 | return(exp)
27 | }
28 |
--------------------------------------------------------------------------------
/man/delayedarray_normalize.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/delayedarray_normalize.R
3 | \name{delayedarray_normalize}
4 | \alias{delayedarray_normalize}
5 | \title{Efficiently normalize a DelayedArray}
6 | \usage{
7 | delayedarray_normalize(
8 | exp,
9 | log_norm = TRUE,
10 | min_max = TRUE,
11 | plot_hists = FALSE,
12 | no_cores = 1
13 | )
14 | }
15 | \arguments{
16 | \item{exp}{Input matrix (e.g. gene expression).}
17 |
18 | \item{log_norm}{Whether to first log-normalise \code{exp}
19 | with \link[base]{log1p}.}
20 |
21 | \item{min_max}{Whether to min/max-normalise \code{exp}.}
22 |
23 | \item{no_cores}{Number of cores to parallelise across.}
24 | }
25 | \value{
26 | Normalised matrix.
27 | }
28 | \description{
29 | The following is a matrix normalization procedure that takes advantage of
30 | functions designed to be more efficient for DelayedArray objects.
31 | }
32 | \keyword{internal}
33 |
--------------------------------------------------------------------------------
/R/cell_list_dist.r:
--------------------------------------------------------------------------------
1 | #' cell_list_dist
2 | #'
3 | #' specificity is generated in the main_CellTypeAnalysis_Preperation.r file
4 | #'
5 | #' @param hits List of gene symbols containing the target gene list.
6 | #' @inheritParams bootstrap_enrichment_test
7 | #' @returns The summed specificity of each celltype
8 | #' across a set of \code{hits}.
9 | #'
10 | #' @keywords internal
11 | cell_list_dist <- function(hits,
12 | sct_data,
13 | annotLevel) {
14 | ValidGenes <-
15 | rownames(sct_data[[annotLevel]]$specificity)[
16 | rownames(sct_data[[annotLevel]]$specificity) %in% hits
17 | ]
18 | temp <- sct_data[[annotLevel]]$specificity[ValidGenes, ,drop=FALSE]
19 |
20 | # If the function was based a single gene list... just return temp
21 | # if(is.null(dim(hits)[1])){
22 | # return(temp)
23 | # }else{
24 | return(apply(temp, 2, sum))
25 | # }
26 | }
27 |
--------------------------------------------------------------------------------
/R/filter_genes_without_1to1_homolog.r:
--------------------------------------------------------------------------------
1 | #' filter_genes_without_1to1_homolog
2 | #'
3 | #' Deprecated function. Please use \link[EWCE]{filter_nonorthologs} instead.
4 | #'
5 | #' @inherit filter_nonorthologs
6 | #' @export
7 | filter_genes_without_1to1_homolog <- function(filenames,
8 | input_species = "mouse",
9 | convert_nonhuman_genes = TRUE,
10 | annot_levels = NULL,
11 | suffix = "_orthologs",
12 | verbose = TRUE) {
13 | .Deprecated("filter_nonorthologs")
14 | newFilenames <- filter_nonorthologs(filenames,
15 | input_species = "mouse",
16 | convert_nonhuman_genes = TRUE,
17 | annot_levels = NULL,
18 | suffix = "_orthologs",
19 | verbose = TRUE
20 | )
21 | return(newFilenames)
22 | }
23 |
--------------------------------------------------------------------------------
/R/run_limma.r:
--------------------------------------------------------------------------------
1 | #' Run DGE: \pkg{limma}
2 | #'
3 | #' Run Differential Gene Expression with \pkg{limma}.
4 | #'
5 | #' @return \code{limma} results.
6 | #'
7 | #' @inheritParams drop_uninformative_genes
8 | #'
9 | #' @keywords internal
10 | #' @importFrom limma lmFit eBayes
11 | #' @importFrom stats model.matrix p.adjust
12 | run_limma <- function(exp,
13 | level2annot,
14 | mtc_method = "BH",
15 | verbose = TRUE,
16 | ...) {
17 | messager("DGE:: Limma...", v = verbose)
18 | ## Prepare groupings
19 | level2_options <- as.factor(as.character(level2annot))
20 | mod_matrix <- stats::model.matrix(~level2_options)
21 | fit <- limma::lmFit(exp, mod_matrix, ...)
22 | eb <- limma::eBayes(fit)
23 | #### Compute correct p-value ####
24 | eb$q <- stats::p.adjust(
25 | p = eb$F.p.value,
26 | method = mtc_method
27 | )
28 | return(eb)
29 | }
30 |
--------------------------------------------------------------------------------
/tests/testthat/test-bin_columns_into_quantiles.r:
--------------------------------------------------------------------------------
1 | test_that("bin_columns_into_quantiles works", {
2 | if (!is_32bit()) {
3 | set.seed(1234)
4 | #### Test 1: CTD ####
5 | ctd <- ewceData::ctd()
6 | ctd[[1]]$specificity_quantiles <- apply(ctd[[1]]$specificity, 2,
7 | FUN = bin_columns_into_quantiles,
8 | numberOfBins = 40
9 | )
10 | all_values <- unlist(as.list(ctd[[1]]$specificity_quantiles))
11 | testthat::expect_equal(sort(unique(all_values)), seq(0, 40))
12 |
13 | #### Test 2: When <2 unique non-zero values ####
14 | mat <- ctd[[1]]$specificity_quantiles
15 | mat[, 1] <- sample(c(0, 1), size = nrow(mat), replace = TRUE)
16 | apply
17 | mat2 <- apply(mat, 2,
18 | FUN = bin_columns_into_quantiles,
19 | numberOfBins = 40
20 | )
21 | testthat::expect_equal(sort(unique(mat2[, 1])), c(0, 20))
22 | }
23 | })
24 |
--------------------------------------------------------------------------------
/man/plot_ctd.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/plot_ctd.R
3 | \name{plot_ctd}
4 | \alias{plot_ctd}
5 | \title{Plot \emph{CellTypeData} metrics}
6 | \usage{
7 | plot_ctd(ctd, genes, level = 1, metric = "specificity", show_plot = TRUE)
8 | }
9 | \arguments{
10 | \item{ctd}{CellTypeDataset.}
11 |
12 | \item{genes}{Which genes in \code{ctd} to plot.}
13 |
14 | \item{level}{Annotation level in \code{ctd} to plot.}
15 |
16 | \item{metric}{Which metric in the \code{ctd} to plot:
17 | \itemize{
18 | \item{"mean_exp"}
19 | \item{"specificity"}
20 | \item{"specificity_quantiles"}
21 | }}
22 |
23 | \item{show_plot}{Whether to print the plot or simply return it.}
24 | }
25 | \value{
26 | ggplot object.
27 | }
28 | \description{
29 | Plot \emph{CellTypeData} metrics such as mean_exp, specificity and/or
30 | specificity_quantiles.
31 | }
32 | \examples{
33 | ctd <- ewceData::ctd()
34 | plt <- EWCE::plot_ctd(ctd, genes = c("Apoe", "Gfap", "Gapdh"))
35 | }
36 |
--------------------------------------------------------------------------------
/R/get_sig_results.R:
--------------------------------------------------------------------------------
1 | #' Extract significant results
2 | #'
3 | #' Extract significant results from output of
4 | #' \link[EWCE]{bootstrap_enrichment_test}.
5 | #'
6 | #' @param full_results Output of \link[EWCE]{bootstrap_enrichment_test}.
7 | #' @param q_threshold Maximum multiple-testing-corrected p-value to include.
8 | #' @inheritParams bootstrap_enrichment_test
9 | #'
10 | #' @return Filtered enrichment results table.
11 | #'
12 | #' @keywords internal
13 | #' @importFrom stats p.adjust
14 | get_sig_results <- function(full_results,
15 | mtc_method = "BH",
16 | q_threshold = .05,
17 | verbose = TRUE) {
18 | res <- full_results$results
19 | if (!"q" %in% colnames(res)) {
20 | res$q <- stats::p.adjust(res$p, method = mtc_method)
21 | }
22 | messager(nrow(res), "signficiant enrichment results @", mtc_method, "<",
23 | q_threshold,
24 | v = verbose
25 | )
26 | return(res)
27 | }
28 |
--------------------------------------------------------------------------------
/R/create_quadrants.R:
--------------------------------------------------------------------------------
1 | create_quadrants <- function(data_byGene2) {
2 | #### GET QUANTILES FOR TRANSCRIPT LENGTH + GC CONTENT ####
3 | tl_quants <- stats::quantile(data_byGene2$transcript_length,
4 | probs = seq(0.1, 1, 0.1)
5 | )
6 | gc_quants <- stats::quantile(data_byGene2$percentage_gene_gc_content,
7 | probs = seq(0.1, 1, 0.1)
8 | )
9 | #### ASSIGN EACH GENE TO A QUANTILE QUADRANT ####
10 | quadrant <- matrix(0,
11 | nrow = dim(data_byGene2)[1],
12 | ncol = 2
13 | )
14 | colnames(quadrant) <- c("TL", "GC")
15 | for (i in seq_len(dim(data_byGene2)[1])) {
16 | quadrant[i, 1] <- which(data_byGene2[i, 2] < tl_quants)[1]
17 | quadrant[i, 2] <- which(data_byGene2[i, 3] < gc_quants)[1]
18 | }
19 | data_byGene2$uniq_quad <- sprintf("%s_%s", quadrant[, 1], quadrant[, 2])
20 | data_byGene2 <- data_byGene2[
21 | !data_byGene2$uniq_quad %in% c("2_NA", "NA_2", "3_NA"),
22 | ]
23 | return(data_byGene2)
24 | }
25 |
--------------------------------------------------------------------------------
/man/filter_variance_quantiles.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/filter_variance_quantiles.r
3 | \name{filter_variance_quantiles}
4 | \alias{filter_variance_quantiles}
5 | \title{Filter variance quantiles}
6 | \usage{
7 | filter_variance_quantiles(
8 | exp,
9 | log10_norm = TRUE,
10 | n_quantiles = 10,
11 | min_variance_quantile = as.integer(n_quantiles/2),
12 | verbose = TRUE
13 | )
14 | }
15 | \arguments{
16 | \item{exp}{Gene expression matrix.}
17 |
18 | \item{log10_norm}{Log10-normalise \code{exp} before computing variance.}
19 |
20 | \item{n_quantiles}{Number of quantile bins to use.
21 | Defaults to deciles (\code{n_quantiles=10}).}
22 |
23 | \item{min_variance_quantile}{The minimum variance quantile
24 | to keep values from.}
25 |
26 | \item{verbose}{Print messages.}
27 | }
28 | \value{
29 | Filtered \code{exp}.
30 | }
31 | \description{
32 | Remove rows in \code{exp} that do not vary substantially across rows.
33 | }
34 | \keyword{internal}
35 |
--------------------------------------------------------------------------------
/man/get_celltype_table.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/get_celltype_table.r
3 | \name{get_celltype_table}
4 | \alias{get_celltype_table}
5 | \title{get_celltype_table}
6 | \usage{
7 | get_celltype_table(annot)
8 | }
9 | \arguments{
10 | \item{annot}{An annotation dataframe, which columns named 'level1class',
11 | 'level2class' and 'dataset_name'}
12 | }
13 | \value{
14 | A dataframe with columns 'name', 'level', 'freq' and 'dataset_name'
15 | }
16 | \description{
17 | \code{ get_celltype_table} Generates a table that can be used for
18 | supplemenary tables of publications.
19 | The table lists how many cells are associated with each cell type, the level
20 | of annotation, and the dataset from which it was generated.
21 | }
22 | \examples{
23 | # See PrepLDSC.Rmd for origin of merged_ALLCELLS$annot
24 | cortex_mrna <- ewceData::cortex_mrna()
25 | cortex_mrna$annot$dataset_name <- "cortex_mrna"
26 | celltype_table <- EWCE::get_celltype_table(cortex_mrna$annot)
27 | }
28 |
--------------------------------------------------------------------------------
/R/theme_graph.R:
--------------------------------------------------------------------------------
1 | #' Get graph theme
2 | #'
3 | #' Get graph theme for plots created by
4 | #' \link[EWCE]{generate_bootstrap_plots_for_transcriptome}.
5 | #' @return \code{ggplot2} graph theme.
6 | #' @keywords internal
7 | theme_graph <- function(){
8 | requireNamespace("ggplot2")
9 | ggplot2::theme_bw(base_size = 12,
10 | base_family = "Helvetica") +
11 | ggplot2::theme(
12 | panel.grid.major = ggplot2::element_line(linewidth = .25,
13 | color = "grey"),
14 | axis.line = ggplot2::element_line(linewidth = .35,
15 | color = "black"),
16 | text = ggplot2::element_text(size = 14),
17 | axis.title.x = ggplot2::element_text(vjust = -0.35),
18 | axis.title.y = ggplot2::element_text(vjust = 0.6),
19 | # legend.title = ggplot2::element_blank(),
20 | strip.background = ggplot2::element_rect(fill="transparent")
21 | )
22 | }
23 |
--------------------------------------------------------------------------------
/R/to_dataframe.R:
--------------------------------------------------------------------------------
1 | #' Convert object to data.frame
2 | #'
3 | #' Convert a variety of object types to data.frame format.
4 | #'
5 | #' @param X Object.
6 | #' @param verbose Print messages.
7 | #'
8 | #' @return \link[base]{data.frame}.
9 | #'
10 | #' @keywords internal
11 | #' @importFrom methods is
12 | to_dataframe <- function(X,
13 | verbose = TRUE) {
14 | if (methods::is(X, "data.frame")) {
15 | return(X)
16 | } else if (is_matrix(X)) {
17 | messager("Converting to data.frame", v = verbose)
18 | nn <- colnames(X)
19 | rr <- rownames(X)
20 | if (is_delayed_array(X) || is_sparse_matrix(X)) {
21 | X <- as.matrix(X)
22 | }
23 | X <- data.frame(X,
24 | stringsAsFactors = FALSE,
25 | check.rows = FALSE,
26 | check.names = FALSE
27 | )
28 | colnames(X) <- nn
29 | rownames(X) <- rr
30 | return(X)
31 | } else {
32 | stop("Format ", methods::is(X)[1], " is not supported.")
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/R/to_sparse_matrix.R:
--------------------------------------------------------------------------------
1 | #' Convert object to sparse matrix
2 | #'
3 | #' Convert a variety of object types to sparse matrix format.
4 | #'
5 | #' @param exp Object.
6 | #' @param as_sparse Whether to convert \code{exp} to sparse matrix
7 | #' @param verbose Print messages.
8 | #'
9 | #' @return Sparse matrix.
10 | #'
11 | #' @keywords internal
12 | #' @importFrom DelayedArray DelayedArray
13 | to_sparse_matrix <- function(exp,
14 | as_sparse = TRUE,
15 | verbose = TRUE) {
16 | if (as_sparse) {
17 | messager("Converting to sparse matrix.", v = verbose)
18 | if (!is_sparse_matrix(exp)) {
19 | if (!is_matrix(exp)) {
20 | exp <- as.matrix(exp)
21 | }
22 | exp <- methods::as(exp, "sparseMatrix")
23 | }
24 | } else {
25 | #### Convert to dense matrix ####
26 | exp <- as.matrix(exp, "matrix")
27 | #### Convert characters to numbers ####
28 | exp <- check_numeric(exp = exp)
29 | }
30 | return(exp)
31 | }
32 |
--------------------------------------------------------------------------------
/man/check_ewce_expression_data_args.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/check_ewce_expression_data_args.R
3 | \name{check_ewce_expression_data_args}
4 | \alias{check_ewce_expression_data_args}
5 | \title{check_ewce_expression_data_args}
6 | \usage{
7 | check_ewce_expression_data_args(sortBy, tt, thresh)
8 | }
9 | \arguments{
10 | \item{sortBy}{Column name of metric in \code{tt}
11 | which should be used to sort up- from down- regulated genes (Default: "t").}
12 |
13 | \item{tt}{Differential expression table.
14 | Can be output of \link[limma]{topTable} function.
15 | Minimum requirement is that one column stores a metric of
16 | increased/decreased expression (i.e. log fold change, t-statistic for
17 | differential expression etc) and another contains gene symbols.}
18 |
19 | \item{thresh}{The number of up- and down- regulated genes to be included in
20 | each analysis (Default: 250).}
21 | }
22 | \value{
23 | Null output.
24 | }
25 | \description{
26 | Check the input arguments of the
27 | \link[EWCE]{ewce_expression_data}.
28 | }
29 | \keyword{internal}
30 |
--------------------------------------------------------------------------------
/man/fix_celltype_names.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/fix_celltype_names.R
3 | \name{fix_celltype_names}
4 | \alias{fix_celltype_names}
5 | \title{Fix celltype names}
6 | \usage{
7 | fix_celltype_names(
8 | celltypes,
9 | replace_chars = "[-]|[.]|[ ]|[//]|[\\\\/]",
10 | make_unique = TRUE
11 | )
12 | }
13 | \arguments{
14 | \item{celltypes}{Character vector of celltype names.}
15 |
16 | \item{replace_chars}{Regex string of characters to replace
17 | with "_" when renaming columns.}
18 |
19 | \item{make_unique}{Make all entries unique.}
20 | }
21 | \value{
22 | Fixed celltype names.
23 | }
24 | \description{
25 | Make sure celltypes don't contain characters that could interfere with
26 | downstream analyses. For example, the R package
27 | \href{https://github.com/neurogenomics/MAGMA_Celltyping}{MAGMA.Celltyping}
28 | cannot have spaces in celltype names because spaces are used as a delimiter
29 | in later steps.
30 | }
31 | \examples{
32 | ct <- c("microglia", "astryocytes", "Pyramidal SS")
33 | ct_fixed <- fix_celltype_names(celltypes = ct)
34 | }
35 |
--------------------------------------------------------------------------------
/man/merge_sce_list.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/merge_sce_list.R
3 | \name{merge_sce_list}
4 | \alias{merge_sce_list}
5 | \title{Merge of list of SingleCellExperiment objects}
6 | \usage{
7 | merge_sce_list(
8 | SCE_lists = NULL,
9 | parent_folder = NULL,
10 | pattern = ".rds$",
11 | merge_levels = seq(1, 5),
12 | gene_union = TRUE,
13 | as_sparse = TRUE,
14 | as_DelayedArray = TRUE,
15 | verbose = TRUE
16 | )
17 | }
18 | \arguments{
19 | \item{SCE_lists}{A list of \link[SingleCellExperiment]{SingleCellExperiment}
20 | objects.}
21 |
22 | \item{parent_folder}{Can supply the path to a folder
23 | instead of \code{SCE_lists}.
24 | Any \link[SingleCellExperiment]{SingleCellExperiment}
25 | objects matching \code{pattern} will be imported.}
26 |
27 | \item{merge_levels}{CellTypeDataset levels to merge.}
28 | }
29 | \value{
30 | SingleCellExperiment
31 | }
32 | \description{
33 | Merge of list of CellTypeDatasets stored as
34 | \link[SingleCellExperiment]{SingleCellExperiment} objects
35 | into one \link[SingleCellExperiment]{SingleCellExperiment} object.
36 | }
37 | \keyword{internal}
38 |
--------------------------------------------------------------------------------
/man/check_generate_controlled_bootstrap_geneset.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in
3 | % R/check_generate_controlled_bootstrapped_geneset.R
4 | \name{check_generate_controlled_bootstrap_geneset}
5 | \alias{check_generate_controlled_bootstrap_geneset}
6 | \title{generate_controlled_bootstrap_geneset}
7 | \usage{
8 | check_generate_controlled_bootstrap_geneset(
9 | controlledCT,
10 | annotLevel,
11 | sct_data,
12 | hits
13 | )
14 | }
15 | \arguments{
16 | \item{controlledCT}{[Optional] If not NULL, and instead is the name of a
17 | cell type, then the bootstrapping controls for expression within that
18 | cell type.}
19 |
20 | \item{annotLevel}{An integer indicating which level of \code{sct_data} to
21 | analyse (\emph{Default: 1}).}
22 |
23 | \item{sct_data}{List generated using \link[EWCE]{generate_celltype_data}.}
24 |
25 | \item{hits}{List of gene symbols containing the target gene list.
26 | Will automatically be converted to human gene symbols
27 | if \code{geneSizeControl=TRUE}.}
28 | }
29 | \value{
30 | Null output.
31 | }
32 | \description{
33 | Check input arguments to \link[EWCE]{generate_controlled_bootstrap_geneset}.
34 | }
35 | \keyword{internal}
36 |
--------------------------------------------------------------------------------
/man/get_exp_data_for_bootstrapped_genes.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/get_exp_data_for_bootstrapped_genes.R
3 | \name{get_exp_data_for_bootstrapped_genes}
4 | \alias{get_exp_data_for_bootstrapped_genes}
5 | \title{get_exp_data_for_bootstrapped_genes}
6 | \usage{
7 | get_exp_data_for_bootstrapped_genes(
8 | results,
9 | signif_res,
10 | sct_data,
11 | hits,
12 | combinedGenes,
13 | annotLevel,
14 | nReps = 100,
15 | as_sparse = TRUE,
16 | verbose = TRUE
17 | )
18 | }
19 | \arguments{
20 | \item{signif_res}{signif_res (#fix).}
21 |
22 | \item{sct_data}{List generated using \link[EWCE]{generate_celltype_data}.}
23 |
24 | \item{hits}{Gene hits.}
25 |
26 | \item{combinedGenes}{Combined list of genes from \code{sct_data},
27 | \code{hits}, and background \code{bg}.}
28 |
29 | \item{annotLevel}{An integer indicating which level of \code{sct_data} to
30 | analyse (\emph{Default: 1}).}
31 |
32 | \item{verbose}{Print messages.}
33 |
34 | \item{full_results}{full_results (#fix).}
35 | }
36 | \value{
37 | exp_mats
38 | }
39 | \description{
40 | Support function for
41 | \link[EWCE]{generate_bootstrap_plots_for_transcriptome}.
42 | }
43 | \keyword{internal}
44 |
--------------------------------------------------------------------------------
/tests/testthat/test-ewce_plot.r:
--------------------------------------------------------------------------------
1 | test_that("ewce_plot works", {
2 |
3 | full_results <- EWCE::example_bootstrap_results()
4 | ctd <- ewceData::ctd()
5 | #### ewce_plot ####
6 | ewce_plot_res <- ewce_plot(
7 | total_res = full_results$results,
8 | ctd = ctd,
9 | make_dendro = TRUE
10 | )
11 | # Fail if any but ggplot returned
12 | testthat::expect_true(methods::is(ewce_plot_res$plain, "gg"))
13 | testthat::expect_true(methods::is(ewce_plot_res$withDendro, "gg"))
14 | #remove short cut dendrogram res from ctd anbd rerun, should get same order
15 | ctd_basic <- ctd
16 | ctd_basic[[1]]$plotting <- NULL
17 | #### ewce_plot ####
18 | ewce_plot_res_basic <- ewce_plot(
19 | total_res = full_results$results,
20 | ctd = ctd_basic,
21 | make_dendro = TRUE
22 | )
23 | #so order of 4 plots should be the same
24 | testthat::expect_true(
25 | all(sapply(list(ewce_plot_res_basic$withDendro$data$CellType,
26 | ewce_plot_res$plain$data$CellType,
27 | ewce_plot_res_basic$plain$data$CellType),
28 | FUN = identical, ewce_plot_res$withDendro$data$CellType))
29 | )
30 | })
31 |
--------------------------------------------------------------------------------
/tests/testthat/test-generate_celltype_data.r:
--------------------------------------------------------------------------------
1 | test_that("generate_celltype_data works", {
2 | if (!is_32bit()) {
3 | # Load the single cell data
4 | cortex_mrna <- ewceData::cortex_mrna()
5 | # Use only a subset to keep the example quick
6 | expData <- cortex_mrna$exp[seq(1, 100), ]
7 | l1 <- cortex_mrna$annot$level1class
8 | l2 <- cortex_mrna$annot$level2class
9 | annotLevels <- list(l1 = l1, l2 = l2)
10 | #### As DelayedArray ####
11 | res <- EWCE::generate_celltype_data(
12 | exp = expData,
13 | annotLevels = annotLevels,
14 | convert_orths = TRUE,
15 | input_species = "mouse",
16 | output_species = "human",
17 | # Converts expData to DelayedArray before processed further.
18 | # Doesn't convert CTD matrices into DelayedArray.
19 | as_DelayedArray = TRUE,
20 | groupName = "allKImouse",
21 | return_ctd = TRUE
22 | )
23 | testthat::expect_true(EWCE:::is_celltypedataset(res$ctd))
24 | testthat::expect_true(EWCE:::is_sparse_matrix(res$ctd[[1]]$mean_exp))
25 | testthat::expect_true(file.exists(res$fNames))
26 | }
27 | })
28 |
--------------------------------------------------------------------------------
/R/calculate_specificity_for_level.R:
--------------------------------------------------------------------------------
1 | #' Calculate specificity for one CTD level
2 | #'
3 | #' Calculate specificity for one CellTypeDataset (CTD) level.
4 | #'
5 | #' @param ctd_oneLevel One level from a CTD.
6 | #' @param matrix_name Name of the matrix to extract.
7 | #' @inheritParams to_sparse_matrix
8 | #' @return One CTD level.
9 | #'
10 | #' @keywords internal
11 | #' @importFrom Matrix t
12 | calculate_specificity_for_level <- function(ctd_oneLevel,
13 | matrix_name = "mean_exp",
14 | as_sparse = TRUE,
15 | verbose = TRUE) {
16 | if (!matrix_name %in% names(ctd_oneLevel)) {
17 | messager(matrix_name, "not found in ctd_oneLevel.", v = verbose)
18 | }
19 | expMatrix <- ctd_oneLevel[[matrix_name]]
20 | normalised_meanExp <- Matrix::t(Matrix::t(expMatrix) *
21 | (1 / colSums(expMatrix)))
22 | spec <- normalised_meanExp /
23 | (apply(normalised_meanExp, 1, sum, na.rm = TRUE) + 1e-12)
24 | ctd_oneLevel$specificity <- to_sparse_matrix(
25 | exp = spec,
26 | as_sparse = as_sparse,
27 | verbose = verbose
28 | )
29 | return(ctd_oneLevel)
30 | }
31 |
--------------------------------------------------------------------------------
/R/get_ctd_matrix_names.R:
--------------------------------------------------------------------------------
1 | #' Get CTD matrix names
2 | #'
3 | #' Find the names of all data matrices in a CellTypeDataset.
4 | #'
5 | #' @param ctd CellTypeDataset. If set to \code{NULL} (default),
6 | #' will simply return all possible matrix names.
7 | #' @param matrices Matrix names to search for.
8 | #' @param verbose Print messages.
9 | #' @keywords internal
10 | #' @returns List of matrix names.
11 | get_ctd_matrix_names <- function(ctd=NULL,
12 | matrices=c("mean_exp",
13 | "median_exp",
14 | "specificity",
15 | "median_specificity",
16 | "specificity_quantiles"),
17 | verbose=TRUE){
18 | if(is.null(ctd)){
19 | messager("Returning all possible matrix names.",v=verbose)
20 | return(matrices)
21 | }
22 | nms <- lapply(ctd, function(ctd_lvl){
23 | names(ctd_lvl)[names(ctd_lvl) %in% matrices]
24 | }) |> unlist() |> unique()
25 | messager("Found",length(nms),"matrix types across",
26 | length(ctd),"CTD levels.",v=verbose)
27 | return(nms)
28 | }
29 |
--------------------------------------------------------------------------------
/man/check_bootstrap_args.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/check_bootstrap_args.R
3 | \name{check_bootstrap_args}
4 | \alias{check_bootstrap_args}
5 | \title{check_bootstrap_args}
6 | \usage{
7 | check_bootstrap_args(
8 | sct_data,
9 | hits,
10 | annotLevel,
11 | reps,
12 | controlledCT = NULL,
13 | fix_celltypes = TRUE
14 | )
15 | }
16 | \arguments{
17 | \item{sct_data}{List generated using \link[EWCE]{generate_celltype_data}.}
18 |
19 | \item{hits}{List of gene symbols containing the target gene list.
20 | Will automatically be converted to human gene symbols
21 | if \code{geneSizeControl=TRUE}.}
22 |
23 | \item{annotLevel}{An integer indicating which level of \code{sct_data} to
24 | analyse (\emph{Default: 1}).}
25 |
26 | \item{reps}{Number of random gene lists to generate (\emph{Default: 100},
27 | but should be >=10,000 for publication-quality results).}
28 |
29 | \item{controlledCT}{[Optional] If not NULL, and instead is the name of a
30 | cell type, then the bootstrapping controls for expression within that
31 | cell type.}
32 | }
33 | \value{
34 | Null output.
35 | }
36 | \description{
37 | Check the input arguments of the
38 | \link[EWCE]{bootstrap_enrichment_test}.
39 | }
40 | \keyword{internal}
41 |
--------------------------------------------------------------------------------
/R/drop_nonexpressed_cells.R:
--------------------------------------------------------------------------------
1 | #' Drop cells with zero gene counts
2 | #'
3 | #' Remove columns (cells) in which (gene) counts sum to zero.
4 | #'
5 | #' @param exp Gene expression matrix.
6 | #' @param annotLevels Cell-wise annotations to be subset
7 | #' if some cells are dropped.
8 | #' @param verbose Print messages.
9 | #'
10 | #' @return List of filtered \code{exp} and \code{annotLevels}.
11 | #'
12 | #' @keywords internal
13 | #' @importFrom Matrix colSums
14 | drop_nonexpressed_cells <- function(exp,
15 | annotLevels,
16 | verbose = TRUE) {
17 | messager("Checking for cells with no expressed genes.", v = verbose)
18 | orig.dims <- dim(exp)
19 | col.sums <- Matrix::colSums(exp) # MUST be from Matrix
20 | n_zeros <- sum(col.sums <= 0, na.rm = TRUE)
21 | #### Drop genes ####
22 | if (n_zeros > 0) {
23 | exp <- exp[, col.sums > 0]
24 | ### Make sure annotLevels are also subset appropriately.
25 | annotLevels <- lapply(annotLevels, function(x) x[col.sums > 0])
26 | messager(nrow(exp) - orig.dims[1], "/", nrow(exp),
27 | "cells dropped",
28 | v = verbose
29 | )
30 | }
31 | return(list(
32 | exp = exp,
33 | annotLevels = annotLevels
34 | ))
35 | }
36 |
--------------------------------------------------------------------------------
/R/sct_normalize.R:
--------------------------------------------------------------------------------
1 | #' Normalize expression matrix
2 | #'
3 | #' Normalize expression matrix by accounting for library size.
4 | #' Uses \pkg{sctransform}.
5 | #'
6 | #' @param exp Gene x cell expression matrix.
7 | #' @param as_sparse Convert \code{exp} to sparse matrix.
8 | #' @param verbose Print messages.
9 | #'
10 | #' @return Normalised expression matrix.
11 | #'
12 | #' @examples
13 | #' cortex_mrna <- ewceData::cortex_mrna()
14 | #' exp_sct_normed <- EWCE::sct_normalize(exp = cortex_mrna$exp[1:300, ])
15 | #' @export
16 | #' @importFrom Matrix t colSums
17 | sct_normalize <- function(exp,
18 | as_sparse = TRUE,
19 | verbose = TRUE) {
20 | requireNamespace("sctransform")
21 | exp <- to_sparse_matrix(
22 | exp = exp,
23 | as_sparse = as_sparse,
24 | verbose = verbose
25 | )
26 | sct <- sctransform::vst(
27 | umi = exp,
28 | return_cell_attr = TRUE,
29 | verbosity = if (verbose) 2 else 0
30 | )
31 | exp_sct <- sctransform::correct_counts(
32 | x = sct,
33 | umi = exp,
34 | # UMI_corrected
35 | verbosity = if (verbose) 2 else 0
36 | )
37 | exp_sct_normed <- Matrix::t(Matrix::t(exp_sct) *
38 | (1 / Matrix::colSums(exp_sct)))
39 | return(exp_sct_normed)
40 | }
41 |
--------------------------------------------------------------------------------
/man/check_percent_hits.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/check_percent_hits.R
3 | \name{check_percent_hits}
4 | \alias{check_percent_hits}
5 | \title{Get percentage of target cell type hits}
6 | \usage{
7 | check_percent_hits(
8 | full_results,
9 | target_celltype,
10 | mtc_method = "bonferroni",
11 | q_threshold = 0.05,
12 | verbose = TRUE
13 | )
14 | }
15 | \arguments{
16 | \item{full_results}{\code{bootstrap_enrichment_test} results.}
17 |
18 | \item{target_celltype}{Substring to search to matching
19 | cell types (case-insensitive).}
20 |
21 | \item{mtc_method}{Multiple-testing correction method.}
22 |
23 | \item{q_threshold}{Corrected significance threshold.}
24 |
25 | \item{verbose}{Print messages.}
26 | }
27 | \value{
28 | Report list.
29 | }
30 | \description{
31 | After you run \link[EWCE]{bootstrap_enrichment_test},
32 | check what percentage of significantly enriched
33 | cell types match an expected cell type.
34 | }
35 | \examples{
36 | ## Bootstrap significance test,
37 | ## no control for transcript length or GC content
38 | ## Use pre-computed results to speed up example
39 | full_results <- EWCE::example_bootstrap_results()
40 |
41 | report <- EWCE::check_percent_hits(
42 | full_results = full_results,
43 | target_celltype = "microglia"
44 | )
45 | }
46 |
--------------------------------------------------------------------------------
/R/create_list_network.R:
--------------------------------------------------------------------------------
1 | #' \code{create_list_network}
2 | #'
3 | #' Support function for \code{prepare_genesize_control_network}.
4 | #'
5 | #' @return List network
6 | #'
7 | #' @keywords internal
8 | #' @importFrom parallel mclapply
9 | #' @importFrom data.table data.table
10 | create_list_network <- function(data_byGene2,
11 | hits_NEW,
12 | reps = 10000,
13 | no_cores = 1) {
14 |
15 | # Get all sctSpecies genes in each quadrant
16 | quad_genes <- list()
17 | for (uq in unique(data_byGene2$uniq_quad)) {
18 | quad_genes[[uq]] <-
19 | unique(data_byGene2[data_byGene2$uniq_quad == uq, "HGNC.symbol"])
20 | }
21 |
22 | list_network <- parallel::mclapply(hits_NEW, function(gene) {
23 | this_gene_quad <- data_byGene2[
24 | data_byGene2$HGNC.symbol == gene,
25 | "uniq_quad"
26 | ][1]
27 | candidates <- as.vector(unlist(quad_genes[this_gene_quad]))
28 | data.table::data.table(sample(
29 | x = candidates,
30 | size = reps,
31 | replace = TRUE
32 | ))
33 | }, mc.cores = no_cores) |>
34 | do.call(what = "cbind") |>
35 | as.matrix() |>
36 | `colnames<-`(NULL)
37 | return(list_network)
38 | }
39 |
--------------------------------------------------------------------------------
/R/fix_celltype_names.R:
--------------------------------------------------------------------------------
1 | #' Fix celltype names
2 | #'
3 | #' Make sure celltypes don't contain characters that could interfere with
4 | #' downstream analyses. For example, the R package
5 | #' \href{https://github.com/neurogenomics/MAGMA_Celltyping}{MAGMA.Celltyping}
6 | #' cannot have spaces in celltype names because spaces are used as a delimiter
7 | #' in later steps.
8 | #'
9 | #' @param celltypes Character vector of celltype names.
10 | #' @param replace_chars Regex string of characters to replace
11 | #' with "_" when renaming columns.
12 | #' @param make_unique Make all entries unique.
13 | #' @returns Fixed celltype names.
14 | #'
15 | #' @export
16 | #' @examples
17 | #' ct <- c("microglia", "astryocytes", "Pyramidal SS")
18 | #' ct_fixed <- fix_celltype_names(celltypes = ct)
19 | fix_celltype_names <- function(celltypes,
20 | replace_chars = "[-]|[.]|[ ]|[//]|[\\/]",
21 | make_unique = TRUE) {
22 | if (is.null(celltypes)) {
23 | return(NULL)
24 | }
25 | celltypes <- gsub(replace_chars, "_", celltypes)
26 | ### Remove repeating "_" ####
27 | celltypes <- gsub("[_]+", "_", celltypes)
28 | #### Make sure all are unique ####
29 | if(isTRUE(make_unique)){
30 | celltypes <- make.unique(celltypes)
31 | }
32 | return(celltypes)
33 | }
34 |
--------------------------------------------------------------------------------
/man/check_species.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/check_species.R
3 | \name{check_species}
4 | \alias{check_species}
5 | \title{Check species}
6 | \usage{
7 | check_species(
8 | genelistSpecies = NULL,
9 | sctSpecies = NULL,
10 | sctSpecies_origin = NULL,
11 | sctSpecies_origin_default = "mouse",
12 | verbose = TRUE
13 | )
14 | }
15 | \arguments{
16 | \item{genelistSpecies}{Species that \code{hits} genes came from
17 | (no longer limited to just "mouse" and "human").
18 | See \link[EWCE]{list_species} for all available species.}
19 |
20 | \item{sctSpecies}{Species that \code{sct_data} is currently formatted as
21 | (no longer limited to just "mouse" and "human").
22 | See \link[EWCE]{list_species} for all available species.}
23 |
24 | \item{sctSpecies_origin}{Species that the \code{sct_data}
25 | originally came from, regardless of its current gene format
26 | (e.g. it was previously converted from mouse to human gene orthologs).
27 | This is used for computing an appropriate backgrund.}
28 |
29 | \item{sctSpecies_origin_default}{Default value for \code{sctSpecies_origin}.}
30 |
31 | \item{verbose}{Print messages.}
32 | }
33 | \value{
34 | List of corrected species names.
35 | }
36 | \description{
37 | If species arguments are \code{NULL}, set default species.
38 | }
39 | \keyword{internal}
40 |
--------------------------------------------------------------------------------
/R/fix_celltype_names_full_results.R:
--------------------------------------------------------------------------------
1 | #' Fix celltype name in full results
2 | #'
3 | #' Aligns celltype names in full results generated by
4 | #' \link[EWCE]{bootstrap_enrichment_test} with the standardised
5 | #' CellTypeDataset (CTD) produced by \link[EWCE]{standardise_ctd}.
6 | #'
7 | #' @param full_results Cell-type enrichment results generated by
8 | #' \link[EWCE]{bootstrap_enrichment_test}.
9 | #' @param verbose Print messages.
10 | #'
11 | #' @return Fixed full results.
12 | #'
13 | #' @keywords internal
14 | fix_celltype_names_full_results <- function(full_results,
15 | verbose = TRUE) {
16 | if(all(is.na(full_results))) return(NA)
17 | if(is.null(full_results)) return(NULL)
18 |
19 | messager("Aligning celltype names with standardise_ctd format.",
20 | v = verbose
21 | )
22 | rownames(full_results$results) <- fix_celltype_names(
23 | rownames(full_results$results)
24 | )
25 | full_results$results$CellType <- fix_celltype_names(
26 | full_results$results$CellType
27 | )
28 | names(full_results$hit.cells) <- fix_celltype_names(
29 | names(full_results$hit.cells)
30 | )
31 | colnames(full_results$bootstrap_data) <- fix_celltype_names(
32 | colnames(full_results$bootstrap_data)
33 | )
34 | return(full_results)
35 | }
36 |
--------------------------------------------------------------------------------
/man/bin_specificity_into_quantiles.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/bin_specificity_into_quantiles.r
3 | \name{bin_specificity_into_quantiles}
4 | \alias{bin_specificity_into_quantiles}
5 | \title{bin_specificity_into_quantiles}
6 | \usage{
7 | bin_specificity_into_quantiles(
8 | ctdIN,
9 | numberOfBins,
10 | matrix_name = "specificity_quantiles",
11 | as_sparse = TRUE,
12 | verbose = TRUE
13 | )
14 | }
15 | \arguments{
16 | \item{ctdIN}{A single annotLevel of a ctd, i.e. \code{ctd[[1]]}
17 | (the function is intended to be used via \code{apply}).}
18 |
19 | \item{numberOfBins}{Number of quantile 'bins' to use (40 is recommended).}
20 |
21 | \item{matrix_name}{Name of the specificity matrix to create
22 | (default: "specificity_quantiles").}
23 |
24 | \item{as_sparse}{Convert to sparseMatrix.}
25 |
26 | \item{verbose}{Print messages.}
27 | }
28 | \value{
29 | A ctd with "specificity_quantiles" matrix in each level
30 | (or whatever \code{matrix_name} was set to.).
31 | }
32 | \description{
33 | \code{bin_specificity_into_quantiles} is an internal function used to convert
34 | add '$specificity_quantiles' to a ctd
35 | }
36 | \examples{
37 | ctd <- ewceData::ctd()
38 | ctd <- lapply(ctd, EWCE::bin_specificity_into_quantiles, numberOfBins = 40)
39 | print(ctd[[1]]$specificity_quantiles[1:3, ])
40 | }
41 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/bug_report.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Bug report
3 | about: Create a report to help us improve
4 | title: ''
5 | labels: bug
6 | assignees: ''
7 |
8 | ---
9 |
10 | ## 1. Bug description
11 |
12 | (A clear and concise description of what the bug is.)
13 |
14 | ### Console output
15 |
16 | ```
17 | # Paste console output here (e.g. from R/python/command line)
18 |
19 | ```
20 |
21 | ### Expected behaviour
22 |
23 | (A clear and concise description of what you expected to happen.)
24 |
25 |
26 | ## 2. Reproducible example
27 |
28 | ### Code
29 |
30 | (Please add the steps to reproduce the bug here. See [here](https://www.r-bloggers.com/2020/10/how-to-make-a-reprex/) for an intro to making a reproducible example (i.e. reprex) and why they're important! __This will help us to help you much faster.__)
31 |
32 | ```R
33 | # Paste example here
34 |
35 | ```
36 |
37 | ### Data
38 |
39 | (If possible, upload a small sample of your data so that we can reproduce the bug on our end. If that's not possible, please at least include a screenshot of your data and other relevant details.)
40 |
41 |
42 | ## 3. Session info
43 |
44 | (Add output of the R function `utils::sessionInfo()` below. This helps us assess version/OS conflicts which could be causing bugs.)
45 |
46 |