Snakefile 6.98 KB
Newer Older
1
import os.path
Raphael Müller's avatar
Raphael Müller committed
2
import re
3
4
5
6
7
8

configfile: "config.yml"

NFS = config["nextflow_script"]
OPS = config["original_perl_script"]
DATA = config["datadir"]
Raphael Müller's avatar
Raphael Müller committed
9
10
11
ASSEMBLY = config["assembly"]
WD = config["workdir"]+"/"

12
13
include: "snakemake_workflows/bam_prep.smk"
include: "snakemake_workflows/bams_illumina_pacbio_nanopore.smk"
Raphael Müller's avatar
Raphael Müller committed
14
15
16
17
18
include: "snakemake_workflows/nanopore.smk"
include: "snakemake_workflows/nanopore_multi.smk"
include: "snakemake_workflows/pacbio_multi.smk"
include: "snakemake_workflows/pacbio_nanopore.smk"
include: "snakemake_workflows/pacbio_only.smk"
Raphael Müller's avatar
Raphael Müller committed
19
include: "snakemake_workflows/paired_multi.smk"
Raphael Müller's avatar
Raphael Müller committed
20
21
22
23
24
25
26
include: "snakemake_workflows/paired_nanopore.smk"
include: "snakemake_workflows/paired_only.smk"
include: "snakemake_workflows/paired_pacbio.smk"
include: "snakemake_workflows/paired_pacbio_nanopore.smk"
include: "snakemake_workflows/single_multi.smk"
include: "snakemake_workflows/single_nanopore.smk"
include: "snakemake_workflows/single_only.smk"
Raphael Müller's avatar
Raphael Müller committed
27
include: "snakemake_workflows/single_pacbio.smk"
Raphael Müller's avatar
Raphael Müller committed
28
29
30
31
32
include: "snakemake_workflows/single_pacbio_nanopore.smk"
include: "snakemake_workflows/single_paired.smk"
include: "snakemake_workflows/single_paired_nanopore.smk"
include: "snakemake_workflows/single_paired_pacbio.smk"
include: "snakemake_workflows/single_paired_pacbio_nanopore.smk"
33
34
35

rule all:
  input: 
Raphael Müller's avatar
Raphael Müller committed
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
    rules.assembly_nanopore_multi_perl.output,
    rules.assembly_nanopore_multi_nextflow.output,
    rules.assembly_nanopore_multi_nextflow_params.output,
    rules.assembly_nanopore_perl.output,
    rules.assembly_nanopore_nextflow.output,
    rules.assembly_pacbio_multi_perl.output,
    rules.assembly_pacbio_multi_nextflow.output,
    rules.assembly_pacbio_multi_nextflow_params.output,
    rules.assembly_pacbio_nanopore_perl.output,
    rules.assembly_pacbio_nanopore_nextflow.output,
    rules.assembly_pacbio_perl.output,
    rules.assembly_pacbio_nextflow.output,
    rules.assembly_paired_multi_perl.output,
    rules.assembly_paired_multi_nextflow.output,
    rules.assembly_paired_multi_nextflow_params.output,
    rules.assembly_paired_pacbio_nanopore_perl.output,
    rules.assembly_paired_pacbio_nanopore_nextflow.output,
    rules.assembly_paired_perl.output,
    rules.assembly_paired_nextflow.output,
    rules.assembly_single_paired_pacbio_nanopore_perl.output,
    rules.assembly_single_paired_pacbio_nanopore_nextflow.output,
    rules.assembly_paired_pacbio_perl.output,
    rules.assembly_paired_pacbio_nextflow.output,
Raphael Müller's avatar
Raphael Müller committed
59
60
    rules.assembly_single_multi_perl.output,
    rules.assembly_single_multi_nextflow.output,
Raphael Müller's avatar
Raphael Müller committed
61
62
63
    rules.assembly_single_multi_nextflow_params.output,
    rules.assembly_single_nanopore_perl.output,
    rules.assembly_single_nanopore_nextflow.output,
Raphael Müller's avatar
Raphael Müller committed
64
65
    rules.assembly_single_perl.output,
    rules.assembly_single_nextflow.output,
Raphael Müller's avatar
Raphael Müller committed
66
67
    rules.assembly_single_pacbio_nanopore_perl.output,
    rules.assembly_single_pacbio_nanopore_nextflow.output,
Raphael Müller's avatar
Raphael Müller committed
68
69
    rules.assembly_single_pacbio_perl.output,
    rules.assembly_single_pacbio_nextflow.output,
Raphael Müller's avatar
Raphael Müller committed
70
71
72
73
74
75
76
77
    rules.assembly_single_paired_nanopore_perl.output,
    rules.assembly_single_paired_nanopore_nextflow.output,
    rules.assembly_single_paired_pacbio_nanopore_perl.output,
    rules.assembly_single_paired_pacbio_nanopore_nextflow.output,
    rules.assembly_single_paired_pacbio_perl.output,
    rules.assembly_single_paired_pacbio_nextflow.output,
    rules.assembly_single_paired_perl.output,
    rules.assembly_single_paired_nextflow.output,
78
79
    rules.bams_illumina_paired_pacbio_nanopore_perl.output,
    rules.bams_illumina_paired_pacbio_nanopore_nextflow.output,
80
    rules.bams_with_assembly_illumina_paired_pacbio_nanopore_nextflow.output,
81

Raphael Müller's avatar
Raphael Müller committed
82

Raphael Müller's avatar
Raphael Müller committed
83
rule data_prep:
Raphael Müller's avatar
Raphael Müller committed
84
  input:
Raphael Müller's avatar
Raphael Müller committed
85
    lambda wc: os.path.join(config["datadir"],config[wc.name])
Raphael Müller's avatar
Raphael Müller committed
86
  output:
Raphael Müller's avatar
Raphael Müller committed
87
    "data_prep/{name}.{divider}.{offset}.fastq"
Raphael Müller's avatar
Raphael Müller committed
88
89
  shell:
    """
Raphael Müller's avatar
Raphael Müller committed
90
    sed -n '{wildcards.offset}~{wildcards.divider}{{N;N;N;p}}' {input} > {output}
91
    """
Raphael Müller's avatar
Raphael Müller committed
92

93
94
95
96
97
98
99
100
101
102
103
104
105
rule install_perl_packages:
  output: "logs/install_perl_packages.log"
  conda: "envs/perl.yml"
  params:
    packages=" ".join(config["perl_packages"])
  shell:
    """
    env PERL5LIB="" PERL_LOCAL_LIB_ROOT="" PERL_MM_OPT="" PERL_MB_OPT="" cpanm {params.packages} 2>&1 > {output}
    for i in {params.packages};
    do
      perl -M"$i" -e 'print "Modul exists\\n";'
    done
    """
Raphael Müller's avatar
Raphael Müller committed
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127

rule nanosim:
  input:
    genome = ASSEMBLY,
    training = multiext("no_backup/nanosim/", #rules.nanosim_training.output
        "training_aligned_reads.pkl", 
        "training_aligned_region.pkl", 
        "training_chimeric_info", 
        "training_error_markov_model", 
        "training_error_rate.tsv", 
        "training_first_match.hist", 
        "training_gap_length.pkl", 
        "training_ht_length.pkl", 
        "training_ht_ratio.pkl", 
        "training_match_markov_model", 
        "training_model_profile", 
        "training_reads_alignment_rate", 
        "training_strandness_rate", 
        "training_unaligned_length.pkl" 
      )
  output:
    "data_prep/nanopore.sim.{number}.fastq"
128
  conda: "envs/nanosim.yml"
Raphael Müller's avatar
Raphael Müller committed
129
130
131
132
133
134
135
136
  shadow: "full"
  threads: 8
  shell:
    """
      simulator.py genome --ref_g {input.genome} --output {output} --number {wildcards.number} --fastq --num_threads {threads} --basecaller guppy -c no_backup/nanosim/training;
      cat {output}_aligned_reads.fastq {output}_unaligned_reads.fastq > {output}
    """

Raphael Müller's avatar
Raphael Müller committed
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#rule perl_backmap_with_assembly:
#  input:
#    infiles = lambda wildcards: [os.path.join(DATA,infile) for infile in config["cases"][wildcards.run]["input_files"]],
#    assembly = ASSEMBLY
#  output:
#    os.path.join(config["workdir"],"{run}","original","{name,[A-Za-z0-9]+}"+"{extension}") 
#  threads: 1
##  shadow: "full"
#  params:
#    prgm = OPS,
#    outdir = lambda wc: os.path.join(WD, wc.run, "original"),
#    params = lambda wc: expand(" ".join(config["cases"][wc.run]["params"]), datadir=DATA),
#  log:
#    stdout = os.path.join(config["workdir"],"{run}","original","{name}{extension}.stdout.log"),
#    stderr = os.path.join(config["workdir"],"{run}","original","{name}{extension}.stderr.log")
#  shell:
#    """
#    {params.prgm} -kt -v -a {input.assembly} -o {params.outdir} -pre {wildcards.name} -t {threads} {params.params} 1> {log.stdout} 2> {log.stderr}
#    """
#
#rule nextflow_backmap_with_assembly:
#  input:
#    infiles = lambda wildcards: [os.path.join(DATA,infile) for infile in config["cases"][wildcards.run]["input_files"]],
#    assembly = ASSEMBLY
#  output:
#    os.path.join(config["workdir"],"{run}","nextflow","{name,[A-Za-z0-9]+}"+"{extension}") 
#  threads: 1
##  shadow: "full"
#  params:
#    prgm = NFS,
#    outdir = lambda wc: os.path.join(WD, wc.run, "nextflow"),
#    params = lambda wc: expand(re.sub(r'(\s|^)-', r'\1--', " ".join(config["cases"][wc.run]["params"])), datadir=DATA),
#  log:
#    stdout = os.path.join(config["workdir"],"{run}","nextflow","{name}{extension}.stdout.log"),
#    stderr = os.path.join(config["workdir"],"{run}","nextflow","{name}{extension}.stderr.log")
#  shell:
#    """
#    {params.prgm} --a {input.assembly} --o {params.outdir} --pre {wildcards.name} --t {threads} {params.params} 1> {log.stdout} 2> {log.stderr}
#    """