diff --git a/pling/align_snakemake/Snakefile b/pling/align_snakemake/Snakefile index a29d86f..6ccf92c 100644 --- a/pling/align_snakemake/Snakefile +++ b/pling/align_snakemake/Snakefile @@ -1,5 +1,6 @@ import os import pandas as pd +from pling.utils import get_pling_root_dir configfile: "../config.yaml" @@ -32,7 +33,8 @@ rule make_unimogs: params: genome1 = lambda wildcards: wildcards.genome1, genome2 = lambda wildcards: wildcards.genome2, - identity_threshold = config["identity_threshold"] + identity_threshold = config["identity_threshold"], + pling_root_dir = get_pling_root_dir() conda: "../envs/integerise.yaml" shadow: "shallow" shell: @@ -45,7 +47,7 @@ rule make_unimogs: # This is the expected behaviour, is not a bug in conda or snakemake. # For more details, see https://github.com/conda/conda/issues/9392#issuecomment-1291041085 PATH="$CONDA_PREFIX"/bin:$PATH # quick fix for the issue described above - python pling/align_snakemake/unimog.py \ + python {params.pling_root_dir}/pling/align_snakemake/unimog.py \ --genome_1_fasta {input.genome_1_fasta} \ --genome1 {params.genome1} \ --genome_2_fasta {input.genome_2_fasta} \ diff --git a/pling/anno_snakemake/Snakefile b/pling/anno_snakemake/Snakefile index 4d11962..12237a9 100644 --- a/pling/anno_snakemake/Snakefile +++ b/pling/anno_snakemake/Snakefile @@ -1,5 +1,6 @@ import os import pandas as pd +from pling.utils import get_pling_root_dir configfile: "../config.yaml" @@ -111,7 +112,8 @@ rule consolidation: params: pafs=f"{OUTPUTPATH}/tmp_files/minimap/{{community}}/output", genomes = lambda wildcards: COMMUNITY_TO_PLASMID[wildcards.community], - outputpath = OUTPUTPATH + outputpath = OUTPUTPATH, + pling_root_dir = get_pling_root_dir() shell: """ # set conda env first in $PATH - TODO: keep this or manage in other way? # this issue happens when running a pipeline and a conda env is already active but it is not the first @@ -121,7 +123,7 @@ rule consolidation: # This is the expected behaviour, is not a bug in conda or snakemake. # For more details, see https://github.com/conda/conda/issues/9392#issuecomment-1291041085 PATH="$CONDA_PREFIX"/bin:$PATH # quick fix for the issue described above - python pling/anno_snakemake/consolidation.py {params.pafs} "{params.genomes}" {output.unimog} {output.map} + python {params.pling_root_dir}/pling/anno_snakemake/consolidation.py {params.pafs} "{params.genomes}" {output.unimog} {output.map} """ @@ -154,7 +156,8 @@ if config.get("dedup", False): params: pafs=f"{OUTPUTPATH}/tmp_files/minimap/{{community}}/output", nucmer_threshold=config["dedup_threshold"], - genomes = lambda wildcards: COMMUNITY_TO_PLASMID[wildcards.community] + genomes = lambda wildcards: COMMUNITY_TO_PLASMID[wildcards.community], + pling_root_dir = get_pling_root_dir() shell: """ # set conda env first in $PATH - TODO: keep this or manage in other way? # this issue happens when running a pipeline and a conda env is already active but it is not the first @@ -164,7 +167,7 @@ if config.get("dedup", False): # This is the expected behaviour, is not a bug in conda or snakemake. # For more details, see https://github.com/conda/conda/issues/9392#issuecomment-1291041085 PATH="$CONDA_PREFIX"/bin:$PATH # quick fix for the issue described above - python pling/anno_snakemake/multipartite.py \ + python {params.pling_root_dir}/pling/anno_snakemake/multipartite.py \ {input.fasta} {input.unimog} {input.map} \ {params.pafs} {params.nucmer_threshold} "{params.genomes}" \ {output.nucmer} {output.relabelled_unimog} {output.dedup_map} @@ -183,7 +186,8 @@ rule blocks: mem_mb = lambda wildcards, attempt: attempt * config["blocks_mem"] params: genomes = lambda wildcards: COMMUNITY_TO_PLASMID[wildcards.community], - relabelled_dir = f"{OUTPUTPATH}/unimogs/relabelled/blocks" + relabelled_dir = f"{OUTPUTPATH}/unimogs/relabelled/blocks", + pling_root_dir = get_pling_root_dir() shell: """ # set conda env first in $PATH - TODO: keep this or manage in other way? # this issue happens when running a pipeline and a conda env is already active but it is not the first @@ -193,7 +197,7 @@ rule blocks: # This is the expected behaviour, is not a bug in conda or snakemake. # For more details, see https://github.com/conda/conda/issues/9392#issuecomment-1291041085 PATH="$CONDA_PREFIX"/bin:$PATH # quick fix for the issue described above - python pling/anno_snakemake/blocks.py \ + python {params.pling_root_dir}/pling/anno_snakemake/blocks.py \ {input} \ "{params.genomes}" {params.relabelled_dir} \ {output.relabelled_unimog} {output.blocks_map} \ diff --git a/pling/jac_network_snakemake/Snakefile b/pling/jac_network_snakemake/Snakefile index 24c0742..92decf6 100644 --- a/pling/jac_network_snakemake/Snakefile +++ b/pling/jac_network_snakemake/Snakefile @@ -1,5 +1,6 @@ import os import pandas as pd +from pling.utils import get_pling_root_dir configfile: "../config.yaml" @@ -30,6 +31,7 @@ rule pairwise_seq_jaccard: genome1 = lambda wildcards: wildcards.genome1, genome2 = lambda wildcards: wildcards.genome2, identity_threshold = config["identity_threshold"], + pling_root_dir = get_pling_root_dir() shadow: "shallow" shell: """ # set conda env first in $PATH - TODO: keep this or manage in other way? @@ -41,7 +43,7 @@ rule pairwise_seq_jaccard: # For more details, see https://github.com/conda/conda/issues/9392#issuecomment-1291041085 PATH="$CONDA_PREFIX"/bin:$PATH # quick fix for the issue described above - python pling/jac_network_snakemake/seq_jaccard.py \ + python {params.pling_root_dir}/pling/jac_network_snakemake/seq_jaccard.py \ {params.genome1} {params.genome2} \ {input.genome_1_fasta} {input.genome_2_fasta} \ {params.identity_threshold} \ diff --git a/pling/utils.py b/pling/utils.py new file mode 100644 index 0000000..9bb18b1 --- /dev/null +++ b/pling/utils.py @@ -0,0 +1,5 @@ +from pathlib import Path + + +def get_pling_root_dir() -> Path: + return Path(__file__).parent.parent