r - linux集群上Rscript中的R getopt包返回错误
问题描述
我已经共享了一个 Rscript 以在 linux 集群上运行,这是我以前从未做过的事情(现在由于 covid 限制,没有人可以调试它)。该脚本以 R getopt 包开头,矩阵下方似乎是一个 if 选项:
library("getopt")
optspec <- matrix(c(
'reads', 'r', 1, 'character', '/path/to/fastq/reads/',
'out_dir', 'o', 1, 'character', 'Path to output directory',
'aggregate', 'a', 0, 'logical', 'Produce aggregated plots',
'help', 'h', 0, 'logical', 'Display help'
),byrow=TRUE,ncol=5)
opt <- getopt(optspec)
if (!is.null(opt$help)) {
cat(getopt(optspec,usage=TRUE))
q(status=1)
}
if (is.null(opt$reads)) {
cat("Error: no reads argument provconda ided\n")
cat(getopt(optspec,usage=TRUE))
q(status=1)
}
if (is.null(opt$out_dir)) {
cat("Error: no out_dir argument provided\n")
cat(getopt(optspec,usage=TRUE))
q(status=1)
}
aggregate=FALSE
if (!is.null(opt$aggregate)) {
aggregate=TRUE
}
我在集群生成的输出文件中返回的错误始终是:
错误:没有读取参数 provconda ided
这就是为什么我一直专注于代码行
'reads', 'r', 1, 'character', '/path/to/fastq/reads/',
我尝试过以各种方式编辑 fastq 文件的路径(脚本最初说“读取”、“r”、1、“字符”、“输入目录的路径”)我已经看到 R 和 linux 中显示的文件路径(引用标记,开始时没有 /,用 . 等替换路径)但仍然得到相同的错误,所以我现在不知道是什么原因造成的。我确定它很容易我错过/不理解,但我无法发现我哪里出错了。
脚本以
#!/usr/bin/env Rscript
#$ -j y
#$ -cwd
并且是我的 cwd 中的 qsubbed,这是我需要分析的 fastq 文件所在的位置。我在集群上的 dada2 环境中运行,因为这是序列分析协议的一部分。谢谢你提供的所有帮助。
解决方案
上面的代码不是设置脚本需要的选项的地方。参数需要从命令行传入。
而不是运行脚本使用my_script_name
您需要使用my_script_name -r /path/to/fastq/reads
或my_scrip_name --reads /path/to/fastq/reads
您显示的代码是脚本学习接受哪些选项以及必须设置哪些选项的地方。不要编辑这些。
作为一个例子
'读取','r',1,'字符','/path/to/fastq/reads/'
前两个条目是选项名称的长短形式(读取或 r),“r”后面的 1 表示此选项后面需要一个字符类型的参数,每行的最后一个条目是帮助消息。
上面代码中的 if 语句意味着如果你不给 -r(或 --reads)和 -o(或 --out_dir),脚本将打印帮助消息(你也可以通过调用脚本来获得-h 作为选项)。q(status=1) 是导致脚本不做任何事情而返回的原因。
-a (或 --aggragate)是可选的,默认为 FALSE 。如果通过在命令行末尾添加“-a”来为脚本提供此选项,那么它将以某种方式更改绘图样式,而您显示的代码并未显示。
推荐阅读
- sql - 如何获取Oracle中所有表的所有列名?
- c++ - 填充二叉树
- c++ - C/C++:静态 const 与 .h/.hpp 中的简单 const
- javascript - Nuxt.js – 在整个项目中使用文档的脚本
- arduino - 串行通信 Arduino 到 NodeMcu
- mongodb - 查询 mongo 集合作为对象(不是数组)
- c# - 如何使用 sql 在引导程序中填充下拉列表
- typescript - 为什么 d.ts 文件在导入不存在的变量/类型时不会抛出错误?
- flutter - 如何显示像弹出窗口这样的小部件
- oracle - ORACLE SQL 开发人员计划作业