blob: 8e50160dc9ca4ddbe6556894530b425a7d79b855 (
plain)
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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
|
;;; pyhegp --- Homomorphic encryption of genotypes and phenotypes
;;; Copyright © 2025 Arun Isaac <arunisaac@systemreboot.net>
;;;
;;; This file is part of pyhegp.
;;;
;;; pyhegp is free software: you can redistribute it and/or modify it
;;; under the terms of the GNU General Public License as published by
;;; the Free Software Foundation, either version 3 of the License, or
;;; (at your option) any later version.
;;;
;;; pyhegp is distributed in the hope that it will be useful, but
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
;;; General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with pyhegp. If not, see <https://www.gnu.org/licenses/>.
(define-module (hsmice-test)
#:use-module ((gn packages bioinformatics) #:select (r-genio))
#:use-module ((gn packages julia) #:select (julia-pipe))
#:use-module ((gn packages julia) #:select (julia-jwas) #:prefix guix:)
#:use-module ((gnu packages base) #:select (tar))
#:use-module ((gnu packages compression) #:select (gzip))
#:use-module ((gnu packages cran) #:select (r-dplyr r-purrr r-qqman r-stringr))
#:use-module ((gnu packages julia) #:select (julia))
#:use-module ((gnu packages julia-xyz) #:select (julia-csv julia-dataframes))
#:use-module ((gnu packages python) #:select (python))
#:use-module ((gnu packages python-science) #:select (python-pandas))
#:use-module ((gnu packages python-xyz) #:select (python-click))
#:use-module ((gnu packages statistics) #:select (r r-readr r-tibble r-tidyr))
#:use-module (guix build-system r)
#:use-module (guix download)
#:use-module (guix gexp)
#:use-module (guix git-download)
#:use-module ((guix licenses) #:prefix license:)
#:use-module (guix packages)
#:use-module (guix profiles)
#:use-module (guix utils)
#:use-module ((pyhegp-package) #:select (pyhegp)))
;; See details of dataset at
;; https://rdr.ucl.ac.uk/articles/dataset/HSmice_tar_gz/24114471?file=42304248
(define hsmice-data
(origin
(method url-fetch)
(uri "https://ndownloader.figshare.com/files/42304248")
(file-name "HSmice.tar.gz")
(sha256
(base32
"1s6a83r0mll8z2lfv1b94zr2sjdrky5nyq1mpgl8fjjb5s8v2vyx"))))
(define-public r-mixed-model-gwas
(package
(name "r-mixed-model-gwas")
(version "1.3.1")
(source (origin
(method git-fetch)
(uri (git-reference
(url "https://github.com/encryption4genetics/mixed-model-gwas")
(commit (string-append "v" version))))
(file-name (git-file-name name version))
(sha256
(base32
"0vll55v8wjc0179n5q9ch9ah3dvgymc374wlbz33yzyi35yr8ds2"))))
(build-system r-build-system)
(home-page "https://github.com/encryption4genetics/mixed-model-gwas")
(synopsis "R mixed model GWAS")
(description "@code{r-mixed-model-gwas} implements a mixed model @acronym{GWAS,
genome-wide association study} library for R.")
(license license:gpl3+)))
(define hsmice-wrangled-gexp
(let ((script-profile (profile
(content (packages->manifest
(list gzip tar r r-dplyr r-genio
r-purrr r-readr r-tibble r-tidyr))))))
(with-imported-modules '((guix build utils))
#~(begin
(use-modules (guix build utils))
(mkdir #$output)
(set-path-environment-variable
"PATH" '("bin") '(#$script-profile))
(set-path-environment-variable
"R_LIBS_SITE" '("site-library") '(#$script-profile))
(invoke "tar" "-xvf" #$hsmice-data
"./HSmice/1_QTL_data/")
(invoke "Rscript"
#$(local-file "../e2e-tests/hsmice/wrangle.r")
"HSmice/1_QTL_data" #$output)))))
(define hsmice-wrangled
(computed-file "hsmice-wrangled" hsmice-wrangled-gexp))
(define hsmice-ciphertext-gexp
(let ((script-profile (profile
(content (packages->manifest (list pyhegp))))))
(with-imported-modules '((guix build utils))
#~(begin
(use-modules (guix build utils)
(srfi srfi-26))
(mkdir #$output)
(set-path-environment-variable
"PATH" '("bin") '(#$script-profile))
(for-each (cut install-file <> (getcwd))
(find-files #$hsmice-wrangled "\\.tsv$"))
;; Simple data sharing workflow
(invoke "pyhegp" "encrypt" "genotype.tsv" "phenotype.tsv")
;; Joint/federated analysis workflow
(invoke "pyhegp" "summary" "genotype1.tsv" "-o" "summary1")
(invoke "pyhegp" "summary" "genotype2.tsv" "-o" "summary2")
(invoke "pyhegp" "pool" "-o" "complete-summary" "summary1" "summary2")
(invoke "pyhegp" "encrypt" "-s" "complete-summary" "genotype1.tsv" "phenotype1.tsv")
(invoke "pyhegp" "encrypt" "-s" "complete-summary" "genotype2.tsv" "phenotype2.tsv")
(invoke "pyhegp" "cat-genotype" "-o" "complete-genotype.tsv.hegp"
"genotype1.tsv.hegp" "genotype2.tsv.hegp")
(invoke "pyhegp" "cat-phenotype" "-o" "complete-phenotype.tsv.hegp"
"phenotype1.tsv.hegp" "phenotype2.tsv.hegp")
(for-each (cut install-file <> #$output)
(find-files (getcwd) "\\.tsv.hegp$"))))))
(define hsmice-ciphertext
(computed-file "hsmice-ciphertext" hsmice-ciphertext-gexp))
(define hsmice-r-mixed-model-gwas-gexp
(let ((gwas-script (local-file "../e2e-tests/hsmice/gwas.r"))
(script-profile (profile
(content (packages->manifest
(list r r-dplyr r-mixed-model-gwas
r-qqman r-readr r-stringr
r-tibble r-tidyr))))))
(with-imported-modules '((guix build utils))
#~(begin
(use-modules (guix build utils))
(mkdir #$output)
(set-path-environment-variable
"PATH" '("bin") '(#$script-profile))
(set-path-environment-variable
"R_LIBS_SITE" '("site-library") '(#$script-profile))
;; GWAS on plaintext
(invoke "Rscript" #$gwas-script
#$(file-append hsmice-wrangled "/genotype.tsv")
#$(file-append hsmice-wrangled "/phenotype.tsv")
(string-append #$output "/plaintext-pvalues"))
(copy-file "Rplots.pdf"
(string-append #$output "/plaintext-manhattan.pdf"))
;; GWAS with simple ciphertext data sharing
(invoke "Rscript" #$gwas-script
#$(file-append hsmice-ciphertext "/genotype.tsv.hegp")
#$(file-append hsmice-ciphertext "/phenotype.tsv.hegp")
(string-append #$output "/ciphertext-pvalues"))
(copy-file "Rplots.pdf"
(string-append #$output "/ciphertext-manhattan.pdf"))
;; Joint federated GWAS
(invoke "Rscript" #$gwas-script
#$(file-append hsmice-ciphertext "/complete-genotype.tsv.hegp")
#$(file-append hsmice-ciphertext "/complete-phenotype.tsv.hegp")
(string-append #$output "/federated-ciphertext-pvalues"))
(copy-file "Rplots.pdf"
(string-append #$output "/federated-ciphertext-manhattan.pdf"))))))
(define hsmice-r-mixed-model-gwas
(computed-file "hsmice-r-mixed-model-gwas" hsmice-r-mixed-model-gwas-gexp))
(define hsmice-qtl-checked-gexp
(let ((script-profile (profile
(content (packages->manifest
(list python python-pandas))))))
(with-imported-modules '((guix build utils))
#~(begin
(use-modules (guix build utils)
(srfi srfi-26))
(mkdir #$output)
(set-path-environment-variable
"PATH" '("bin") '(#$script-profile))
(set-path-environment-variable
"GUIX_PYTHONPATH"
'(#$(string-append "lib/python"
(version-major+minor (package-version python))
"/site-packages"))
'(#$script-profile))
;; Check that the QTL is where it should be.
(for-each (cut invoke
"python3"
#$(local-file "../e2e-tests/hsmice/check-qtl.py")
<>
"p < 1e-10")
(find-files #$hsmice-r-mixed-model-gwas
"\\-pvalues$"))))))
(define hsmice-qtl-checked
(computed-file "hsmice-qtl-checked" hsmice-qtl-checked-gexp))
;; Our CI system does not have enough memory to run tests for
;; julia-jwas. So, we disable them.
(define julia-jwas
(package
(inherit guix:julia-jwas)
(arguments
(substitute-keyword-arguments (package-arguments guix:julia-jwas)
((#:tests? tests? #f) #f)))))
(define hsmice-jwas-gwas-gexp
(let ((gwas-script (local-file "../e2e-tests/hsmice/jwas-gwas.jl"))
(jwas-manhattan-script (local-file "../e2e-tests/hsmice/jwas-manhattan.r"))
(script-profile (profile
(content (packages->manifest
(list julia julia-csv julia-dataframes
julia-jwas julia-pipe
r r-dplyr r-qqman r-readr))))))
(with-imported-modules '((guix build utils))
#~(begin
(use-modules (guix build utils))
(mkdir #$output)
(setenv "HOME" "/tmp")
(set-path-environment-variable
"PATH" '("bin") '(#$script-profile))
(set-path-environment-variable
"JULIA_LOAD_PATH" '("share/julia/loadpath") '(#$script-profile))
(set-path-environment-variable
"JULIA_DEPOT_PATH" '("share/julia") '(#$script-profile))
(set-path-environment-variable
"R_LIBS_SITE" '("site-library") '(#$script-profile))
;; GWAS on plaintext
(invoke "julia" #$gwas-script
#$(file-append hsmice-wrangled "/genotype.tsv")
#$(file-append hsmice-wrangled "/phenotype.tsv")
(string-append #$output "/plaintext-jwas-gwas.tsv"))
(invoke "Rscript" #$jwas-manhattan-script
(string-append #$output "/plaintext-jwas-gwas.tsv"))
(copy-file "Rplots.pdf"
(string-append #$output "/plaintext-jwas-manhattan.pdf"))
;; GWAS with simple ciphertext data sharing
(invoke "julia" #$gwas-script
#$(file-append hsmice-ciphertext "/genotype.tsv.hegp")
#$(file-append hsmice-ciphertext "/phenotype.tsv.hegp")
(string-append #$output "/ciphertext-jwas-gwas.tsv"))
(invoke "Rscript" #$jwas-manhattan-script
(string-append #$output "/ciphertext-jwas-gwas.tsv"))
(copy-file "Rplots.pdf"
(string-append #$output "/ciphertext-jwas-manhattan.pdf"))
;; Joint federated GWAS
(invoke "julia" #$gwas-script
#$(file-append hsmice-ciphertext "/complete-genotype.tsv.hegp")
#$(file-append hsmice-ciphertext "/complete-phenotype.tsv.hegp")
(string-append #$output "/federated-ciphertext-jwas-gwas.tsv"))
(invoke "Rscript" #$jwas-manhattan-script
(string-append #$output "/federated-ciphertext-jwas-gwas.tsv"))
(copy-file "Rplots.pdf"
(string-append #$output "/federated-ciphertext-jwas-manhattan.pdf"))))))
(define hsmice-jwas-gwas
(computed-file "hsmice-jwas-gwas" hsmice-jwas-gwas-gexp))
(define hsmice-jwas-qtl-checked-gexp
(let ((script-profile (profile
(content (packages->manifest
(list python python-pandas))))))
(with-imported-modules '((guix build utils))
#~(begin
(use-modules (guix build utils)
(srfi srfi-26))
(mkdir #$output)
(set-path-environment-variable
"PATH" '("bin") '(#$script-profile))
(set-path-environment-variable
"GUIX_PYTHONPATH"
'(#$(string-append "lib/python"
(version-major+minor (package-version python))
"/site-packages"))
'(#$script-profile))
;; Check that the QTL is where it should be.
(for-each (cut invoke
"python3"
#$(local-file "../e2e-tests/hsmice/check-qtl.py")
<>
"modelfrequency > 0.4")
(find-files #$hsmice-jwas-gwas
"\\-gwas.tsv$"))))))
(define hsmice-jwas-qtl-checked
(computed-file "hsmice-jwas-qtl-checked" hsmice-jwas-qtl-checked-gexp))
(define-public hsmice-test
(directory-union "hsmice-test"
(list hsmice-r-mixed-model-gwas
hsmice-qtl-checked
hsmice-jwas-gwas
hsmice-jwas-qtl-checked)))
hsmice-test
|