-
Notifications
You must be signed in to change notification settings - Fork 0
/
Snakefile
77 lines (68 loc) · 2.01 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
"""
First three rules align the reads to reference
then sort and index for further analysis
"""
configfile: "workflow/config/config.yaml"
SAMPLE = ["bc01"]
# REFERENCE = "../data/CaenCA_mtgenome_final.fasta"
rule all:
input:
expand("data/variants/{sample}_variants.vcf", sample=SAMPLE)
# merge sample fastqs into one file
rule merge_fastqs:
output:
"data/samples/{sample}.fastq"
shell:
"cat data/samples_raw/{wildcards.sample}/*.fastq > {output}"
# gzip fastq
rule gzip_fastq:
input:
"data/samples/{sample}.fastq"
output:
"data/samples/{sample}.fastq.gz"
shell:
"gzip {input}"
# align reads using minimap > convert to bam > sort bam
rule align_reads:
input:
reads="data/samples/{sample}.fastq.gz",
ref=expand("{ref}", ref=config["reference"])
output:
bam="data/mapped_reads/{sample}.bam"
conda:
"workflow/envs/main.yaml"
shell:
"minimap2 -ax map-ont {input.ref} {input.reads} | "
"samtools view -Sb | samtools sort -o {output}"
rule index_reference:
input:
ref=expand("{ref}", ref=config["reference"])
output:
ref_idx=expand("{ref}.fai", ref=config["reference"])
conda:
"workflow/envs/main.yaml"
shell:
"samtools faidx {input.ref}"
# index bam
rule index_alignment:
input:
bam="data/mapped_reads/{sample}.bam"
output:
indexed_bam="data/mapped_reads/{sample}.bam.bai"
conda:
"workflow/envs/main.yaml"
shell:
"samtools index -b {input.bam}"
# call SNPs using longshot
rule find_variants:
input:
bam="data/mapped_reads/{sample}.bam",
indexed_bam="data/mapped_reads/{sample}.bam.bai",
ref=expand("{ref}", ref=config["reference"]),
ref_idx=expand("{ref}.fai", ref=config["reference"])
output:
variants="data/variants/{sample}_variants.vcf"
conda:
"workflow/envs/main.yaml"
shell:
"longshot --ref {input.ref} --bam {input.bam} --out {output.variants}"