aboutsummaryrefslogtreecommitdiff
path: root/scripts/precompute/run-gemma.scm
blob: 4952834528699f02fec9869a1b3afa64ad2a8b6c (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
#! Run GEMMA

A simple script that takes the JSON input from list-traits-to-compute and runs
GEMMA on those.

Run from base dir with

 ~/opt/guix-pull/bin/guix shell guile guile-dbi guile-json -- guile -L . -e main -s scripts/precompute/run-gemma.scm 115476.json

and with some extra paths (for gemma)

~/opt/guix-pull/bin/guix shell -C -F xz python python-lmdb tar time parallel coreutils-minimal guile guile-dbi guile-json ruby --expose=/home/wrk/iwrk/opensource/code/genetics/gemma-wrapper/=/gemma-wrapper --expose=/home/wrk/iwrk/opensource/code/genetics/gemma/=/gemma -- env TMPDIR=tmp GEMMA_COMMAND=/gemma/bin/gemma-0.98.5-linux-static-debug  guile -L . -e main -s ./scripts/precompute/run-gemma.scm --id 21529

!#

(use-modules ; (gn data dataset)
             ; (gn data hits)
             ; (gn data strains)
             ; (gn util convert)
             (gn runner gemma)
             (ice-9 getopt-long)
             (ice-9 match)
             (ice-9 textual-ports)
             (json)
             (rnrs bytevectors)
             (srfi srfi-1)
             )

(define (main args)
  ;; (write args)
  (let* [
         (option-spec '( (version (single-char #\v) (value #f))
                         (id      (value #t))
                         (help    (single-char #\h) (value #f))))
         (options (getopt-long args option-spec))
         (show-version (option-ref options 'version #f))
         (help-wanted (option-ref options 'help #f))]
    (if show-version
        (begin
          (display "run-gemma version 1.0\n")
          (exit)))
    (if help-wanted
        (format #t "run-gemma
Usage: run-gemma [options...] filename(s)
  --id               Run on identifier
  -v --version       Display version
  -h --help          Display this help
")
        (let* [(trait-id (option-ref options 'id "0"))
          (trait-fn (string-append trait-id ".json"))
          ]

      (call-with-input-file trait-fn
        (lambda (port)
          (let* [(json (json->scm port))
                 (dataset (car (assoc-ref json "data")))
                 (data (cdr dataset))
                 (dataset-name (assoc-ref data "name"))
                 (trait-name (assoc-ref data "trait-name"))
                 (traits (assoc-ref data "traits"))
                 (pheno-fn (string-append trait-id "-pheno.txt"))
                 ]
            (write-pheno-file pheno-fn traits)
            (invoke-gemma-wrapper-loco dataset-name trait-name trait-fn pheno-fn "BXD.8_geno.txt.gz")
            )))))))