Specify target rules via command line from a python executable for Snakemake workflows

Viewed 156

I am executing a Snakemake workflow via a command line python application which works more or less in this way:

./run.py workflowfile -argument1 -argument2...

In the workflow file is specified a target rule, which is passed to the "targets" argument of the Snakemake API, like this:

with open(workflowfile, 'rt') as fp:
    workflow_info = json.load(fp)

target = workflow_info['workflow_target']
status = snakemake.snakemake(....targets=[target]....)

Where "targets" must be a list. Now, I am trying to get rid of the "workflowfile" and I want to specify via another argument the target rule name, to obtain:

./run.py -w "targetrulename" -a1 -a2...

In the Snakemake command line interface this is done in a simple way, with "target", by calling:

snakemake  targetrulename

where targetrulename is simply the name of the rule you want to be targeted. So I tried to implement a new command line argument with argparse in the following way:

parser.add_argument('-w', '--workflow', action="append", help='specify the workflow from the following: ')

and then

targets=args.workflow

but in a way or another I get different errors. Some examples:

-TypeError: unsupported operand type(s) for +: 'NoneType' and 'int'
-TypeError: unhashable type: 'list'
-No rule to produce c  (If I type "complete" as target rule name)

Sorry for being noob, I just started in the field of bioinformatics (I am a biotech) and this is my first question on Stack Overflow. Hope I have done everything correctly. Thanks for any tips or advice

edit:

the minimal example for the python script is:

import argparse
import snakemake

def main(args)
    snakefile=snakefile_path
    snakemake.snakemake(snakefile, configfiles=[args.configfile] …)

if __name__ == ‘__main__’
    parser=argparse.ArgumentParser(description=””, usage=””)
    parser.add_argument(‘-c’, ‘--configfile’, action=’store’)
    [...]
    args = parser.parse_argse()

edit: solved

0 Answers
Related