How to add help function in a snakemake file
2
4
Entering edit mode
5.5 years ago
c.clarido ▴ 110

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.

snakemake snakefile helpfunction • 3.1k views
ADD COMMENT
2
Entering edit mode
5.5 years ago

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'
ADD COMMENT
0
Entering edit mode

Thank you, I added a rule where I "cat" the help description from a file and it works fine.

ADD REPLY
1
Entering edit mode
5.5 years ago

Maybe this older tutorial and its answers can help you?

ADD COMMENT

Login before adding your answer.

Traffic: 2657 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6