Phage.smk 3.68 KB
Newer Older
Laura Denies's avatar
Laura Denies committed
1
2
3
4
5
6
7
8
9
#Plasmid

import glob
import os

##########################
#     Phage Prediction   #
##########################

10
# VIRSORTER 
Laura Denies's avatar
Laura Denies committed
11
12

rule run_VirSorter:
13
    input:
Laura Denies's avatar
Laura Denies committed
14
        os.path.join(DATA_DIR,"{project}/PathoFact_intermediate/renamed/{sample}_Contig_ID.fna")
15
    output:
Laura Denies's avatar
Laura Denies committed
16
        temp(os.path.join(DATA_DIR,"{project}/PathoFact_intermediate/MGE/phage/{sample}/virsorter/VIRSorter_global-phage-signal.csv"))
17
    log:
Laura Denies's avatar
Laura Denies committed
18
        os.path.join(DATA_DIR,"{project}/logs/{sample}/VIRSorter_global-phage-signal.log")
19
    params:
20
21
        runtime=config["pathofact"]["runtime"]["long"],
        mem=config["pathofact"]["mem"]["big_mem_per_core_gb"]
22
23
24
    conda:
        "../../envs/VirSorter.yaml"
    threads:
25
        config["pathofact"]["mem"]["big_mem_cores"]
Laura Denies's avatar
Laura Denies committed
26
    message: "Executing VirSorter with {threads} threads on the following sample(s): {wildcards.project} - {wildcards.sample}"
27
28
    shell:
        """
Laura Denies's avatar
Laura Denies committed
29
        wrapper_phage_contigs_sorter_iPlant.pl -f {input} --ncpu {threads} --wdir {config[pathofact][datadir]}/{wildcards.project}/PathoFact_intermediate/MGE/phage/{wildcards.sample}/virsorter --data-dir {config[pathofact][scripts]}/virsorter-data &> {log}
30
31
        """

32
33
localrules: aggregate_VirSorter
rule aggregate_VirSorter:
34
    input:
Laura Denies's avatar
Laura Denies committed
35
        os.path.join(DATA_DIR,"{project}/PathoFact_intermediate/MGE/phage/{sample}/virsorter/VIRSorter_global-phage-signal.csv")
36
    output:
Laura Denies's avatar
Laura Denies committed
37
        os.path.join(DATA_DIR,"{project}/PathoFact_intermediate/MGE/phage/{sample}_VIRSorter_aggregated.csv")
Laura Denies's avatar
Laura Denies committed
38
    message: "VirSorter failsave for empty files: {wildcards.project} - {wildcards.sample}"
39
    shell:
40
        """
41
        if [ -s {input} ]
42
        then
43
           mv {input} {output}
44
        else
45
           cp scripts/virsorter_headers.csv {output}
46
        fi
Laura Denies's avatar
Laura Denies committed
47
        rm -rf {config[pathofact][datadir]}/{wildcards.project}/PathoFact_intermediate/MGE/phage/{wildcards.sample}/virsorter
48
        """
Laura Denies's avatar
Laura Denies committed
49
50

# VIRFINDER Prediction
51
rule run_VirFinder:
52
    input:
Laura Denies's avatar
Laura Denies committed
53
        os.path.join(DATA_DIR,"{project}/PathoFact_intermediate/contig_splitted/{sample}/{file_i}.fasta")
54
    output:
Laura Denies's avatar
Laura Denies committed
55
        temp(os.path.join(DATA_DIR,"{project}/PathoFact_intermediate/MGE/phage/{sample}/virfinder/{file_i}.fasta_gt1bp_dvfpred.txt"))
56
    log:
Laura Denies's avatar
Laura Denies committed
57
        os.path.join(DATA_DIR,"{project}/logs/{sample}/{file_i}.fasta_gt1bp_dvfpred.log")
58
    params:
59
60
        runtime=config["pathofact"]["runtime"]["long"],
        mem=config["pathofact"]["mem"]["big_mem_per_core_gb"]
61
62
    conda:
        "../../envs/DeepVirFinder.yaml"
Laura Denies's avatar
Laura Denies committed
63
    threads: config["pathofact"]["mem"]["big_mem_cores"]
Laura Denies's avatar
Laura Denies committed
64
    message: "Executing Deep-VirFinder with {threads} threads on the following sample(s): {wildcards.project} - {wildcards.sample}"
65
    shell:
Laura Denies's avatar
Laura Denies committed
66
        "python {config[pathofact][deepvirfinder]} -i {input} -o {config[pathofact][datadir]}/{wildcards.project}/PathoFact_intermediate/MGE/phage/{wildcards.sample}/virfinder -c {threads} &> {log}"
Laura Denies's avatar
Laura Denies committed
67

68
def aggregate_VirFinder(wildcards):
69
    checkpoint_output= checkpoints.splitcontig.get(**wildcards).output.split
70
    return expand(
Laura Denies's avatar
Laura Denies committed
71
        os.path.join(DATA_DIR,"{project}/PathoFact_intermediate/MGE/phage/{sample}/virfinder/{file_i}.fasta_gt1bp_dvfpred.txt"),
72
        project=wildcards.project,
73
        sample=wildcards.sample,
74
        file_i=glob_wildcards(os.path.join(checkpoint_output, "{i}.fasta")).i
75
    )
Laura Denies's avatar
Laura Denies committed
76

77
rule aggregate_VirFinder:
78
    input:
79
        aggregate_VirFinder
80
    output:
Laura Denies's avatar
Laura Denies committed
81
        os.path.join(DATA_DIR,"{project}/PathoFact_intermediate/MGE/phage/{sample}_VirFinder_aggregated.csv")
82
    params:
83
84
        runtime=config["pathofact"]["runtime"]["short"],
        mem=config["pathofact"]["mem"]["normal_mem_per_core_gb"]
Laura Denies's avatar
Laura Denies committed
85
    message: "Aggregate VirFinder predictions on the following sample(s): {wildcards.project} - {wildcards.sample}"
86
87
    shell:
        "cat {input} >{output}"