singler-一-参考数据集的构建方法.md 3.6 KB


title: SingleR (一) 参考数据集的构建方法 tags: [] id: '656' categories:

  • - Seurat教程
  • - 生物信息学 date: 2021-09-20 00:36:50 ---

第一步 下载所需的参考数据集

第二步 读入下载的参考数据集与注释

  • 读入 Human M1 10x

    ref_meta <- read.csv("/home/rqzhang/zlliu/R_data/human_M1_10x/metadata.csv")
    ref_counts <- read.csv("/home/rqzhang/zlliu/R_data/human_M1_10x/matrix.csv")
    

  • 读入 Human Multiple Cortical Areas SMART-seq

    ref2_meta <- read.csv("/home/rqzhang/zlliu/R_data/Human_Multiple_Cortical_Areas_SMART-seq/metadata.csv")
    ref2_counts <- read.csv("/home/rqzhang/zlliu/R_data/Human_Multiple_Cortical_Areas_SMART-seq/matrix.csv")
    

第三步 转置矩阵

now_t <- Sys.time ()
ref_t_counts <- t(ref_counts) #超级慢,15分钟,似乎没有其他解决方案
Sys.time () - now_t

now_t <- Sys.time ()
ref2_t_counts <- t(ref2_counts) #超级慢,10分钟,似乎没有其他解决方案
Sys.time () - now_t

ref_d_counts <- data.frame(ref_t_counts[-1,], stringsAsFactors = F)
ref2_d_counts <- data.frame(ref2_t_counts[-1,], stringsAsFactors = F)

colnames(ref_d_counts) <- ref_t_counts[1,]
colnames(ref2_d_counts) <- ref2_t_counts[1,]

ref_d_counts <- as.data.frame(lapply(ref_d_counts, as.integer))
ref2_d_counts <- as.data.frame(lapply(ref2_d_counts, as.integer))

第四步 加载程辑包并计算SummarizedExperiment

library(SummarizedExperiment)
library(scater)

ref_d_counts <- SummarizedExperiment(assays=list(counts=ref_d_counts))
ref2_d_counts <- SummarizedExperiment(assays=list(counts=ref2_d_counts))

ref_d_counts <- logNormCounts(ref_d_counts)
ref2_d_counts <- logNormCounts(ref2_d_counts)

第五步 与metadata一起保存

ref_d_counts$meta <- ref_meta
ref2_d_counts$meta <- ref2_meta