-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSnakefile
176 lines (162 loc) · 7.38 KB
/
Snakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
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
176
import pandas as pd
import os
import yaml
# Include additionnal functions
include: "common.smk"
include: "config/resources.smk"
#popsize config
#configfile: "config/config.yaml"
# Add complementary config
popsize_config = yaml.safe_load(open("workflow/modules/popsize/config/config.yaml"))
config.update(popsize_config)
samples = pd.read_table(config["samples"], sep=",", dtype=str).replace(' ', '_', regex=True)
REFGENOME = samples['refGenome'].unique().tolist()
rule all:
input:
expand("results/{refGenome}/popsize/SFS_{prefix}.fs", refGenome=REFGENOME, prefix=config['final_prefix']),
expand("results/{refGenome}/popsize/output_stats/{prefix}_PCA.png", refGenome=REFGENOME, prefix=config['final_prefix']),
*(expand("results/{refGenome}/popsize/output_smcpp/{prefix}.final.json", refGenome=REFGENOME,
prefix=config['final_prefix']) if "smcpp" in config['popsize_tools'] else []),
*(expand("results/{refGenome}/popsize/output_stairwayplot2/{prefix}/{prefix}.final.summary", refGenome=REFGENOME,
prefix=config['final_prefix']) if "swp2" in config['popsize_tools'] else []),
# Wait for dadi output if used in config
*(expand("results/{refGenome}/popsize/output_dadi/{prefix}.InferDM.bestfits", refGenome=REFGENOME,
prefix=config['final_prefix']) if "dadi" in config['popsize_tools'] else []),
# Wait for PSMC output if used in config
*(expand("results/{refGenome}/popsize/output_psmc/{prefix}.eps", refGenome=REFGENOME,
prefix=config['final_prefix']) if "psmc" in config['popsize_tools'] else []),
# Wait for MSMC2 output if used in config
*(expand("results/{refGenome}/popsize/output_msmc2/{prefix}_msmc2.final.txt", refGenome=REFGENOME,
prefix=config['final_prefix']) if "msmc2" in config['popsize_tools'] else [])
rule init_module:
"""
intial checks and creates the config file
"""
input:
vcf = "results/{refGenome}/{prefix}_raw.vcf.gz",
results_folder = "results/{refGenome}",
config_template = "workflow/modules/popsize/config/deminfhelper_template.yml"
output:
config_file = "results/{refGenome}/popsize/{prefix}_deminfhelper.yml"
run:
build_deminfhelper_config(results_folder = input.results_folder, vcf_file = input.vcf,
prefix = config['final_prefix'], output = output.config_file, global_config = config, module_config = input.config_template)
rule compute_sfs:
"""
computes sfs from the VCF
"""
input:
config_file = "results/{refGenome}/popsize/{prefix}_deminfhelper.yml"
output:
sfs_file = "results/{refGenome}/popsize/SFS_{prefix}.fs"
conda:
"envs/deminfhelper.yml"
shell:
"python3 workflow/modules/popsize/scripts/deminfhelper.py --sfs --config_file {input.config_file}"
rule stairwayplot2:
"""
run stairwayplot2 using the generated config
"""
input:
config_file = "results/{refGenome}/popsize/{prefix}_deminfhelper.yml",
sfs_file = "results/{refGenome}/popsize/SFS_{prefix}.fs"
output:
stairwayplot2_summary = "results/{refGenome}/popsize/output_stairwayplot2/{prefix}/{prefix}.final.summary"
conda:
"envs/deminfhelper.yml"
resources:
mem_mb = lambda wildcards, attempt: attempt * resources['swp2']['mem_mb']
threads:
resources['swp2']['threads']
shell:
"python3 workflow/modules/popsize/scripts/deminfhelper.py --config_file {input.config_file} --stairwayplot2 ;"+ \
"python3 workflow/modules/popsize/scripts/deminfhelper.py --config_file {input.config_file} --plot_stairwayplot2"
rule smcpp:
"""
run smc++ using the generated config
"""
input:
config_file = "results/{refGenome}/popsize/{prefix}_deminfhelper.yml",
vcf_index = "results/{refGenome}/{prefix}_raw.vcf.gz.tbi"
output:
smcpp_summary = "results/{refGenome}/popsize/output_smcpp/{prefix}.final.json"
conda:
"envs/smcpp.yml"
resources: mem_mb = lambda wildcards, attempt: attempt * resources['smcpp']['mem_mb']
threads: resources['smcpp']['threads']
shell:
"python3 workflow/modules/popsize/scripts/deminfhelper.py --config_file {input.config_file} --cpus {threads} --smcpp ;"+ \
"python3 workflow/modules/popsize/scripts/deminfhelper.py --config_file {input.config_file} --plot_smcpp"
rule dadi:
"""
run dadi using the generated config
"""
input:
config_file = "results/{refGenome}/popsize/{prefix}_deminfhelper.yml",
sfs_file = "results/{refGenome}/popsize/SFS_{prefix}.fs"
output:
dadi_summary = "results/{refGenome}/popsize/output_dadi/{prefix}.InferDM.bestfits"
conda:
"envs/deminfhelper.yml"
shell:
"python3 workflow/modules/popsize/scripts/deminfhelper.py --config_file {input.config_file} --dadi ;"+ \
"python3 workflow/modules/popsize/scripts/deminfhelper.py --config_file {input.config_file} --plot_dadi"
rule psmc:
"""
run psmc using the generated config
"""
input:
config_file = "results/{refGenome}/popsize/{prefix}_deminfhelper.yml",
vcf = "results/{refGenome}/{prefix}_raw.vcf.gz",
vcf_index = "results/{refGenome}/{prefix}_raw.vcf.gz.tbi",
ref_genome = "results/{refGenome}/data/genome/{refGenome}.fna"
output:
psmc_output = "results/{refGenome}/popsize/output_psmc/{prefix}_combined.psmc.final"
threads: resources['psmc']['threads']
conda:
"envs/deminfhelper.yml"
shell:
"python3 workflow/modules/popsize/scripts/deminfhelper.py --config_file {input.config_file} --psmc"
rule psmc_plot:
"""
produce psmc plot
"""
input:
config_file = "results/{refGenome}/popsize/{prefix}_deminfhelper.yml",
psmc_output = "results/{refGenome}/popsize/output_psmc/{prefix}_combined.psmc.final"
output:
psmc_figure = "results/{refGenome}/popsize/output_psmc/{prefix}.eps"
conda:
"envs/deminfhelper.yml"
shell:
"python3 workflow/modules/popsize/scripts/deminfhelper.py --config_file {input.config_file} --plot_psmc"
rule msmc2:
"""
run msmc2 using the generated config
"""
input:
config_file = "results/{refGenome}/popsize/{prefix}_deminfhelper.yml",
vcf = "results/{refGenome}/{prefix}_raw.vcf.gz"
output:
msmc2_output = "results/{refGenome}/popsize/output_msmc2/{prefix}_msmc2.final.txt"
resources: mem_mb = lambda wildcards, attempt: attempt * resources['msmc2']['mem_mb']
threads: resources['msmc2']['threads']
conda:
"envs/deminfhelper.yml"
shell:
"python3 workflow/modules/popsize/scripts/deminfhelper.py --config_file {input.config_file} --msmc2 ;"+ \
"python3 workflow/modules/popsize/scripts/deminfhelper.py --config_file {input.config_file} --plot_msmc2"
rule statistics:
"""
Compute some statistics like PCA or Genotyping Quality distribution
"""
input:
config_file = "results/{refGenome}/popsize/{prefix}_deminfhelper.yml",
vcf = "results/{refGenome}/{prefix}_raw.vcf.gz"
output:
pca_output = "results/{refGenome}/popsize/output_stats/{prefix}_PCA.png"
conda:
"envs/deminfhelper.yml"
shell:
"python3 workflow/modules/popsize/scripts/deminfhelper.py --config_file {input.config_file} --pca ;"+ \
"python3 workflow/modules/popsize/scripts/deminfhelper.py --config_file {input.config_file} --gq_distrib"