Hello all,
When I am executing my snakemake pipeline I am trying to pass command line arguments with the --config flag in a python script.
rule assembly:
input:
"trim/{sample}_1.fastq.gz",
"trim/{sample}_2.fastq.gz",
output:
"assembly/{sample}.fa"
params:
fastq1 = "trim/{sample}_1.fastq.gz",
fastq2 = "trim/{sample}_2.fastq.gz",
conda: "environment.yaml"
script:
"assembly.py"
The Python script
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('--config', type=str, required=True)
args = parser.parse_args()
if args.config["assembly"] == "megahit":
shell ("megahit .........")
elif config["assembly"] == "metaspades":
shell ("metaspades.py ........")
I am executing the pipeline like this:
snakemake --cores 5 --config assembly="megahit"
or
snakemake --cores 5 --config assembly="metaspades"
When I do that I am getting the following error:
error: the following arguments are required: --config
- Is there a way to make this work?
- Am I completely wrong by choosing this option? (I did because when I used the snakemake run directive I was getting the "conda environments are only allowed with shell script notebook or wrapper directives (not with run)" error.
Thanking you in advance!
i don't think you need to add the addparse stuff, just use a generic configfile with a default value and your inline arguments should work
So, you suggest instead of --config use the --configfile and specify the different params in this one?
all this is unnecessary:
When i have the following code in the script :
I am getting the following error:
and I execute my pipeline like this
config
won't exist unless you have a configfile. do you have one?May be gb 's answer to your earlier post is useful to you: Snakemake command line arguments.
By using the run directive, you cannot use conda environments... I need to load my programs from conda
You could do something like (unstested and quickly typed so only for inspiration):
And in the script:
But I personally prefer something you are already doing:
and
The above is just to push you in the right direction. If you can't figure it out I can make a working example. Also the
shell
line in the python script looks weird but for now I assume it is just a example or not real code.Hello!
Thank you for the reply. Yes, the shell directive is an example and not the real code.
I will try your suggestion and I will get back to you.