Hey, everyone! I'm having struggles importing a module in Snakemake. When I run Snakemake -np
in the directory outside of the following snakefile:
import subprocess
from pathlib import Path
from snakemake.utils import min_version
min_version("6.0")
config_path = "workflow/config/config.yaml"
configfile: config_path
main_dir = "results"
reference_fasta = Path(config['ref_fna']).name
ref_base = Path(reference_fasta).with_suffix('')
wildcard_constraints:
SRR = r"[R-S0-9]{10}"
module haplo_call:
snakefile: github("alemanac/GATK_haplotype_module", path="workflow/snakefile", tag="main")
config: config_path
use rule all from haplo_call as haplo_call with:
input:
expand("{main_dir}/{SRR}/lifted_over_and_combined_vcfs/variants.final.vcf", main_dir=main_dir, SRR=config['test_sample'])
I get the following error:
TypeError in file https://raw.githubusercontent.com/alemanac/GATK_haplotype_module/main/workflow/snakefile, line 7:
string indices must be integers
File "/home/ac.aleman/Bacterial_GATK_SNPs_aleman/workflow/snakefile", line 36, in <module>
File "https://raw.githubusercontent.com/alemanac/GATK_haplotype_module/main/workflow/snakefile", line 7, in <module>
I'm unsure how to resolve this. Here's the snakefile of the imported module:
import subprocess
from pathlib import Path
config_path = "workflow/config/config.yaml"
configfile: config_path
print(config)
reference_fasta = Path(config['ref_fna']).name
ref_base = Path(reference_fasta).with_suffix('')
main_dir = f"results/{config['run_name']}"
wildcard_constraints:
SRR = r"[R-S0-9]{10}"
include: "rules/alignment.smk"
include: "rules/alignment_shifted.smk"
include: "rules/ref_processing.smk"
include: "rules/haplotype_caller.smk"
rule all:
input:
expand("{main_dir}/{SRR}/lifted_over_and_combined_vcfs/variants.final.vcf", main_dir=main_dir, SRR=config['test_sample']),
expand("{main_dir}/copied_config.yaml", main_dir=main_dir)
rule copy_config:
output:
copied_config = "{main_dir}/copied_config.yaml"
params:
config_path = config_path
shell:
"""
cp {params.config_path} {output.copied_config}
"""
The module runs fine on its own. Unsure what to do. I would appreciate any help! TY!
My guess is that the config file of the parent snakefile is passed as a string to the module rather than a dictionary as usual. How could I resolve this while ensuring the module works on its own?