aboutsummaryrefslogtreecommitdiff
path: root/gn/data/hits.scm
blob: a7ba45a8bba96162854490dab5bbddc7fe037ed5 (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
(define-module (gn data hits)
  #:use-module (json)
  #:use-module (ice-9 match)
  #:use-module (ice-9 format)
  #:use-module (ice-9 iconv)
  #:use-module (ice-9 receive)
  #:use-module (ice-9 string-fun)
  #:use-module (srfi srfi-9)
  ;; #:use-module (gn db sparql)
  #:use-module (dbi dbi)
  #:use-module (gn db mysql)
  #:use-module (gn data group)
  #:use-module (gn util convert)
  #:use-module (web gn-uri)

  #:export (
            get-precompute-hits
            get-precompute-hit
            set-precompute-hit-status!
            update-precompute!
            hit-data-id
            hit-probeset-id
            hit-probesetfreeze-id
            ))


(define-record-type <hit>
  (make-hit data-id probeset-id probesetfreeze-id)
  hit?
  (data-id hit-data-id)
  (probeset-id hit-probeset-id)
  (probesetfreeze-id hit-probesetfreeze-id)
  )

(define (get-precompute-hits db first-id num)
  (dbi-query db (string-append "select Locus, DataId, ProbeSetId, ProbeSetFreezeId from ProbeSetXRef where DataId>" (int-to-string first-id) " AND Locus_old is NULL ORDER BY DataId LIMIT " (format #f "~d" num)))
  (map (lambda (r)
         (make-hit (assoc-ref r "DataId") (assoc-ref r "ProbeSetId") (assoc-ref r "ProbeSetFreezeId")))
         (get-rows db '())
  ))

(define (get-precompute-hit db prev-id)
  (car (get-precompute-hits db prev-id 1)))

(define (set-precompute-hit-status! db data-id-str status-str)
  "Set status of precompute record - typically from NULL to 'GEMMA-START' or 'NON-BXD'.
On completion it is set to 'GEMMA-DONE'.
This is a temporary measure to get precompute going.
Note we are counting on automated MariaDB transactions to not compete."
  (dbi-query db (string-append "UPDATE ProbeSetXRef SET Locus_old=\"" status-str "\" WHERE DataId=" data-id-str))
  (ensure db)
  )

;; MariaDB [db_webqtl]> UPDATE ProbeSetXRef SET Locus_old=Locus,LRS_old=LRS,Locus="new",LRS=9.9,pValue=1.0,additive=1.0 WHERE ProbeSetFreezeId=1 AND DataId=2 AND Locus_old="GEMMA-START" ;

(define (update-precompute! db data-id-str status-str locus lrs pvalue, additive)
  "Once precompute is run we can update the table moving old values and plugging in the new.
"
  (dbi-query db (string-append "UPDATE ProbeSetXRef SET Locus_old=Locus,LRS_old=LRS,Locus=\"" locus "\",LRS=" lrs ",pValue=" pvalue ",additive=" additive " WHERE DataId=" data-id-str " AND Locus_old is \"GEMMA-START\""))
  (ensure db)
  )