From 8294b95324af7cb86b4abec6ee9d09b8684f137e Mon Sep 17 00:00:00 2001 From: Pjotr Prins Date: Mon, 13 May 2024 11:42:36 +0200 Subject: Start on json output for strains --- scripts/precompute/list-traits-to-compute.scm | 32 ++++++++++++++++----------- 1 file 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 ))) -- cgit v1.2.3