在使用 Snakemake 变量在 R 脚本中时出错。

huangapple go评论105阅读模式
英文:

Error when using Snakemake variable in R script

问题

The issue you're encountering is related to how you're trying to access the elements of the snakemake object in your R script. It seems like you're using HTML-encoded characters like " instead of the actual double quotes ".

To fix this, you should use double quotes directly when accessing elements of the snakemake object. For example:

Instead of:

  1. save(dds, snakemake@output[[2]])

Use:

  1. save(dds, snakemake@output[[2]])

Make sure you replace all instances of " with actual double quotes " in your R script where you access elements of the snakemake object. This should resolve the "object not found" error you're encountering.

英文:

I have got the following Snakemake rule:

  1. rule deseq2:
  2. input:
  3. salmon=expand("salmon/{sample}/quant.sf", sample=SAMPLES)
  4. output:
  5. xlsx="deseq2/deseq2_diff_trx.xlsx",
  6. rdata="deseq2/dds.Rdata",
  7. params:
  8. map_with,
  9. genome,
  10. gtf,
  11. log:
  12. "logs/deseq2/deseq2.log"
  13. conda:
  14. "envs/deseq2.yml"
  15. threads: config["resources"]["deseq2"]["cpu"]
  16. resources:
  17. runtime=config["resources"]["deseq2"]["time"]
  18. script:
  19. "scripts/deseq2.R"

The part of that R script that the rule runs that gives an error is when I save a variable to a file name in the output section of the snakemake variable:

  1. save(dds, snakemake@output[[2]])
  1. Error in save(dds, snakemake@output[[2]]) :
  2. object snakemake@output[[2]]’ not found

Earlier in the script I access the params part of the snakemake variable in a similar way, but without any errors:

  1. map.with <- snakemake@params[[1]]
  2. genome <- snakemake@params[[2]]
  3. gtf <- snakemake@params[[3]]

When I print the snakemake variable I get this (only partial,relevant output):

  1. An object of class "Snakemake"
  2. Slot "input":
  3. [[1]]
  4. [1] "salmon/Control-1/quant.sf"
  5. [[2]]
  6. [1] "salmon/Control-2/quant.sf"
  7. [[3]]
  8. [1] "salmon/Control-Hypoxia-1/quant.sf"
  9. [[4]]
  10. [1] "salmon/Control-Hypoxia-2/quant.sf"
  11. $salmon
  12. [1] "salmon/Control-1/quant.sf" "salmon/Control-2/quant.sf"
  13. [3] "salmon/Control-Hypoxia-1/quant.sf" "salmon/Control-Hypoxia-2/quant.sf"
  14. Slot "output":
  15. [[1]]
  16. [1] "deseq2/deseq2_diff_trx.xlsx"
  17. [[2]]
  18. [1] "deseq2/dds.Rdata"
  19. $xlsx
  20. [1] "deseq2/deseq2_diff_trx.xlsx"
  21. $rdata
  22. [1] "deseq2/dds.Rdata"
  23. Slot "params":
  24. [[1]]
  25. [1] "salmon"
  26. [[2]]
  27. [1] "hg38"
  28. [[3]]
  29. [1] "/home/user/Documents/references/gtf/hg38/gencode.v43.annotation.gtf"

I have also saved the work space to a file for debugging as suggest by the snakemake web site. When I load this into R I can do the following things:

  1. > snakemake@output[["rdata"]]
  2. [1] "deseq2/dds.Rdata"
  3. > snakemake@output[[2]]
  4. [1] "deseq2/dds.Rdata"

But when the above code is include in the proper script I get the object not found (see above) error.

What am I doing wrong?

答案1

得分: 1

  1. 未经测试,但我认为您想要的是:

save(dds, file = snakemake@output[[2]])

  1. 在您的代码中,`snakemake@output[[2]]` 出现为要保存的对象,而不是要保存到的文件。从`?save` 中相关的部分应该是:

用法:

  1. save(..., list = character(),
  2. file = stop("必须指定 'file'"),
  3. ascii = FALSE, version = NULL, envir = parent.frame(),
  4. compress = isTRUE(!ascii), compression_level,
  5. eval.promises = TRUE, precheck = TRUE)
  6. save.image(file = ".RData", version = NULL, ascii = FALSE,
  7. compress = !ascii, safe = TRUE)

参数:

  1. ...: 要保存的对象的名称(作为符号或字符字符串)。
  2. list: 包含要保存的对象名称的字符向量。
  3. file: 一个可写的二进制模式连接或要保存数据的文件的名称(进行波浪线扩展时)。必须是 'save.image' 'version = 1' 的文件名。
  1. <details>
  2. <summary>英文:</summary>
  3. Not tested, but I think you want:

save(dds, file = snakemake@output[[2]])

  1. In your code, `snakemake@output[[2]]` appears as an object to be saved, not as the file to save to. The relevant bit from `?save` should be:

Usage:

  1. save(..., list = character(),
  2. file = stop(&quot;&#39;file&#39; must be specified&quot;),
  3. ascii = FALSE, version = NULL, envir = parent.frame(),
  4. compress = isTRUE(!ascii), compression_level,
  5. eval.promises = TRUE, precheck = TRUE)
  6. save.image(file = &quot;.RData&quot;, version = NULL, ascii = FALSE,
  7. compress = !ascii, safe = TRUE)

Arguments:

  1. ...: the names of the objects to be saved (as symbols or character
  2. strings).
  3. list: A character vector containing the names of objects to be
  4. saved.
  5. file: a (writable binary-mode) connection or the name of the file
  6. where the data will be saved (when tilde expansion is done).
  7. Must be a file name for save.image or version = 1’.
  1. </details>

huangapple
  • 本文由 发表于 2023年6月26日 15:49:30
  • 转载请务必保留本文链接:https://go.coder-hub.com/76554595.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定