-
Notifications
You must be signed in to change notification settings - Fork 0
/
Snakefile
210 lines (195 loc) · 5.79 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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
configfile: "config.yaml"
SAMPLES = config['SAMPLES']
rule all:
input:
expand("{sample}.bam", sample =config['SAMPLES']),
expand("{cohort}.vcf", cohort=config['VCF']),
expand("{vcf}.vcf.gz", vcf=config['VCF']),
expand("{vcf}.vcf.gz.tbi", vcf=config['VCF']),
expand("{vcf}.relatedness",vcf=config['VCF']),
expand("{vcf}.relatedness2", vcf=config['VCF']),
expand("{vcf}.bed", vcf = config['VCF']),
expand("{vcf}.kin", vcf = config['VCF']),
expand("{sample}.kinship.txt", sample =config['SAMPLES'])
if config['PAIRED']:
rule trim:
input:
r1 = "{sample}.r_1.fq.gz",
r2 = "{sample}.r_2.fq.gz"
output:
"galore/{sample}.r_1_val_1.fq.gz",
"galore/{sample}.r_2_val_2.fq.gz"
conda: 'env/env-trim.yaml'
shell:
"""
mkdir -p galore
mkdir -p fastqc
trim_galore --gzip --retain_unpaired --trim1 --fastqc --fastqc_args "--outdir fastqc" -o galore --paired {input.r1} {input.r2}
"""
rule tosam:
input:
genome =expand("{genome}.fasta", genome = config['GENOME']),
r1 = "galore/{sample}.r_1_val_1.fq.gz",
r2 = "galore/{sample}.r_2_val_2.fq.gz"
output:
'{sample}.sam'
conda: 'env/env-align.yaml'
shell:
"bwa mem {input.genome} {input.r1} {input.r2} > {output}"
else:
rule trim:
input:
"{sample}.trimmed.fq.gz",
output:
"galore/{sample}_trimmed.fq.gz",
conda: 'env/env-trim.yaml'
shell:
"""
mkdir -p galore
mkdir -p fastqc
trim_galore --gzip --retain_unpaired --trim1 --fastqc --fastqc_args "--outdir fastqc" -o galore {input}
"""
rule tosam:
input:
genome =expand("{genome}.fasta", genome = config['GENOME']),
reads = "galore/{sample}_trimmed.fq.gz"
conda: 'env/env-align.yaml'
output:
'{sample}.sam'
conda: 'env/env-align.yaml'
shell:
"bwa mem {input.genome} {input.reads} > {output}"
rule sam_bam:
input:
"{sample}.sam"
output:
"{sample}.bam"
conda: 'env/env-tools.yaml'
shell:
"""
samtools view -S -b {input} > {output}
samtools index {input}
"""
rule tobcf:
input:
"{sample}.bam"
output:
"{sample}.bcf"
params:
expand("{genome}.fasta", genome = config['GENOME'])
conda: 'env/env-tools.yaml'
shell:
"""
bcftools mpileup --fasta-ref {params} {input} -d 10000 | bcftools call -vcO v -o {output}
"""
rule vcf:
input:
genome = expand("{genome}.fasta", genome = config['GENOME']),
samples = expand("{sample}.bam", sample =config['SAMPLES'])
params:
I = lambda w: " -Ou " +" ".join(expand("{sample}.bam", sample =config['SAMPLES']))
output:
expand("{cohort}.vcf", cohort=config['VCF'])
conda: 'env/env-tools.yaml'
shell:
"""
bcftools mpileup --fasta-ref {input.genome} {params.I} -d 10000 --threads 10 | bcftools call -vcO v -o {output}
"""
rule bgzip:
input:
"{cohort}.vcf"
output:
"{cohort}.vcf.gz"
conda: 'env/env-htslib.yaml'
shell:
"""
bgzip -c {input} > {output}
"""
rule tabix:
input:
"{cohort}.vcf.gz"
output:
"{cohort}.vcf.gz.tbi"
conda: 'env/env-htslib.yaml'
shell:
"""
tabix -p vcf {input}
"""
rule relatedness:
input:
"{cohort}.vcf.gz"
params:
"{cohort}"
conda: 'env/env-tools.yaml'
output:
"{cohort}.log",
"{cohort}.relatedness"
shell:
"""
vcftools --gzvcf {input} --relatedness --out {params}
"""
rule relatedness2:
input:
"{cohort}.vcf.gz"
params:
"{cohort}"
conda: 'env/env-tools.yaml'
output:
"{cohort}.log",
"{cohort}.relatedness2"
shell:
"""
vcftools --gzvcf {input} --relatedness2 --out {params}
"""
rule makebed:
input:
"{cohort}.vcf.gz"
output:
"{cohort}.bed",
"{cohort}.fam",
"{cohort}.bim"
params:
vcf = "{cohort}"
shell:
"""
plink --vcf {input} --make-bed --out {params}
"""
rule kinship:
input:
"{cohort}.bed",
"{cohort}.fam",
"{cohort}.bim"
params:
vcf = "{cohort}"
conda: 'env/env-kinship.yaml'
output:
"{cohort}.kin"
shell:
"""
king -b {input[0]} --fam {input[1]} --bim {input[2]} --related
king -b {input[0]} --fam {input[1]} --bim {input[2]} --kinship
king -b {input[0]} --fam {input[1]} --bim {input[2]} --ibdseg
king -b {input[0]} --fam {input[1]} --bim {input[2]} --ibs
king -b {input[0]} --fam {input[1]} --bim {input[2]} --homog
mv king.kin {output}
"""
rule get_phased:
output:
"1000G.phase3.integrated.sites_only.no_MATCHED_REV.hg38.vcf",
"1000G.phase3.integrated.sites_only.no_MATCHED_REV.hg38.vcf.idx"
shell:
"""
wget wget https://storage.googleapis.com/genomics-public-data/resources/broad/hg38/v0/1000G.phase3.integrated.sites_only.no_MATCHED_REV.hg38.vcf
wget wget https://storage.googleapis.com/genomics-public-data/resources/broad/hg38/v0/1000G.phase3.integrated.sites_only.no_MATCHED_REV.hg38.vcf.idx
"""
rule akt_kinship:
input:
"{sample}.bcf",
"1000G.phase3.integrated.sites_only.no_MATCHED_REV.hg38.vcf"
output:
"{sample}.kinship.txt"
conda: 'env/env-kinship.yaml'
shell:
"""
akt kin -R {input[1]} -M 1 {input[0]} > {output}
"""