![](/img/trans.png)
[英]How to write a Snakemake rule-all, where expand statements can handle the absence of all particular input files
[英]Snakemake multiple input files with expand but no repetitions
我是蛇形的新手,我不知道如何解決這個問題。
我的規則有兩個輸入:
rule test
input_file1=f1
input_file2=f2
f1 在 [A{1}$, A{2}£, B{1}€, B{2}¥]
f2 在 [C{1}, C{2}]
這些數字是來自擴展調用的通配符。 我需要找到一種方法將一對與數字完全匹配的文件傳遞給文件 f1 和 f2。 例如:
f1 = A1
f2 = C1
或者
f1 = B1
f2 = C1
我必須避免組合,例如:
f1 = A1
f2 = C2
我會創建一個函數來在文件之間進行這種匹配,但同樣應該同時管理 input_file1 和 input_file2。 我想創建一個函數來創建一個具有不同允許組合的字典,但是在擴展過程中我將如何“迭代”它?
謝謝
假設規則test
在輸出中為您提供一個名為{f1}.{f2}.txt
,那么您需要某種機制來正確配對 f1 和 f2 並創建一個{f1}.{f2}.txt
文件列表。
如何創建此列表取決於您, expand
只是一個方便的功能,但在這種情況下,您可能希望避免使用它。
這是一個超級簡單的例子:
fin1 = ['A1$', 'A2£', 'B1€', 'B2¥']
fin2 = ['C1', 'C2']
outfiles = []
for x in fin1:
for y in fin2:
## Here you pair f1 and f2. This is a very trivial way of doing it:
if y[1] in x:
outfiles.append('%s.%s.txt' % (x, y))
wildcard_constraints:
f1 = '|'.join([re.escape(x) for x in fin1]),
f2 = '|'.join([re.escape(x) for x in fin2]),
rule all:
input:
outfiles,
rule test:
input:
input_f1 = '{f1}.txt',
input_f2 = '{f2}.txt',
output:
'{f1}.{f2}.txt',
shell:
r"""
cat {input} > {output}
"""
此管道將執行以下命令
cat A2£.txt C2.txt > A2£.C2.txt
cat A1$.txt C1.txt > A1$.C1.txt
cat B1€.txt C1.txt > B1€.C1.txt
cat B2¥.txt C2.txt > B2¥.C2.txt
如果您使用touch 'A1$.txt' 'A2£.txt' 'B1€.txt' 'B2¥.txt' 'C1.txt' 'C2.txt'
觸摸起始輸入文件,您應該能夠運行它例子。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.