单细胞转录组和空间转录组的有些操作是基于@p,@x,@i这几个slot进行计算的。
而这几个slot并不是来自于seurat或其他单细胞对象的,
而是由Matrix包的稀疏矩阵dgCMatrix对象所携带的。
所以这几个slot的具体含义是什么呢
Matrix的官方文档给予了说法
```
i:
Object of class "integer" of length nnzero (number of non-zero elements). These are the 0-based row numbers for each non-zero element in the matrix, i.e., i must be in 0:(nrow(.)-1).
p:
integer vector for providing pointers, one for each column, to the initial (zero-based) index of elements in the column. .@p is of length ncol(.) + 1, with p[1] == 0 and p[length(p)] == nnzero, such that in fact, diff(.@p) are the number of non-zero elements for each column.
In other words, m@p[1:ncol(m)] contains the indices of those elements in m@x that are the first elements in the respective column of m.
x:
Object of class "numeric" - the non-zero elements of the matrix
````
但是觉得挺不讲人话
所以用通俗语言解释
@x 是把稀疏矩阵中所有的非零元素的值一一写出来(是按矩阵列的方向)
@i 是稀疏矩阵中所有非零元素的行索引值,也就是所有非零元素的行号
所以i的个数和x的个数是一样的多的。
但是这种索引类似Python,以0为起始
(是按矩阵列的方向)
@p 比较复杂,是一种计数累加
第一项是0,
第二项是原稀疏矩阵第一列的非零元素数目,
第三项是原稀疏矩阵第一列到第二列的非零元素数目之和,
第四项是原稀疏矩阵第一列到第三列的非零元素数目之和
后面每一项依次
(注意不是非零元素值之和)
(所以相数等于矩阵列数+1)
那如果想求每一列的元素数目呢,
用diff(.@p)函数
所以综上
@x是稀疏矩阵里元素的具体值
@p是元素的列信息
@i是元素的行信息
通过三者即可确定每一个元素,还原矩阵。