#! Step p1 lists traits that need to be computed. This is a script that fetches trait IDs from the GN database directly. The direct database calls are used right now and ought to be turned into a REST API. Run from base dir with . .guix-shell -- guile -L . -s ./scripts/precompute/list-traits-to-compute.scm You may want to forward a mysql port if there is no DB locally ssh -L 3306:127.0.0.1:3306 -f -N tux02.genenetwork.org test connection with mysql client: mysql -uwebqtlout -pwebqtlout -A -h 127.0.0.1 -P 3306 db_webqtl -e "show tables;" to create a clean slate, for now, update Locus_old with update ProbeSetXRef set Locus_old=NULL; you should see MariaDB [db_webqtl]> select count(Locus_old) from ProbeSetXRef where Locus_old != NULL limit 5; +------------------+ | count(Locus_old) | +------------------+ | 0 | +------------------+ Now list the next 1000 trait IDs: . .guix-shell -- guile -L . -s ./scripts/precompute/list-traits-to-compute.scm --next 1000 The current logic is to list all datasets that contain a BXD. (bxd-strain-id-names #:used-for-mapping? #t) fetches all ids and strain names listed in GN. Note that this differs from the actual genotype file. To find the StrainId in a dataset: MariaDB [db_webqtl]> SELECT StrainId,value from ProbeSetData WHERE Id=115467; +----------+---------+ | StrainId | value | +----------+---------+ | 1 | 9.47169 | | 2 | 9.21621 | | 3 | 9.728 | | 4 | 9.28976 | | 5 | 9.55523 | | 6 | 9.63562 ... to speed things up a little we batch them up and check whether the BXD is part of it. When that is the case we might as well write the phenotype file because we have the trait values. !# (use-modules (dbi dbi) (gn db mysql) (gn data dataset) (gn data hits) (gn data strains) (gn util convert) (gn runner gemma) ; (rnrs base) (ice-9 match) (srfi srfi-1) ) (call-with-db (lambda (db) (begin (let [(bxd-strains (memo-bxd-strain-id-names #:used-for-mapping? #t))] (define (run-list-traits-to-compute db prev-id count) (let* [(hits (get-precompute-hits db prev-id count)) (data-ids (map (lambda (hit) (let* [(data-id (assoc-ref hit "DataId")) ; (data-id-str (int-to-string data-id)) ] data-id)) hits)) (data-str-ids (map (lambda (id) (string-append "Id=" (int-to-string id))) data-ids)) (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) '()) )] (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) ; (display nrecs) ))) (run-list-traits-to-compute db 0 1000) ;; start precompute ;; (write bxd-strains) ))))