blob: 1982f65328ba9e7fdbebba3528cb234a80f0ad1d (
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
|
;;; 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 ((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 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")
<>)
(find-files #$hsmice-r-mixed-model-gwas
"\\-pvalues$"))))))
(define hsmice-qtl-checked
(computed-file "hsmice-qtl-checked" hsmice-qtl-checked-gexp))
(define-public hsmice-test
(directory-union "hsmice-test"
(list hsmice-r-mixed-model-gwas
hsmice-qtl-checked)))
hsmice-test
|