首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >专栏 >Scissor工具常见报错及解决

Scissor工具常见报错及解决

原创
作者头像
凑齐六个字吧
修改2025-09-21 13:00:29
修改2025-09-21 13:00:29
1900
代码可运行
举报
文章被收录于专栏:转录组转录组
运行总次数:0
代码可运行

最近有小伙伴问起Scissor工具的报错,因此就再次回顾一下。目前在很多分析中都会用到Scissor法,但由于Scissor法目前没有更新还是最兼容Seurat V4版本。如果要在Seurat V5中使用时,需要注意和修改两句代码。

既往流程:Scissor算法-从含有表型的bulkRNA数据中提取信息去鉴别单细胞亚群 https://mp.weixin.qq.com/s/yUaeJKpuF1NzaD0fnhhUuQ

在Seurat V5时使用Scissor法会出现的常见报错:

1.没有提取到矩阵

2.preprocessCore::normalize.quantiles() 要求输入是一个数值型矩阵

修改Scissor代码

主要注意和修改如下两句话即可

代码语言:javascript
代码运行次数:0
运行
复制
sc_exprs <- as.matrix(sc_dataset@assays$RNA@data)
network  <- as.matrix(sc_dataset@graphs$RNA_snn)

改成

代码语言:javascript
代码运行次数:0
运行
复制
sc_exprs <- as.matrix(GetAssayData(sc_dataset, assay="RNA", layer="data"))
network <- as.matrix(sc_dataset@graphs$RNA_snn)

当然如果使用了其他整合方式的时候,也需要适时的修改assay

修改后的完整代码,全流程可以浏览既往推文
代码语言:javascript
代码运行次数:0
运行
复制
runScissor <- function (bulk_dataset, sc_dataset, phenotype, tag = NULL, alpha = NULL,
  cutoff = 0.2, family = c("gaussian", "binomial", "cox"),
  Save_file = "Scissor_inputs.RData", Load_file = NULL)
{
  library(Seurat)
  library(Matrix)
  library(preprocessCore)
  if (is.null(Load_file)) {
    common <- intersect(rownames(bulk_dataset), rownames(sc_dataset))
    if (length(common) == 0) {
      stop("There is no common genes between the given single-cell and bulk samples.")
    }
    if (class(sc_dataset) == "Seurat") {
      sc_exprs <- as.matrix(GetAssayData(sc_dataset, assay="RNA", layer="data"))
      network <- as.matrix(sc_dataset@graphs$RNA_snn)
    }
    else {
      sc_exprs <- as.matrix(sc_dataset)
      Seurat_tmp <- CreateSeuratObject(sc_dataset)
      Seurat_tmp <- FindVariableFeatures(Seurat_tmp, selection.method = "vst",
        verbose = F)
      Seurat_tmp <- ScaleData(Seurat_tmp, verbose = F)
      Seurat_tmp <- RunPCA(Seurat_tmp, features = VariableFeatures(Seurat_tmp),
        verbose = F)
      Seurat_tmp <- FindNeighbors(Seurat_tmp, dims = 1:10,
        verbose = F)
      network <- as.matrix(Seurat_tmp@graphs$RNA_snn)
    }
    diag(network) <- 0
    network[which(network != 0)] <- 1
    dataset0 <- cbind(bulk_dataset[common, ], sc_exprs[common,
      ])
    dataset1 <- normalize.quantiles(dataset0)
    rownames(dataset1) <- rownames(dataset0)
    colnames(dataset1) <- colnames(dataset0)
    Expression_bulk <- dataset1[, 1:ncol(bulk_dataset)]
    Expression_cell <- dataset1[, (ncol(bulk_dataset) +
      1):ncol(dataset1)]
    X <- cor(Expression_bulk, Expression_cell)
    quality_check <- quantile(X)
    print("|**************************************************|")
    print("Performing quality-check for the correlations")
    print("The five-number summary of correlations:")
    print(quality_check)
    print("|**************************************************|")
    if (quality_check[3] < 0.01) {
      warning("The median correlation between the single-cell and bulk samples is relatively low.")
    }
    if (family == "binomial") {
      Y <- as.numeric(phenotype)
      z <- table(Y)
      if (length(z) != length(tag)) {
        stop("The length differs between tags and phenotypes. Please check Scissor inputs and selected regression type.")
      }
      else {
        print(sprintf("Current phenotype contains %d %s and %d %s samples.",
          z[1], tag[1], z[2], tag[2]))
        print("Perform logistic regression on the given phenotypes:")
      }
    }
    if (family == "gaussian") {
      Y <- as.numeric(phenotype)
      z <- table(Y)
      if (length(z) != length(tag)) {
        stop("The length differs between tags and phenotypes. Please check Scissor inputs and selected regression type.")
      }
      else {
        tmp <- paste(z, tag)
        print(paste0("Current phenotype contains ",
          paste(tmp[1:(length(z) - 1)], collapse = ", "),
          ", and ", tmp[length(z)], " samples."))
        print("Perform linear regression on the given phenotypes:")
      }
    }
    if (family == "cox") {
      Y <- as.matrix(phenotype)
      if (ncol(Y) != 2) {
        stop("The size of survival data is wrong. Please check Scissor inputs and selected regression type.")
      }
      else {
        print("Perform cox regression on the given clinical outcomes:")
      }
    }
    save(X, Y, network, Expression_bulk, Expression_cell,
      file = Save_file)
  }
  else {
    load(Load_file)
  }
  if (is.null(alpha)) {
    alpha <- c(0.005, 0.01, 0.05, 0.1, 0.2, 0.3, 0.4, 0.5,
      0.6, 0.7, 0.8, 0.9)
  }
  for (i in 1:length(alpha)) {
    set.seed(123)
    fit0 <- APML1(X, Y, family = family, penalty = "Net",
      alpha = alpha[i], Omega = network, nlambda = 100,
      nfolds = min(10, nrow(X)))
    fit1 <- APML1(X, Y, family = family, penalty = "Net",
      alpha = alpha[i], Omega = network, lambda = fit0$lambda.min)
    if (family == "binomial") {
      Coefs <- as.numeric(fit1$Beta[2:(ncol(X) + 1)])
    }
    else {
      Coefs <- as.numeric(fit1$Beta)
    }
    Cell1 <- colnames(X)[which(Coefs > 0)]
    Cell2 <- colnames(X)[which(Coefs < 0)]
    percentage <- (length(Cell1) + length(Cell2))/ncol(X)
    print(sprintf("alpha = %s", alpha[i]))
    print(sprintf("Scissor identified %d Scissor+ cells and %d Scissor- cells.",
      length(Cell1), length(Cell2)))
    print(sprintf("The percentage of selected cell is: %s%%",
      formatC(percentage * 100, format = "f", digits = 3)))
    if (percentage < cutoff) {
      break
    }
    cat("\n")
  }
  print("|**************************************************|")
  return(list(para = list(alpha = alpha[i], lambda = fit0$lambda.min,
    family = family), Coefs = Coefs, Scissor_pos = Cell1,
    Scissor_neg = Cell2))
}
参考资料:
  1. Scissor: https://github.com/sunduanchen/Scissor

:若对内容有疑惑或者有发现明确错误的朋友,请联系后台。更多相关内容可关注公众号:生信方舟

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 在Seurat V5时使用Scissor法会出现的常见报错:
    • 修改Scissor代码
      • 修改后的完整代码,全流程可以浏览既往推文
  • 参考资料:
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档