Phage.smk 2.91 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:
14
        "{datadir}/{project}/renamed/{sample}_Contig_ID.fna"
15
    output:
16
        "{datadir}/{project}/MGE/phage/{sample}/virsorter/VIRSorter_global-phage-signal.csv"
17
    log:
18
        "{datadir}/{project}/MGE/phage/{sample}/virsorter/VIRSorter_global-phage-signal.log"
19
    params:
20
21
22
        outdir="{datadir}",
        runtime=config["pathofact"]["runtime"]["long"],
        mem=config["pathofact"]["mem"]["big_mem_per_core_gb"]
23
24
25
    conda:
        "../../envs/VirSorter.yaml"
    threads:
26
        config["pathofact"]["mem"]["big_mem_cores"]
27
28
    shell:
        """
29
        wrapper_phage_contigs_sorter_iPlant.pl -f {input} --ncpu {threads} --wdir {wildcards.datadir}/{wildcards.project}/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:
35
        "{datadir}/{project}/MGE/phage/{sample}/virsorter/VIRSorter_global-phage-signal.csv"
36
    output:
37
        "{datadir}/{project}/MGE/phage/{sample}_VIRSorter_aggregated.csv"
38
    params:
39
        outdir="{datadir}"
40
    shell:
41
42
43
44
45
46
47
48
        """
        if [ -s {output} ]
        then
            mv {input} {output}
        else
            cp scripts/virsorter_headers.csv {output}
        fi
        """
Laura Denies's avatar
Laura Denies committed
49
50

# VIRFINDER Prediction
51
rule run_VirFinder:
52
    input:
53
        "{datadir}/{project}/contig_splitted/{sample}/{file_i}.fasta"
54
    output:
55
        "{datadir}/{project}/MGE/phage/{sample}/virfinder/{file_i}.fasta_gt1bp_dvfpred.txt"
56
    log:
57
        "{datadir}/{project}/MGE/phage/{sample}/virfinder/{file_i}.fasta_gt1bp_dvfpred.log"
58
    params:
59
60
61
        outdir="{datadir}",
        runtime=config["pathofact"]["runtime"]["long"],
        mem=config["pathofact"]["mem"]["big_mem_per_core_gb"]
62
63
64
    conda:
        "../../envs/DeepVirFinder.yaml"
    threads:
65
        config["pathofact"]["mem"]["big_mem_cores"]
66
    shell:
67
        "python {config[pathofact][deepvirfinder]} -i {input} -o {wildcards.datadir}/{wildcards.project}/MGE/phage/{wildcards.sample}/virfinder -c {threads} &> {log}"
Laura Denies's avatar
Laura Denies committed
68

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

79
rule aggregate_VirFinder:
80
    input:
81
        aggregate_VirFinder
82
    output:
83
        "{datadir}/{project}/MGE/phage/{sample}_VirFinder_aggregated.csv"
84
    params:
85
86
87
        outdir="{datadir}",
        runtime=config["pathofact"]["runtime"]["short"],
        mem=config["pathofact"]["mem"]["normal_mem_per_core_gb"]
88
89
    shell:
        "cat {input} >{output}"