Compute a manifold for gene expression count data
compute_manifold.RdCompute a manifold for gene expression count data
Usage
compute_manifold(
counts,
method = "neighbor",
preprocess = TRUE,
ncores = 1,
nfeatures = 3000,
dims = 20,
neighbors = 20
)Arguments
- counts
An expression count matrix. The rows correspond to genes and the columns correspond to cells. It can be sparse.
- method
Method for estimating the manifold. Can be either "SAVER", which uses SAVER to recover the true expression, or 'neighbor', which uses nearest neighbors to approximate the true expression
- 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. (SAVER only)
- nfeatures
Number of features to use for FindVariableFeatures. Default is 3000. (Neighbor-based only)
- dims
Number of dimensions for nearest neighbors. Default is 20.(Neighbor-based only)
- neighbors
Number of neighbors to output. Default is 20. (Neighbor-based only)
Examples
# Load test data from Tabula Muris Senis
tms_marrow <- TabulaMurisSenisData::TabulaMurisSenisDroplet(tissues = "Marrow")
#> see ?TabulaMurisSenisData and browseVignettes('TabulaMurisSenisData') for documentation
#> downloading 1 resources
#> retrieving 1 resource
#> loading from cache
#> require(“rhdf5”)
#> see ?TabulaMurisSenisData and browseVignettes('TabulaMurisSenisData') for documentation
#> downloading 1 resources
#> retrieving 1 resource
#> loading from cache
#> require(“S4Vectors”)
#> see ?TabulaMurisSenisData and browseVignettes('TabulaMurisSenisData') for documentation
#> downloading 1 resources
#> retrieving 1 resource
#> loading from cache
#> see ?TabulaMurisSenisData and browseVignettes('TabulaMurisSenisData') for documentation
#> downloading 1 resources
#> retrieving 1 resource
#> loading from cache
#> see ?TabulaMurisSenisData and browseVignettes('TabulaMurisSenisData') for documentation
#> downloading 1 resources
#> retrieving 1 resource
#> loading from cache
#> see ?TabulaMurisSenisData and browseVignettes('TabulaMurisSenisData') for documentation
#> downloading 1 resources
#> retrieving 1 resource
#> 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 using both methods
tms_marrow_manifold_saver <- compute_manifold(tms_marrow_counts, method = "SAVER")
#> 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 SAVER method...
#> 14812 genes, 1980 cells
#> Running SAVER with 1 worker(s)
#> Calculating predictions for 14812 genes using 6619 genes and 1980 cells...
#> Start time: 2024-09-11 23:38:09.359904
#> Estimating finish time...
#> Finished 8/14812 genes. Approximate finish time: 2024-09-11 23:55:14.393807
#> Calculating max cor cutoff...
#> Finished 100/14812 genes. Approximate finish time: 2024-09-12 00:20:45.504609
#> Calculating lambda coefficients...
#> Finished 237/14812 genes. Approximate finish time: 2024-09-12 00:22:59.564327
#> Predicting remaining genes...
#> Finished 3881/14812 genes. Approximate finish time: 2024-09-12 00:52:45.79581
#> Predicting remaining genes...
#> Done!
#> Finish time: 2024-09-12 00:50:40.965346
#> Total time: 1.208779 hours
#> Finished computing manifold using SAVER. Time taken: 4354.29 seconds.
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.43 seconds.