-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbench.R
69 lines (50 loc) · 1.59 KB
/
bench.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
library(Matrix)
library(scPort)
library(Seurat)
# pbmc
counts <- Read10X(data.dir = "../../data/scRNA/filtered_gene_bc_matrices/hg19/")
# 似乎R代码更高效
tx <- bench::mark(
clr_norm(counts,lang = "R"),
clr_norm(counts,lang = "Rcpp"),
as(Seurat::NormalizeData(counts,normalization.method = "CLR"),Class = "dgCMatrix"),
iterations = 1
)
# Initialize the Seurat object with the raw (non-normalized data).
pbmc <- CreateSeuratObject(counts = counts, project = "pbmc3k", min.cells = 3, min.features = 200)
pbmc <- NormalizeData(pbmc)
pbmc <- FindVariableFeatures(pbmc, selection.method = "vst", nfeatures = 2000)
head(VariableFeatures(pbmc))
# 基因方差
bench::mark(
Seurat:::SparseRowVar2(counts,hvf.info$mean,display_progress = F),
sparseMatrixStats::rowVars(counts)
)
pbmc[["percent.mt"]] <- PercentageFeatureSet(pbmc, pattern = "^MT-")
# scale_data
pbmc <- ScaleData(pbmc)
bench::mark(
scPort:::regress_out_matrix(
LayerData(pbmc,layer = "data")[VariableFeatures(pbmc),],
latent.data = pbmc[["percent.mt"]]
),
Seurat:::RegressOutMatrix(
LayerData(pbmc,layer = "data")[VariableFeatures(pbmc),],
latent.data = pbmc[["percent.mt"]],
model.use = "linear"
),iterations = 1
)
bench::mark(
{
data <- Seurat:::FastSparseRowScale(LayerData(pbmc,layer = "data"))
dimnames(data) <- dimnames(LayerData(pbmc,layer = "data"))
data
},
Seurat:::FastRowScale(as.matrix(LayerData(pbmc,layer = "data"))),
iterations = 1
)
bench::mark(
Seurat:::FastSparseRowScale(LayerData(pbmc,layer = "data")),
FastSparseRowScale_rcpp(LayerData(pbmc,layer = "data")),
iterations = 1
)