aboutsummaryrefslogtreecommitdiff
path: root/gn/packages/genenetwork.scm
blob: 5390faa84794673bc23a01b02995273aaee5224d (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
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
;; 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)
  #: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 build-system pyproject)
  #:use-module (guix graph)
  #:use-module (guix scripts graph)
  #:use-module (guix store)
  #:use-module (guix gexp)
  #:use-module (guix packages)
  #:use-module (gnu packages)
  #:use-module (gnu packages base)
  #:use-module (gnu packages certs)
  #: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 machine-learning)
  #:use-module (gnu packages parallel)
  #:use-module (gnu packages python)
  #:use-module (gnu packages python-build)
  #: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 search)
  #:use-module (gnu packages statistics)
  #:use-module (gnu packages textutils)
  #:use-module (gnu packages version-control)
  #:use-module (gnu packages web)
  #:use-module (gnu packages xml)
  #:use-module (gn packages bioinformatics)
  #:use-module (gn packages crates-io)
  #:use-module (gn packages gemma)
  #:use-module (gn packages javascript)
  #:use-module (gn packages node)
  #:use-module (gn packages python)
  #:use-module (gn packages statistics)
  #:use-module (gn packages web)
  #:use-module (gn packages python-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))))

; Tests on the upstream python-pengouin package are broken. So, we
; create this temporary workaround.
(define python-pingouin-without-tests
 (package
   (inherit python-pingouin)
   (arguments
    (substitute-keyword-arguments (package-arguments python-pingouin)
      ((#:tests? _ #f) #f)))))

(define-public genenetwork3
  (let ((commit "5ea318ef0dc5e0e54801d5d27aa9d55c168cabb0")
        (revision "5"))
    (package
      (name "genenetwork3")
      (version (git-version "0.1.0" revision commit))
      (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
           "14b8jzmwbjjrkhh6ajvp6xc7c8fsl918swjj7j6imy2pv7d9dcb3"))))
      (inputs
       (list python-click))
      (native-inputs
       (list python-hypothesis
             python-mypy
             python-mypy-extensions
             python-pylint))
      (propagated-inputs
       (list csvdiff
             diffutils
             nss-certs
             gemma-wrapper
             gn-rust-correlation
             python-argon2-cffi
             python-authlib
             python-bcrypt ;; Replace use of bcrypt with argon
             python-biopython
             python-email-validator
             python-flask
             python-flask-cors
             python-lmdb
             python-mysqlclient
             python-numpy
             python-pandas
             python-pingouin-without-tests
             python-plotly
             python-pyld
             python-pymonad
             python-pytest
             python-pytest-mock
             python-redis
             python-requests
             python-scikit-learn
             python-scipy
             python-sparqlwrapper
             python-wrapper
             python-xapian-bindings
             r
             r-ctl
             r-optparse
             r-qtl
	     r-qtl2
             r-rjson
             r-stringi
             r-wgcna
             rust-qtlreaper))
      (build-system python-build-system)
      (arguments
       (list #:phases
             #~(modify-phases %standard-phases
                 (replace 'check
                   (lambda* (#:key tests? #:allow-other-keys)
                     (when tests?
                       (invoke "pytest" "-k" "unit_test")))))))
      (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 "32140f60183c008830294a9fd2f4a0477b29f3b7")
        (revision "4"))
    (package
      (name "genenetwork2")
      (version (git-version "3.11" revision commit))
      (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
                  "15vfwjq0y8g0kyk2qfsdisxw1k747mnbmskfisyvdgzjw5hlg184"))))
      (native-inputs
       (list graphviz))
      (propagated-inputs
       (list genenetwork3
             coreutils
             nss-certs
             gemma
             gemma-wrapper
             git
             glibc-utf8-locales
             gn-rust-correlation
             grep
             gunicorn
	     javascript-ace
             javascript-bootstrap
             javascript-chroma
             javascript-ckeditor
             javascript-colorbox
             javascript-cytoscape
             javascript-cytoscape-panzoom
             javascript-cytoscape-qtip
             javascript-d3-tip
             javascript-d3js ;; very old
             javascript-d3js-7
             javascript-d3panels
             javascript-datatables
             javascript-datatables-buttons
             javascript-datatables-buttons-bootstrap
             javascript-datatables-buttons-styles
             javascript-datatables-col-reorder
             javascript-datatables-col-resize
             javascript-datatables-plugins
             javascript-datatables-scroller
	     javascript-diff
	     javascript-diff2html
	     javascript-diff2html-ui
             javascript-font-awesome
             javascript-htmx
	     javascript-highlight
	     javascript-highlight-ui
             javascript-jquery
             javascript-jquery-cookie
             javascript-jquery-ui
             javascript-jscolor
             javascript-jszip
             javascript-linkify
             javascript-linkify-html
	     javascript-marked
	     javascript-marked-highlight
             javascript-nouislider
             javascript-nvd3
             javascript-plotly
             javascript-purescript-genome-browser
             javascript-qtip2
             javascript-shapiro-wilk
             javascript-twitter-post-fetcher
             javascript-typeahead
             javascript-uikit
             javascript-underscore-string
             javascript-zxcvbn
             js-jstat
             js-md5
             js-parsley
             js-smart-time-ago
             js-underscore
             mariadb
             nginx
             parallel
             plink-ng-gn
             python-authlib
             python-autopep8
             python-beautifulsoup4
             python-configparser
             python-coverage
             python-cssselect
             python-flask
             python-flask-debugtoolbar
             python-flask-session
             python-htmlgen
             python-ijson
             python-jinja2
             python-lxml
             python-markdown
             python-mypy
             python-mysqlclient
             python-numpy
             python-pandas
             python-pillow
             python-pylint
             python-pymonad
             python-pytest
             python-pytest-mock
             python-rdflib
             python-redis
             python-requests
             python-rpy2
             python-scipy
             python-setuptools
             python-simplejson
             python-sqlalchemy
             python-wrapper
             python-xlsxwriter
             r
             r-ctl
             r-qtl
             r-wgcna
             redis
             rust-qtlreaper
             which
             ; javascript-xterm -- disabled until we know what to do with it, not working on production
             ; javascript-xterm-style
             ; javascript-xterm-addon-fit
             ))
      (inputs
       (list javascript-colorbox))
      (build-system python-build-system)
      (arguments
       (list #:tests? #f
             #:phases
             #~(modify-phases %standard-phases
                 (delete 'reset-gzip-timestamps)
                 (add-after 'unpack 'fix-paths-to-static-files
                   (lambda* (#:key inputs outputs #:allow-other-keys)
                     ;; Set absolute store paths to installed static files.
                     (substitute* "gn2/wqflask/marker_regression/display_mapping_results.py"
                       (("\\./gn2/wqflask/static/fonts")
                        (string-append (site-packages inputs outputs)
                                       "/gn2/wqflask/static/fonts")))
                     (substitute* "gn2/wqflask/views.py"
                       (("\\./gn2/wqflask/static/gif/error")
                        (string-append (site-packages inputs outputs)
                                       "/gn2/wqflask/static/gif/error")))
		     (substitute* "gn2/wqflask/app_errors.py"
                       (("\\./gn2/wqflask/static/gif/error")
                        (string-append (site-packages inputs outputs)
                                       "/gn2/wqflask/static/gif/error")))))
                 (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")))))
                 (add-before 'install 'fix-paths
                   (lambda* (#:key inputs #:allow-other-keys)
                     (let* ((plink2cmd (string-append (assoc-ref inputs "plink-ng-gn") "/bin/plink2"))
                            (gemmacmd (string-append (assoc-ref inputs "gemma") "/bin/gemma")))
                       (substitute* '("gn2/default_settings.py")
                              (("^PLINK_COMMAND =.*") (string-append "PLINK_COMMAND = \"" plink2cmd "\"\n" ))
                              (("^GEMMA_COMMAND =.*") (string-append "GEMMA_COMMAND = \"" gemmacmd "\"\n" )))))))))
       (home-page "http://genenetwork.org/")
       (synopsis "Full genenetwork services")
       (description "Genenetwork installation sumo.")
       (license license:agpl3+))))

(define-public genenetwork3-stable
  (let ((commit "e5569c3bb1c0d59ff7142273c5f51fe19f06cfe8")
        (revision "1"))
    (package
     (inherit genenetwork3)
     (name "genenetwork3-stable")
     (version (string-append (git-version "3.11" revision commit)))
     (arguments
       (list
         #:tests? #f
         #:phases
           #~(modify-phases %standard-phases
             (add-before 'build 'update-paths
               (lambda _
               (for-each (lambda (fn)
                  (substitute* (string-append "gn3/" fn)
                     (("scripts/")
                      (string-append #$output "/scripts/"))))
                      '("api/rqtl.py"
                        "computations/wgcna.py"
                        "computations/ctl.py"
                        "api/general.py"))))
             (add-before 'install 'install-scripts
               (lambda _
                 (begin
                  (mkdir (string-append #$output "scripts"))
                  (for-each (lambda (fn)
                    (install-file fn
                      (string-append #$output "/scripts")))
                      '("scripts/rqtl_wrapper.R"
                        "scripts/ctl_analysis.R"
                        "scripts/wgcna_analysis.R"
                        ))))))))

     (source
      (git-checkout
       (url "https://github.com/genenetwork/genenetwork3")
       (branch "prod"))))))

(define-public genenetwork2-stable
  (let ((commit "95e634ca90d52922812b93df162686b348288651")
        (revision "1"))
    (package
     (inherit genenetwork2)
     (name "genenetwork2-stable")
     (version (string-append "stable-" (git-version "3.12" revision commit)))
     (source
      (git-checkout
       (url "https://github.com/genenetwork/genenetwork2")
       (branch "prod")))
     (arguments
       (list
         #:tests? #f
         #:phases
           #~(modify-phases %standard-phases
               (add-before 'build 'update-font-paths
                 (lambda* (#:key inputs outputs #:allow-other-keys)
                   (for-each (lambda (fn)
                       (substitute* (string-append "gn2/" fn)
                                    (("\\./gn2/wqflask/static/fonts/")
                                     (string-append (site-packages inputs outputs) "/gn2/wqflask/static/fonts/"))))
                     '("utility/Plot.py"
                       "wqflask/marker_regression/display_mapping_results.py"))))
     ))))))

(define-public gn-uploader
  (let ((commit "60fde66e02dba842b20fa126ff3b2ed9ec2638e6")
       (version "0.0.1"))
    (package
     (name "gn-uploader")
     (version (string-append version "-" (string-take commit 8)))
     (source
      (origin
       (method git-fetch)
       (uri (git-reference
            (url "https://git.genenetwork.org/gn-uploader")
            (commit commit)))
       (hash
       (content-hash
        (base32
         "1q04viyf7d0q30k3424hrzsh9wxhhgs7hywlhzl3m68jki4zq1i7")))))
     (build-system python-build-system)
     (arguments
      (list
       #:phases
       #~(modify-phases %standard-phases
                       (replace 'check
                                (lambda* (#:key tests? #:allow-other-keys)
                                        (when tests?
                                          (invoke "pytest" "-m" "unit_test")))))))
     (native-inputs
      (list python-mypy
            python-pylint
            python-pytest
            python-hypothesis))
     (propagated-inputs
      (list gunicorn
            nss-certs
            python-redis
            python-flask
            python-pyyaml
            python-authlib
            python-pymonad
            python-jsonpickle
            python-mysqlclient
            python-flask-session
            javascript-jquery
            javascript-bootstrap
            node-resumablejs))
     (synopsis "GeneNetwork Quality Control Application")
     (description
      "gn-uploader is a service allowing upload of new data into GeneNetwork,
 that does quality control for the data files that is being uploaded to ensure
 it fulfils all conditions before it can be accepted.")
     (home-page "https://git.genenetwork.org/gn-uploader")
     (license license:agpl3+))))

(define-public gn-auth
  (let ((commit "4c21d0e43cf0de1084d0e0a243e441c6e72236eb")
        (revision "01"))
    (package
      (name "gn-auth")
      (version (git-version "1.0.1" revision commit))
      (source
       (origin
         (method git-fetch)
         (uri (git-reference
               (url "https://git.genenetwork.org/gn-auth")
               (commit commit)))
         (hash
          (content-hash
           (base32
            "0z9qpgn0j9idzi975ykh04bq2r4pz5d0pppk2zvxiyhxxgxjydrx")))))
      (build-system python-build-system)
      (arguments
       (list
        #:phases
        #~(modify-phases %standard-phases
            (replace 'check
              (lambda* (#:key tests? #:allow-other-keys)
                (when tests?
                  (invoke "pytest" "-k" "unit_test")))))))
      (native-inputs
       (list python-hypothesis
             python-mypy
             python-mypy-extensions
             python-pylint
             python-pytest
             python-pytest-mock))
      (propagated-inputs
       (list gunicorn
             nss-certs
             python-blinker
             python-argon2-cffi
             python-authlib
             python-email-validator
             python-flask
             python-flask-cors
             python-mysqlclient
             python-pymonad
             python-redis
             yoyo-migrations))
      (home-page "https://github.com/genenetwork/gn-auth")
      (synopsis "Authentication and Authorisation server for GeneNetwork services")
      (description "Authentication and Authorisation server for GeneNetwork services.")
      (license license:agpl3+))))


(define-public gn-libs
  (let ((commit "eb99148991a5869cf10c241aeff6c47708986a3a")
        (revision "01"))
    (package
      (name "gn-libs")
      (version (git-version "0.0.0" revision commit))
      (source
       (origin
         (method git-fetch)
         (uri (git-reference
               (url "https://git.genenetwork.org/gn-libs")
               (commit commit)))
         (hash
          (content-hash
           (base32
            "1lbvpn0ddsbj8xvnkzs352n7dg8drpvgx4j9xsxb24ny1f2ij323")))))
      (build-system pyproject-build-system)
      (arguments
       (list
        #:phases
        #~(modify-phases %standard-phases
            (replace 'check
              (lambda* (#:key tests? #:allow-other-keys)
                (when tests?
                  (invoke "pytest" "-k" "unit_test")))))))
      (native-inputs
       (list python-mypy
             python-pylint
             python-pytest))
      (propagated-inputs
       (list python-authlib
             python-pymonad
             python-mysqlclient))
      (home-page "https://github.com/genenetwork/gn-libs")
      (synopsis "Tools/utilities for GeneNetwork projects.")
      (description "A collection of tools and utilities used across multiple
GeneNetwork projects.")
      (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)))