aboutsummaryrefslogtreecommitdiff
path: root/examples/probeset.scm
blob: e0a7685c23e481a0a5734f9cddb35e04f0e1b35a (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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#! /usr/bin/env guile
!#

(use-modules (srfi srfi-1)
             (srfi srfi-26)
             (ice-9 getopt-long)
             (ice-9 match)
             (ice-9 regex)
             (transform strings)
             (transform sql)
             (transform triples)
             (transform special-forms))

(define-transformer probeset
  (tables (ProbeSet
           (left-join GeneChip "ON GeneChip.Id = ProbeSet.ChipId")
           (left-join Species "ON GeneChip.SpeciesId = Species.Id")))
  (schema-triples
   (gnt:hasChip a owl:ObjectProperty)
   (gnt:hasChip rdfs:domain gnc:Probeset)
   (gnt:hasTargetId a owl:ObjectProperty)
   (gnt:hasTargetId rdfs:domain gnc:Probeset)
   (gnt:symbol rdfs:domain gnc:Probeset)
   (gnt:location rdfs:domain gnc:ProbeSet)
   (gnt:location a owl:ObjectProperty)
   (gnt:strandPosition rdfs:domain gnc:ProbeSet)
   (gnt:strandPosition a owl:ObjectProperty)
   (gnt:targetsRegion a owl:ObjectProperty)
   (gnt:targetsRegion rdfs:domain gnc:Probeset)
   (gnt:chr rdfs:domain gnc:Probeset)
   (gnt:mb rdfs:domain gnc:Probeset)
   (gnt:hasSpecificity a owl:ObjectProperty)
   (gnt:hasSpecificity rdfs:domain gnc:Probeset)
   (gnt:hasBlatScore a owl:ObjectProperty)
   (gnt:hasBlatScore rdfs:domain gnc:Probeset)
   (gnt:hasBlatMbStart a owl:ObjectProperty)
   (gnt:hasBlatMbStart rdfs:domain gnc:Probeset)
   (gnt:hasBlatMbEnd a owl:ObjectProperty)
   (gnt:hasBlatMbEnd rdfs:domain gnc:Probeset)
   (gnt:hasBlatSeq a owl:ObjectProperty)
   (gnt:hasBlatSeq rdfs:domain gnc:Probeset)
   (gnt:hasTargetSeq a owl:ObjectProperty)
   (gnt:hasTargetSeq rdfs:domain gnc:Probeset))
  (triples
      (let ((id (field ("IF(NULLIF(TRIM(ProbeSet.Name), '') IS NULL, '', TRIM(ProbeSet.Name))"
                        ProbeSetIdName)))
            (probeset-id (field ProbeSet Id)))
        (string->identifier
         "probeset"
         (if (string-null? id)
             (number->string probeset-id)
             (regexp-substitute/global
              #f "[^A-Za-z0-9:]"
              id
              'pre "_" 'post))))
    (set rdf:type 'gnc:Probeset)
    (set rdfs:label (field ProbeSet Name))
    (set skos:altLabel
         (replace-substrings
          (field ProbeSet alias)
          '(("\r\n" . "; "))))
    (set gnt:hasChip
         (string->identifier
          "platform"
          (field ("IFNULL(GeneChip.Name, '')" GeneChipName))))
    (set gnt:hasTargetId
         (field ("NULLIF(TRIM(ProbeSet.TargetId), '')"
                 TargetId)))
    (set gnt:symbol (field ProbeSet Symbol))
    (set dct:description (sanitize-rdf-string (field ProbeSet description)))
    (set gnt:targetsRegion
         (sanitize-rdf-string
          (field ("NULLIF(TRIM(ProbeSet.Probe_set_target_region), '')"
                  Probe_set_target_region))))
    (set gnt:chr (field ProbeSet Chr))
    (set gnt:mb (annotate-field (field ("IFNULL(ProbeSet.Mb, '')" Mb)) '^^xsd:double))
    (set gnt:location
         (let* ((mb (field ProbeSet Mb))
                (chr (field ProbeSet Chr))
                (strand-probe (field ProbeSet Strand_Probe))
                (location (list chr mb)))
           (match location
             (("Un" mb)
              (format #f "Not available"))
             ((chr "")
              (format #f "Chr ~a @ Unknown position ~a~:[~;~a~]"
                      chr mb
                      (and (string? strand-probe) (or (string=? "+" strand-probe)
                                                      (string=? "-" strand-probe)))
                      (cond ((string=? "+" strand-probe)
                             " on the plus strand")
                            ((string=? "-" strand-probe)
                             " on the minus strand")
                            (else ""))))
             (_
              (format #f "Chr ~a @ ~a~:[~;~a~]"
                      chr mb
                      (and (string? strand-probe) (or (string=? "+" strand-probe)
                                                      (string=? "-" strand-probe)))
                      (cond ((string=? "+" strand-probe)
                             " on the plus strand")
                            ((string=? "-" strand-probe)
                             " on the minus strand")
                            (else "")))))))
    (set gnt:strandProbe
         (field ProbeSet Strand_Probe))
    (set gnt:hasSpecificity
         (field ("IFNULL(ProbeSet.Probe_set_specificity, '')"
                 Probe_set_specificity)))
    (set gnt:hasBlatScore
         (field ("IFNULL(ProbeSet.Probe_set_BLAT_score, '')"
                 Probe_set_BLAT_score)))
    (set gnt:hasBlatMbStart
         (annotate-field (field ("IFNULL(ProbeSet.Probe_set_Blat_Mb_start, '')"
                                 Probe_set_Blat_Mb_start))
                         '^^xsd:double))
    (set gnt:hasBlatMbEnd
         (annotate-field (field ("IFNULL(ProbeSet.Probe_set_Blat_Mb_end, '')"
                                 Probe_set_Blat_Mb_end))
                         '^^xsd:double))
    (set gnt:hasBlatSeq (sanitize-rdf-string (field ProbeSet BlatSeq)))
    (set gnt:hasTargetSeq (sanitize-rdf-string (field ProbeSet TargetSeq)))))




(let* ((option-spec
        '((settings (single-char #\s) (value #t))
          (output (single-char #\o) (value #t))
          (documentation (single-char #\d) (value #t))))
       (options (getopt-long (command-line) option-spec))
       (settings (option-ref options 'settings #f))
       (output (option-ref options 'output #f))
       (documentation (option-ref options 'documentation #f))
       (%connection-settings
        (call-with-input-file settings
          read)))
  (with-documentation
   (name "ProbeSet Metadata")
   (connection %connection-settings)
   (table-metadata? #f)
   (prefixes
    '(("gn:" "<http://genenetwork.org/id/>")
      ("probeset:" "<http://genenetwork.org/probeset/>")
      ("gnc:" "<http://genenetwork.org/category/>")
      ("gnt:" "<http://genenetwork.org/term/>")
      ("rdf:" "<http://www.w3.org/1999/02/22-rdf-syntax-ns#>")
      ("rdfs:" "<http://www.w3.org/2000/01/rdf-schema#>")
      ("dct:" "<http://purl.org/dc/terms/>")
      ("owl:" "<http://www.w3.org/2002/07/owl#>")
      ("xsd:" "<http://www.w3.org/2001/XMLSchema#>")
      ("qb:" "<http://purl.org/linked-data/cube#>")
      ("sdmx-measure:" "<http://purl.org/linked-data/sdmx/2009/measure#>")
      ("skos:" "<http://www.w3.org/2004/02/skos/core#>")))
   (inputs
    (list probeset))
   (outputs
    `(#:documentation ,documentation
      #:rdf ,output))))