**************************************************|
Centering and scaling data matrix
|================================================================================| 100%
执行PCA分析...
执行JackStraw检验...
最佳PCA维度: 13
执行Leiden聚类...
计算差异表达基因...
----- 处理样本 29 / 54 : GSM8452876_Pt-9B -----
执行数据标准化...
Normalizing layer: counts
Performing log-normalization
0% 10 20 30 40 50 60 70 80 90 100%
[----|----|----|----|----|----|----|----|----|----|
**************************************************|
Finding variable features for layer counts
Calculating gene variances
0% 10 20 30 40 50 60 70 80 90 100%
[----|----|----|----|----|----|----|----|----|----|
**************************************************|
Calculating feature variances of standardized and clipped values
0% 10 20 30 40 50 60 70 80 90 100%
[----|----|----|----|----|----|----|----|----|----|
**************************************************|
Centering and scaling data matrix
|================================================================================| 100%
执行PCA分析...
执行JackStraw检验...
最佳PCA维度: 11
执行Leiden聚类...
计算差异表达基因...
----- 处理样本 30 / 54 : GSM8452877_Pt-9C -----
执行数据标准化...
Normalizing layer: counts
Performing log-normalization
0% 10 20 30 40 50 60 70 80 90 100%
[----|----|----|----|----|----|----|----|----|----|
**************************************************|
Finding variable features for layer counts
Calculating gene variances
0% 10 20 30 40 50 60 70 80 90 100%
[----|----|----|----|----|----|----|----|----|----|
**************************************************|
Calculating feature variances of standardized and clipped values
0% 10 20 30 40 50 60 70 80 90 100%
[----|----|----|----|----|----|----|----|----|----|
**************************************************|
Centering and scaling data matrix
|================================================================================| 100%
执行PCA分析...
执行JackStraw检验...
最佳PCA维度: 11
执行Leiden聚类...
计算差异表达基因...
----- 处理样本 31 / 54 : GSM8452878_Pt-9D -----
执行数据标准化...
Normalizing layer: counts
Performing log-normalization
0% 10 20 30 40 50 60 70 80 90 100%
[----|----|----|----|----|----|----|----|----|----|
**************************************************|
Finding variable features for layer counts
Calculating gene variances
0% 10 20 30 40 50 60 70 80 90 100%
[----|----|----|----|----|----|----|----|----|----|
**************************************************|
Calculating feature variances of standardized and clipped values
0% 10 20 30 40 50 60 70 80 90 100%
[----|----|----|----|----|----|----|----|----|----|
**************************************************|
Centering and scaling data matrix
|================================================================================| 100%
执行PCA分析...
执行JackStraw检验...
最佳PCA维度: 9
执行Leiden聚类...
计算差异表达基因...
----- 处理样本 32 / 54 : GSM8452879_Pt-10A -----
执行数据标准化...
Normalizing layer: counts
Performing log-normalization
0% 10 20 30 40 50 60 70 80 90 100%
[----|----|----|----|----|----|----|----|----|----|
**************************************************|
Finding variable features for layer counts
Calculating gene variances
0% 10 20 30 40 50 60 70 80 90 100%
[----|----|----|----|----|----|----|----|----|----|
**************************************************|
Calculating feature variances of standardized and clipped values
0% 10 20 30 40 50 60 70 80 90 100%
[----|----|----|----|----|----|----|----|----|----|
**************************************************|
Centering and scaling data matrix
|================================================================================| 100%
执行PCA分析...
执行JackStraw检验...
最佳PCA维度: 10
执行Leiden聚类...
计算差异表达基因...
----- 处理样本 33 / 54 : GSM8452880_Pt-10B -----
执行数据标准化...
Normalizing layer: counts
Performing log-normalization
0% 10 20 30 40 50 60 70 80 90 100%
[----|----|----|----|----|----|----|----|----|----|
**************************************************|
Finding variable features for layer counts
Calculating gene variances
0% 10 20 30 40 50 60 70 80 90 100%
[----|----|----|----|----|----|----|----|----|----|
**************************************************|
Calculating feature variances of standardized and clipped values
0% 10 20 30 40 50 60 70 80 90 100%
[----|----|----|----|----|----|----|----|----|----|
**************************************************|
Centering and scaling data matrix
|================================================================================| 100%
执行PCA分析...
执行JackStraw检验...
最佳PCA维度: 12
执行Leiden聚类...
计算差异表达基因...
----- 处理样本 34 / 54 : GSM8452881_Pt-10C -----
执行数据标准化...
Normalizing layer: counts
Performing log-normalization
0% 10 20 30 40 50 60 70 80 90 100%
[----|----|----|----|----|----|----|----|----|----|
**************************************************|
Finding variable features for layer counts
Calculating gene variances
0% 10 20 30 40 50 60 70 80 90 100%
[----|----|----|----|----|----|----|----|----|----|
**************************************************|
Calculating feature variances of standardized and clipped values
0% 10 20 30 40 50 60 70 80 90 100%
[----|----|----|----|----|----|----|----|----|----|
**************************************************|
Centering and scaling data matrix
|================================================================================| 100%
执行PCA分析...
执行JackStraw检验...
最佳PCA维度: 12
执行Leiden聚类...
计算差异表达基因...
----- 处理样本 35 / 54 : GSM8452882_Pt-10D -----
执行数据标准化...
Normalizing layer: counts
Performing log-normalization
0% 10 20 30 40 50 60 70 80 90 100%
[----|----|----|----|----|----|----|----|----|----|
**************************************************|
Finding variable features for layer counts
Calculating gene variances
0% 10 20 30 40 50 60 70 80 90 100%
[----|----|----|----|----|----|----|----|----|----|
**************************************************|
Calculating feature variances of standardized and clipped values
0% 10 20 30 40 50 60 70 80 90 100%
[----|----|----|----|----|----|----|----|----|----|
**************************************************|
Centering and scaling data matrix
|================================================================================| 100%
执行PCA分析...
执行JackStraw检验...
最佳PCA维度: 8
执行Leiden聚类...
计算差异表达基因...
----- 处理样本 36 / 54 : GSM8452883_Pt-11A -----
执行数据标准化...
Normalizing layer: counts
Performing log-normalization
0% 10 20 30 40 50 60 70 80 90 100%
[----|----|----|----|----|----|----|----|----|----|
**************************************************|
Finding variable features for layer counts
Calculating gene variances
0% 10 20 30 40 50 60 70 80 90 100%
[----|----|----|----|----|----|----|----|----|----|
**************************************************|
Calculating feature variances of standardized and clipped values
0% 10 20 30 40 50 60 70 80 90 100%
[----|----|----|----|----|----|----|----|----|----|
**************************************************|
Centering and scaling data matrix
|================================================================================| 100%
执行PCA分析...
执行JackStraw检验...
最佳PCA维度: 18
执行Leiden聚类...
计算差异表达基因...
----- 处理样本 37 / 54 : GSM8452884_Pt-11B -----
执行数据标准化...
Normalizing layer: counts
Performing log-normalization
0% 10 20 30 40 50 60 70 80 90 100%
[----|----|----|----|----|----|----|----|----|----|
**************************************************|
Finding variable features for layer counts
Calculating gene variances
0% 10 20 30 40 50 60 70 80 90 100%
[----|----|----|----|----|----|----|----|----|----|
**************************************************|
Calculating feature variances of standardized and clipped values
0% 10 20 30 40 50 60 70 80 90 100%
[----|----|----|----|----|----|----|----|----|----|
**************************************************|
Centering and scaling data matrix
|================================================================================| 100%
执行PCA分析...
执行JackStraw检验...
最佳PCA维度: 10
执行Leiden聚类...
计算差异表达基因...
----- 处理样本 38 / 54 : GSM8452885_Pt-11C -----
执行数据标准化...
Normalizing layer: counts
Performing log-normalization
0% 10 20 30 40 50 60 70 80 90 100%
[----|----|----|----|----|----|----|----|----|----|
**************************************************|
Finding variable features for layer counts
Calculating gene variances
0% 10 20 30 40 50 60 70 80 90 100%
[----|----|----|----|----|----|----|----|----|----|
**************************************************|
Calculating feature variances of standardized and clipped values
0% 10 20 30 40 50 60 70 80 90 100%
[----|----|----|----|----|----|----|----|----|----|
**************************************************|
Centering and scaling data matrix
|================================================================================| 100%
执行PCA分析...
执行JackStraw检验...
最佳PCA维度: 12
执行Leiden聚类...
计算差异表达基因...
----- 处理样本 39 / 54 : GSM8452886_Pt-11D -----
执行数据标准化...
Normalizing layer: counts
Performing log-normalization
0% 10 20 30 40 50 60 70 80 90 100%
[----|----|----|----|----|----|----|----|----|----|
**************************************************|
Finding variable features for layer counts
Calculating gene variances
0% 10 20 30 40 50 60 70 80 90 100%
[----|----|----|----|----|----|----|----|----|----|
**************************************************|
Calculating feature variances of standardized and clipped values
0% 10 20 30 40 50 60 70 80 90 100%
[----|----|----|----|----|----|----|----|----|----|
**************************************************|
Centering and scaling data matrix
|================================================================================| 100%
执行PCA分析...
执行JackStraw检验...
最佳PCA维度: 11
执行Leiden聚类...
计算差异表达基因...
----- 处理样本 40 / 54 : GSM8452887_Pt-12A -----
执行数据标准化...
Normalizing layer: counts
Performing log-normalization
0% 10 20 30 40 50 60 70 80 90 100%
[----|----|----|----|----|----|----|----|----|----|
**************************************************|
Finding variable features for layer counts
Calculating gene variances
0% 10 20 30 40 50 60 70 80 90 100%
[----|----|----|----|----|----|----|----|----|----|
**************************************************|
Calculating feature variances of standardized and clipped values
0% 10 20 30 40 50 60 70 80 90 100%
[----|----|----|----|----|----|----|----|----|----|
**************************************************|
Centering and scaling data matrix
|================================================================================| 100%
执行PCA分析...
执行JackStraw检验...
最佳PCA维度: 9
执行Leiden聚类...
计算差异表达基因...
----- 处理样本 41 / 54 : GSM8452888_Pt-12B -----
执行数据标准化...
Normalizing layer: counts
Performing log-normalization
0% 10 20 30 40 50 60 70 80 90 100%
[----|----|----|----|----|----|----|----|----|----|
**************************************************|
Finding variable features for layer counts
Calculating gene variances
0% 10 20 30 40 50 60 70 80 90 100%
[----|----|----|----|----|----|----|----|----|----|
**************************************************|
Calculating feature variances of standardized and clipped values
0% 10 20 30 40 50 60 70 80 90 100%
[----|----|----|----|----|----|----|----|----|----|
**************************************************|
Centering and scaling data matrix
|================================================================================| 100%
执行PCA分析...
执行JackStraw检验...
最佳PCA维度: 9
执行Leiden聚类...
计算差异表达基因...
----- 处理样本 42 / 54 : GSM8452889_Pt-12C -----
执行数据标准化...
Normalizing layer: counts
Performing log-normalization
0% 10 20 30 40 50 60 70 80 90 100%
[----|----|----|----|----|----|----|----|----|----|
**************************************************|
Finding variable features for layer counts
Calculating gene variances
0% 10 20 30 40 50 60 70 80 90 100%
[----|----|----|----|----|----|----|----|----|----|
**************************************************|
Calculating feature variances of standardized and clipped values
0% 10 20 30 40 50 60 70 80 90 100%
[----|----|----|----|----|----|----|----|----|----|
**************************************************|
Centering and scaling data matrix
|================================================================================| 100%
执行PCA分析...
执行JackStraw检验...
最佳PCA维度: 13
执行Leiden聚类...
计算差异表达基因...
----- 处理样本 43 / 54 : GSM8452890_Pt-12D -----
执行数据标准化...
Normalizing layer: counts
Performing log-normalization
0% 10 20 30 40 50 60 70 80 90 100%
[----|----|----|----|----|----|----|----|----|----|
**************************************************|
Finding variable features for layer counts
Calculating gene variances
0% 10 20 30 40 50 60 70 80 90 100%
[----|----|----|----|----|----|----|----|----|----|
**************************************************|
Calculating feature variances of standardized and clipped values
0% 10 20 30 40 50 60 70 80 90 100%
[----|----|----|----|----|----|----|----|----|----|
**************************************************|
Centering and scaling data matrix
|================================================================================| 100%
执行PCA分析...
执行JackStraw检验...
最佳PCA维度: 18
执行Leiden聚类...
计算差异表达基因...
----- 处理样本 44 / 54 : GSM8452891_Pt-13A -----
执行数据标准化...
Normalizing layer: counts
Performing log-normalization
0% 10 20 30 40 50 60 70 80 90 100%
[----|----|----|----|----|----|----|----|----|----|
**************************************************|
Finding variable features for layer counts
Calculating gene variances
0% 10 20 30 40 50 60 70 80 90 100%
[----|----|----|----|----|----|----|----|----|----|
**************************************************|
Calculating feature variances of standardized and clipped values
0% 10 20 30 40 50 60 70 80 90 100%
[----|----|----|----|----|----|----|----|----|----|
**************************************************|
Centering and scaling data matrix
|================================================================================| 100%
执行PCA分析...
执行JackStraw检验...
最佳PCA维度: 20
执行Leiden聚类...
计算差异表达基因...
----- 处理样本 45 / 54 : GSM8452892_Pt-13B -----
执行数据标准化...
Normalizing layer: counts
Performing log-normalization
0% 10 20 30 40 50 60 70 80 90 100%
[----|----|----|----|----|----|----|----|----|----|
**************************************************|
Finding variable features for layer counts
Calculating gene variances
0% 10 20 30 40 50 60 70 80 90 100%
[----|----|----|----|----|----|----|----|----|----|
**************************************************|
Calculating feature variances of standardized and clipped values
0% 10 20 30 40 50 60 70 80 90 100%
[----|----|----|----|----|----|----|----|----|----|
**************************************************|
Centering and scaling data matrix
|================================================================================| 100%
执行PCA分析...
执行JackStraw检验...
最佳PCA维度: 14
执行Leiden聚类...
计算差异表达基因...
----- 处理样本 46 / 54 : GSM8452893_Pt-13C -----
执行数据标准化...
Normalizing layer: counts
Performing log-normalization
0% 10 20 30 40 50 60 70 80 90 100%
[----|----|----|----|----|----|----|----|----|----|
**************************************************|
Finding variable features for layer counts
Calculating gene variances
0% 10 20 30 40 50 60 70 80 90 100%
[----|----|----|----|----|----|----|----|----|----|
**************************************************|
Calculating feature variances of standardized and clipped values
0% 10 20 30 40 50 60 70 80 90 100%
[----|----|----|----|----|----|----|----|----|----|
**************************************************|
Centering and scaling data matrix
|================================================================================| 100%
执行PCA分析...
执行JackStraw检验...
最佳PCA维度: 19
执行Leiden聚类...
计算差异表达基因...
----- 处理样本 47 / 54 : GSM8452894_Pt-13D -----
执行数据标准化...
Normalizing layer: counts
Performing log-normalization
0% 10 20 30 40 50 60 70 80 90 100%
[----|----|----|----|----|----|----|----|----|----|
**************************************************|
Finding variable features for layer counts
Calculating gene variances
0% 10 20 30 40 50 60 70 80 90 100%
[----|----|----|----|----|----|----|----|----|----|
**************************************************|
Calculating feature variances of standardized and clipped values
0% 10 20 30 40 50 60 70 80 90 100%
[----|----|----|----|----|----|----|----|----|----|
**************************************************|
Centering and scaling data matrix
|================================================================================| 100%
执行PCA分析...
执行JackStraw检验...
最佳PCA维度: 19
执行Leiden聚类...
计算差异表达基因...
----- 处理样本 48 / 54 : GSM8452895_Pt-13E -----
执行数据标准化...
Normalizing layer: counts
Performing log-normalization
0% 10 20 30 40 50 60 70 80 90 100%
[----|----|----|----|----|----|----|----|----|----|
**************************************************|
Finding variable features for layer counts
Calculating gene variances
0% 10 20 30 40 50 60 70 80 90 100%
[----|----|----|----|----|----|----|----|----|----|
**************************************************|
Calculating feature variances of standardized and clipped values
0% 10 20 30 40 50 60 70 80 90 100%
[----|----|----|----|----|----|----|----|----|----|
**************************************************|
Centering and scaling data matrix
|================================================================================| 100%
执行PCA分析...
执行JackStraw检验...
最佳PCA维度: 15
执行Leiden聚类...
计算差异表达基因...
----- 处理样本 49 / 54 : GSM8714177_Pt3_Pri2 -----
执行数据标准化...
Normalizing layer: counts
Performing log-normalization
0% 10 20 30 40 50 60 70 80 90 100%
[----|----|----|----|----|----|----|----|----|----|
**************************************************|
Finding variable features for layer counts
Calculating gene variances
0% 10 20 30 40 50 60 70 80 90 100%
[----|----|----|----|----|----|----|----|----|----|
**************************************************|
Calculating feature variances of standardized and clipped values
0% 10 20 30 40 50 60 70 80 90 100%
[----|----|----|----|----|----|----|----|----|----|
**************************************************|
Centering and scaling data matrix
|================================================================================| 100%
执行PCA分析...
执行JackStraw检验...
最佳PCA维度: 4
执行Leiden聚类...
计算差异表达基因...
----- 处理样本 50 / 54 : GSM8714178_Pt6_Pri2 -----
执行数据标准化...
Normalizing layer: counts
Performing log-normalization
0% 10 20 30 40 50 60 70 80 90 100%
[----|----|----|----|----|----|----|----|----|----|
**************************************************|
Finding variable features for layer counts
Calculating gene variances
0% 10 20 30 40 50 60 70 80 90 100%
[----|----|----|----|----|----|----|----|----|----|
**************************************************|
Calculating feature variances of standardized and clipped values
0% 10 20 30 40 50 60 70 80 90 100%
[----|----|----|----|----|----|----|----|----|----|
**************************************************|
Centering and scaling data matrix
|================================================================================| 100%
执行PCA分析...
执行JackStraw检验...
最佳PCA维度: 3
执行Leiden聚类...
计算差异表达基因...
----- 处理样本 51 / 54 : GSM8714179_Pt6_Pri3 -----
执行数据标准化...
Normalizing layer: counts
Performing log-normalization
0% 10 20 30 40 50 60 70 80 90 100%
[----|----|----|----|----|----|----|----|----|----|
**************************************************|
Finding variable features for layer counts
Calculating gene variances
0% 10 20 30 40 50 60 70 80 90 100%
[----|----|----|----|----|----|----|----|----|----|
**************************************************|
Calculating feature variances of standardized and clipped values
0% 10 20 30 40 50 60 70 80 90 100%
[----|----|----|----|----|----|----|----|----|----|
**************************************************|
Centering and scaling data matrix
|================================================================================| 100%
执行PCA分析...
执行JackStraw检验...
最佳PCA维度: 6
执行Leiden聚类...
计算差异表达基因...
----- 处理样本 52 / 54 : GSM8714180_Pt8_Pri2 -----
执行数据标准化...
Normalizing layer: counts
Performing log-normalization
0% 10 20 30 40 50 60 70 80 90 100%
[----|----|----|----|----|----|----|----|----|----|
**************************************************|
Finding variable features for layer counts
Calculating gene variances
0% 10 20 30 40 50 60 70 80 90 100%
[----|----|----|----|----|----|----|----|----|----|
**************************************************|
Calculating feature variances of standardized and clipped values
0% 10 20 30 40 50 60 70 80 90 100%
[----|----|----|----|----|----|----|----|----|----|
**************************************************|
Centering and scaling data matrix
|================================================================================| 100%
执行PCA分析...
执行JackStraw检验...
最佳PCA维度: 6
执行Leiden聚类...
计算差异表达基因...
----- 处理样本 53 / 54 : GSM8714181_Pt13_Pri2 -----
执行数据标准化...
Normalizing layer: counts
Performing log-normalization
0% 10 20 30 40 50 60 70 80 90 100%
[----|----|----|----|----|----|----|----|----|----|
**************************************************|
Finding variable features for layer counts
Calculating gene variances
0% 10 20 30 40 50 60 70 80 90 100%
[----|----|----|----|----|----|----|----|----|----|
**************************************************|
Calculating feature variances of standardized and clipped values
0% 10 20 30 40 50 60 70 80 90 100%
[----|----|----|----|----|----|----|----|----|----|
**************************************************|
Centering and scaling data matrix
|================================================================================| 100%
执行PCA分析...
执行JackStraw检验...
最佳PCA维度: 3
执行Leiden聚类...
计算差异表达基因...
----- 处理样本 54 / 54 : GSM8714182_Pt13_Pri3 -----
执行数据标准化...
Normalizing layer: counts
Performing log-normalization
0% 10 20 30 40 50 60 70 80 90 100%
[----|----|----|----|----|----|----|----|----|----|
**************************************************|
Finding variable features for layer counts
Calculating gene variances
0% 10 20 30 40 50 60 70 80 90 100%
[----|----|----|----|----|----|----|----|----|----|
**************************************************|
Calculating feature variances of standardized and clipped values
0% 10 20 30 40 50 60 70 80 90 100%
[----|----|----|----|----|----|----|----|----|----|
**************************************************|
Centering and scaling data matrix
|================================================================================| 100%
执行PCA分析...
执行JackStraw检验...
最佳PCA维度: 7
执行Leiden聚类...
计算差异表达基因...
===== 所有样本处理完成 =====
sample dim2use
1 GSM8452847_Pt-1A 11
2 GSM8452849_Pt-1C 14
3 GSM8452850_Pt-2A 16
4 GSM8452851_Pt-2B 19
5 GSM8452852_Pt-2C 16
6 GSM8452853_Pt-3A 20
7 GSM8452854_Pt-3B 11
8 GSM8452855_Pt-3C 13
9 GSM8452856_Pt-4A 13
10 GSM8452857_Pt-4B 9
11 GSM8452858_Pt-4C 14
12 GSM8452859_Pt-4D 14
13 GSM8452860_Pt-5A 20
14 GSM8452861_Pt-5B 20
15 GSM8452862_Pt-5C 20
16 GSM8452863_Pt-6A 12
17 GSM8452864_Pt-6B 18
18 GSM8452865_Pt-6C 13
19 GSM8452866_Pt-6D 5
20 GSM8452867_Pt-7A 16
21 GSM8452868_Pt-7B 17
22 GSM8452869_Pt-7C 19
23 GSM8452870_Pt-7D 15
24 GSM8452871_Pt-8A 15
25 GSM8452872_Pt-8B 14
26 GSM8452873_Pt-8C 19
27 GSM8452874_Pt-8D 12
28 GSM8452875_Pt-9A 13
29 GSM8452876_Pt-9B 11
30 GSM8452877_Pt-9C 11
31 GSM8452878_Pt-9D 9
32 GSM8452879_Pt-10A 10
33 GSM8452880_Pt-10B 12
34 GSM8452881_Pt-10C 12
35 GSM8452882_Pt-10D 8
36 GSM8452883_Pt-11A 18
37 GSM8452884_Pt-11B 10
38 GSM8452885_Pt-11C 12
39 GSM8452886_Pt-11D 11
40 GSM8452887_Pt-12A 9
41 GSM8452888_Pt-12B 9
42 GSM8452889_Pt-12C 13
43 GSM8452890_Pt-12D 18
44 GSM8452891_Pt-13A 20
45 GSM8452892_Pt-13B 14
46 GSM8452893_Pt-13C 19
47 GSM8452894_Pt-13D 19
48 GSM8452895_Pt-13E 15
49 GSM8714177_Pt3_Pri2 4
50 GSM8714178_Pt6_Pri2 3
51 GSM8714179_Pt6_Pri3 6
52 GSM8714180_Pt8_Pri2 6
53 GSM8714181_Pt13_Pri2 3
54 GSM8714182_Pt13_Pri3 7
> View(result)
> View(result)
> ## 1. 定义补充统计信息的函数
> add_missing_statistics <- function(analysis_result) {
+ # 遍历所有样本
+ for (i in seq_along(analysis_result$objects)) {
+ # 获取当前样本对象
+ seurat_obj <- analysis_result$objects[[i]]
+ sample_name <- names(analysis_result$objects)[i]
+
+ cat("正在处理样本:", sample_name, " (", i, "/", length(analysis_result$objects), ")\n", sep = "")
+
+ # 补充基因计数统计
+ seurat_obj@misc$gene_counts <- table(seurat_obj@misc$markers$cluster)
+
+ # 补充斑点聚类信息
+ seurat_obj@misc$spot_clusters <- seurat_obj@meta.data[["seurat_clusters"]]
+
+ # 补充聚类大小统计
+ seurat_obj@misc$cluster_sizes <- table(seurat_obj@meta.data[["seurat_clusters"]])
+
+ # 更新结果列表中的对象
+ analysis_result$objects[[i]] <- seurat_obj
+ }
+
+ cat("\n所有样本统计信息补充完成!\n")
+ return(analysis_result)
+ }
> View(result)
> # 应用补充函数
> result_with_stats <- add_missing_statistics(result)
正在处理样本:GSM8452847_Pt-1A (1/54)
正在处理样本:GSM8452849_Pt-1C (2/54)
正在处理样本:GSM8452850_Pt-2A (3/54)
正在处理样本:GSM8452851_Pt-2B (4/54)
正在处理样本:GSM8452852_Pt-2C (5/54)
正在处理样本:GSM8452853_Pt-3A (6/54)
正在处理样本:GSM8452854_Pt-3B (7/54)
正在处理样本:GSM8452855_Pt-3C (8/54)
正在处理样本:GSM8452856_Pt-4A (9/54)
正在处理样本:GSM8452857_Pt-4B (10/54)
正在处理样本:GSM8452858_Pt-4C (11/54)
正在处理样本:GSM8452859_Pt-4D (12/54)
正在处理样本:GSM8452860_Pt-5A (13/54)
正在处理样本:GSM8452861_Pt-5B (14/54)
正在处理样本:GSM8452862_Pt-5C (15/54)
正在处理样本:GSM8452863_Pt-6A (16/54)
正在处理样本:GSM8452864_Pt-6B (17/54)
正在处理样本:GSM8452865_Pt-6C (18/54)
正在处理样本:GSM8452866_Pt-6D (19/54)
正在处理样本:GSM8452867_Pt-7A (20/54)
正在处理样本:GSM8452868_Pt-7B (21/54)
正在处理样本:GSM8452869_Pt-7C (22/54)
正在处理样本:GSM8452870_Pt-7D (23/54)
正在处理样本:GSM8452871_Pt-8A (24/54)
正在处理样本:GSM8452872_Pt-8B (25/54)
正在处理样本:GSM8452873_Pt-8C (26/54)
正在处理样本:GSM8452874_Pt-8D (27/54)
正在处理样本:GSM8452875_Pt-9A (28/54)
正在处理样本:GSM8452876_Pt-9B (29/54)
正在处理样本:GSM8452877_Pt-9C (30/54)
正在处理样本:GSM8452878_Pt-9D (31/54)
正在处理样本:GSM8452879_Pt-10A (32/54)
正在处理样本:GSM8452880_Pt-10B (33/54)
正在处理样本:GSM8452881_Pt-10C (34/54)
正在处理样本:GSM8452882_Pt-10D (35/54)
正在处理样本:GSM8452883_Pt-11A (36/54)
正在处理样本:GSM8452884_Pt-11B (37/54)
正在处理样本:GSM8452885_Pt-11C (38/54)
正在处理样本:GSM8452886_Pt-11D (39/54)
正在处理样本:GSM8452887_Pt-12A (40/54)
正在处理样本:GSM8452888_Pt-12B (41/54)
正在处理样本:GSM8452889_Pt-12C (42/54)
正在处理样本:GSM8452890_Pt-12D (43/54)
正在处理样本:GSM8452891_Pt-13A (44/54)
正在处理样本:GSM8452892_Pt-13B (45/54)
正在处理样本:GSM8452893_Pt-13C (46/54)
正在处理样本:GSM8452894_Pt-13D (47/54)
正在处理样本:GSM8452895_Pt-13E (48/54)
正在处理样本:GSM8714177_Pt3_Pri2 (49/54)
正在处理样本:GSM8714178_Pt6_Pri2 (50/54)
正在处理样本:GSM8714179_Pt6_Pri3 (51/54)
正在处理样本:GSM8714180_Pt8_Pri2 (52/54)
正在处理样本:GSM8714181_Pt13_Pri2 (53/54)
正在处理样本:GSM8714182_Pt13_Pri3 (54/54)
所有样本统计信息补充完成!
> View(result_with_stats)
> ## 3. 验证补充结果
> cat("\n===== 验证结果 =====")
===== 验证结果 =====
> # 查看第一个样本的补充统计信息
> sample1 <- result_with_stats$objects[[1]]
> cat("\n样本", names(result_with_stats$objects)[1], "的基因计数:\n")
样本 GSM8452847_Pt-1A 的基因计数:
> print(sample1@misc$gene_counts)
1 2 3 4 5 6 7 8 9 10 11
3785 1111 2471 810 5578 5294 1822 847 2782 1911 674
> cat("\n样本", names(result_with_stats$objects)[1], "的聚类大小:\n")
样本 GSM8452847_Pt-1A 的聚类大小:
> print(sample1@misc$cluster_sizes)
1 2 3 4 5 6 7 8 9 10 11
440 354 349 297 294 200 187 177 159 112 105
> cat("\n样本", names(result_with_stats$objects)[1], "的spot:\n")
样本 GSM8452847_Pt-1A 的spot:
> print(sample1@misc$spot_clusters)
[1] 5 11 1 5 1 9 9 6 9 1 8 4 6 5 10 11 7 1 3 2 2 10 2 5 4 5 1 5
[29] 8 1 6 1 2 4 1 10 10 7 1 4 1 7 4 2 3 3 10 11 2 10 5 4 4 9 3 11
[57] 11 3 5 5 6 1 8 1 11 5 8 4 2 3 3 3 1 5 8 2 1 4 2 1 9 3 3 6
[85] 3 4 11 9 10 2 1 3 4 8 8 5 9 4 5 6 3 8 1 3 1 1 1 2 10 2 4 2
[113] 2 2 5 4 2 2 5 3 7 6 6 4 3 6 3 3 1 3 7 2 6 1 9 5 1 2 3 1
[141] 6 4 1 2 2 3 1 1 4 3 3 9 3 9 8 8 1 11 9 6 7 5 1 10 6 2 3 6
[169] 3 6 8 3 3 9 4 4 11 5 7 10 9 3 6 5 3 2 1 11 5 6 2 1 6 2 5 3
[197] 2 11 1 8 1 1 9 6 5 5 1 6 3 5 10 3 9 2 8 6 5 9 4 2 3 6 1 5
[225] 10 8 1 5 4 6 5 4 11 3 9 3 6 9 5 1 2 2 5 9 5 11 1 4 1 7 2 4
[253] 7 7 2 3 10 4 9 6 4 6 8 9 6 11 4 2 8 4 7 2 1 2 2 11 3 8 4 1
[281] 5 9 3 6 2 2 4 1 8 8 1 11 1 5 6 1 2 10 1 6 4 3 6 6 1 7 5 4
[309] 11 1 5 1 11 3 6 3 4 10 1 3 7 7 1 2 1 2 3 7 4 2 3 4 3 5 5 1
[337] 9 4 3 10 8 6 4 1 1 3 2 8 4 11 3 6 2 6 8 11 2 6 4 8 3 9 2 2
[365] 7 1 4 1 11 3 2 7 2 4 1 8 6 4 7 3 1 1 1 6 4 1 1 2 1 7 1 8
[393] 10 4 2 4 1 4 8 4 1 5 4 2 4 6 10 11 7 1 5 11 4 10 2 3 1 5 10 5
[421] 1 11 2 4 1 1 3 5 2 5 11 3 3 5 1 11 1 1 9 1 6 1 8 1 9 2 10 9
[449] 7 2 9 5 1 1 4 3 11 5 6 9 1 2 3 6 5 1 2 9 4 1 6 3 4 3 4 6
[477] 1 3 3 9 5 11 5 10 7 10 6 3 1 8 5 3 2 4 9 2 8 4 1 3 3 9 2 6
[505] 8 8 3 4 8 5 11 4 6 8 6 4 9 2 4 2 9 5 3 4 8 8 11 1 1 1 2 7
[533] 1 2 6 3 1 7 5 2 7 11 1 3 3 6 5 1 2 1 3 2 6 5 2 3 11 7 4 9
[561] 2 9 1 7 5 4 5 1 6 4 7 1 8 8 4 5 2 7 4 9 6 2 4 1 3 2 9 2
[589] 1 9 11 7 4 1 1 3 6 5 1 5 2 1 10 2 4 4 8 6 11 8 9 2 1 2 6 5
[617] 1 5 3 2 4 1 8 1 8 10 7 8 4 3 10 1 10 4 2 2 6 4 1 7 1 1 3 6
[645] 10 4 1 1 2 1 3 1 11 2 7 8 2 10 1 11 5 10 1 11 10 1 5 4 4 3 5 5
[673] 2 2 1 8 2 8 7 1 2 4 1 2 1 2 6 6 4 5 1 3 4 9 2 4 5 10 5 2
[701] 7 8 4 5 8 3 6 10 1 5 11 6 10 1 3 6 1 5 4 9 5 2 3 10 1 5 3 10
[729] 5 1 4 4 2 9 4 7 2 1 8 2 3 10 2 3 3 6 5 1 2 4 2 7 4 2 3 3
[757] 5 11 5 6 1 1 1 9 7 4 11 10 1 1 2 1 3 9 6 1 3 4 4 1 7 4 10 10
[785] 7 10 9 4 8 9 3 2 7 2 5 2 3 3 5 3 1 7 4 2 5 4 9 4 3 2 1 1
[813] 5 1 8 4 5 2 1 2 6 1 8 11 6 1 3 5 10 1 1 1 3 4 10 2 2 1 2 3
[841] 6 9 9 1 2 4 2 4 2 5 3 5 5 11 5 1 5 4 5 9 3 4 1 2 1 6 2 7
[869] 1 4 1 8 1 2 5 7 5 7 2 9 9 9 1 8 5 7 2 2 4 5 8 5 5 1 8 8
[897] 10 3 2 3 3 2 7 5 3 4 3 3 3 7 9 3 8 1 3 3 3 5 7 1 5 4 1 1
[925] 1 3 8 5 1 3 9 9 6 2 5 1 3 2 4 5 3 1 3 7 4 7 1 4 3 1 5 7
[953] 5 1 9 2 4 4 3 4 6 2 11 9 1 3 6 1 10 4 4 1 2 3 4 8 3 3 3 9
[981] 7 10 7 5 10 8 3 5 7 2 2 7 8 5 7 2 1 11 3 9
[ reached 'max' / getOption("max.print") -- omitted 1674 entries ]
Levels: 1 2 3 4 5 6 7 8 9 10 11
> rm(result)
> rm(filtered)
> View(result_with_stats)
> # 提取每个样本的聚类结果
> leiden_results <- lapply(processed_list, function(obj) {
+ list(
+ markers = obj@misc$markers,
+ gene_counts = obj@misc$gene_counts,
+ spot_clusters = obj@misc$spot_clusters,
+ cluster_sizes = obj@misc$cluster_sizes
+ )
+ })
错误于h(simpleError(msg, call)):
在为函数“lapply”选择方法时计算参数“X”时出错:找不到对象'processed_list'
> View(result_with_stats)
> # 提取每个样本的聚类结果
> leiden_results <- lapply(result_with_stats$objects, function(obj) {
+ list(
+ markers = obj@misc$markers,
+ gene_counts = obj@misc$gene_counts,
+ spot_clusters = obj@misc$spot_clusters,
+ cluster_sizes = obj@misc$cluster_sizes
+ )
+ })
> View(leiden_results)
> View(leiden_results)
> ## 1. 加载必要包
> library(scalop)
> library(NMF)
> library(MetBrewer)
错误于library(MetBrewer): 不存在叫‘MetBrewer’这个名称的程序包
> library(colorspace)
> library(patchwork)
> library(reshape2)
> library(ggplot2)
> BiocManager::install("MetBrewer")
'getOption("repos")' replaces Bioconductor standard repositories, see
'help("repositories", package = "BiocManager")' for details.
Replacement repositories:
CRAN: https://mirrors.tuna.tsinghua.edu.cn/CRAN/
Bioconductor version 3.21 (BiocManager 1.30.25), R 4.5.0 (2025-04-11 ucrt)
Installing package(s) 'MetBrewer'
试开URL’https://mirrors.tuna.tsinghua.edu.cn/CRAN/bin/windows/contrib/4.5/MetBrewer_0.2.0.zip'
Content type 'application/zip' length 68335 bytes (66 KB)
downloaded 66 KB
程序包‘MetBrewer’打开成功,MD5和检查也通过
下载的二进制程序包在
C:\Users\lenovo\AppData\Local\Temp\Rtmp4cfrUA\downloaded_packages里
Old packages: 'annotate', 'BiocFileCache', 'BiocManager', 'BiocParallel', 'broom',
'Cairo', 'checkmate', 'commonmark', 'ComplexHeatmap', 'cowplot', 'crosstalk', 'curl',
'data.table', 'dendextend', 'Deriv', 'DESeq2', 'doBy', 'DropletUtils', 'DT', 'edgeR',
'emmeans', 'evaluate', 'FactoMineR', 'fields', 'fitdistrplus', 'future',
'future.apply', 'gargle', 'GenomeInfoDb', 'ggforce', 'ggpubr', 'ggraph', 'ggridges',
'gh', 'googlesheets4', 'h5mread', 'haven', 'httr2', 'KEGGREST', 'later', 'limma',
'magick', 'maps', 'Matrix', 'openssl', 'parallelly', 'patchwork', 'pbapply',
'pbkrtest', 'pheatmap', 'pillar', 'pkgbuild', 'pkgdown', 'plotly', 'promises', 'purrr',
'ragg', 'Rcpp', 'RcppArmadillo', 'RcppParallel', 'restfulr', 'reticulate', 'rhdf5',
'roxygen2', 'rprojroot', 'Rsamtools', 'RSQLite', 'rvest', 'S4Arrays', 'SeuratObject',
'shiny', 'SparseArray', 'spatstat.data', 'spatstat.explore', 'spatstat.geom',
'spatstat.random', 'spatstat.univar', 'spatstat.utils', 'statnet.common', 'stringr',
'survminer', 'tensor', 'textshaping', 'TH.data', 'tibble', 'usethis', 'utf8', 'waldo',
'xfun', 'xgboost', 'XML', 'xml2', 'zip', 'boot', 'lattice', 'mgcv'
Update all/some/none? [a/s/n]:
n
> library(MetBrewer)
警告信息:
程序包‘MetBrewer’是用R版本4.5.1 来建造的
> ## 2. 结果整合(对应原代码118-135行)
> ### 2.1 合并基因签名表
> # 创建基因签名表
> genes_sig <- leiden_results[[1]]$markers
> genes_sig$sample <- rep(names(leiden_results)[1], nrow(genes_sig))
> View(genes_sig)
> # 循环合并所有样本
> for (i in 2:length(leiden_results)) {
+ temp <- leiden_results[[i]]$markers
+ temp$sample <- rep(names(leiden_results)[i], nrow(temp))
+ genes_sig <- rbind(genes_sig, temp)
+ }
> ### 2.2 合并斑点分配表
> # 创建斑点分配表
> spots_assign <- as.data.frame(leiden_results[[1]]$spot_clusters)
> spots_assign$sample <- rep(names(leiden_results)[1], nrow(spots_assign))
> rownames(spots_assign) <- paste(rownames(spots_assign), names(leiden_results)[1], sep = "_")
> colnames(spots_assign) <- c("cluster", "sample")
> # 循环合并所有样本
> for (i in 2:length(leiden_results)) {
+ temp <- as.data.frame(leiden_results[[i]]$spot_clusters)
+ temp$sample <- rep(names(leiden_results)[i], nrow(temp))
+ rownames(temp) <- paste(rownames(temp), names(leiden_results)[i], sep = "_")
+ colnames(temp) <- c("cluster", "sample")
+ spots_assign <- rbind(spots_assign, temp)
+ }
> ## 3. 基因程序识别(对应原代码137-169行)
> ### 3.1 提取top50差异基因
> genes_list <- lapply(leiden_results, function(sample_data) {
+ # 按cluster拆分标记基因
+ split_markers <- split(sample_data$markers, sample_data$markers$cluster)
+ # 提取每个cluster的top50基因
+ lapply(split_markers, function(cluster) {
+ cluster_sorted <- cluster[order(cluster$avg_log2FC, decreasing = TRUE), ]
+ head(cluster_sorted$gene, 50)
+ })
+ })
> genes_list <- unlist(genes_list, recursive = FALSE)
> names(genes_list) <- unlist(lapply(names(leiden_results), function(sample) {
+ paste(sample, names(leiden_results[[sample]]$cluster_sizes), sep = "_")
+ }))
> View(genes_list)
> ### 3.2 Jaccard相似度分析与聚类
> # 计算Jaccard矩阵
> jac_mat <- Jaccard(genes_list)
> jac_matord <- scalop::hca_reorder(jac_mat)
错误于is_square(m) && unique(diag(m)) != max.dist:
'length = 11' in coercion to 'logical(1)'
> ### 3.2 Jaccard相似度分析与聚类
> # 计算Jaccard矩阵
> jac_mat <- Jaccard(genes_list)
> jac_matord <- scalop::hca_reorder(jac_mat)
错误于is_square(m) && unique(diag(m)) != max.dist:
'length = 11' in coercion to 'logical(1)'
> # 假设您的基因列表存储在genes_list变量中
> clean_genes_list <- function(genes_list) {
+ # 1. 移除空元素和无效基因集
+ valid_idx <- sapply(genes_list, function(x) {
+ is.vector(x) && is.character(x) && length(x) > 0 && !all(is.na(x))
+ })
+
+ if (!all(valid_idx)) {
+ cat("移除", sum(!valid_idx), "个无效基因集\n")
+ genes_list <- genes_list[valid_idx]
+ }
+
+ # 2. 确保所有基因集长度一致(可选,根据需要调整)
+ genes_list <- lapply(genes_list, function(x) head(x, 50)) # 统一取前50个基因
+
+ # 3. 处理重复名称
+ if (length(unique(names(genes_list))) != length(genes_list)) {
+ cat("修复重复名称...\n")
+ names(genes_list) <- make.unique(names(genes_list))
+ }
+
+ # 4. 验证是否为空
+ if (length(genes_list) == 0) {
+ stop("清理后基因列表为空,请检查输入数据")
+ }
+
+ return(genes_list)
+ }
> # 应用清理函数
> cleaned_genes_list <- clean_genes_list(genes_list)
> ```
错误: 不能用零长度变量名
> # 验证清理结果
> cat("===== 基因列表验证 =====", "\n")
===== 基因列表验证 =====
> cat("总基因集数量:", length(cleaned_genes_list), "\n")
总基因集数量: 527
> cat("第一个基因集名称:", names(cleaned_genes_list)[1], "\n")
第一个基因集名称: GSM8452847_Pt-1A_1
> cat("第一个基因集基因数量:", length(cleaned_genes_list[[1]]), "\n")
第一个基因集基因数量: 50
> cat("第一个基因集示例:", paste(head(cleaned_genes_list[[1]]), collapse=", "), "\n")
第一个基因集示例: LINC01583, LINC01431, AP001065.3, UTS2B, RCAN3AS, AC073957.3
> # 检查是否有重复名称
> if (any(duplicated(names(cleaned_genes_list)))) {
+ stop("仍存在重复名称,请检查清理函数")
+ }
> # 确保scalop包版本兼容
> if (!require("scalop") || packageVersion("scalop") < "1.0.3") {
+ install.packages("scalop")
+ library(scalop)
+ }
> # 计算Jaccard矩阵
> cat("\n===== 计算Jaccard矩阵 =====", "\n")
===== 计算Jaccard矩阵 =====
> jac_mat <- Jaccard(cleaned_genes_list)
> # 验证矩阵是否为方阵
> if (nrow(jac_mat) != ncol(jac_mat)) {
+ stop("Jaccard矩阵不是方阵,行=", nrow(jac_mat), ", 列=", ncol(jac_mat))
+ }
> # 验证对角线元素
> diag_vals <- diag(jac_mat)
> if (!all(diag_vals == 1)) {
+ warning("Jaccard矩阵对角线元素不为1,最小值=", min(diag_vals))
+ }
> # 继续hca_reorder
> jac_matord <- scalop::hca_reorder(jac_mat)
错误于is_square(m) && unique(diag(m)) != max.dist:
'length = 11' in coercion to 'logical(1)'
> # 如果上述方法仍失败,使用基础方法计算Jaccard
> jaccard <- function(a, b) {
+ length(intersect(a, b)) / length(union(a, b))
+ }
> # 手动构建Jaccard矩阵
> n <- length(cleaned_genes_list)
> jac_mat <- matrix(0, nrow = n, ncol = n)
> rownames(jac_mat) <- names(cleaned_genes_list)
> colnames(jac_mat) <- names(cleaned_genes_list)
> for (i in 1:n) {
+ for (j in 1:n) {
+ jac_mat[i, j] <- jaccard(cleaned_genes_list[[i]], cleaned_genes_list[[j]])
+ }
+ }
> diag(jac_mat) <- 1 # 确保对角线为1
> jac_matord <- scalop::hca_reorder(jac_mat)
错误于is_square(m) && unique(diag(m)) != max.dist:
'length = 11' in coercion to 'logical(1)'
> rm(jac_mat)
> ### 3.2 Jaccard相似度分析与聚类
> # 计算Jaccard矩阵
> jac_mat <- Jaccard(genes_list)
> class(jac_mat)
[1] "matrix" "array"
> str(jac_mat)
num [1:527, 1:527] 1 0 0 0 0 0 0 0 0 0 ...
- attr(*, "dimnames")=List of 2
..$ : chr [1:527] "GSM8452847_Pt-1A_1" "GSM8452847_Pt-1A_2" "GSM8452847_Pt-1A_3" "GSM8452847_Pt-1A_4" ...
..$ : chr [1:527] "GSM8452847_Pt-1A_1" "GSM8452847_Pt-1A_2" "GSM8452847_Pt-1A_3" "GSM8452847_Pt-1A_4" ...
> is_square(jac_mat)
[1] TRUE
> unique(diag(jac_mat)) != max.dist
错误: 找不到对象'max.dist'
> unique(diag(jac_mat))
[1] 1
> dist_mat <- 1 - jac_mat
>
> diag(dist_mat) <- 0
>
> stopifnot(
+ is.matrix(dist_mat),
+ nrow(dist_mat) == ncol(dist_mat), # 验证方阵
+ all(diag(dist_mat) == 0), # 验证对角线全0
+ isSymmetric(dist_mat, tol = sqrt(.Machine$double.eps)) # 验证对称性
+ )
> jac_matord <- scalop::hca_reorder(dist_mat)
错误于is_square(m) && unique(diag(m)) != max.dist:
'length = 11' in coercion to 'logical(1)'
此外: 警告信息:
In .hca_dist(x, method = dist.method, max.dist = max.dist) :
<max.dist> = 1 but <m> diagonal = 0...