Skip to content

Instantly share code, notes, and snippets.

@bsipos
Created November 3, 2016 09:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bsipos/11f8c2c80aab280f2b7146d206e04f03 to your computer and use it in GitHub Desktop.
Save bsipos/11f8c2c80aab280f2b7146d206e04f03 to your computer and use it in GitHub Desktop.
# This snippet add the "self-documenting" feature to snakemake files.
# It is inspired by the Makefile in https://github.com/audreyr/cookiecutter-pypackage
# Add the follwing to your snakefile or include: "self_document.snake"
import re
def generate_help(sfile):
"""Parse out target and help message from file."""
handler = open(sfile, "r")
for line in handler:
match = re.match(r'^rule\s+([a-zA-Z_-]+):.*?## (.*)$$', line)
if match:
target, help = match.groups()
print("%-20s %s" % (target, help))
rule help: ## print list of all targets with help
input:
workflow.included
run:
print("--------------------------------------------")
[generate_help(sfile) for sfile in input]
print("--------------------------------------------")
# Then simply add a comment to your rule line preceded by '##'. Invoking snakemake help will print all targets and their descriptions.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment