about summary refs log tree commit diff
path: root/gn
diff options
context:
space:
mode:
Diffstat (limited to 'gn')
-rw-r--r--gn/runner/gemma.scm43
1 files changed, 23 insertions, 20 deletions
diff --git a/gn/runner/gemma.scm b/gn/runner/gemma.scm
index 131284a..4c1c374 100644
--- a/gn/runner/gemma.scm
+++ b/gn/runner/gemma.scm
@@ -10,16 +10,37 @@
   #:use-module (rnrs base)
 
   #:export (
+            write-pheno-file
             run-gemma
             ))
 
+(define (write-pheno-file fn traits)
+  (define bxd-inds (geno-inds-bxd "BXD.json"))
+  (assert (= 235 (length bxd-inds)))
+  (display bxd-inds)
+  (call-with-output-file fn
+    (lambda (port)
+      (for-each
+       (lambda (ind)
+         (begin
+           (let* [(value (assoc-ref traits ind))
+                  (outvalue (if value
+                                value
+                                "NA"))]
+             (format #t "~s ~s" ind outvalue)
+             (newline)
+             (display outvalue port)
+             (newline port))))
+       bxd-inds)
+      (close port)
+      ))
+)
+
 (define (run-gemma population data-id probeset-id probesetfreeze-id name trait-name traits)
   "Run gemma-wrapper to compute GRM and GWA. On failure the run will stop(!)"
-  (define bxd-inds (geno-inds-bxd "BXD.json"))
   (define ids (string-append (int-to-string data-id) ","
                              (int-to-string probeset-id) ","
                              (int-to-string probesetfreeze-id)))
-  (assert (= 235 (length bxd-inds)))
   (if name
       (display (string-append "WE HAVE OUR " population " DATASET " name " and trait " trait-name " for precompute!\n")))
   (display ids)
@@ -31,24 +52,6 @@
          (pheno-fn (string-append tmpdir "/pheno.txt"))
          (k-json-fn (string-append tmpdir "/K.json"))
          (gwa-json-fn (string-append tmpdir "/GWA.json"))]
-    (call-with-output-file pheno-fn
-      (lambda (port)
-        (for-each (lambda (ind)
-                    (begin
-                      (let* [(value (assoc-ref traits ind))
-                             (outvalue (if value
-                                           value
-                                           "NA"))]
-                        (display outvalue)
-                        (newline)
-                        (display outvalue port)
-                        (newline port))))
-                  bxd-inds)
-        (close port)
-       ))
-
-    ;; set up with ./.guix-shell -- guile -L . -s ./scripts/precompute/precompute-hits.scm
-
     ;; ---- to start GEMMA precompute inside container
     ;; env TMPDIR=. LD_LIBRARY_PATH=$GUIX_ENVIRONMENT/lib/ guile -L . -s ./scripts/precompute/precompute-hits.scm
     ;; --- First we compute K - control output goes to K.json