about summary refs log tree commit diff
path: root/scripts/precompute
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/precompute')
-rwxr-xr-xscripts/precompute/list-traits-to-compute.scm32
1 files changed, 19 insertions, 13 deletions
diff --git a/scripts/precompute/list-traits-to-compute.scm b/scripts/precompute/list-traits-to-compute.scm
index 37b3e6e..07e80e9 100755
--- a/scripts/precompute/list-traits-to-compute.scm
+++ b/scripts/precompute/list-traits-to-compute.scm
@@ -69,10 +69,17 @@ When that is the case we might as well write the phenotype file because we have
              ; (rnrs base)
              (ice-9 getopt-long)
              (ice-9 match)
+             (json)
              (srfi srfi-1)
              )
 
 
+(define (write-json id recs)
+  (display id)
+  (newline)
+  (display (scm->json (reverse recs)))
+  )
+
 (define (write-phenotypes first-id num batch-size)
   (call-with-db
    (lambda (db)
@@ -94,27 +101,26 @@ When that is the case we might as well write the phenotype file because we have
                 (data-ids-query (string-join data-str-ids " OR "))
                 (query (string-append "SELECT Id,StrainId,value FROM ProbeSetData WHERE " data-ids-query))
                 ]
-           ;; (display query)
            (dbi-query db query)
            (let [(id-traits (get-rows db '()))
                  (nrecs '())]
              (for-each (lambda (r)
                     (let* [(data-id (assoc-ref r "Id"))
-                          (strain-id (assoc-ref r "StrainId"))
-                          (value (assoc-ref r "value"))
-                          (has-lst (assoc-ref nrecs data-id))
-                          (lst (if has-lst
-                                   (acons strain-id value has-lst)
-                                   '())
-                               )]
+                           (strain-id (assoc-ref r "StrainId"))
+                           (value (assoc-ref r "value"))
+                           (has-lst (assoc-ref nrecs data-id))
+                           (lst (if has-lst
+                                    (acons strain-id value has-lst)
+                                    '())
+                                )]
                       (set! nrecs (assoc-set! nrecs data-id lst))))
                        id-traits)
              (for-each (lambda (r)
-                         (if (has-bxd? (cdr r))
-                             (begin
-                               (display (car r))
-                               (newline))
-                             )) nrecs)
+                         (match r
+                           ((id . recs) (if (has-bxd? recs)
+                                              (write-json id recs)
+                                            ))
+                            )) nrecs)
              (if (> rest 0)
                  (run-list-traits-to-compute db rest (first (reverse data-ids)))) ;; start precompute
            )))