aboutsummaryrefslogtreecommitdiff
path: root/gn/packages/genenetwork.scm
blob: 42baeafccc08d09da01c35f948039c40a7b4160b (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
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
;; Bioinformatics module

(define-module (gn packages genenetwork)
  #:use-module ((guix licenses) #:prefix license:)
  #:use-module (guix packages)
  #:use-module (guix utils)
  #:use-module (guix download)
  #:use-module (guix git-download)
  #:use-module (guix build-system cargo)
  #:use-module (guix build-system gnu)
  #:use-module (guix build-system python)
  #:use-module (guix build-system trivial)
  #:use-module (guix graph)
  #:use-module (guix scripts graph)
  #:use-module (guix store)
  #:use-module (guix gexp)
  #:use-module (gnu packages)
  #:use-module (gnu packages base)
  #:use-module (gnu packages bioconductor)
  #:use-module (gnu packages bioinformatics)
  #:use-module (gnu packages check)
  #:use-module (gnu packages cran)
  #:use-module (gnu packages crates-io)
  #:use-module (gnu packages compression)
  #:use-module (gnu packages databases)
  #:use-module (gnu packages ghostscript)
  #:use-module (gnu packages golang)
  #:use-module (gnu packages graph)
  #:use-module (gnu packages graphviz)
  #:use-module (gnu packages parallel)
  #:use-module (gnu packages python)
  #:use-module (gnu packages python-check)
  #:use-module (gnu packages python-crypto)
  #:use-module (gnu packages python-science)
  #:use-module (gnu packages python-web)
  #:use-module (gnu packages python-xyz)
  #:use-module (gnu packages rdf)
  #:use-module (gnu packages rust)
  #:use-module (gnu packages scheme)
  #:use-module (gnu packages statistics)
  #:use-module (gnu packages version-control)
  ; #:use-module (gnu packages vim)
  #:use-module (gnu packages web)
  ; #:use-module (gnu packages wget)
  #:use-module (gnu packages xml)
  #:use-module (gn packages bioinformatics)
  #:use-module (gn packages gemma)
  #:use-module (gn packages javascript)
  #:use-module (gn packages python)
  #:use-module (gn packages statistics)
  #:use-module (gn packages twint)
  #:use-module (gn packages web)
  #:use-module (srfi srfi-1))


(define-public rust-qtlreaper
  (let ((commit "2e7fed6d45b0b602d80fa2a55835f96ef1cba9e3")
        (revision "1"))
    (package
      (name "rust-qtlreaper")
      (version "0.1.4")
      (source
        (origin
          (method git-fetch)
          (uri (git-reference
                 (url "https://github.com/chfi/rust-qtlreaper.git")
                 (commit commit)))
          (file-name (git-file-name name version))
          (sha256
           (base32
            "0h70aalsplmc6xn1w7ha102n3bsi3gqkbnbrjvjm2za37c07gv0g"))))
      (build-system cargo-build-system)
      (arguments
       `(#:cargo-inputs
         (("rust-rand" ,rust-rand-0.6)
          ("rust-structopt" ,rust-structopt-0.2)
          ("rust-rayon" ,rust-rayon-1)
          ("rust-serde" ,rust-serde-1)
          ("rust-serde-json" ,rust-serde-json-1)
          ("rust-ndarray" ,rust-ndarray-0.12))
         #:phases
         (modify-phases %standard-phases
           ;; Test results vary based on the machine running them.
           (replace 'check
             (lambda _
               (or (assoc-ref %standard-phases 'check)
                   (begin
                     (substitute* "src/geneobject.rs"
                       ;; array![Genotype::Unk, Genotype::Unk, Genotype::Pat]
                       (("0.3421367343627405") "0.3421367343627406")
                       ;; array![Genotype::Unk, Genotype::Unk, Genotype::Unk]
                       (("-0.3223330030526561") "-0.32233300305265566"))
                     (assoc-ref %standard-phases 'check)))
               #t)))))
      (home-page "https://github.com/chfi/rust-qtlreaper")
      (synopsis "Reimplementation of genenetwork/QTLReaper in Rust")
      (description "Reimplementation of genenetwork/QTLReaper in Rust")
      (license #f))))


(define-public genenetwork3
  (let ((commit "77c274b79c3ec01de60e90db3299763cb58f715b"))
    (package
      (name "genenetwork3")
      (version (string-append "0.0.1-guix-" (string-take commit 7)))
      (source
       (origin
         (method git-fetch)
         (uri (git-reference
               (url "https://github.com/genenetwork/genenetwork3.git")
               (commit commit)))
         (file-name (git-file-name name version))
         (sha256
          (base32
           "0ha70ibr7dqz0kzmgccx5l6nrmmf2a2mj7scg6jllx232crjby72"))))
      (propagated-inputs `(("coreutils" ,coreutils)
                           ("gemma-wrapper" ,gemma-wrapper)
                           ("csvdiff" ,go-github-com-aswinkarthik-csvdiff)
                           ("python" ,python-wrapper)
                           ("python-bcrypt" ,python-bcrypt)
                           ("python-flask" ,python-flask)
                           ("python-flask-cors" ,python-flask-cors)
                           ("python-ipfshttpclient" ,python-ipfshttpclient)
                           ("python-mypy" ,python-mypy)
                           ("python-mypy-extensions" ,python-mypy-extensions)
                           ("python-mysqlclient" ,python-mysqlclient)
                           ("python-numpy" ,python-numpy)
                           ("python-pylint" ,python-pylint)
                           ("python-redis" ,python-redis)
                           ("python-requests" ,python-requests)
                           ("python-scipy" ,python-scipy)
                           ("python-plotly" ,python-plotly)
                           ("python-sqlalchemy-stubs"
                            ,python-sqlalchemy-stubs)
                           ("r-optparse" ,r-optparse)
                           ("r-qtl" ,r-qtl)
                           ("r-stringi" ,r-stringi)
			   ("r-wgcna" ,r-wgcna)
			   ("r-rjson" ,r-rjson)))
      (build-system python-build-system)
      (home-page "https://github.com/genenetwork/genenetwork3")
      (synopsis "GeneNetwork3 API for data science and machine learning.")
      (description "GeneNetwork3 API for data science and machine learning.")
      (license license:agpl3+))))

(define-public genenetwork2
  (let ((commit "fe345c9f2e99be748511f6889420d6560a553a37"))
    (package
      (name "genenetwork2")
      (version (string-append "3.11-guix-" (string-take commit 7) ))
      (source (origin
                (method git-fetch)
                (uri (git-reference
                      (url "https://github.com/genenetwork/genenetwork2.git")
                      (commit commit)))
                (file-name (string-append name "-" version))
                (sha256
                 (base32
                  "1y6psmxpm3qn78dx6xfc11rdpf22vf807qb7grnp82gl19q6408w"))))
      (native-inputs
       `(("graphviz" ,graphviz)
         ;; And the graphs
         ;("genenetwork-graph" ,genenetwork-graph)
         ;("dag-svg-file" ,dag-svg-file)
         ))
      (propagated-inputs
       `(("genenetwork3" ,genenetwork3)
         ("parallel" ,parallel) ;; GNU parallel
         ("coreutils" ,coreutils)
         ("git" ,git)
         ("which" ,which)
         ("grep" ,grep)
         ("r" ,r)
         ("r-ctl" ,r-ctl)
         ; ("r-phewas" ,r-phewas)
         ("r-qtl" ,r-qtl)
         ("r-wgcna" ,r-wgcna)
         ("redis" ,redis)
         ("mariadb" ,mariadb)
         ("gemma" ,gemma-gn2)
         ("gemma-wrapper" ,gemma-wrapper)
         ; ("genenetwork2-files-small" ,genenetwork2-files-small)
         ("plink-ng-gn" ,plink-ng-gn)
         ; ("pylmm-gn2" ,pylmm-gn2)
         ("rust-qtlreaper" ,rust-qtlreaper)
         ("glibc-utf8-locales" ,glibc-utf8-locales)
         ("nginx" ,nginx)
         ("python" ,python-wrapper)
         ("python-pillow" ,python-pillow)
         ("python-coverage" ,python-coverage)
         ("python-configparser" ,python-configparser) ;; maintenance/scripts
         ("python-flask" ,python-flask)
         ("gunicorn" ,gunicorn)
         ("python-autopep8" ,python-autopep8)
         ("python-cssselect" ,python-cssselect)
         ("python-flask-debugtoolbar" ,python-flask-debugtoolbar)
         ("python-elasticsearch" ,python-elasticsearch)
         ("python-htmlgen" ,python-htmlgen)
         ("python-jinja2" ,python-jinja2)
         ("python-sqlalchemy" ,python-sqlalchemy)
         ("python-flask-sqlalchemy" ,python-flask-sqlalchemy)
         ("python-setuptools" ,python-setuptools)
         ("python-scipy" ,python-scipy)
         ("python-lxml" ,python-lxml)
         ("python-mechanize" ,python-mechanize)
         ("python-mysqlclient" ,python-mysqlclient)
         ("python-mypy" ,python-mypy)
         ("python-numpy" ,python-numpy)
         ("python-pandas" ,python-pandas)
         ("python-parameterized" ,python-parameterized)
         ("python-passlib" ,python-passlib)
         ("python-pylint" ,python-pylint)
         ("python-redis" ,python-redis)
         ("python-requests" ,python-requests)
         ("python-simplejson" ,python-simplejson)
         ("python-pyyaml" ,python-pyyaml)
         ("python-markdown" ,python-markdown)
         ("python-rdflib" ,python-rdflib)
         ("python-twint" ,python-twint)
         ("python-unittest2" ,python-unittest2)
         ;; TODO: Get rid of Python R bindings
         ("python-rpy2" ,python-rpy2-next)
         ("python-beautifulsoup4" ,python-beautifulsoup4)
         ;; Disable for now. Build fails on Penguin2
         ;; ("python-flask-socketio" ,python-flask-socketio)
         ("python-xlsxwriter" ,python-xlsxwriter)
         ;; All the external js dependencies
         ("javascript-twitter-post-fetcher" ,javascript-twitter-post-fetcher)
         ("javascript-cytoscape" ,javascript-cytoscape)
         ("javascript-panzoom" ,javascript-cytoscape-panzoom)
         ("javascript-qtip" ,javascript-cytoscape-qtip)
         ("javascript-chroma" ,javascript-chroma)
         ("javascript-d3-tip" ,javascript-d3-tip)
         ("javascript-jscolor" ,javascript-jscolor)
         ("javascript-colorbox" ,javascript-colorbox)
         ("javascript-jszip" ,javascript-jszip)
         ("js-jstat" ,js-jstat)
         ("js-md5" ,js-md5)
         ("js-parsley" ,js-parsley)
         ("javascript-plotly" ,javascript-plotly)
         ("javascript-typeahead" ,javascript-typeahead)
         ("js-underscore" ,js-underscore)
         ("js-smart-time-ago" ,js-smart-time-ago)
         ("javascript-nouislider" ,javascript-nouislider)
         ("javascript-purescript-genome-browser" ,javascript-purescript-genome-browser)
         ("javascript-ckeditor" ,javascript-ckeditor)
         ("javascript-datatables" ,javascript-datatables)
         ("javascript-datatables-scroller" ,javascript-datatables-scroller)
         ("javascript-datatables-buttons" ,javascript-datatables-buttons)
         ("javascript-datatables-buttons-bootstrap" ,javascript-datatables-buttons-bootstrap)
         ("javascript-datatables-plugins" ,javascript-datatables-plugins)
         ("javascript-datatables-col-reorder" ,javascript-datatables-col-reorder)
         ("javascript-datatables-col-resize" ,javascript-datatables-col-resize)
         ("javascript-datatables-buttons-styles" ,javascript-datatables-buttons-styles)
         ("javascript-shapiro-wilk" ,javascript-shapiro-wilk)
         ("javascript-underscore-string" ,javascript-underscore-string)
         ("javascript-qtip2" ,javascript-qtip2)
         ("javascript-d3js" ,javascript-d3js)
         ("javascript-nvd3" ,javascript-nvd3)
         ("javascript-bootstrap" ,javascript-bootstrap)
         ("javascript-jquery" ,javascript-jquery)
         ("javascript-zxcvbn" ,javascript-zxcvbn)
         ("javascript-jquery-ui" ,javascript-jquery-ui)
         ("javascript-jquery-cookie" ,javascript-jquery-cookie)
         ("javascript-font-awesome" ,javascript-font-awesome)))
      (inputs
       `(("javascript-colorbox" ,(package-source javascript-colorbox))))
      (build-system python-build-system)
      (arguments
       `(#:tests? #f        ; no 'setup.py test'
         #:phases
         (modify-phases %standard-phases
            (delete 'reset-gzip-timestamps)
            (add-after 'unpack 'fix-paths-scripts
              (lambda _
                (substitute* "bin/genenetwork2"
                  (("/usr/bin/env") (which "env"))
                  (("python ") (string-append (which "python3") " "))
                  (("readlink") (which "readlink"))
                  (("dirname") (which "dirname"))
                  (("basename") (which "basename"))
                  (("cat") (which "cat"))
                  (("echo") (which "echo"))
                  (("redis-server") (which "redis-server"))
                  (("git") (which "git"))
                  (("grep") (which "grep"))
                  (("rm") (which "rm"))
                  (("which") (which "which")))
                #t))
            ; (add-after 'unpack 'patch-javascript
            ;  (lambda* (#:key inputs #:allow-other-keys)
            ;    (let ((colorbox (assoc-ref inputs "javascript-colorbox"))
            ;          (gn2 "/share/genenetwork2/javascript/"))
            ;      (delete-file-recursively "wqflask/wqflask/static/packages/colorbox")
            ;      (copy-recursively colorbox "wqflask/wqflask/static/packages/colorbox")
            ;      #t)))
            (add-before 'install 'fix-paths
              (lambda* (#:key inputs #:allow-other-keys)
                (let* (
                       ; (datafiles (string-append (assoc-ref inputs "genenetwork2-files-small") "/share/genenetwork2"))
                       ; (pylmmcmd (string-append (assoc-ref inputs "pylmm-gn2") "/bin/pylmm_redis"))
                       (plink2cmd (string-append (assoc-ref inputs "plink-ng-gn") "/bin/plink2"))
                       (gemmacmd (string-append (assoc-ref inputs "gemma") "/bin/gemma"))
                       )

                  (substitute* '("etc/default_settings.py")
                    ; (("^GENENETWORK_FILES +=.*") (string-append "GENENETWORK_FILES = \"" datafiles "\"\n" ))
                    ; (("^PYLMM_COMMAND =.*") (string-append "PYLMM_COMMAND = \"" pylmmcmd "\"\n" ))
                    (("^PLINK_COMMAND =.*") (string-append "PLINK_COMMAND = \"" plink2cmd "\"\n" ))
                    (("^GEMMA_COMMAND =.*") (string-append "GEMMA_COMMAND = \"" gemmacmd "\"\n" ))
                    )
                  )))
            ; (add-after 'install 'generate-graph
            ;  (lambda* (#:key inputs outputs #:allow-other-keys)
            ;    (call-with-output-file
            ;        (string-append
            ;         (assoc-ref outputs "out")
            ;         "/lib/python"
            ;         (python-version (assoc-ref inputs "python"))
            ;         "/site-packages"
            ;         "/wqflask/dependency-graph.html")
            ;      (lambda (port)
            ;        (format
            ;         port "~a"
            ;         ,(call-with-output-string
            ;            (lambda (p)
            ;              (with-output-to-port p
            ;                (lambda ()
            ;                  (run-with-store
            ;                      (open-connection)
            ;                    (export-graph
            ;                     (list this-package)
            ;                     p
            ;                     #:node-type %package-node-type
            ;                     #:backend %d3js-backend)))))))))))
            ;(add-after 'install 'generate-dag-svg-file
            ;  (lambda* (#:key inputs outputs #:allow-other-keys)
            ;    (let* ((output-dir
            ;            (string-append
            ;             (assoc-ref outputs "out")
            ;             "/lib/python"
            ;             (python-version (assoc-ref inputs "python"))
            ;             "/site-packages/wqflask/"))
            ;           (dot-file
            ;            (string-append
            ;             output-dir
            ;             "dependency-graph.dot"))
            ;           (svg-file
            ;            (string-append
            ;             output-dir
            ;             "dependency-graph.svg")))
            ;      (begin
            ;        (call-with-output-file
            ;            dot-file
            ;          (lambda (port)
            ;            (format
            ;             port "~a"
            ;             ,(call-with-output-string
            ;                (lambda (p)
            ;                  (with-output-to-port p
            ;                    (lambda ()
            ;                      (run-with-store
            ;                          (open-connection)
            ;                        (export-graph
            ;                         (list this-package)
            ;                         p
            ;                         #:node-type %package-node-type
            ;                         #:backend %graphviz-backend)))))))))
            ;        (invoke "dot" "-Tsvg" "-o" svg-file dot-file)))))

            ;; TODO: Use this to replace the two previous phases.
            ;(add-after 'install 'install-generated-files
            ;  (lambda* (#:key inputs outputs #:allow-other-keys)
            ;    (let ((output-dir
            ;           (string-append
            ;            (assoc-ref outputs "out")
            ;            "/lib/python"
            ;            (python-version (assoc-ref inputs "python"))
            ;            "/site-packages/wqflask/")))
            ;      (install-file (string-append %dag-svg-file "/dependency-graph.dot") output-dir)
            ;      (install-file (string-append %dag-svg-file "/dependency-graph.svg") output-dir)
            ;      (install-file (string-append %genenetwork-graph "/dependency-graph.html") output-dir)
            ;      #t)))

            (add-after 'install 'generate-dependency-file
              (lambda* (#:key inputs outputs #:allow-other-keys)
                (call-with-output-file
                    (string-append
                     (assoc-ref outputs "out")
                     "/lib/python"
                     (python-version (assoc-ref inputs "python"))
                     "/site-packages"
                     "/wqflask/DEPENDENCIES.md")
                  (lambda (port)
                    (format
                     port "
#### System Inputs (generated from ~a package defined in ~a)
|Name | Description |
|-----|-------------|
~a
"
                     ,(package-name this-package)
                     (string-append
                      "[genenetwork.scm]"
                      "(http://git.genenetwork.org/"
                      "guix-bioinformatics/guix-bioinformatics"
                      "/src/branch/master/gn/packages/"
                      "genenetwork.scm)")
                     ,(apply
                       string-append
                       (map
                        (lambda (input)
                          (let* ((pkg (cadr input))
                                 (name (package-name pkg))
                                 (version (package-version pkg))
                                 (home-page (package-home-page pkg))
                                 (description (package-synopsis pkg)))
                            (string-append
                             "| **[" name "](" home-page ")** v"
                             version"| "
                             description " |\n")))
                        (package-propagated-inputs this-package)))))))))))
      (home-page "http://genenetwork.org/")
      (synopsis "Full genenetwork services")
      (description "Genenetwork installation sumo.")
      (license license:agpl3+))))

;; ./pre-inst-env guix download http://files.genenetwork.org/raw_database/db_webqtl_s.zip
;; 0sscjh0wml2lx0mb43vf4chg9gpbfi7abpjxb34n3kyny9ll557x

(define-public genenetwork2-files-small
  (let ((pfff "xx"))
    (package
    (name "genenetwork2-files-small")
    (version "1.0")
    (source
     (origin
       (method url-fetch)
       (uri "http://files.genenetwork.org/data_files/gn2_data_s-20160303-C9E672ECED1F51B915DE419B5B2C524E.tar.lz4")
       (file-name (string-append name "-" pfff))
       (sha256
        (base32 "058ymx3af6abdhdxyxj0i9qfvb6v7j091frjpp6jh4ahks7r23lj"))))
    (build-system trivial-build-system)
    (native-inputs `(("lz4" ,lz4)
                     ("tar" ,tar)
                     ("source" ,source)))

    (arguments
     `(#:modules ((guix build utils))
       #:builder
       (let* ((out (assoc-ref %outputs "out"))
              (name "gn2_data_s")
              (tarfn (string-append name ".tar"))
              (targetdir (string-append out "/share/genenetwork2/")))
           (begin
             (use-modules (guix build utils))
             (let ((source (assoc-ref %build-inputs "source"))
                   (lz4unpack (string-append (assoc-ref %build-inputs "lz4") "/bin/lz4"))
                   (tar (string-append (assoc-ref %build-inputs "tar") "/bin/tar")))
               (and
                 (zero? (system* lz4unpack source "-d" tarfn))
                 (zero? (system* tar "xf" tarfn))
                 (mkdir-p targetdir)
                 (copy-recursively name targetdir)))))))
    (home-page "http://genenetwork.org/")
    (synopsis "Small file archive to run on genenetwork")
    (description "Genenetwork genotype and mapping files.")
    (license license:agpl3+))))

(define-public genenetwork2-database-small
  (let ((md5 "93e745e9c"))
    (package
    (name "genenetwork2-database-small")
    (version "1.0")
    (source
     (origin
       (method url-fetch)
       (uri "http://files.genenetwork.org/raw_database/db_webqtl_s.zip")
       (file-name (string-append name "-" md5))
       (sha256
        (base32 "0sscjh0wml2lx0mb43vf4chg9gpbfi7abpjxb34n3kyny9ll557x"))))
    (build-system trivial-build-system)
    (native-inputs `(("unzip" ,unzip)
                     ("source" ,source)))

    (arguments
     `(#:modules ((guix build utils))
       #:builder (begin
                   (use-modules (guix build utils))
                   (let ((source (assoc-ref %build-inputs "source"))
                         (unzip (string-append (assoc-ref %build-inputs "unzip") "/bin/unzip")))
                   (and (mkdir "db")
                        (zero? (system* unzip source "-d" "db"))
                        (chdir "db"))))))
    (home-page "http://genenetwork.org/")
    (synopsis "Small database to run on genenetwork")
    (description "Genenetwork installation + database.")
    (license license:agpl3+))))



(define (genenetwork-graph)
  (with-imported-modules '((guix build utils))
    (gexp->derivation "genenetwork-graph"
      #~(begin
          (use-modules (guix build utils)
                       (srfi srfi-1))

          (define (python-version package)
            (let* ((version     (last (string-split
                                        package
                                        #\-)))
                   (components  (string-split version #\.))
                   (major+minor (take components 2)))
              (string-join major+minor ".")))

          (let ((html-file (string-append #$output
                                          "/lib/python"
                                          (python-version #$python)
                                          "/site-packages/wqflask"
                                          "/dependency-graph.html")))
            (mkdir-p (dirname html-file))
            (call-with-output-file html-file
              (lambda (port)
                (format
                  port "~a"
                  #$(call-with-output-string
                     (lambda (p)
                       (with-output-to-port p
                         (lambda ()
                           (run-with-store
                             (open-connection)
                             (export-graph
                              (list genenetwork2)
                              p
                              #:node-type %package-node-type
                              #:backend %d3js-backend))))))))))))))

;(define (computed-genenetwork-graph)
;  (with-imported-modules '((guix build utils))
;    (computed-file "genenetwork-graph"
;      #~(begin
;          (use-modules (guix build utils))
;            (call-with-output-file #$output
;              (lambda (port)
;                (format
;                  port "~a"
;                  #$(call-with-output-string
;                      (lambda (p)
;                        (with-output-to-port p
;                          (lambda ()
;                            (run-with-store
;                              (open-connection)
;                              (export-graph
;                                (list genenetwork1)
;                                p
;                                #:node-type %package-node-type
;                                #:backend %d3js-backend)))))))))))))

(define (dag-svg-file)
  (with-imported-modules '((guix build utils))
    (gexp->derivation "dag-svg-file"
      #~(begin
          (use-modules (guix build utils)
                       (srfi srfi-1))

        (define (python-version package)
          (let* ((version     (last (string-split
                                      package
                                      #\-)))
                 (components  (string-split version #\.))
                 (major+minor (take components 2)))
            (string-join major+minor ".")))

          (let* ((dest-dir (string-append #$output
                                          "/lib/python"
                                          (python-version #$python)
                                          "/site-packages/wqflask"))
                 (dot-file (string-append dest-dir "/dependency-graph.dot"))
                 (svg-file (string-append dest-dir "/dependency-graph.svg")))
            (mkdir-p dest-dir)
            (call-with-output-file dot-file
              (lambda (port)
                (format
                  port "~a"
                  #$(call-with-output-string
                     (lambda (p)
                       (with-output-to-port p
                         (lambda ()
                           (run-with-store
                             (open-connection)
                             (export-graph
                              (list genenetwork2)
                              p
                              #:node-type %package-node-type
                              #:backend %graphviz-backend)))))))))
            (invoke #+(file-append graphviz "/bin/dot")
                    "-Tsvg" "-o" svg-file dot-file))))))

;(define-public genenetwork2-combined
;  (directory-union
;    "genenetwork2"
;    (list genenetwork2 genenetwork-graph dag-svg-file)))