Estimate dispersion parameters
estimate_dispersion.RdEstimate dispersion parameters
Usage
estimate_dispersion(
counts,
manifold,
cell.types,
ages,
model = "cCV",
preprocess = TRUE,
ncores = 1,
size.factor = NULL,
cell.types.to.use = NULL,
ages.to.use = NULL,
cell.types.cutoff = 10
)Arguments
- counts
An expression count matrix. The rows correspond to genes and the columns correspond to cells. It can be sparse.
- manifold
The computed manifold from compute_manifold. It should be a matrix of the same dimension as counts.
- cell.types
A vector with the same length as the columns of counts. Each value should be a string corresponding to the cell type of each cell in counts.
- ages
A vector with the same length as the columns of counts. Each value should be a string corresponding to the age group of each cell in counts.
- model
Model to be used for estimating dispersion parameters. Can be either "cCV" (constant CV), "cFF" (constant Fano factor), or "cVar" (constant variance).
- preprocess
Whether the expression count matrix should be preprocessed, where all genes with zero counts will removed. Default is TRUE.
- ncores
Number of cores to use. Default is 1.
- size.factor
A vector of cell size normalization factors. Default uses mean library size normalization.
- cell.types.to.use
A vector of unique cell types to be used in the estimation process. Default is all cell types.
- ages.to.use
A vector of unique age groups to be used in the estimation process. Default is all age groups.
- cell.types.cutoff
Minimum number of cells in a cell type * age group. Default is 10.
Value
A named list for all dispersion parameters. Each element is a table of dispersion parameters for a cell type. The columns in each table contain dispersion parameters for each age group.
Examples
# Load test data from Tabula Muris Senis
tms_marrow <- TabulaMurisSenisData::TabulaMurisSenisDroplet(tissues = "Marrow")
#> see ?TabulaMurisSenisData and browseVignettes('TabulaMurisSenisData') for documentation
#> loading from cache
#> see ?TabulaMurisSenisData and browseVignettes('TabulaMurisSenisData') for documentation
#> loading from cache
#> see ?TabulaMurisSenisData and browseVignettes('TabulaMurisSenisData') for documentation
#> loading from cache
#> see ?TabulaMurisSenisData and browseVignettes('TabulaMurisSenisData') for documentation
#> loading from cache
#> see ?TabulaMurisSenisData and browseVignettes('TabulaMurisSenisData') for documentation
#> loading from cache
#> see ?TabulaMurisSenisData and browseVignettes('TabulaMurisSenisData') for documentation
#> loading from cache
tms_marrow_counts <- tms_marrow$Marrow@assays@data$counts
rownames(tms_marrow_counts) <- rownames(tms_marrow$Marrow)
colnames(tms_marrow_counts) <- colnames(tms_marrow$Marrow)
tms_marrow_counts <- as(tms_marrow_counts, "dgCMatrix")
# Subset age groups and cell types
subset_ages <- which(tms_marrow$Marrow$age %in% c("3m", "30m"))
subset_cell_types <- which(tms_marrow$Marrow$cell_ontology_class %in% c(
"hematopoietic precursor cell", "megakaryocyte-erythroid progenitor cell",
"precursor B cell"
))
tms_marrow_counts <- tms_marrow_counts[, intersect(subset_ages, subset_cell_types)]
# Compute the manifold
tms_marrow_manifold_neighbor <- compute_manifold(tms_marrow_counts, method = "neighbor")
#> Starting manifold computation...
#> The initial matrix size is 20138 genes and 1980 cells.
#> After removing genes with zero counts, the new matrix size is 14812 genes and 1980 cells.
#> Estimating the manifold using the neighbor-based method...
#> Normalizing layer: counts
#> Finding variable features for layer counts
#> Centering and scaling data matrix
#> PC_ 1
#> Positive: Ly6e, Bst2, Lgals1, Eef1g, Tspan13, Hspe1, Irf8, Tcf4, Fyb, Ctss
#> Gas5, Selplg, Rnase6, Crip1, Siglech, Dnajc7, Pld4, Tsc22d1, Cnp, Npm1
#> Cd7, Hsp90ab1, Tmsb10, Ly86, Cox6a2, Nme2, Bmyc, Ctsl, Pafah1b3, Ly6d
#> Negative: Pglyrp1, S100a9, S100a8, Camp, Ngp, 1100001G20Rik, Hp, Lcn2, Cebpe, Chi3l3
#> Anxa1, Clec4a2, Fcnb, Trem3, Dstn, Lyz2, Serpinb1a, Lyz1, Lrg1, Cd63
#> Gsr, 1810033B17Rik, Sepx1, Cd177, Hmgn2, Mgst1, Arhgdib, Ltf, Glrx, Anxa3
#> PC_ 2
#> Positive: Ptma, Stmn1, Cks1b, Hmgb1, Hist1h2ao, Cks2, Atpif1, Top2a, Cmtm7, Tuba1b
#> H2afx, Birc5, Cdca8, Plac8, Hist1h2ae, Mki67, Rps27l, Spc24, Smc2, Gpx1
#> Hmgb3, Ran, Tpx2, Lmnb1, Cdca3, Ybx1, Igfbp4, Ccna2, Eif5a, Myb
#> Negative: Ccl5, Gimap4, Cd3d, Ms4a4b, Cd3g, Ltb, Shisa5, AW112010, Gimap3, Thy1
#> Cd2, Lck, Ctsw, Gimap6, Ms4a6b, Cd3e, Skap1, Gimap7, Il2rb, Sh2d1a
#> Xcl1, Lime1, Fam189b, Tmsb10, Klrk1, Arl4c, Txk, Zap70, Cd160, Bcl2
#> PC_ 3
#> Positive: Ctla2a, Nkg7, AW112010, Ccnd2, Gpr56, Ccl5, Mif, Gimap4, Cd3d, Cd3g
#> Ms4a4b, Rab38, Cd27, Lck, Bcl2, Rps2, Muc13, Lat, Klk8, Ltb
#> Angpt1, Gimap3, Ms4a6b, Nrgn, Thy1, Serpina3g, Pdcd4, Rpl22l1, Gata2, Tspan4
#> Negative: Grn, Ctsh, Siglech, Pld4, Rnase6, Mpeg1, Lair1, Ctsl, Cybasc3, Unc93b1
#> Ctsb, Cox6a2, Nucb2, Ppfia4, Irf8, Ly86, Upb1, Tcf4, 2210020M01Rik, Ccr9
#> Clec12a, Psap, Ly6d, Pltp, Runx2, Bst2, Spib, Cd300c, Atp1b1, Ccnd1
#> PC_ 4
#> Positive: Ptma, Actg1, Rps2, Rpl22l1, Ldha, Ybx1, Nop10, Gpi1, Mif, Arhgdib
#> Npm1, Rps15a-ps4, Pgam1, Nme2, Snrpf, Igfbp4, C1qbp, Impdh2, Tpi1, Cd34
#> Gar1, Nhp2, Hspa8, Emb, Set, Cdca7, Pebp1, Cdk4, Hsp90ab1, Srm
#> Negative: Gypa, Slc4a1, Rhd, Trim10, Tspan33, Beta-s, Tspo2, Snca, Rhag, Epb4.2
#> Cldn13, Alas2, Ctse, Fech, Slc25a37, Isg20, Mgst3, Kel, Car2, Hmbs
#> Hbb-b2, Blvrb, Fam55b, Ermap, Hemgn, Hbq1b, Cpox, Slc43a1, Apol11b, Dhrs11
#> PC_ 5
#> Positive: Top2a, Tubb5, H2afx, Prc1, Nusap1, Racgap1, Cenpf, Cenpe, Kif11, Smc4
#> Tpx2, Kif22, Kif23, Birc5, Ccna2, Aurkb, Tuba1b, Hist1h2ae, Mis18bp1, Cdca8
#> Ube2s, Nek2, Ube2c, Cdca3, Hmmr, Kif20b, Spc24, Cks1b, Mki67, Cep55
#> Negative: Sdpr, Pf4, Mpl, Rab27b, Gng11, Itga2b, Treml1, Gp9, Mmrn1, Esam
#> Gp1bb, Gp5, Gucy1a3, Vwf, Fhl1, Rbpms2, Dusp3, Selp, Cttn, Mrvi1
#> Clu, Tbxas1, Arhgap6, Ifitm3, Trpc6, Ptrf, F2rl2, Pbx1, Myct1, Gucy1b3
#> Computing nearest neighbors
#> Only one graph name supplied, storing nearest-neighbor graph only
#> Successfully extracted the nearest neighbors. Estimation procedure is starting.
#> Finished computing manifold using the neighbor-based method. Time taken: 7.42 seconds.
# Estimate the dispersion parameters
tms_marrow_cell_types <- tms_marrow$Marrow$cell_ontology_class[intersect(
subset_ages,
subset_cell_types
)]
tms_marrow_ages <- tms_marrow$Marrow$age[intersect(subset_ages, subset_cell_types)]
tms_marrow_dispersions <- estimate_dispersion(tms_marrow_counts, tms_marrow_manifold_neighbor,
tms_marrow_cell_types, tms_marrow_ages,
model = "cCV", ncores = 2, cell.types.cutoff = 10
)
#> Preprocessing the count matrix
#> The initial matrix size is 20138 genes and 1980 cells.
#> After removing genes with zero counts, the new matrix size is 14812 genes and 1980 cells.
#> Calculating normalization factors
#> Estimating dispersion parameters for 3m hematopoietic precursor cell
#> 14812 genes, 285 cells
#> Running SAVER given prior means with 2 worker(s)
#> Start time: 2024-09-12 00:51:32.973619
#> Estimating finish time...
#> Finished 100/14812 genes. Approximate finish time: 2024-09-12 00:52:00.454067
#> Finished 3778/14812 genes. Approximate finish time: 2024-09-12 00:52:02.145553
#> Finished 7456/14812 genes. Approximate finish time: 2024-09-12 00:52:02.078804
#> Finished 11134/14812 genes. Approximate finish time: 2024-09-12 00:52:01.84097
#> Finished 14812/14812 genes. Approximate finish time: 2024-09-12 00:52:01.559812
#> Done!
#> Finish time: 2024-09-12 00:52:01.560309
#> Total time: 28.58656 secs
#> Estimating dispersion parameters for 30m hematopoietic precursor cell
#> 14812 genes, 524 cells
#> Running SAVER given prior means with 2 worker(s)
#> Start time: 2024-09-12 00:52:02.373137
#> Estimating finish time...
#> Finished 100/14812 genes. Approximate finish time: 2024-09-12 00:52:41.425087
#> Finished 3778/14812 genes. Approximate finish time: 2024-09-12 00:52:43.771587
#> Finished 7456/14812 genes. Approximate finish time: 2024-09-12 00:52:43.290991
#> Finished 11134/14812 genes. Approximate finish time: 2024-09-12 00:52:43.891029
#> Finished 14812/14812 genes. Approximate finish time: 2024-09-12 00:52:43.94988
#> Done!
#> Finish time: 2024-09-12 00:52:43.950384
#> Total time: 41.57711 secs
#> Estimating dispersion parameters for 3m megakaryocyte-erythroid progenitor cell
#> 14812 genes, 133 cells
#> Running SAVER given prior means with 2 worker(s)
#> Start time: 2024-09-12 00:52:44.326618
#> Estimating finish time...
#> Finished 100/14812 genes. Approximate finish time: 2024-09-12 00:53:12.640007
#> Finished 3778/14812 genes. Approximate finish time: 2024-09-12 00:53:14.634922
#> Finished 7456/14812 genes. Approximate finish time: 2024-09-12 00:53:14.016319
#> Finished 11134/14812 genes. Approximate finish time: 2024-09-12 00:53:13.795353
#> Finished 14812/14812 genes. Approximate finish time: 2024-09-12 00:53:13.807001
#> Done!
#> Finish time: 2024-09-12 00:53:13.807492
#> Total time: 29.48075 secs
#> Estimating dispersion parameters for 30m megakaryocyte-erythroid progenitor cell
#> 14812 genes, 616 cells
#> Running SAVER given prior means with 2 worker(s)
#> Start time: 2024-09-12 00:53:14.71503
#> Estimating finish time...
#> Finished 100/14812 genes. Approximate finish time: 2024-09-12 00:53:53.597785
#> Finished 3778/14812 genes. Approximate finish time: 2024-09-12 00:53:56.983838
#> Finished 7456/14812 genes. Approximate finish time: 2024-09-12 00:53:57.456635
#> Finished 11134/14812 genes. Approximate finish time: 2024-09-12 00:53:57.035486
#> Finished 14812/14812 genes. Approximate finish time: 2024-09-12 00:53:57.188777
#> Done!
#> Finish time: 2024-09-12 00:53:57.189302
#> Total time: 42.47413 secs
#> Estimating dispersion parameters for 3m precursor B cell
#> 14812 genes, 259 cells
#> Running SAVER given prior means with 2 worker(s)
#> Start time: 2024-09-12 00:53:57.622453
#> Estimating finish time...
#> Finished 100/14812 genes. Approximate finish time: 2024-09-12 00:54:20.469027
#> Finished 3778/14812 genes. Approximate finish time: 2024-09-12 00:54:22.041002
#> Finished 7456/14812 genes. Approximate finish time: 2024-09-12 00:54:22.327964
#> Finished 11134/14812 genes. Approximate finish time: 2024-09-12 00:54:22.339151
#> Finished 14812/14812 genes. Approximate finish time: 2024-09-12 00:54:22.445389
#> Done!
#> Finish time: 2024-09-12 00:54:22.445879
#> Total time: 24.82328 secs
#> Estimating dispersion parameters for 30m precursor B cell
#> 14812 genes, 163 cells
#> Running SAVER given prior means with 2 worker(s)
#> Start time: 2024-09-12 00:54:22.785662
#> Estimating finish time...
#> Finished 100/14812 genes. Approximate finish time: 2024-09-12 00:54:39.100077
#> Finished 3778/14812 genes. Approximate finish time: 2024-09-12 00:54:43.558793
#> Finished 7456/14812 genes. Approximate finish time: 2024-09-12 00:54:43.129726
#> Finished 11134/14812 genes. Approximate finish time: 2024-09-12 00:54:43.122894
#> Finished 14812/14812 genes. Approximate finish time: 2024-09-12 00:54:42.973785
#> Done!
#> Finish time: 2024-09-12 00:54:42.974282
#> Total time: 20.18849 secs