在 snakemake R 脚本中循环遍历列表的问题
problem with loop through a list in snakemake R script
我尝试在 snakemake 规则中循环遍历 R 脚本中的列表,如下面的 snakefile,但出现错误。
from snakemake.utils import R
rule test:
run:
R("""
print("hello!")
a = c(1, 2, 3)
for (i in a)
{
print(i)
}
""")
这是错误。
RuleException:
NameError in line 12 of Snakefile:
The name '\n print(i)\n' is unknown in this context. Please make sure that you defined that variable. Also note that braces not used for variable access have to be escaped by repeating them, i.e. {{print }}
File "Snakefile", line 12, in __rule_test
File "~/miniconda/envs/py36/lib/python3.6/concurrent/futures/thread.py", line 56, in run
Exiting because a job execution failed. Look above for error message
Shutting down, this might take some time.
当我直接在 R 中 运行 时,代码没有给出任何错误。任何人都知道哪里出了问题?谢谢
{
和}
用于在snakemake中调用变量,即使在run
命令中也是如此。
您必须将它们加倍才能逃脱它们。
错误消息是信息性的:
The name '\n print(i)\n' is unknown in this context. Please make
sure that you defined that variable. Also note that braces not used
for variable access have to be escaped by repeating them, i.e. {{print
}}
所以你的代码应该是这样的:
from snakemake.utils import R
rule test:
run:
R("""
print("hello!")
a = c(1, 2, 3)
for (i in a)
{{
print(i)
}}
""")
我尝试在 snakemake 规则中循环遍历 R 脚本中的列表,如下面的 snakefile,但出现错误。
from snakemake.utils import R
rule test:
run:
R("""
print("hello!")
a = c(1, 2, 3)
for (i in a)
{
print(i)
}
""")
这是错误。
RuleException:
NameError in line 12 of Snakefile:
The name '\n print(i)\n' is unknown in this context. Please make sure that you defined that variable. Also note that braces not used for variable access have to be escaped by repeating them, i.e. {{print }}
File "Snakefile", line 12, in __rule_test
File "~/miniconda/envs/py36/lib/python3.6/concurrent/futures/thread.py", line 56, in run
Exiting because a job execution failed. Look above for error message
Shutting down, this might take some time.
当我直接在 R 中 运行 时,代码没有给出任何错误。任何人都知道哪里出了问题?谢谢
{
和}
用于在snakemake中调用变量,即使在run
命令中也是如此。
您必须将它们加倍才能逃脱它们。
错误消息是信息性的:
The name '\n print(i)\n' is unknown in this context. Please make sure that you defined that variable. Also note that braces not used for variable access have to be escaped by repeating them, i.e. {{print }}
所以你的代码应该是这样的:
from snakemake.utils import R
rule test:
run:
R("""
print("hello!")
a = c(1, 2, 3)
for (i in a)
{{
print(i)
}}
""")