python - 单独调用规则的变量并为特定规则添加独立环境
问题描述
我需要在集群中运行一个snakemake规则,因此对于某些规则,我需要一些工具和库来加载,而这些工具是独立/专有于其他规则的。在这种情况下,我如何在我的蛇形规则中指定这些。例如,由于rule score
我需要module load r/3.5.1
并且export R_lib =/user/tools/software
目前,我在运行 snakemake 之前在命令行中分别运行这些行。但是,如果有办法在规则范围内做到这一点,那就太好了env
。
- 问题,
我有如下规则,
rule score:
input:
count=os.path.join(config['general']['paths']['outdir'], 'count_expression', '{sample}.tsv'),
libsize=os.path.join(config['general']['paths']['outdir'], 'count_expression', '{sample}.size_tsv')
params:
result_dir=os.path.join(config['general']['paths']['outdir'], 'score'),
cancertype=config['general']['paths']['cancertype'],
sample_id=expand('{sample}',sample=samples['sample'].unique())
output:
files=os.path.join(config['general']['paths']['outdir'], 'score', '{sample}_bg_scores.tsv', '{sample}_tp_scores.tsv')
shell:
'mkdir -p {params.result_dir};Rscript {config[general][paths][tool]} {params.result_dir} {params.cancertype} {params.sample_id} {input.count} {input.libsize}'
我对上述代码片段的实际行为是:
shell:
mkdir -p /cluster/user/snakemake_test/results_april30/score;Rscript /cluster/home/user/Projects/R_scripts/scoretool.R /cluster/user/snakemake_test/results_april30/score DMC GNMS4 MRT5T /cluster/projects/test/results/exp/MRT5T.tsv /cluster/projects/test/results/Exp/MRT5T.size.tsv
而预期的行为是:
shell:
mkdir -p /cluster/user/snakemake_test/results_april30/score;Rscript /cluster/home/user/Projects/R_scripts/scoretool.R /cluster/user/snakemake_test/results_april30/score DMC MRT5T /cluster/projects/test/results/exp/MRT5T.tsv /cluster/projects/test/results/Exp/MRT5T.size.tsv
对于第二个样本,
shell:
mkdir -p /cluster/user/snakemake_test/results_april30/score;Rscript /cluster/home/user/Projects/R_scripts/scoretool.R /cluster/user/snakemake_test/results_april30/score DMC GNMS4 /cluster/projects/test/results/exp/GNMS4.tsv /cluster/projects/test/results/Exp/GNMS4.ize.tsv
我需要变量 sample_d
['GNMS4', 'MRT5T']
应该单独使用,而不是在一个 shell 命令行中一起使用。
解决方案
关于您的第一个问题:您可以在规则部分中放置您喜欢的任何内容module load
或export
命令shell
。
关于你的第二个问题,你可能不应该expand
在params
你的规则部分使用。实际上expand('{sample}',sample=samples['sample'].unique())
,您并没有使用sample
通配符的值,而是在sample['sample']
. 您可能只需要wildcards.sample
在 shell 命令的定义中使用而不是使用params
元素。
如果要score
根据 的可能值运行规则的多个实例,则sample
需要使用另一个希望将 的输出score
作为其输入的规则来“驱动”它。
请注意,为了提高可读性,您可以使用 python 的多行字符串(三引号)。
总而言之,你可以尝试这样的事情:
rule all:
input:
expand(
os.path.join(
config['general']['paths']['outdir'],
'score',
'{sample}_bg_scores.tsv',
'{sample}_tp_scores.tsv'),
sample=samples['sample'].unique())
rule score:
input:
count = os.path.join(
config['general']['paths']['outdir'],
'count_expression', '{sample}.tsv'),
libsize = os.path.join(
config['general']['paths']['outdir'],
'count_expression', '{sample}.size_tsv')
params:
result_dir = os.path.join(config['general']['paths']['outdir'], 'score'),
cancertype = config['general']['paths']['cancertype'],
output:
files = os.path.join(
config['general']['paths']['outdir'],
'score', '{sample}_bg_scores.tsv', '{sample}_tp_scores.tsv')
shell:
"""
module load r/3.5.1
export R_lib =/user/tools/software
mkdir -p {params.result_dir}
Rscript {config[general][paths][tool]} {params.result_dir} {params.cancertype} {wildcards.sample} {input.count} {input.libsize}
"""
推荐阅读
- powerapps - 如何在powerapps公式栏中链接两个公式?
- wordpress - Aavance 自定义字段无法隐藏我的页面内容编辑器
- html - 容器没有响应“justify-content: space-around”(css、flexbox)
- java - io.prometheus.client.Gauge 是否可用于线程安全计数器
- javascript - 如何在展示广告中显示动态日期
- spring - 使用 @Bean 注释的 SOAP 客户端的动态配置
- prometheus - 格式化 PromQL 值
- c# - LiveCharts 上的自定义类?
- powershell - 在多个窗口中打开网站并使用 powershell 向下滚动它们
- oracle-apex - Oracle APEX:如何更改交互式网格中开关列的值(使用动态操作 - JavaScript)?