在Snakemake中插入运行Rscript的问题

问题描述 投票:0回答:0

我写了一个包含 Rscript 的 snakemake 用于绘图,比如:

rule R_drawing:
    input:
        "XXX.tsv"
    output:
        "XXX.pdf"
    script:
        "./Tail.R"

Rscript 使用ggplot2 绘图并使用ggsave 保存pdf。 (我把情节保存为变体,所以在屏幕上绘图没有问题)

当我在 shell R 中输入我的 R 代码时,它运行良好并在 1 分钟内完成。 但是当我运行snakemake时,它显示虽然有'library'信息和ggplot信息我在shell print in screen中也遇到过,但花费了很多时间(感觉它卡在了一些步骤)。 最后花了 2 个小时,输出的图看起来很奇怪:它的尺寸比正常的大很多,而且情节似乎有些图已经被绘制了很多次。 我怀疑这可能是多CPU的错误,但是当我更改

-c1
时,问题仍然存在。

SO希望各位朋友多多指教,谢谢!

举个例子:

蛇形:

rule polyA_results:
    input:
        "./{example}/analysis/polyA_estimate/header.tsv",
        "./{example}/analysis/polyA_estimate/polya_results.pass_only.tsv"
    output:
        "./{example}/analysis/polyA_estimate/polyA_estimate.tsv"
    shell:
        "cat {input[0]} {input[1]} > {output}"

rule R_drawing:
    input:
        "./{example}/analysis/polyA_estimate/polyA_estimate.tsv"
    output:
        "./{example}/analysis/polyA_estimate/polyA_estimate.pdf"
    script:
        "./Tail.R"

Rscript

library(ggplot2)
library(hrbrthemes)
library(viridis)
library(cowplot)
library(showtext)
font_add('Arial','/usr/share/fonts/LiberationSans-Regular.ttf')
showtext_auto() 

percontig <- read.csv(snakemake@input[[1]],sep = "\t",header = F)
contigsummary <- aggregate(percontig$V9,by=list(type=percontig$V2),mean)
contigsummary$y <- c("plus")


p1 <- ggplot(contigsummary) +
  geom_violin(mapping = aes(x=contigsummary$y,y=contigsummary$x),width=0.6,fill="#5A005A") + 
  geom_boxplot(mapping=aes(x=contigsummary$y,y=contigsummary$x), color="grey",width=0.1, alpha=0.2) +
  scale_fill_viridis(discrete = TRUE) +
  theme_ipsum() +
  theme(
    legend.position="none",
    plot.title = element_text(size=16,hjust = 0.5),
    axis.text.y = element_text(size = 10, family = "myFont", vjust = 0.5, hjust = 0.5),
    axis.title.y = element_text(size=13, face="plain" , vjust = 10.2, hjust = 0.5),
    axis.title.x = element_text(size=13, face="plain" ,  hjust = 0.5),
    panel.border = element_blank(),
    axis.line = element_line(size=1, colour = "black")
  ) +
  ggtitle("Poly(A) Length of Reads") +
  theme(axis.text.x = element_blank()) +
  xlab("Reads") +
  ylab("Poly(A) Length (nt)")



p2 <- ggplot(percontig) + 
  geom_violin(mapping = aes(x=percontig$V10,y=percontig$V9),width=0.6,fill="#316397")+
  geom_boxplot(mapping=aes(x=percontig$V10,y=percontig$V9), color="grey",width=0.1, alpha=0.2) +
  scale_fill_viridis(discrete = TRUE) +
  theme_ipsum() +
  theme(
    legend.position="none",
    plot.title = element_text(size=16,hjust = 0.5),
    axis.text.y = element_text(size = 10, family = "myFont", vjust = 0.5, hjust = 0.5),
    axis.title.y = element_text(size=13, face="plain" , vjust = 10.2, hjust = 0.5),
    axis.title.x = element_text(size=13, face="plain" , hjust = 0.5),
    panel.border = element_blank(),
    axis.line = element_line(size=1, colour = "black")
  ) +
  ggtitle("Poly(A) Length of Contigs") +
  theme(axis.text.x = element_blank()) +
  xlab("Contigs") +
  ylab("Poly(A) Length (nt)")

p3 <- cowplot::plot_grid(p1, p2, ncol = 2,labels = LETTERS[1:2])

ggsave(snakemake@output[[1]],p3,width = 20, height = 20)
snakemake rscript
© www.soinside.com 2019 - 2024. All rights reserved.