samplevis.json 16 KB
Newer Older
jhoogenboom's avatar
jhoogenboom committed
1
2
3
{
  "width": 600,
  "height": 10,
4
5
6
7
8
9
10
11
12
13
14
15
16
  "signals": [
    {
      "name": "amplitude_threshold",
      "init": 5
    },
    {
      "name": "amplitude_pct_threshold",
      "init": 0.5
    },
    {
      "name": "orientation_threshold",
      "init": 0
    },
17
18
19
20
    {
      "name": "show_negative",
      "init": true
    },
21
22
23
24
25
26
    {
      "name": "bias_threshold",
      "init": 25
    },
    {
      "name": "filter_marker",
27
28
29
30
31
32
      "init": ""
    },
    {
      "name": "marker_regex",
      "init": {"expr": "regexp('(?:' + replace(replace(replace(filter_marker, /^ *(.*?) *$/, '$1'), /(^| )=(.*?)(?= |$)/g, '$1^$2$$'), / +/g, ')|(?:') + ')')"},
      "expr": "regexp('(?:' + replace(replace(replace(filter_marker, /^ *(.*?) *$/, '$1'), /(^| )=(.*?)(?= |$)/g, '$1^$2$$'), / +/g, ')|(?:') + ')')"
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
    },
    {
      "name": "barwidth",
      "init": 15
    },
    {
      "name": "subgraphoffset",
      "init": 70
    },
    {
      "name": "clickedAllele",
      "verbose": true,
      "streams": [
        {"type": "@alleleSelector:click", "expr": "datum.thedatum"}
      ]
    }
  ],
jhoogenboom's avatar
jhoogenboom committed
50
51
  "data": [
    {
jhoogenboom's avatar
jhoogenboom committed
52
      "name": "raw",
jhoogenboom's avatar
jhoogenboom committed
53
54
55
56
57
      "values": "sample_data_file_contents_here",
      "format": {
        "type": "tsv",
        "parse": {
          "forward": "number",
58
59
          "forward_noise": "number",
          "forward_add": "number",
Hoogenboom, Jerry's avatar
Hoogenboom, Jerry committed
60
          "reverse": "number",
61
62
          "reverse_noise": "number",
          "reverse_add": "number",
jhoogenboom's avatar
jhoogenboom committed
63
64
65
66
67
68
          "total": "number",
          "total_noise": "number",
          "total_add": "number"
        }
      },
      "transform": [
69
70
71
72
73
74
75
76
77
78
        {
          "type": "formula",
          "field": "forward_corr",
          "expr": "datum.forward_noise? datum.forward-datum.forward_noise : datum.forward"
        },
        {
          "type": "formula",
          "field": "reverse_corr",
          "expr": "datum.reverse_noise? datum.reverse-datum.reverse_noise : datum.reverse"
        },
jhoogenboom's avatar
jhoogenboom committed
79
80
81
82
83
84
85
        {
          "type": "formula",
          "field": "total_corr",
          "expr": "datum.total_noise? datum.total-datum.total_noise : datum.total"
        },
        {
          "type": "formula",
86
87
          "field": "forward_added",
          "expr": "datum.forward_add? datum.forward_corr+datum.forward_add : datum.forward_corr"
jhoogenboom's avatar
jhoogenboom committed
88
        },
jhoogenboom's avatar
jhoogenboom committed
89
90
        {
          "type": "formula",
91
92
93
94
95
96
97
          "field": "reverse_added",
          "expr": "datum.reverse_add? datum.reverse_corr+datum.reverse_add : datum.reverse_corr"
        },
        {
          "type": "formula",
          "field": "total_added",
          "expr": "datum.total_add? datum.total_corr+datum.total_add : datum.total_corr"
jhoogenboom's avatar
jhoogenboom committed
98
99
100
101
        }
      ]
    },
    {
102
      "name": "aggr",
jhoogenboom's avatar
jhoogenboom committed
103
104
105
106
107
      "source": "raw",
      "transform": [
        {
          "type": "aggregate",
          "groupby": ["name"],
108
          "summarize": {"total_added": ["sum", "max"]}
jhoogenboom's avatar
jhoogenboom committed
109
110
111
112
        }
      ]
    },
    {
113
      "name": "annotated",
jhoogenboom's avatar
jhoogenboom committed
114
115
      "source": "raw",
      "transform": [
116
117
        {
          "type": "filter",
118
          "test": "test(marker_regex, datum.name)"
119
        },
jhoogenboom's avatar
jhoogenboom committed
120
121
        {
          "type": "lookup",
122
          "on": "aggr",
jhoogenboom's avatar
jhoogenboom committed
123
124
125
          "onKey": "name",
          "keys": ["name"],
          "as": ["aggr"],
126
          "default": {"max_total_added": 0, "sum_total_added": 0}
jhoogenboom's avatar
jhoogenboom committed
127
128
129
        },
        {
          "type": "formula",
130
131
132
          "field": "pct_of_max",
          "expr": "datum.aggr.max_total_added? (datum.total_added / datum.aggr.max_total_added * 100) : 100"
        },        {
133
          "type": "formula",
134
135
          "field": "pct_of_sum",
          "expr": "datum.aggr.sum_total_added? (datum.total_added / datum.aggr.sum_total_added * 100) : 100"
136
        },
jhoogenboom's avatar
jhoogenboom committed
137
138
139
140
141
142
143
144
        {
          "type": "formula",
          "field": "shared",
          "expr": "max(0, datum.total_corr)"
        },
        {
          "type": "formula",
          "field": "corr_shared",
145
          "expr": "min(datum.total, datum.total_added)"
jhoogenboom's avatar
jhoogenboom committed
146
147
148
149
150
151
152
153
154
        },
        {
          "type": "formula",
          "field": "corr_decreased",
          "expr": "max(datum.total, datum.corr_shared)"
        },
        {
          "type": "formula",
          "field": "corr_increased",
155
          "expr": "max(datum.corr_shared, datum.total_added)"
jhoogenboom's avatar
jhoogenboom committed
156
157
158
159
        },
        {
          "type": "formula",
          "field": "forwardpct",
160
          "expr": "datum.total_added? (100.0 / datum.total_added * datum.forward_added) : 50"
jhoogenboom's avatar
jhoogenboom committed
161
        },
Hoogenboom, Jerry's avatar
Hoogenboom, Jerry committed
162
163
164
165
166
167
168
169
        {
          "type": "formula",
          "field": "xlow",
          "expr": "min(0, datum.total_corr*1.05)"
        },
        {
          "type": "formula",
          "field": "xhigh",
170
          "expr": "max(datum.total*1.05, datum.total_added*1.05)"
Hoogenboom, Jerry's avatar
Hoogenboom, Jerry committed
171
172
173
174
        },
        {
          "type": "formula",
          "field": "biasmark",
175
176
177
178
179
180
181
182
183
184
185
          "expr": "50-abs(datum.forwardpct-50) < bias_threshold? '\u2605' : ''"
        },
        {
          "type": "formula",
          "field": "thedatum",
          "expr": "datum"
        }
      ]
    },
    {
      "name": "table",
186
      "source": "annotated",
187
188
189
      "transform": [
        {
          "type": "filter",
190
          "test": "(show_negative? abs(datum.total_added) : datum.total_added) >= amplitude_threshold && (show_negative? abs(datum.pct_of_max) : datum.pct_of_max) >= amplitude_pct_threshold && min(show_negative? abs(datum.forward_added) : datum.forward_added, show_negative? abs(datum.reverse_added) : datum.reverse_added) >= orientation_threshold"
Hoogenboom, Jerry's avatar
Hoogenboom, Jerry committed
191
        },
jhoogenboom's avatar
jhoogenboom committed
192
193
        {
          "type": "sort",
194
          "by": ["name", "-total_added", "-total_corr", "-total", "allele"]
jhoogenboom's avatar
jhoogenboom committed
195
196
197
198
        }
      ]
    },
    {
199
      "name": "barcounts",
jhoogenboom's avatar
jhoogenboom committed
200
201
202
203
204
205
206
207
208
209
      "source": "table",
      "transform": [
        {
          "type": "aggregate",
          "groupby": ["name"],
          "summarize": {"*": "count"}
        }
      ]
    },
    {
210
211
      "name": "subgraphpadding",
      "source": "barcounts",
jhoogenboom's avatar
jhoogenboom committed
212
213
214
      "transform": [
        {
          "type": "cross",
215
216
          "diagonal": false,
          "filter": "datum.b.name < datum.a.name"
jhoogenboom's avatar
jhoogenboom committed
217
218
219
220
        },
        {
          "type": "formula",
          "field": "name",
jhoogenboom's avatar
jhoogenboom committed
221
222
223
224
225
226
          "expr": "datum.a.name"
        },
        {
          "type": "aggregate",
          "groupby": ["name"],
          "summarize": [{"field": "*", "ops": ["count"], "as": ["cumulpadding"]}]
jhoogenboom's avatar
jhoogenboom committed
227
228
229
230
        }
      ]
    },
    {
231
232
      "name": "subgraphoffsets",
      "source": "barcounts",
jhoogenboom's avatar
jhoogenboom committed
233
234
235
      "transform": [
        {
          "type": "cross",
236
237
238
          "with": "table",
          "diagonal": false,
          "filter": "datum.b.name < datum.a.name"
jhoogenboom's avatar
jhoogenboom committed
239
240
241
242
        },
        {
          "type": "formula",
          "field": "name",
jhoogenboom's avatar
jhoogenboom committed
243
244
245
246
247
248
          "expr": "datum.a.name"
        },
        {
          "type": "aggregate",
          "groupby": ["name"],
          "summarize": [{"field": "*", "ops": ["count"], "as": ["cumulcount"]}]
jhoogenboom's avatar
jhoogenboom committed
249
250
251
252
253
        }
      ]
    },
    {
      "name": "yscale",
254
      "source": "barcounts",
jhoogenboom's avatar
jhoogenboom committed
255
256
      "transform": [
        {
jhoogenboom's avatar
jhoogenboom committed
257
          "type": "lookup",
258
          "on": "subgraphpadding",
jhoogenboom's avatar
jhoogenboom committed
259
260
261
          "onKey": "name",
          "keys": ["name"],
          "as": ["paddingobj"],
jhoogenboom's avatar
jhoogenboom committed
262
263
264
          "default": {"cumulpadding": 0}
        },
        {
jhoogenboom's avatar
jhoogenboom committed
265
          "type": "lookup",
266
          "on": "subgraphoffsets",
jhoogenboom's avatar
jhoogenboom committed
267
268
269
          "onKey": "name",
          "keys": ["name"],
          "as": ["offsetobj"],
jhoogenboom's avatar
jhoogenboom committed
270
271
272
273
274
          "default": {"cumulcount": 0}
        },
        {
          "type": "formula",
          "field": "offset",
275
          "expr": "barwidth*datum.offsetobj.cumulcount + subgraphoffset*datum.paddingobj.cumulpadding"
jhoogenboom's avatar
jhoogenboom committed
276
277
278
279
        },
        {
          "type": "formula",
          "field": "end",
280
          "expr": "datum.offset + barwidth*datum.count"
jhoogenboom's avatar
jhoogenboom committed
281
282
        }
      ]
Hoogenboom, Jerry's avatar
Hoogenboom, Jerry committed
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
    },
    {
      "name": "selectedAlleles",
      "modify": [
        {
          "type": "toggle",
          "signal": "clickedAllele",
          "field": "allele"
        }
      ],
      "transform": [
        {
          "type": "filter",
          "test": "datum.allele"
        }
      ]
    }
  ],
  "predicates": [
    {
      "name": "isSelected",
      "type": "in",
      "item": {"arg": "allele"},
      "data": "selectedAlleles",
      "field": "allele"
jhoogenboom's avatar
jhoogenboom committed
308
309
310
    }
  ],
  "scales": [
Hoogenboom, Jerry's avatar
Hoogenboom, Jerry committed
311
312
313
314
    {
      "name": "b",
      "type": "ordinal",
      "range": ["black", "red"],
315
      "domain": ["", "\u2605"]
Hoogenboom, Jerry's avatar
Hoogenboom, Jerry committed
316
    },
jhoogenboom's avatar
jhoogenboom committed
317
318
319
320
    {
      "name": "c",
      "type": "ordinal",
      "range": ["#5e3c99", "#b2abd2", "#fdb863", "#e66101"],
Hoogenboom, Jerry's avatar
Hoogenboom, Jerry committed
321
322
323
324
325
326
      "domain": ["Genuine reads", "Noise reads", "Noise/recovered overlap", "Recovered reads"]
    },
    {
      "name": "d",
      "type": "ordinal",
      "range": ["transparent"],
327
      "domain": ["\u2014 Strand balance"]
jhoogenboom's avatar
jhoogenboom committed
328
329
330
331
332
333
334
335
336
    }
  ],
  "marks": [
    {
      "type": "text",
      "from": {
        "data": "yscale"
      },
      "properties": {
337
        "update": {
jhoogenboom's avatar
jhoogenboom committed
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
          "x": {"field": {"group": "width"}, "mult": 0.5},
          "y": {"field": "offset"},
          "fontWeight": {"value": "bold"},
          "text": {"field": "name"},
          "align": {"value": "center"},
          "baseline": {"value": "bottom"},
          "fill": {"value": "black"}
        }
      }
    },
    {
      "type": "group",
      "from": {
        "data": "table",
        "transform": [
          {
            "type": "facet",
            "groupby": ["name"]
          },
          {
jhoogenboom's avatar
jhoogenboom committed
358
359
360
361
            "type": "lookup",
            "on": "yscale",
            "onKey": "name",
            "keys": ["name"],
362
            "as": ["subgraphscale"]
jhoogenboom's avatar
jhoogenboom committed
363
364
365
366
          }
        ]
      },
      "properties": {
367
        "update": {
jhoogenboom's avatar
jhoogenboom committed
368
369
          "x": {"value": 0},
          "width": {"field": {"group": "width"}},
370
371
          "y": {"field": "subgraphscale.offset"},
          "y2": {"field": "subgraphscale.end"},
jhoogenboom's avatar
jhoogenboom committed
372
373
374
375
376
377
          "stroke": {"value": "#dddddd"}
        }
      },
      "scales": [
        {
          "name": "x",
378
          "type": "linear",
Hoogenboom, Jerry's avatar
Hoogenboom, Jerry committed
379
          "nice": true,
jhoogenboom's avatar
jhoogenboom committed
380
          "range": "width",
Hoogenboom, Jerry's avatar
Hoogenboom, Jerry committed
381
          "domain": {"field": ["xlow", "xhigh"]}
jhoogenboom's avatar
jhoogenboom committed
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
        },
        {
          "name": "y",
          "type": "ordinal",
          "range": "height",
          "domain": {"field": "allele"}
        }
      ],
      "axes": [
        {
          "type": "x",
          "scale": "x",
          "grid": true,
          "layer": "back",
          "title": "Number of reads",
          "properties": {
            "labels": {
              "align": {"value": "right"},
              "baseline": {"value": "middle"},
              "dy": {"value": 3},
              "angle": {"value": -25}
            }
          }
        },
        {
          "type": "y",
Hoogenboom, Jerry's avatar
Hoogenboom, Jerry committed
408
409
410
411
412
413
          "scale": "y",
          "properties": {
            "labels": {
              "fill": {"value": "transparent"}
            }
          }
jhoogenboom's avatar
jhoogenboom committed
414
415
416
417
418
419
420
421
422
423
424
425
        }
      ],
      "legends": [
        {
          "fill": "c",
          "properties": {
            "symbols": {
              "size": {"value": 100},
              "stroke": {"value": "transparent"},
              "fillOpacity": {"value": 0.8}
            }
          }
Hoogenboom, Jerry's avatar
Hoogenboom, Jerry committed
426
427
428
429
430
431
432
433
434
435
436
        },
        {
          "fill": "d",
          "properties": {
            "symbols": {
              "stroke": {"value": "transparent"}
            },
            "labels": {
              "x": {"value": 2}
            }
          }
jhoogenboom's avatar
jhoogenboom committed
437
438
439
440
441
442
        }
      ],
      "marks": [
        {
          "type": "rect",
          "properties": {
443
            "update": {
jhoogenboom's avatar
jhoogenboom committed
444
445
446
447
              "x": {"scale": "x", "value": 0},
              "x2": {"scale": "x", "field": "shared"},
              "y": {"scale": "y", "field": "allele", "offset": 1},
              "height": {"scale": "y", "band": true, "offset": -2},
Hoogenboom, Jerry's avatar
Hoogenboom, Jerry committed
448
              "fill": {"scale": "c", "value": "Genuine reads"},
jhoogenboom's avatar
jhoogenboom committed
449
450
451
452
453
454
455
              "fillOpacity": {"value": 0.8}
            }
          }
        },
        {
          "type": "rect",
          "properties": {
456
            "update": {
jhoogenboom's avatar
jhoogenboom committed
457
458
459
460
              "x": {"scale": "x", "field": "corr_shared"},
              "x2": {"scale": "x", "field": "corr_decreased"},
              "y": {"scale": "y", "field": "allele", "offset": 1},
              "height": {"scale": "y", "band": true, "offset": -2},
Hoogenboom, Jerry's avatar
Hoogenboom, Jerry committed
461
              "fill": {"scale": "c", "value": "Noise reads"},
jhoogenboom's avatar
jhoogenboom committed
462
463
464
465
466
467
468
              "fillOpacity": {"value": 0.8}
            }
          }
        },
        {
          "type": "rect",
          "properties": {
469
            "update": {
jhoogenboom's avatar
jhoogenboom committed
470
471
472
473
              "x": {"scale": "x", "field": "total_corr"},
              "x2": {"scale": "x", "field": "corr_shared"},
              "y": {"scale": "y", "field": "allele", "offset": 1},
              "height": {"scale": "y", "band": true, "offset": -2},
Hoogenboom, Jerry's avatar
Hoogenboom, Jerry committed
474
              "fill": {"scale": "c", "value": "Noise/recovered overlap"},
jhoogenboom's avatar
jhoogenboom committed
475
476
477
478
479
480
481
              "fillOpacity": {"value": 0.8}
            }
          }
        },
        {
          "type": "rect",
          "properties": {
482
            "update": {
jhoogenboom's avatar
jhoogenboom committed
483
484
485
486
              "x": {"scale": "x", "field": "corr_shared"},
              "x2": {"scale": "x", "field": "corr_increased"},
              "y": {"scale": "y", "field": "allele", "offset": 1},
              "height": {"scale": "y", "band": true, "offset": -2},
Hoogenboom, Jerry's avatar
Hoogenboom, Jerry committed
487
              "fill": {"scale": "c", "value": "Recovered reads"},
jhoogenboom's avatar
jhoogenboom committed
488
489
490
491
492
493
494
495
496
497
              "fillOpacity": {"value": 0.8}
            }
          }
        },
        {
          "type": "group",
          "from": {
            "transform": [{"type": "facet", "groupby": ["allele"]}]
          },
          "properties": {
498
            "update": {
jhoogenboom's avatar
jhoogenboom committed
499
500
501
502
503
504
505
506
507
508
509
              "x": {"value": 0},
              "width": {"field": {"group": "width"}},
              "y": {"scale": "y", "field": "key", "offset": 1},
              "height": {"scale": "y", "band": true, "offset": -2}
            }
          },
          "scales": [
            {
              "name": "balance",
              "range": "height",
              "nice": false,
510
              "clamp": true,
jhoogenboom's avatar
jhoogenboom committed
511
512
513
514
515
              "domain": [0, 100]
            }
          ],
          "marks": [
            {
516
              "type": "rule",
jhoogenboom's avatar
jhoogenboom committed
517
              "properties": {
518
                "update": {
jhoogenboom's avatar
jhoogenboom committed
519
                  "x": {"scale": "x", "value": 0},
520
521
522
523
                  "x2": {"scale": "x", "field": "total_added"},
                  "y": {"scale": "balance", "field": "forwardpct"},
                  "stroke": {"scale": "b", "field": "biasmark"},
                  "strokeWidth": {"value": 1}
Hoogenboom, Jerry's avatar
Hoogenboom, Jerry committed
524
525
526
527
528
529
                }
              }
            },
            {
              "type": "text",
              "properties": {
530
                "update": {
Hoogenboom, Jerry's avatar
Hoogenboom, Jerry committed
531
532
533
534
535
536
537
538
539
540
541
                  "x": {"scale": "x", "field": "xhigh", "mult": 0.952381, "offset": 5},
                  "y": {"scale": "balance", "value": 50},
                  "baseline": {"value": "middle"},
                  "fill": {"scale": "b", "field": "biasmark"},
                  "text": {"field": "biasmark"}
                }
              }
            },
            {
              "type": "text",
              "properties": {
542
                "update": {
Hoogenboom, Jerry's avatar
Hoogenboom, Jerry committed
543
544
545
546
                  "x": {"value": -10},
                  "y": {"scale": "balance", "value": 50},
                  "baseline": {"value": "middle"},
                  "align": {"value": "right"},
547
                  "text": {"field": "allele"},
Hoogenboom, Jerry's avatar
Hoogenboom, Jerry committed
548
549
550
551
552
553
554
555
556
                  "fill": {
                    "rule": [
                      {
                        "predicate": {
                          "name": "isSelected",
                          "allele": {"field": "thedatum"}
                        },
                        "value": "green"
                      },
557
                      {"value": "#aaaaaa"}
Hoogenboom, Jerry's avatar
Hoogenboom, Jerry committed
558
559
560
561
562
563
564
565
566
                    ]
                  },
                  "fontStyle": {
                    "rule": [
                      {
                        "predicate": {
                          "name": "isSelected",
                          "allele": {"field": "thedatum"}
                        },
567
                        "value": "normal"
Hoogenboom, Jerry's avatar
Hoogenboom, Jerry committed
568
                      },
569
                      {"value": "italic"}
Hoogenboom, Jerry's avatar
Hoogenboom, Jerry committed
570
571
                    ]
                  }
jhoogenboom's avatar
jhoogenboom committed
572
573
574
575
                }
              }
            }
          ]
Hoogenboom, Jerry's avatar
Hoogenboom, Jerry committed
576
577
578
579
580
        },
        {
          "name": "alleleSelector",
          "type": "rect",
          "properties": {
581
            "update": {
Hoogenboom, Jerry's avatar
Hoogenboom, Jerry committed
582
583
584
585
586
587
588
              "x": {"value": 0},
              "width": {"field": {"group": "width"}},
              "y": {"scale": "y", "field": "allele"},
              "height": {"scale": "y", "band": true},
              "fill": {"value": "transparent"}
            }
          }
jhoogenboom's avatar
jhoogenboom committed
589
590
591
592
        }
      ]
    }
  ]
Hoogenboom, Jerry's avatar
Hoogenboom, Jerry committed
593
}