allelevis.json 6.38 KB
Newer Older
1
{
2
  "width": 600,
3
4
5
6
7
  "height": 500,
  "data": [
    {
      "name": "raw",
      "values": "VALUES HERE",
8
      "format": {"type": "tsv"},
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
      "transform": [
        {
          "type": "formula",
          "field": "samplemarker",
          "expr": "datum.sample + datum.marker"
        },
        {
          "type": "formula",
          "field": "markerallele",
          "expr": "datum.marker + datum.allele"
        },
        {
          "type": "formula",
          "field": "samplemarkerallele",
          "expr": "datum.samplemarker + datum.allele"
        }
      ]
    },
    {
      "name": "homozygotes",
      "source": "raw",
      "transform": [
        {
          "type": "aggregate",
          "groupby": ["samplemarker"],
          "summarize": {"allele": "distinct"}
        },
        {
          "type": "filter",
          "test": "datum.distinct_allele == 1"
        },
        {
          "type": "lookup",
          "on": "raw",
          "onKey": "samplemarker",
          "keys": ["samplemarker"],
          "as": ["alleleobj"]
        },
        {
          "type": "formula",
          "field": "markerallele",
          "expr": "datum.alleleobj.markerallele"
        },
        {
          "type": "aggregate",
          "groupby": ["markerallele"],
          "summarize": {"*": "count"}
        }
      ]
    },
    {
60
      "name": "samplecounts",
61
62
63
64
65
66
      "source": "raw",
      "transform": [
        {
          "type": "aggregate",
          "groupby": ["marker", "allele"],
          "summarize": {"*": "count"}
67
68
69
70
71
72
73
74
75
76
77
        }
      ]
    },
    {
      "name": "indices",
      "source": "samplecounts",
      "transform": [
        {
          "type": "cross",
          "diagonal": false,
          "filter": "datum.a._id > datum.b._id"
78
79
80
81
        },
        {
          "type": "formula",
          "field": "markerallele",
82
          "expr": "datum.a.marker + datum.a.allele"
83
        },
84
85
86
87
88
89
90
91
92
93
94
        {
          "type": "aggregate",
          "groupby": ["markerallele"],
          "summarize": [{"field": "*", "ops": ["count"], "as": ["index"]}]
        }
      ]
    },
    {
      "name": "nodes",
      "source": "samplecounts",
      "transform": [
95
96
        {
          "type": "lookup",
97
          "on": "indices",
98
99
          "onKey": "markerallele",
          "keys": ["markerallele"],
100
101
          "as": ["indexobj"],
          "default": {"index": 0}
102
103
104
        },
        {
          "type": "formula",
105
106
107
108
109
110
111
112
113
114
          "field": "markerallele",
          "expr": "datum.marker + datum.allele"
        },
        {
          "type": "lookup",
          "on": "homozygotes",
          "onKey": "markerallele",
          "keys": ["markerallele"],
          "as": ["homcount"],
          "default": {"count": 0}
115
116
117
118
119
        }
      ]
    },
    {
      "name": "edges",
120
      "source": "raw",
121
122
123
      "transform": [
        {
          "type": "cross",
124
125
126
          "with": "nodes",
          "output": {"left": "samples", "right": "source"},
          "filter": "datum.source.markerallele == datum.samples.markerallele"
127
128
129
130
        },
        {
          "type": "cross",
          "with": "nodes",
131
132
          "output": {"left": "a", "right": "target"},
          "filter": "datum.a.source.marker == datum.target.marker && datum.a.source.allele < datum.target.allele"
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
        },
        {
          "type": "formula",
          "field": "samplemarkerallele",
          "expr": "datum.a.samples.sample + datum.target.marker + datum.target.allele"
        },
        {
          "type": "lookup",
          "on": "raw",
          "onKey": "samplemarkerallele",
          "keys": ["samplemarkerallele"],
          "as": ["targetsample"],
          "default": {"sample": "NOTFOUND"}
        },
        {
          "type": "filter",
          "test": "datum.targetsample.sample != 'NOTFOUND'"
        },
        {
          "type": "formula",
          "field": "source",
154
          "expr": "datum.a.source.indexobj.index"
155
156
157
158
        },
        {
          "type": "formula",
          "field": "target",
159
          "expr": "datum.target.indexobj.index"
160
161
162
163
164
165
166
        },
        {
          "type": "aggregate",
          "groupby": ["source", "target"],
          "summarize": {"*": "count"}
        }
      ]
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
    },
    {
      "name": "layout",
      "source": "nodes",
      "transform": [
        {
          "type": "force",
          "links": "edges",
          "linkDistance": 30,
          "linkStrength": 0.1,
          "charge": -20,
          "iterations": 1000
        }
      ]
    }
  ],
  "scales": [
    {
      "name": "c",
      "type": "ordinal",
      "range": "category20",
      "domain": {"data": "raw", "field": "marker", "sort": true}
    },
    {
      "name": "legend_sizes",
      "type": "ordinal",
      "range": [1, 5, 10, 20, 50],
      "domain": [1, 5, 10, 20, 50]
    }
  ],
  "legends": [
    {
      "fill": "c",
      "properties": {
        "symbols": {
          "size": {"value": 100},
          "stroke": {"value": "transparent"},
          "fillOpacity": {"value": 0.8}
        }
      }
    },
    {
      "size": "legend_sizes",
      "values": [1, 5, 10, 20, 50]
    }
  ],
  "marks": [
    {
      "type": "path",
      "from": {
        "data": "edges",
        "transform": [
          {
            "type": "lookup",
            "on": "layout",
            "keys": ["source", "target"],
            "as": ["_source", "_target"]
          },
          {
            "type": "sort",
            "by": "_source.marker"
          },
          {"type": "linkpath"}
        ]
      },
      "properties": {
        "update": {
          "path": {"field": "layout_path"},
          "stroke": {"scale": "c", "field": "_source.marker"},
          "strokeWidth": {"field": "count", "mult": 0.5},
          "strokeOpacity": {"value": 0.3}
        }
      }
    },
    {
      "type": "symbol",
      "from": {"data": "layout"},
      "properties": {
        "enter": {
          "size": {"field": "count"}
        },
        "update": {
          "x": {"field": "layout_x"},
          "y": {"field": "layout_y"},
          "fill": {"scale": "c", "field": "marker"},
          "stroke": {"scale": "c", "field": "marker"}
        }
      }
    },
    {
      "type": "symbol",
      "from": {"data": "layout"},
      "properties": {
        "enter": {
          "size": {"field": "homcount.count"}
        },
        "update": {
          "x": {"field": "layout_x"},
          "y": {"field": "layout_y"},
          "fill": {"value": "black"},
          "stroke": {"value": "black"}
        }
      }
270
271
    }
  ]
272
}