Skip to contents

Run mcRigor metacell partition assessment

Usage

RunmcRigor(
  srt,
  cell_membership = NULL,
  metacell.by = NULL,
  mode = c("detect", "optimize"),
  tgamma = NULL,
  gamma_names = NULL,
  assay_type = c("RNA", "ATAC"),
  Gammas = NULL,
  aggregate_method = c("mean", "sum", "geom"),
  output_file = NULL,
  Nrep = 1,
  gene_filter = 0.1,
  feature_use = 2000,
  cor_method = c("pearson", "spearman"),
  prePro = TRUE,
  test_cutoff = 0.01,
  thre_smooth = TRUE,
  thre_bw = 1/6,
  D_bw = 10,
  optim_method = c("tradeoff", "dub_rate_large", "dub_rate_small"),
  weight = 0.5,
  dub_rate = 0.1,
  draw = FALSE,
  pur_metric = NULL,
  check_purity = TRUE,
  fields = NULL,
  step_save = FALSE,
  prefix = "mcRigor",
  tool_name = "mcRigor",
  verbose = TRUE
)

Arguments

srt

A Seurat object containing the original single-cell data.

cell_membership

A data frame or matrix with cells in rows and one or more metacell partitions in columns. Row names should be cell names. If row names are missing and the row count equals ncol(srt), cells are matched in colnames(srt) order.

metacell.by

Metadata column(s) in srt used as metacell partitions when cell_membership = NULL.

mode

McRigor task. "detect" calls mcRigor_DETECT() for one partition; "optimize" calls mcRigor_OPTIMIZE() across candidate partitions.

tgamma

Target partition/gamma for "detect". Can be a membership column name or the numeric gamma label used by mcRigor. If NULL, the first membership column is used.

gamma_names

Optional gamma labels for membership columns. mcRigor requires numeric-like column labels; non-numeric labels are mapped internally to 1:ncol(cell_membership) and recorded in the stored result.

assay_type

Assay type passed to mcRigor.

Gammas

Candidate gamma labels for "optimize". Can use original membership column names or mapped mcRigor gamma labels.

aggregate_method

Metacell aggregation method passed to mcRigor.

output_file

Optional path where mcRigor writes the TabMC RDS file. If NULL, a temporary file is used to avoid creating files in the working directory.

Nrep

Number of permutation repetitions used by mcRigor.

gene_filter, feature_use, cor_method, prePro, test_cutoff, thre_smooth, thre_bw

Parameters forwarded to mcRigor.

D_bw, optim_method, weight, dub_rate

Optimization parameters forwarded to mcRigor_OPTIMIZE().

draw, pur_metric, check_purity, fields, step_save

Plotting, purity, and intermediate-save parameters forwarded to mcRigor.

prefix

Prefix for metadata columns written to srt.

tool_name

Name of the srt@tools entry used to store results.

verbose

Whether to print the message. Default is TRUE.

Value

A Seurat object with mcRigor metadata and a result list stored in srt@tools[[tool_name]].

References

Liu, P. and Li, J.J. (2024). mcRigor: a statistical method to enhance the rigor of metacell partitioning in single-cell data analysis. bioRxiv. doi:10.1101/2024.10.30.621093

Examples

data(pancreas_sub)
set.seed(11)
pancreas_sub <- RunStandardWorkflow(
  pancreas_sub,
  nHVF = 500,
  linear_reduction_dims = 20,
  linear_reduction_dims_use = 1:20,
  nonlinear_reduction_dims = 2,
  verbose = FALSE
)
#>  [2026-08-30 05:52:57] Skip `log1p()` because `layer = data` is not "counts"
mc <- RunMetaCell(
  pancreas_sub,
  method = "supercell",
  gamma = 25
)
#>  [2026-08-30 05:53:07] Running SuperCell with gamma = 25, k.knn = 5 on 1000 cells
#>  [2026-08-30 05:53:08] `RunMetaCell()` ("supercell") built 40 metacells from 1000 cells
#>  [2026-08-30 05:53:08] Metacell size summary: min 5, median 20, mean 25, max 74 cells
#> Warning: Data is of class dgeMatrix. Coercing to dgCMatrix.
#>  [2026-08-30 05:53:08] `RunMetaCell()` returned metacell Seurat with 40 metacells. Original cells in `@misc[["original_srt"]]`

membership <- data.frame(
  Metacell = mc@misc[["cell_membership"]],
  row.names = names(mc@misc[["cell_membership"]])
)

pancreas_sub <- RunmcRigor(
  mc@misc[["original_srt"]],
  cell_membership = membership,
  Nrep = 1,
  feature_use = 100,
  draw = FALSE
)
#>  [2026-08-30 05:53:47] Run mcRigor in "detect" mode with 1 partition
#> Normalizing data...
#> gamma = 1 
#> 
  |                                                                            
  |                                                                      |   0%
  |                                                                            
  |==                                                                    |   2%
  |                                                                            
  |====                                                                  |   5%
  |                                                                            
  |=====                                                                 |   8%
  |                                                                            
  |=======                                                               |  10%
  |                                                                            
  |=========                                                             |  12%
  |                                                                            
  |==========                                                            |  15%
  |                                                                            
  |============                                                          |  18%
  |                                                                            
  |==============                                                        |  20%
  |                                                                            
  |================                                                      |  22%
  |                                                                            
  |==================                                                    |  25%
  |                                                                            
  |===================                                                   |  28%
  |                                                                            
  |=====================                                                 |  30%
  |                                                                            
  |=======================                                               |  32%
  |                                                                            
  |========================                                              |  35%
  |                                                                            
  |==========================                                            |  38%
  |                                                                            
  |============================                                          |  40%
  |                                                                            
  |==============================                                        |  42%
  |                                                                            
  |================================                                      |  45%
  |                                                                            
  |=================================                                     |  48%
  |                                                                            
  |===================================                                   |  50%
  |                                                                            
  |=====================================                                 |  52%
  |                                                                            
  |======================================                                |  55%
  |                                                                            
  |========================================                              |  57%
  |                                                                            
  |==========================================                            |  60%
  |                                                                            
  |============================================                          |  62%
  |                                                                            
  |==============================================                        |  65%
  |                                                                            
  |===============================================                       |  68%
  |                                                                            
  |=================================================                     |  70%
  |                                                                            
  |===================================================                   |  72%
  |                                                                            
  |====================================================                  |  75%
  |                                                                            
  |======================================================                |  78%
  |                                                                            
  |========================================================              |  80%
  |                                                                            
  |==========================================================            |  82%
  |                                                                            
  |============================================================          |  85%
  |                                                                            
  |=============================================================         |  88%
  |                                                                            
  |===============================================================       |  90%
  |                                                                            
  |=================================================================     |  92%
  |                                                                            
  |==================================================================    |  95%
  |                                                                            
  |====================================================================  |  98%
  |                                                                            
  |======================================================================| 100%
#> 
#>     dubious trustworthy 
#>          27          13 
#>  [2026-08-30 05:53:53] mcRigor results stored in `srt@tools[[mcRigor]]`

table(pancreas_sub$mcRigor_status)
#> 
#>     dubious trustworthy 
#>         754         246 

CellDimPlot(
  pancreas_sub,
  group.by = "mcRigor_metacell"
)


CellDimPlot(
  pancreas_sub,
  group.by = "mcRigor_status"
)