R/stability-based-parameter-assessment.R
create_monocle_object.RdUse the expression matrix and the output of the
automatic_stability_assessment function to create a Monocle object
which has the stable numver of clusters.
create_monocle_object(
normalized_expression_matrix,
count_matrix = NULL,
clustassess_object,
metadata,
stable_feature_type,
stable_feature_set_size,
stable_clustering_method,
stable_n_clusters = NULL,
gene_names = NULL,
cell_names = NULL,
use_all_genes = FALSE,
is_object_from_shinyapp = FALSE
)The normalized expression matrix having genes on rows and cells on columns.
The count matrix having genes on rows and cells on columns. If NULL, the normalized_expression_matrix will be used.
The output of the automatic_stability_assessment.
The metadata dataframe having the cell names as rownames. If
NULL, a dataframe with a single column named identical_ident will be
created.
The feature type which leads to stable clusters.
The feature size which leads to stable clusters.
The clustering method which leads to stable clusters.
The number of clusters that are stable. If NULL,
all the clusters will be provided. Defaults to NULL.
The gene names that will be used in the Monocle object.
If NULL, the rownames of the normalized_expression_matrix will be used.
Defaults to NULL.
The cell names that will be used in the Monocle object.
If NULL, the colnames of the normalized_expression_matrix will be used.
Defaults to NULL.
A boolean value indicating if the expression matrix
should be truncated to the genes used in the stability assessment. Defaults
to FALSE.
A boolean value indicating if the ClustAssess
object is extracted from a ShinyApp directory, or is a direct output of the
automatic_stability_assessment function. Defaults to FALSE.
A Monocle object of the expression matrix, having the stable number of clusters identified by ClustAssess.
set.seed(2024)
# create an already-transposed artificial expression matrix
expr_matrix <- matrix(
c(runif(20 * 10), runif(30 * 10, min = 3, max = 4)),
nrow = 10, byrow = FALSE
)
colnames(expr_matrix) <- as.character(seq_len(ncol(expr_matrix)))
rownames(expr_matrix) <- paste("feature", seq_len(nrow(expr_matrix)))
autom_object <- automatic_stability_assessment(
expression_matrix = expr_matrix,
n_repetitions = 3,
n_neigh_sequence = c(5),
resolution_sequence = c(0.1, 0.5),
features_sets = list(
"set1" = rownames(expr_matrix)
),
steps = list(
"set1" = c(5, 7)
),
umap_arguments = list(
# the following parameters have been modified
# from the default values to ensure that the function
# will run under 5 seconds
n_neighbors = 3,
approx_pow = TRUE,
n_epochs = 0,
init = "random",
min_dist = 0.3
),
n_top_configs = 1,
algorithms_clustering_assessment = 1,
save_temp = FALSE,
verbose = FALSE
)
# uncomment to create the monocle object
# mon_obj <- create_monocle_object(
# normalized_expression_matrix = expr_matrix,
# clustassess_object = autom_object,
# metadata = NULL,
# stable_feature_type = "set1",
# stable_feature_set_size = "5",
# stable_clustering_method = "Louvain"
# )