aboutsummaryrefslogtreecommitdiff
path: root/examples/probeset.scm
blob: eeb2dcce57b21d49b706ca0f3dca08914c46dea7 (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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
#! /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 GeneList "ON GeneList.GeneID = ProbeSet.GeneId")
           (left-join GeneList_rn33 "ON GeneList.geneSymbol = ProbeSet.Symbol")
           (left-join Species "ON GeneChip.SpeciesId = Species.Id")))
  (schema-triples
   (gnc:pantherLink rdf:type gnc:ResourceLink)
   (gnc:pantherLink rdfs:label "PANTHER")
   (gnc:pantherLink rdfs:comments "Gene and protein data resources from Celera-ABI")
   (gnc:gnt:NCBIGeneLink rdfs:Class gnc:ResourceLink)
   (gnc:gnt:NCBIGeneLink rdfs:label "Gene")
   (gnc:gnt:NCBIGeneLink rdfs:comments "Info from NCBI Entrez Gene")
   (gnc:omimLink rdfs:Class gnc:ResourceLink)
   (gnc:omimLink rdfs:label "OMIM")
   (gnc:omimLink rdfs:comments "Summary from On Mendelion Inheritance in Man")
   (gnc:homologeneLink rdfs:Class gnc:ResourceLink)
   (gnc:homologeneLink rdfs:label "HomoloGene")
   (gnc:homologeneLink rdfs:comments "Find similar genes in other species")
   (gnc:uniprotLink rdfs:Class gnc:ResourceLink)
   (gnc:uniprotLink rdfs:label "UniProt")
   (gnc:uniprotLink rdfs:comments "UniProt")
   (gnc:stringLink rdfs:Class gnc:ResourceLink)
   (gnc:stringLink rdfs:label "STRING")
   (gnc:stringLink rdfs:comments "Protein interactions: known and inferred")
   (gnc:gtexLink rdfs:Class gnc:ResourceLink)
   (gnc:gtexLink rdfs:label "GTEx Portal")
   (gnc:gtexLink rdfs:comments "GTEx Portal")
   (gnc:ebiGwasLink rdfs:Class gnc:ResourceLink)
   (gnc:ebiGwasLink rdfs:label "EBI GWAS")
   (gnc:ebiGwasLink rdfs:comments "EBI GWAS")
   (gnc:genemaniaLink rdfs:Class gnc:ResourceLink)
   (gnc:genemaniaLink rdfs:label "GeneMANIA")
   (gnc:genemaniaLink rdfs:comments "GeneMANIA")
   (gnc:gemmaLink rdfs:Class gnc:ResourceLink)
   (gnc:gemmaLink rdfs:label "Gemma")
   (gnc:gemmaLink rdfs:comments "Meta-analysis of gene expression data")
   (gnc:biogpsLink rdfs:Class gnc:ResourceLink)
   (gnc:biogpsLink rdfs:label "BioGPS")
   (gnc:biogpsLink rdfs:comments "Expression across many tissues and cell types")
   (gnc:abaLink rdfs:Class gnc:ResourceLink)
   (gnc:abaLink rdfs:label "ABA")
   (gnc:abaLink rdfs:comments "Allen Brain Atlas")
   (gnc:ucsRefSeqLink rdfs:Class gnc:ResourceLink)
   (gnc:ucsRefSeqLink rdfs:label "Info from UCSC Genome Browser")
   (gnc:ucsRefSeqLink rdfs:comments "UCSC")
   (gnc:proteinAtlasLink rdfs:Class gnc:ResourceLink)
   (gnc:proteinAtlasLink rdfs:label "Protein Atlas")
   (gnc:proteinAtlasLink rdfs:comments "Human Protein Atlas")
   (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 "")
              (if (string-blank? chr)
                  (format #f "Not available")
                  (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 "")))))))
    ;; NCBI Gene Link
    (set dct:references
         (let ((geneId (field ProbeSet GeneId)))
           (if (not (string-blank? geneId))
               (string->symbol
                (format #f
                        "<~0@*~a~1@*~a> .~%<~0@*~a~1@*~a> ~2@*~a"
                        "http://www.ncbi.nlm.nih.gov/gene?cmd=Retrieve&dopt=Graphics&list_uids="
                        geneId
                        "a gnc:NCBIGeneLink"))
               "")))
    ;; OMIM Link
    (set dct:references
         (let ((omim (field ProbeSet OMIM)))
           (if (not (string-blank? omim))
               (string->symbol
                (format #f
                        "<~0@*~a~1@*~a> .~%<~0@*~a~1@*~a> ~2@*~a"
                        "http://www.ncbi.nlm.nih.gov/omim/"
                        omim
                        "a gnc:omimLink"))
               "")))
    ;; Homologene Link
    (set dct:references
         (let ((homologene (field ProbeSet HomoloGeneID)))
           (if (not (string-blank? homologene))
               (string->symbol
                (format #f
                        "<~0@*~a~1@*~a> .~%<~0@*~a~1@*~a> ~2@*~a"
                        "http://www.ncbi.nlm.nih.gov/homologene/?term="
                        homologene
                        "a gnc:homologeneLink"))
               "")))
    ;; UniProt Link
    (set dct:references
         (let ((uniprot (field ProbeSet UniProtID)))
           (if (not (string-blank? uniprot))
               (string->symbol
                (format #f
                        "<~0@*~a~1@*~a> .~%<~0@*~a~1@*~a> ~2@*~a"
                        "https://www.uniprot.org/uniprot/"
                        uniprot
                        "a gnc:uniprotLink"))
               "")))
    ;; STRING Link
    (set dct:references
         (let ((symbol (field ProbeSet Symbol)))
           (if (not (string-blank? symbol))
               (string->symbol
                (format #f
                        "<~0@*~a~1@*~a> .~%<~0@*~a~1@*~a> ~2@*~a"
                        "http://string-db.org/newstring_cgi/show_network_section.pl?identifier="
                        symbol
                        "a gnc:stringLink"))
               "")))
    ;; GTEX link
    (set dct:references
         (let ((symbol (field ProbeSet Symbol)))
           (if (not (string-blank? symbol))
               (string->symbol
                (format #f
                        "<~0@*~a~1@*~a> .~%<~0@*~a~1@*~a> ~2@*~a"
                        "https://www.gtexportal.org/home/gene/"
                        (string-trim-both symbol)
                        "a gnc:gtexLink"))
               "")))
    ;; EBI GWAS Link
    (set dct:references
         (let ((symbol (field ProbeSet Symbol)))
           (if (not (string-blank? symbol))
               (string->symbol
                (format #f
                        "<~0@*~a~1@*~a> .~%<~0@*~a~1@*~a> ~2@*~a"
                        "https://www.ebi.ac.uk/gwas/search?query="
                        (string-trim-both symbol)
                        "a gnc:ebiGwasLink"))
               "")))
    ;; Protein Atlas Link
    (set dct:references
         (let ((symbol (field ProbeSet Symbol)))
           (if (not (string-blank? symbol))
               (string->symbol
                (format #f
                        "<~0@*~a~1@*~a> .~%<~0@*~a~1@*~a> ~2@*~a"
                        "http://www.proteinatlas.org/search/"
                        (string-trim-both symbol)
                        "a gnc:proteinAtlasLink"))
               "")))
    ;; UCS Link
    (set dct:references
         (let* ((symbol (field ProbeSet Symbol))
                (species (field Species Name))
                (db (if (string=? species "mouse")
                         "mm10" "rn7"))
                (transcriptId (field ProbeSet RefSeq_TranscriptId))
                (kgId (field GeneList_rn33 kgId))
                (transcriptStart
                 (if (string=? species "mouse")
                     (field ("(GeneList.txStart * 1000000)" TranscriptStartMm10))
                     (field ("(GeneList_rn33.txStart * 1000000)" TranscriptStartRn7))))
                (chromosome
                 (if (string=? species "mouse")
                     (field GeneList Chromosome)
                     (field GeneList_rn33 Chromosome)))
                (transcriptEnd
                 (if (string=? species "mouse")
                     (field ("(GeneList.txEnd * 1000000)" TranscriptEndMm10))
                     (field ("(GeneList_rn33.txEnd * 1000000)" TranscriptEndRn7))))
                (url (format
                      #f
                      "http://genome.cse.ucsc.edu/cgi-bin/hgTracks?db=~a&hgg_gene="
                      db)))
           (if (and (not (string-blank? symbol))
                    (not (string-blank? transcriptId))
                    (number? transcriptStart)
                    (number? transcriptEnd)
                    (not (string-blank? chromosome))
                    (or (string=? species "mouse")
                        (string=? species "rat")))
               (string->symbol
                (format #f
                        "<~0@*~a~1@*~a&hgg_chrom=chr~2@*~a&hgg_start=~3@*~a&hgg_end=~4@*~a> .~%<~0@*~a~1@*~a&hgg_chrom=chr~2@*~a&hgg_start=~3@*~a&hgg_end=~4@*~a> ~2@*~a"
                        url
                        transcriptId
                        chromosome
                        transcriptStart
                        transcriptEnd
                        "a gnc:ucsRefSeqLink"
                        ))
               "")))
    ;; PANTHER link
    (set dct:references
         (let ((symbol (field ProbeSet Symbol)))
           (if (not (string-blank? symbol))
               (string->symbol
                (format #f
                        "<~0@*~a~1@*~a> .~%<~0@*~a~1@*~a> ~2@*~a"
                        "http://www.pantherdb.org/genes/geneList.do?searchType=basic&fieldName=all&organism=all&listType=1&fieldValue="
                        (string-trim-both symbol)
                        "a gnc:PantherLink"))
               "")))
    ;; A GeneManiaLink
    (set dct:references
         (let ((symbol (field ProbeSet GeneId))
               (species (lower-case-and-replace-spaces
                         (field Species FullName))))
           (if (and (not (string-blank? symbol))
                    (not (string-blank? species))
                    (or
                     (string=? species "mus-musculus")
                     (string=? species "rattus-norvegicus")
                     (string=? species "homo-sapiens")))
               (string->symbol
                (format #f "<~0@*~a/~1@*~a/~2@*~a> .~%<~0@*~a/~1@*~a/~2@*~a> ~3@*~a"
                        "https://genemania.org/search" species (string-trim-both symbol)
                        "a gnc:genemaniaLink"))
               "")))
    ;; ABA Link
    (set dct:references
         (let ((symbol (field ProbeSet Symbol))
               (geneId (field ProbeSet GeneId))
               (species (field Species name)))
           (if (and (not (string-blank? symbol))
                    (not (string-blank? species))
                    (or (string=? species "human")
                        (string=? species "mouse")))
               (string->symbol
                (format #f "<~0@*~a> .~%<~0@*~a> ~2@*~a"
                        "http://mouse.brain-map.org/search/show?search_type=gene&search_term="
                        "a "
                        (if (string=? species "mouse")
                            (string-trim-both symbol)
                            geneId)))
               "")))
    ;; Gemma Link
    (set dct:references
         (let ((geneId (field ProbeSet GeneId)))
           (if (not (string-blank? geneId))
               (string->symbol
                (format #f
                        "<~0@*~a~1@*~a> .~%<~0@*~a~1@*~a> ~2@*~a"
                        "http://www.chibi.ubc.ca/Gemma/gene/showGene.html?ncbiid="
                        geneId
                        "a gnc:gemmaLink"))
               "")))
    ;; BioGPS Link
    (set dct:references
         (let ((geneId (field ProbeSet GeneId))
               (species (field Species Name)))
           (if (and (not (string-blank? geneId))
                    (not (string-blank? species))
                    (or
                     (string=? species "mouse")
                     (string=? species "rat")
                     (string=? species "humans")))
               (string->symbol
                (format #f
                        "<~0@*~a~1@*~a~2@*~a~3@*~a> .~%<~0@*~a~1@*~a~2@*~a~3@*~a> ~4@*~a ; ~5@*~a"
                        "http://biogps.org/?org="
                        species
                        "#goto=genereport&id="
                        geneId
                        "a gnc:ResourceLink"))
               "")))
    (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))))