Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix issue with running pling outside of the repo dir #40

Merged
merged 1 commit into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions pling/align_snakemake/Snakefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import pandas as pd
from pling.utils import get_pling_root_dir

configfile: "../config.yaml"

Expand Down Expand Up @@ -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:
Expand All @@ -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} \
Expand Down
16 changes: 10 additions & 6 deletions pling/anno_snakemake/Snakefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import pandas as pd
from pling.utils import get_pling_root_dir

configfile: "../config.yaml"

Expand Down Expand Up @@ -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
Expand All @@ -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}
"""


Expand Down Expand Up @@ -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
Expand All @@ -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}
Expand All @@ -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
Expand All @@ -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} \
Expand Down
4 changes: 3 additions & 1 deletion pling/jac_network_snakemake/Snakefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import pandas as pd
from pling.utils import get_pling_root_dir

configfile: "../config.yaml"

Expand Down Expand Up @@ -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?
Expand All @@ -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} \
Expand Down
5 changes: 5 additions & 0 deletions pling/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from pathlib import Path


def get_pling_root_dir() -> Path:
return Path(__file__).parent.parent