Question: How to add help function in a snakemake file
2
gravatar for c.clarido
22 days ago by
c.clarido40
Netherlands/Rotterdam/Leiden University (Applied Science)
c.clarido40 wrote:

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.

ADD COMMENTlink modified 21 days ago by dariober9.7k • written 22 days ago by c.clarido40
1
gravatar for Philipp Bayer
22 days ago by
Philipp Bayer5.7k
Australia/Perth/UWA
Philipp Bayer5.7k wrote:

Maybe this older tutorial and its answers can help you?

ADD COMMENTlink written 22 days ago by Philipp Bayer5.7k
1
gravatar for dariober
21 days ago by
dariober9.7k
Glasgow - UK
dariober9.7k wrote:

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 COMMENTlink written 21 days ago by dariober9.7k

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

ADD REPLYlink written 20 days ago by c.clarido40
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1441 users visited in the last hour