多分组venn图绘制脚本

绘制多分组venn图时发现好多包都不支持,只能用原始的包,脚本如下 #!/share/work/biosoft/R/latest/bin/Rscriptargs <- commandArgs(trailingOnly = TRUE)library(venn)library(VennDiagra...

绘制多分组venn图时发现好多包都不支持,只能用原始的包,脚本如下

#!/share/work/biosoft/R/latest/bin/Rscript
args <- commandArgs(trailingOnly = TRUE)

library(venn)
library(VennDiagram)
library(purrr)

# 读取命令行参数
input_file <- args[1]
output_prefix <- args[2]

# 读取数据文件, 不转换列名
venn_dat <- read.delim(input_file, check.names = FALSE)

# 从文件中创建一个列表
venn_list <- list(venn_dat[, 1], venn_dat[, 2], venn_dat[, 3], venn_dat[, 4], venn_dat[, 5], venn_dat[, 6])

# 把列名赋值给列表的key值
names(venn_list) <- colnames(venn_dat[1:6])

# 删除列表中每个向量中的NA
venn_list <- purrr::map(venn_list, na.omit)

# 创建png设备
png(paste0(output_prefix, "_venn.png"), h = 3000, w = 3000, res = 300)

# 作图
venn(venn_list, zcolor = "style", opacity = 0.3, box = F, ilcs = 0.5, sncs = 1)

# 关闭png设备
dev.off()

# 创建pdf设备
pdf(paste0(output_prefix, "_venn.pdf"), h = 10, w = 10)

# 作图
venn(venn_list, zcolor = "style", opacity = 0.3, box = F, ilcs = 0.5, sncs = 1)

# 关闭pdf设备
dev.off()

# 导出结果
inter <- get.venn.partitions(venn_list)
for (i in 1:nrow(inter)) inter[i, "values"] <- paste(inter[[i, "..values.."]], collapse = "|")
inter <- subset(inter, select = -..values..)
inter <- subset(inter, select = -..set..)
write.table(inter, paste0(output_prefix, "_result.csv"), row.names = FALSE, sep = ",", quote = FALSE)

我的数据是6组,一列一组,,列名为组名,修改成这样就可以直接用
  • 发表于 2023-05-30 18:05
  • 阅读 ( 914 )
  • 分类:科研作图

你可能感兴趣的文章

相关问题

0 条评论

请先 登录 后评论
xun
xun

电路元件工程师

76 篇文章

作家榜 »

  1. omicsgene 691 文章
  2. 安生水 340 文章
  3. Daitoue 167 文章
  4. 生物女学霸 120 文章
  5. 红橙子 78 文章
  6. xun 76 文章
  7. rzx 74 文章
  8. CORNERSTONE 72 文章