问题
I stuck in a Snakemake issue for a lone while.
Propose I have a dict like:
dict_A = {A:"id1","id2","id3", B:"id2","id3","id4","id5", C:"id1","id4","id5"}
and I want to write rules like:
input:
"{dict_A.keys()}/{dict_A[key]}_R1.txt"
output:
"{dict_A.keys()}/{dict_A[key]}_R1_filter.txt"
shell:
"XXX {input} > {output}"
While, I try to search on google and StackOverflow but I can't figure out this problem. Really hope there is someone can help me !
Really thanks!
回答1:
Snakemake works by providing it a final output we expect it to generate, and rules how to produce output from certain input. When we do not define any output on the command line, snakemake will try to generate the input of the first rule in your Snakefile. So we define a rule all
with as input what we want to generate:
dict_A = {'A': ["id1","id2","id3"],
'B': ["id2","id3","id4","id5"],
'C': ["id1","id4","id5"]}
all_input = []
for key, values in dict_A.items():
for value in values:
all_input.append(f"{key}/{value}_R1_filter.txt")
rule all:
input:
all_input
Now we have to change our rule so that it can fill in the correct wildcards for the output it wants to generate:
rule do_sth_cool:
input:
"{key_wc}/{value_wc}_R1.txt"
output:
"{key_wc}/{value_wc}_R1_filter.txt"
shell:
"XXX {input} > {output}"
Take a look again at the docs and make yourself familiar with the basic concepts of snakemake.
edit:
rule all:
input:
[f"{key}/{value}_R1_filter.txt" for key, values in dict_A.items() for value in values]
来源:https://stackoverflow.com/questions/58848521/how-to-use-dict-value-and-key-in-snakemake-rules