-
Notifications
You must be signed in to change notification settings - Fork 0
/
Selected_populations.smk
152 lines (138 loc) · 6.89 KB
/
Selected_populations.smk
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
from __future__ import print_function
import os
import fnmatch
import pandas as pd
SAMPLES = os.listdir("data/libraries/2-ER-ES_populations")
CONTIGS = pd.read_table("data/genome/schistosoma_mansoni.PRJEA36577.WBPS14.genomic.fa.fai", header=None, usecols=[0], squeeze=True, dtype=str)
GENOME = "data/genome/schistosoma_mansoni.PRJEA36577.WBPS14.genomic.fa"
VCF_PFX = "PZQ_ER-ES"
rule all:
input:
expand("data/libraries/2-ER-ES_populations/{sample}/{sample}_sorted.bam", sample=SAMPLES),
expand("data/libraries/2-ER-ES_populations/{sample}/{sample}_sorted.bam.bai", sample=SAMPLES),
expand("data/libraries/2-ER-ES_populations/{sample}/{sample}_sorted_MD.bam", sample=SAMPLES),
expand("data/libraries/2-ER-ES_populations/{sample}/{sample}_sorted_MD.log", sample=SAMPLES),
expand("data/libraries/2-ER-ES_populations/{sample}/{sample}_sorted_MD.bam.bai", sample=SAMPLES),
expand("data/libraries/2-ER-ES_populations/{sample}/{sample}_sorted_MD.grp", sample=SAMPLES),
expand("data/libraries/2-ER-ES_populations/{sample}/{sample}_sorted_MD_recal.bam", sample=SAMPLES),
expand("data/libraries/2-ER-ES_populations/{sample}/{sample}_sorted_MD_recal.bam.bai", sample=SAMPLES),
expand("data/libraries/2-ER-ES_populations/{sample}/{sample}_sorted_MD_recal.flagstat", sample=SAMPLES),
expand("data/libraries/2-ER-ES_populations/{sample}/{sample}.gvcf.gz", sample=SAMPLES),
expand("data/calling/{vcf_pfx}.gvcf.gz", vcf_pfx=VCF_PFX),
expand("data/calling/{vcf_pfx}.{contig}.vcf.gz", vcf_pfx=VCF_PFX, contig=CONTIGS),
expand("data/calling/{vcf_pfx}.vcf.gz", vcf_pfx=VCF_PFX)
rule alignment:
input:
read1="data/libraries/2-ER-ES_populations/{sample}/{sample}_R1.fastq.gz",
read2="data/libraries/2-ER-ES_populations/{sample}/{sample}_R2.fastq.gz",
genome=GENOME
output:
temp("data/libraries/2-ER-ES_populations/{sample}/{sample}_sorted.bam")
params:
rg=r"@RG\tID:{sample}\tPL:illumina\tLB:{sample}\tSM:{sample}"
shell:
'bwa mem -t $(nproc) -M -R "{params.rg}" "{input.genome}" "{input.read1}" "{input.read2}" | samtools sort -@8 -o "{output}" -'
rule indexing1:
input:
"data/libraries/2-ER-ES_populations/{sample}/{sample}_sorted.bam"
output:
temp("data/libraries/2-ER-ES_populations/{sample}/{sample}_sorted.bam.bai")
shell:
'samtools index "{input}"'
rule mark_duplicates:
input:
bam="data/libraries/2-ER-ES_populations/{sample}/{sample}_sorted.bam",
bai="data/libraries/2-ER-ES_populations/{sample}/{sample}_sorted.bam.bai"
output:
bam=temp("data/libraries/2-ER-ES_populations/{sample}/{sample}_sorted_MD.bam"),
log=protected("data/libraries/2-ER-ES_populations/{sample}/{sample}_sorted_MD.log")
shell:
'gatk --java-options "-Xmx2g" MarkDuplicates -I "{input.bam}" -O "{output.bam}" -M "{output.log}" --VALIDATION_STRINGENCY LENIENT --MAX_FILE_HANDLES_FOR_READ_ENDS_MAP $(ulimit -n)'
rule indexing2:
input:
"data/libraries/2-ER-ES_populations/{sample}/{sample}_sorted_MD.bam"
output:
temp("data/libraries/2-ER-ES_populations/{sample}/{sample}_sorted_MD.bam.bai")
shell:
'samtools index "{input}"'
rule bsqr:
input:
bam="data/libraries/2-ER-ES_populations/{sample}/{sample}_sorted_MD.bam",
bai="data/libraries/2-ER-ES_populations/{sample}/{sample}_sorted_MD.bam.bai",
genome=GENOME,
sites="data/genome/sm_dbSNP_v7.vcf"
output:
table=temp("data/libraries/2-ER-ES_populations/{sample}/{sample}_sorted_MD.grp"),
bam=protected("data/libraries/2-ER-ES_populations/{sample}/{sample}_sorted_MD_recal.bam")
params:
table=r"data/libraries/2-ER-ES_populations/{sample}/{sample}_sorted_MD.grp"
shell:
'gatk --java-options "-Xmx2g" BaseRecalibrator -R "{input.genome}" -I "{input.bam}" --known-sites "{input.sites}" -O "{output.table}" &&\
gatk --java-options "-Xmx2g" ApplyBQSR -R "{input.genome}" -I "{input.bam}" --bqsr-recal-file "{params.table}" -O "{output.bam}"'
rule indexing3:
input:
"data/libraries/2-ER-ES_populations/{sample}/{sample}_sorted_MD_recal.bam"
output:
protected("data/libraries/2-ER-ES_populations/{sample}/{sample}_sorted_MD_recal.bam.bai")
shell:
'samtools index "{input}"'
rule stats:
input:
bam="data/libraries/2-ER-ES_populations/{sample}/{sample}_sorted_MD_recal.bam",
bai="data/libraries/2-ER-ES_populations/{sample}/{sample}_sorted_MD_recal.bam.bai"
output:
protected("data/libraries/2-ER-ES_populations/{sample}/{sample}_sorted_MD_recal.flagstat")
params:
spl=r"data/libraries/2-ER-ES_populations/{sample}/{sample}_sorted_MD_recal.bam"
shell:
'echo -e "File: {params.spl}" > "{output}" ; \
samtools flagstat "{input.bam}" >> "{output}" ; \
echo "\n" >> "{output}"'
rule calling:
input:
bam="data/libraries/2-ER-ES_populations/{sample}/{sample}_sorted_MD_recal.bam",
bai="data/libraries/2-ER-ES_populations/{sample}/{sample}_sorted_MD_recal.bam.bai",
genome=GENOME,
sites="data/genome/sm_dbSNP_v7.vcf"
output:
"data/libraries/2-ER-ES_populations/{sample}/{sample}.gvcf.gz"
shell:
'gatk --java-options "-Xmx2g" HaplotypeCaller -R "{input.genome}" -I "{input.bam}" -D "{input.sites}" --output-mode EMIT_ALL_ACTIVE_SITES -ERC GVCF -O "{output}"'
rule combining:
input:
gvcfs=expand("data/libraries/2-ER-ES_populations/{sample}/{sample}.gvcf.gz", sample=SAMPLES),
genome=GENOME,
sites="data/genome/sm_dbSNP_v7.vcf"
output:
vcf=temp("data/calling/{vcf_pfx}.gvcf.gz")
run:
gvcfs=" -V ".join(input.gvcfs)
shell('gatk --java-options "-Xmx2g" CombineGVCFs -R "{input.genome}" -V {gvcfs} -D "{input.sites}" -O "{output.vcf}"')
rule indexing_gvcf:
input:
gvcf="data/calling/{vcf_pfx}.gvcf.gz"
output:
tbi=temp("data/calling/{vcf_pfx}.gvcf.gz.tbi")
shell:
'gatk --java-options "-Xmx2g" IndexFeatureFile -I "{input.gvcf}"'
rule genotype_variants:
input:
gvcf="data/calling/{vcf_pfx}.gvcf.gz",
tbi="data/calling/{vcf_pfx}.gvcf.gz.tbi",
genome=GENOME,
sites="data/genome/sm_dbSNP_v7.vcf"
output:
vcf=temp("data/calling/{vcf_pfx}.{contig}.vcf.gz"),
tbi=temp("data/calling/{vcf_pfx}.{contig}.vcf.gz.tbi")
params:
contig=r"{contig}"
shell:
'gatk --java-options "-Xmx2g" GenotypeGVCFs -R "{input.genome}" -V "{input.gvcf}" -D "{input.sites}" -L {params.contig} -O "{output.vcf}"'
rule merge_variants:
input:
vcfs=expand("data/calling/{vcf_pfx}.{contig}.vcf.gz", vcf_pfx=VCF_PFX, contig=CONTIGS)
output:
protected("data/calling/{vcf_pfx}.vcf.gz")
run:
vcfs=" -I ".join('"{0}"'.format(w) for w in input.vcfs)
shell('gatk --java-options "-Xmx2g" MergeVcfs -I {vcfs} -O "{output}"')