SingleCellExperiment类使用
SingleCellExperience类用于表示单细胞测序数据。它继承自RangedSummarizedExperiment类,并以相同的方式使用。此外,该类还支持通过reducedDims存储降维结果(如PCA、t-SNE),并通过altExps存储替代特征类型(如spike-ins)。
Usage
SingleCellExperiment(...,reducedDims = list(),altExps = list(),rowPairs = list(),colPairs = list(),mainExpName = NULL )
1. 生成SingleCellExperiment对象
# if (!requireNamespace("BiocManager", quietly = TRUE))
# install.packages("BiocManager")
#
# BiocManager::install("SingleCellExperiment")library("SingleCellExperiment")
ls("package:SingleCellExperiment")
# 只有表达矩阵
counts <- matrix(rpois(100, lambda = 10), ncol=10, nrow=10)
sce <- SingleCellExperiment(counts)
sce <- SingleCellExperiment(list(counts=counts))# 含有降纬数据
ncells <- 100
u <- matrix(rpois(20000, 5), ncol=ncells)
v <- log2(u + 1)pca <- matrix(runif(ncells*5), ncells)
tsne <- matrix(rnorm(ncells*2), ncells)sce <- SingleCellExperiment(assays=list(counts=u, logcounts=v),reducedDims=SimpleList(PCA=pca, tSNE=tsne))# 有SummarizedExperiment对象转化生成
se <- SummarizedExperiment(assays=list(counts=u, logcounts=v))
as(se, "SingleCellExperiment")# 含有colData,rowData 以及metadata
pretend.cell.labels <- sample(letters, ncol(counts), replace=TRUE)
pretend.gene.lengths <- sample(10000, nrow(counts))sce <- SingleCellExperiment(list(counts=counts),colData=DataFrame(label=pretend.cell.labels),rowData=DataFrame(length=pretend.gene.lengths),metadata=list(study="GSE111111"))
2. 提取行列信息,表达矩阵等
library(scRNAseq)
sce <- ReprocessedAllenData("tophat_counts")
# 行:特征,列:单细胞名
dim(assay(sce))
dim(sce)
# 表达矩阵
assay(sce,1)
assays(sce)[[1]]
colnames(colData(sce))
rownames(rowData(sce))
# 元数据
metadata(sce)# Alternative Experiment methods
altExpNames(sce)
altExp(sce, "ERCC")
altExp(sce, 1)
assay(altExp(sce, "ERCC"))
3. 取子集
library(scRNAseq)
sce <- MuraroPancreasData()sce[1:2,1:3]
sce["A1BG__chr19",]
sce[,c("D28-1_1", "D28-1_2")]# 也可以根据rowData(sce)以及colData(sce)进行选择
# 如果有NA,要去除
sce[,sce$donore=="D28"]
4. 其他
library(scRNAseq)
sce <- ReprocessedAllenData("tophat_counts")## 1. 增加logcounts数据 norm + log
counts <- assay(sce, "tophat_counts")
libsizes <- colSums(counts)
size.factors <- libsizes/mean(libsizes)
logcounts(sce) <- log2(t(t(counts)/size.factors) + 1)
assayNames(sce)## 2. 获得logcounts 表达谱数据 matrix
assay(sce, "logcounts")
logcounts(sce)## 3. 增加PCA,TSNE数据
pca_data <- prcomp(t(logcounts(sce)), rank=50)
library(Rtsne)
set.seed(5252)
tsne_data <- Rtsne(pca_data$x[,1:50], pca = FALSE)
reducedDims(sce) <- list(PCA=pca_data$x, TSNE=tsne_data$Y)
sce## 4. getting降纬数据
educedDim(sce, "PCA")
reducedDim(sce, "tSNE")## 5. 增加Alternative Experiment 数据
## ----options, include=FALSE, echo=FALSE---------------------------------------
library(BiocStyle)
knitr::opts_chunk$set(warning=FALSE, error=FALSE, message=FALSE)library(SingleCellExperiment)
counts <- matrix(rpois(100, lambda = 10), ncol=10, nrow=10)
sce <- SingleCellExperiment(counts)
# the same columns
altExp(sce, "Spike") <- SingleCellExperiment(matrix(rpois(20, lambda = 5), ncol=10, nrow=2))
altExp(sce, "Protein") <- SingleCellExperiment(matrix(rpois(50, lambda = 100), ncol=10, nrow=5))
altExp(sce, "CRISPR") <- SingleCellExperiment(matrix(rbinom(80, p=0.1, 1), ncol=10, nrow=8))sce## 6. 函数操作
## -----------------------------------------------------------------------------
totalCount <- function(x, i=1, multiplier=1, subset.row=NULL) {mat <- assay(x, i)if (!is.null(subset.row)) {mat <- mat[subset.row,,drop=FALSE]}colSums(mat) * multiplier
}## -----------------------------------------------------------------------------
totals <- applySCE(sce, FUN=totalCount)
totals## -----------------------------------------------------------------------------
totals.manual <- list( totalCount(sce),Spike=totalCount(altExp(sce, "Spike")),Protein=totalCount(altExp(sce, "Protein")),CRISPR=totalCount(altExp(sce, "CRISPR"))
)
stopifnot(identical(totals, totals.manual))## -----------------------------------------------------------------------------
totals10.manual <- list( totalCount(sce, multiplier=10),Spike=totalCount(altExp(sce, "Spike"), multiplier=10),Protein=totalCount(altExp(sce, "Protein"), multiplier=10),CRISPR=totalCount(altExp(sce, "CRISPR"), multiplier=10)
)## -----------------------------------------------------------------------------
totals10.apply <- applySCE(sce, FUN=totalCount, multiplier=10)
stopifnot(identical(totals10.apply, totals10.manual))## -----------------------------------------------------------------------------
totals10.lapply <- lapply(c(List(sce), altExps(sce)),FUN=totalCount, multiplier=10)
stopifnot(identical(totals10.apply, totals10.lapply))## -----------------------------------------------------------------------------
totals.custom <- applySCE(sce, FUN=totalCount, multiplier=10, ALT.ARGS=list(Spike=list(subset.row=2), Protein=list(subset.row=3:5)))
totals.custom## -----------------------------------------------------------------------------
head.sce <- applySCE(sce, FUN=head, n=5)
head.sce## -----------------------------------------------------------------------------
altExp(head.sce)
altExp(head.sce, "Protein")
altExp(head.sce, "CRISPR")## -----------------------------------------------------------------------------
head.sce.list <- applySCE(sce, FUN=head, n=5, SIMPLIFY=FALSE)
head.sce.list## -----------------------------------------------------------------------------
manual.head <- head(sce, n=5)
altExp(manual.head, "Spike") <- head(altExp(sce, "Spike"), n=5)
altExp(manual.head, "Protein") <- head(altExp(sce, "Protein"), n=5)
altExp(manual.head, "CRISPR") <- head(altExp(sce, "CRISPR"), n=5)
manual.head
SingleCellExperiment类使用相关推荐
- 如何使用Bioconductor进行单细胞分析?
最近的技术进步使得能够在单个细胞中分析全基因组特征.但是,单细胞数据为分析提出了独特的挑战,需要开发专用的方法和数据架构才能成功解析数据背后的生物问题.Bioconductor项目托管了社区开发的开源 ...
- splatter包生成单细胞RNA测序数据
Splatter是一个模拟单细胞RNA测序计数数据的软件包.它提供了一个简单的界面,用于创建可复制且文档充分的复杂模拟.可以从真实数据估计参数,并提供用于比较真实数据集和模拟数据集的函数. # if ...
- SCS【7】单细胞转录组之轨迹分析 (Monocle 3) 聚类、分类和计数细胞
点击关注,桓峰基因 桓峰基因公众号推出单细胞系列教程,有需要生信分析的老师可以联系我们!首选看下转录分析教程整理如下: Topic 6. 克隆进化之 Canopy Topic 7. 克隆进化之 Car ...
- 自己搜集编写的Delphi 通用函数
{ ********************************************************************** } { Currency Common Functio ...
- 继承WebMvcConfigurer 和 WebMvcConfigurerAdapter类依然CORS报错? springboot 两种方式稳定解决跨域问题
继承WebMvcConfigurer 和 WebMvcConfigurerAdapter类依然CORS报错???springboot 两种方式稳定解决跨域问题! 之前我写了一篇文章,来解决CORS报错 ...
- MybatisPlus忽略实体类中的非数据库字段、JPA忽略实体类中的非数据库字段、HeHibernate忽略实体类中的非数据库字段
mybatis plus忽略映射字段时可以在实体类属性上使用以下注解: @TableField(exist = false):表示该属性不为数据库表字段,但又是必须使用的. @TableField(e ...
- IDEA中根据数据库自动生成实体类,并自定义所生成的实体类中的注解 @Table @Id @...
使用IDEA项目添加Hibernate扩展,生成实体类并配置实体类中的注解 一.使用Hibernate自动生成实体类 1.在项目上右键,选择Add Framework Support找到 Hibern ...
- IDEA自动生成类注解,IDEA作者信息自动生成,IDEA类信息自动生成
在新建类文件的时候自动生成注解,诸如我们常见的那些 作者,创建时间,TODO 等等 将以下格式的代码放在Settings -> File and Code Templates -> Inc ...
- javabean实体类与实体类之间的快速转换
一.Dozer是什么? dozer是一个能把实体和实体之间进行转换的工具.只要建立好映射关系.就像是ORM的数据库和实体映射一样. 使用方法示例如下: // article(PO) -> art ...
最新文章
- 等待Ajax结果 再提交表单(ajax同步)
- Exchange2010配置实验(七)DAG配置实验
- Apdex(Application Performance Index)量化应用性能
- CommandLineRunner 和 ApplicationRunner 的区别
- python爬虫之js链接跳转抓取_Python爬虫获取页面所有URL链接过程详解
- java properties $,如何引用java.util.Properties中的另一个属性?
- is_null,is_numeric
- 一个本科毕业生的Java学习之路
- ca系统包括ca服务器,ca认证中心有哪些组成部分
- 自研返利网源码、有需要的私信
- 蓝桥杯练习 小明上楼梯(递归设计)
- 天地波超视距雷达在远洋无人航运中的运用
- 【Ruby】can‘t modify frozen string
- 传奇GOM引擎-GEE引擎版本如何添加GM账号刷装备
- 分布式搜索引擎ElasticSearch(二)---ElasticSearch进阶使用教程
- 【转】从EDA使用角度捋一遍芯片设计流程
- 2016年度中国软件开发者白皮书正式发布(附全文下载)
- webstorm解决git冲突
- 避免踩坑之公网域名之实名认证
- 利用热门关键词截流变现,闷声发大财