华为云的linux系统ubuntu R中跑velocyto.r

华为云的linux系统ubuntu 跑velocyto.r

实战时候,只需要改动subset_data 和path

getwd()
path="/root/yll/code_test/silicosis/yll/0419"
dir.create(path,recursive = TRUE)
setwd(path)

library(Seurat)
load("macrophage_clean.rds")
as.matrix(table(Idents(subset_data), subset_data$stim))
levels(Idents(subset_data))
table(subset_data$stim)
unique(subset_data$stim)
table(Idents(subset_data))
subset_data$cluster = Idents(subset_data)
Idents(subset_data) = subset_data$stim

##	1
library(velocyto.R)
library(sccore)
dir.create(paste(path, "RNAVelocity", sep = "/"))
setwd(paste(path, "RNAVelocity", sep = "/"))
stims = data.frame(stim = unique(subset_data$stim), 
                   loom = c("/root/yll/SiO2_7d.loom", "/root/yll/SiO2_56d_2.loom",
                            "/root/yll/NS_7d.loom", "/root/yll/NS_56d_2.loom"), s1 = c(9, 12, 7, 10))
stims
for(i in 2:nrow(stims)){
  print(stims[i,"stim"])
  subset_data_stim = subset(subset_data, ident = stims[i,"stim"], invert = FALSE)
  Idents(subset_data_stim) = subset_data_stim$cluster
  ldat <- read.loom.matrices(stims[i,"loom"])##	list: spliced, unspliced, ambiguous
  emat.temp <- ldat$spliced
  colnames(emat.temp) = paste(substr(colnames(emat.temp), stims[i, "s1"], (stims[i, "s1"]+15)), i, sep = ".")
  cells = intersect(colnames(emat.temp), colnames(subset_data_stim))
  emat.temp <- emat.temp[,cells]
  nmat.temp <- ldat$unspliced
  colnames(nmat.temp) = paste(substr(colnames(nmat.temp), stims[i, "s1"], (stims[i, "s1"]+15)), i, sep = ".")
  cells = intersect(colnames(nmat.temp), colnames(subset_data_stim))
  nmat.temp <- nmat.temp[,cells]
  emat = emat.temp
  nmat = nmat.temp
  cluster.label <- Idents(subset_data_stim)
  cell.colors <- sccore::fac2col(cluster.label)
  emat <- filter.genes.by.cluster.expression(emat,cluster.label,min.max.cluster.average = 0.5)
  nmat <- filter.genes.by.cluster.expression(nmat,cluster.label,min.max.cluster.average = 0.05)
  emb <- subset_data_stim$tsne@cell.embeddings
  cell.dist <- as.dist(1-armaCor(t(emb)))
  fit.quantile <- 0.02
  rvel.cd <- gene.relative.velocity.estimates(emat,nmat,deltaT=1,kCells=20,cell.dist=cell.dist,fit.quantile=fit.quantile)
  pdf(paste("RNA_Velocity",stims[i, "stim"], "tsne.pdf", sep = "_"))
  p = show.velocity.on.embedding.cor(emb,rvel.cd,n=300,scale='sqrt',cell.colors=ac(cell.colors,alpha=0.5),cex=0.8,arrow.scale=5,show.grid.flow=TRUE,min.grid.cell.mass=0.5,grid.n=40,arrow.lwd=1,do.par=F,cell.border.alpha = 0.1)
  print(p)
  dev.off()
  emb <- subset_data_stim$umap@cell.embeddings
  cell.dist <- as.dist(1-armaCor(t(emb)))
  fit.quantile <- 0.02
  rvel.cd <- gene.relative.velocity.estimates(emat,nmat,deltaT=1,kCells=20,cell.dist=cell.dist,fit.quantile=fit.quantile)
  pdf(paste("RNA_Velocity",stims[i, "stim"], "umap.pdf", sep = "_"))
  p = show.velocity.on.embedding.cor(emb,rvel.cd,n=300,scale='sqrt',cell.colors=ac(cell.colors,alpha=0.5),cex=0.8,arrow.scale=5,show.grid.flow=TRUE,min.grid.cell.mass=0.5,grid.n=40,arrow.lwd=1,do.par=F,cell.border.alpha = 0.1)
  print(p)
  dev.off()
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

生信小博士

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值