-
Notifications
You must be signed in to change notification settings - Fork 0
/
Snakefile
150 lines (133 loc) · 3.82 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
import polars as pl
phenotype_names = (
pl.read_csv("data/pheno/pheno_jan2024.tsv", separator="\t", n_rows=0)
.select("^b_.*$")
.columns
)
rule all:
input:
# Inputs
multiext("data/geno/hapmap3_variants_white_british_100k", ".pgen", ".psam", ".pvar"),
"data/pheno/pheno_jan2024.tsv",
"data/pheno/covar.tsv",
# Outputs
multiext("data/geno/geno_500k", ".pgen", ".psam", ".pvar"),
"data/pheno/binary_pheno.tsv",
multiext("data/grm/gcta.grm", ".bin", ".id", ".N.bin", ".sp"),
expand(
"data/gwas/plink.{phenotype}.glm.linear.zst",
phenotype=phenotype_names
),
rule filter_genotypes:
input:
geno = multiext("data/geno/hapmap3_variants_white_british_100k", ".pgen", ".psam", ".pvar"),
output:
multiext("data/geno/geno_500k", ".pgen", ".psam", ".pvar"),
params:
n_variants = 500_000,
input_prefix = "data/geno/hapmap3_variants_white_british_100k",
output_prefix = "data/geno/geno_500k"
shell:
"""
plink2 \
--pfile {params.input_prefix} \
--thin-count {params.n_variants} \
--make-pgen \
--out {params.output_prefix}
"""
rule filter_binary_pheno:
input:
raw_pheno = "data/pheno/pheno_jan2024.tsv",
psam = "data/geno/geno_500k.psam",
output:
"data/pheno/binary_pheno.tsv",
run:
psam_df = pl.scan_csv(input.psam, separator="\t").select("IID")
(
pl.scan_csv(input.raw_pheno, separator="\t")
.select(pl.col("#FID").alias("FID"), "IID", "^b_.*$")
.join(psam_df, on="IID")
.sink_csv(output[0], separator="\t")
)
rule gcta_grm_part:
input:
geno = multiext("data/geno/geno_500k", ".pgen", ".psam", ".pvar"),
output:
multiext("data/grm/gcta.part_10_{i}.grm", ".bin", ".id", ".N.bin"),
params:
geno_prefix = "data/geno/geno_500k",
output_prefix = "data/grm/gcta",
threads: 35
benchmark: "benchmarks/gcta_grm_part_{i}.txt"
shell:
"""
gcta \
--pfile {params.geno_prefix} \
--make-grm-part 10 {wildcards.i} \
--thread-num {threads} \
--out {params.output_prefix}
"""
rule gcta_collect_grm:
input:
collect(
"data/grm/gcta.part_10_{i}.grm.{ext}",
i=[f"{i:02}" for i in range(1, 11)],
ext=["bin", "id", "N.bin"]
),
output:
bin = "data/grm/gcta.grm.bin",
id = "data/grm/gcta.grm.id",
N = "data/grm/gcta.grm.N.bin",
benchmark: "benchmarks/gcta_collect_grm.txt"
params:
bin_files = " ".join(f"data/grm/gcta.part_10_{i:02}.grm.bin" for i in range(1, 11)),
id_files = " ".join(f"data/grm/gcta.part_10_{i:02}.grm.id" for i in range(1, 11)),
N_files = " ".join(f"data/grm/gcta.part_10_{i:02}.grm.N.bin" for i in range(1, 11))
shell:
"""
cat {params.bin_files} > {output.bin}
cat {params.id_files} > {output.id}
cat {params.N_files} > {output.N}
"""
rule gcta_sparsify_grm:
input:
multiext("data/grm/gcta.grm", ".bin", ".id", ".N.bin"),
output:
"data/grm/gcta.grm.sp",
params:
prefix = "data/grm/gcta",
threads: 35
benchmark: "benchmarks/gcta_sparsify_grm.txt"
shell:
"""
gcta \
--grm {params.prefix} \
--make-bK-sparse 0.05 \
--thread-num {threads} \
--out {params.prefix}
"""
rule gwas:
input:
geno = multiext("data/geno/geno_500k", ".pgen", ".psam", ".pvar"),
pheno = "data/pheno/pheno_jan2024.tsv",
covar = "data/pheno/covar.tsv",
output:
expand(
"data/gwas/plink.{phenotype}.glm.linear.zst",
phenotype=phenotype_names
),
params:
geno_prefix = "data/geno/geno_500k",
output_prefix = "data/gwas/plink",
threads: 35
benchmark: "benchmarks/gwas.txt"
shell:
"""
plink2 \
--pfile {params.geno_prefix} \
--glm zs hide-covar \
--pheno {input.pheno} \
--covar {input.covar} \
--threads {threads} \
--out {params.output_prefix}
"""