Thank you, I added a rule where I "cat" the help description from a file and it works fine.
Hello community,
How do you add help function in a snakemake file such that it will print a description of the workflow when you enter:
snakemake --snakefile Snakefile help
I tried the following: import argparse
parser = argparse.ArgumentParser(
description='''ENTER DESCRIPTION HERE.''')
args = parser.parse_args()
rule invenU:
input: ["/home/bnextgen/reads/bngsa_nietinfected_1.fastq","/home/bnextgen/reads/bngsa_nietinfected_2.fastq"]
output: ["/home/s1104230/output/iutr1.fastq", "/home/s1104230/output/iutr2.fastq"]
script: "/home/s1104230/scripts/inven.py"
# input: ["/home/s1104230/data/bngsa1_24M.txt","/home/s1104230/data/bngsa2_24M.txt"]
# output: ["/home/s1104230/output/iutr1.fastq", "/home/s1104230/output/iutr2.fastq"]
# script: "/home/s1104230/scripts/inven.py"
I get the following error back:
Cedricks-MacBook-Pro:scripts cedrickagaser$ snakemake --snakefile Snakefile help
usage: snakemake [-h]
snakemake: error: unrecognized arguments: --snakefile Snakefile help
SystemExit in line 10 of /Users/cedrickagaser/Documents/bnextgen/scripts/Snakefile:
2
File "/Users/cedrickagaser/Documents/bnextgen/scripts/Snakefile", line 10, in <module>
File "/Users/cedrickagaser/miniconda3/lib/python3.6/argparse.py", line 1737, in parse_args
File "/Users/cedrickagaser/miniconda3/lib/python3.6/argparse.py", line 2393, in error
File "/Users/cedrickagaser/miniconda3/lib/python3.6/argparse.py", line 2380, in exit
the argeparse method works well with other python programs but with Snakefile not.
2 answers
One option may be to print the help when a given configuration key is given, for example help:
snakemake --config help=1 -s snakefile.smk
Help for this script
USAGE
snamekemake -s snakefile.smk ...
I think this works nicely but it's a bit ugly to invoke help using --config help=1.
Alternatively, you could have a help rule that all it does is to print the help message. You then invoke help with:
snakemake -s snakefile.smk help
The problem with this solution is that the help message gets surrounded with the logs from the snakemake execution.
TL;DR Good question. It would be nice if snakemake had a dedicated option for doing this...
The snakefile.smk script:
import os
docstring= r"""
Help for this script
USAGE
snamekemake -s snakefile.smk ...
"""
if 'help' in config:
print(docstring)
os._exit(0)
rule all:
input:
'foo.txt'
rule help:
run:
print(docstring)
rule make_foo:
output:
'foo.txt'
Maybe this older tutorial and its answers can help you?
Log in to answer this question.