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
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
//! Implementation of endpoint `/api/v1/seqvars/annos`.
//!
//! Also includes the implementation of the `/annos/variant` endpoint (deprecated).
use actix_web::{
get,
web::{self, Data, Json, Path},
};
use strum::IntoEnumIterator;
use crate::{
common::{keys, version},
server::run::{fetch::fetch_pos_protobuf, AnnoDb},
};
use super::error::CustomError;
use super::fetch::{
fetch_pos_protobuf_json, fetch_var_protobuf, fetch_var_protobuf_json, fetch_var_tsv_json,
};
/// Parameters for `variant_annos::handle`.
///
/// Defines a variant in VCF-style format with a genome release specification.
#[serde_with::skip_serializing_none]
#[serde_with::serde_as]
#[derive(
Debug, Clone, serde::Serialize, serde::Deserialize, utoipa::ToSchema, utoipa::IntoParams,
)]
pub struct SeqvarsAnnosQuery {
/// Genome release specification.
pub genome_release: String,
/// Chromosome name.
pub chromosome: String,
/// 1-based position for VCF-style variant.
pub pos: u32,
/// Reference allele bases.
pub reference: String,
/// Alterantive allele bases.
pub alternative: String,
}
impl From<SeqvarsAnnosQuery> for keys::Var {
fn from(value: SeqvarsAnnosQuery) -> Self {
keys::Var {
chrom: value.chromosome,
pos: value.pos as i32,
reference: value.reference,
alternative: value.alternative,
}
}
}
impl From<SeqvarsAnnosQuery> for keys::Pos {
fn from(value: SeqvarsAnnosQuery) -> Self {
keys::Pos {
chrom: value.chromosome,
pos: value.pos as i32,
}
}
}
/// Result for `handle`.
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, utoipa::ToSchema)]
#[serde_with::skip_serializing_none]
struct Container {
/// Version of the server code.
pub server_version: String,
/// The query parameters.
pub query: SeqvarsAnnosQuery,
/// Annotations for the variant from each database.
pub result: std::collections::BTreeMap<AnnoDb, Option<serde_json::Value>>,
}
/// Query for annotations for one variant.
#[get("/annos/variant")]
async fn handle(
data: Data<crate::server::run::WebServerData>,
_path: Path<()>,
query: web::Query<SeqvarsAnnosQuery>,
) -> actix_web::Result<Json<Container>, CustomError> {
let genome_release =
query
.clone()
.into_inner()
.genome_release
.parse()
.map_err(|e: strum::ParseError| {
CustomError::new(anyhow::anyhow!("problem getting genome release: {}", e))
})?;
let mut annotations = std::collections::BTreeMap::default();
for anno_db in AnnoDb::iter() {
match anno_db {
AnnoDb::Other => (),
AnnoDb::Clinvar => {
data.annos[genome_release][anno_db]
.as_ref()
.map(|db| {
fetch_var_protobuf_json::<
crate::pbs::clinvar::minimal::ExtractedVcvRecordList,
>(
&db.data,
anno_db.cf_name(),
query.clone().into_inner().into(),
)
})
.transpose()?
.map(|v| annotations.insert(anno_db, v));
}
AnnoDb::Cadd | AnnoDb::Dbnsfp | AnnoDb::Dbscsnv => {
data.annos[genome_release][anno_db]
.as_ref()
.map(|db| {
fetch_var_tsv_json(
&db.data,
anno_db.cf_name(),
query.clone().into_inner().into(),
)
})
.transpose()?
.map(|v| annotations.insert(anno_db, v));
}
AnnoDb::Dbsnp => {
data.annos[genome_release][anno_db]
.as_ref()
.map(|db| {
fetch_var_protobuf_json::<crate::dbsnp::pbs::Record>(
&db.data,
anno_db.cf_name(),
query.clone().into_inner().into(),
)
})
.transpose()?
.map(|v| annotations.insert(anno_db, v));
}
AnnoDb::Helixmtdb => {
data.annos[genome_release][anno_db]
.as_ref()
.map(|db| {
fetch_var_protobuf_json::<crate::helixmtdb::pbs::Record>(
&db.data,
anno_db.cf_name(),
query.clone().into_inner().into(),
)
})
.transpose()?
.map(|v| annotations.insert(anno_db, v));
}
AnnoDb::GnomadMtdna => {
data.annos[genome_release][anno_db]
.as_ref()
.map(|db| {
fetch_var_protobuf_json::<crate::pbs::gnomad::mtdna::Record>(
&db.data,
anno_db.cf_name(),
query.clone().into_inner().into(),
)
})
.transpose()?
.map(|v| annotations.insert(anno_db, v));
}
AnnoDb::GnomadExomes => {
data.annos[genome_release][anno_db]
.as_ref()
.map(|db| {
let db_version = data.db_infos[genome_release][anno_db]
.as_ref()
.expect("must have db info here")
.db_version
.as_ref()
.expect("gnomAD must have db version");
if db_version.starts_with("2.") {
fetch_var_protobuf_json::<crate::pbs::gnomad::gnomad2::Record>(
&db.data,
anno_db.cf_name(),
query.clone().into_inner().into(),
)
} else if db_version.starts_with("4.") {
fetch_var_protobuf_json::<crate::pbs::gnomad::gnomad4::Record>(
&db.data,
anno_db.cf_name(),
query.clone().into_inner().into(),
)
} else {
Err(CustomError::new(anyhow::anyhow!(
"don't know how to handle gnomAD version {}",
db_version
)))
}
})
.transpose()?
.map(|v| annotations.insert(anno_db, v));
}
AnnoDb::GnomadGenomes => {
data.annos[genome_release][anno_db]
.as_ref()
.map(|db| {
let db_version = data.db_infos[genome_release][anno_db]
.as_ref()
.expect("must have db info here")
.db_version
.as_ref()
.expect("gnomAD must have db version");
if db_version.starts_with("2.") {
fetch_var_protobuf_json::<crate::pbs::gnomad::gnomad2::Record>(
&db.data,
anno_db.cf_name(),
query.clone().into_inner().into(),
)
} else if db_version.starts_with("3.") {
fetch_var_protobuf_json::<crate::pbs::gnomad::gnomad3::Record>(
&db.data,
anno_db.cf_name(),
query.clone().into_inner().into(),
)
} else if db_version.starts_with("4.") {
fetch_var_protobuf_json::<crate::pbs::gnomad::gnomad4::Record>(
&db.data,
anno_db.cf_name(),
query.clone().into_inner().into(),
)
} else {
Err(CustomError::new(anyhow::anyhow!(
"don't know how to handle gnomAD version {}",
db_version
)))
}
})
.transpose()?
.map(|v| annotations.insert(anno_db, v));
}
AnnoDb::UcscConservation => {
data.annos[genome_release][anno_db]
.as_ref()
.map(|db| {
let start: keys::Pos = query.clone().into_inner().into();
let start = keys::Pos {
chrom: start.chrom,
pos: start.pos - 2,
};
let stop = query.clone().into_inner().into();
fetch_pos_protobuf_json::<crate::pbs::cons::RecordList>(
&db.data,
anno_db.cf_name(),
start,
stop,
)
})
.transpose()?
.map(|v| annotations.insert(anno_db, v));
}
}
}
let result = Container {
server_version: version().to_string(),
query: query.into_inner(),
result: annotations,
};
Ok(Json(result))
}
/// `SeqvarsAnnosResponse` and related types.
pub mod response {
use crate::{pbs, server::run::clinvar_data::ClinvarExtractedVcvRecord};
/// Protocol buffer for `Vep.domains`
#[derive(
Debug,
Default,
Clone,
serde::Serialize,
serde::Deserialize,
utoipa::ToSchema,
utoipa::ToResponse,
)]
pub struct VepCommonDomain {
/// Domain ID.
pub id: String,
/// Domain source.
pub source: String,
}
impl From<pbs::gnomad::vep_common::Domain> for VepCommonDomain {
fn from(value: pbs::gnomad::vep_common::Domain) -> Self {
VepCommonDomain {
id: value.id,
source: value.source,
}
}
}
/// Store the scoring of a prediction.
#[derive(
Debug,
Default,
Clone,
serde::Serialize,
serde::Deserialize,
utoipa::ToSchema,
utoipa::ToResponse,
)]
pub struct VepCommonPrediction {
/// Prediction.
pub prediction: String,
/// Score.
pub score: f32,
}
impl From<pbs::gnomad::vep_common::Prediction> for VepCommonPrediction {
fn from(value: pbs::gnomad::vep_common::Prediction) -> Self {
VepCommonPrediction {
prediction: value.prediction,
score: value.score,
}
}
}
/// Protocol buffer for the gnomAD-mtDNA VEP predictions.
#[derive(
Debug,
Default,
Clone,
serde::Serialize,
serde::Deserialize,
utoipa::ToSchema,
utoipa::ToResponse,
)]
pub struct Gnomad2Vep {
/// Allele of record.
pub allele: String,
/// Consequence, e.g., `"missense_variant"`.
pub consequence: String,
/// Impact, e.g., `"MODERATE"`.
pub impact: String,
/// Gene symbol, e.g., `"PCSK9"`.
pub symbol: String,
/// Gene ID, `e.g., "ENSG00000169174"`.
pub gene: String,
/// Feature type, e.g., `"Transcript"`.
pub feature_type: String,
/// Feature ID, e.g., `"ENST00000302118"`.
pub feature: String,
/// Feature biotype, e.g., `"protein_coding"`.
pub feature_biotype: String,
/// Ranked exon number, e.g., `"1/4"`.
pub exon: Option<String>,
/// Ranked intron number, e.g., `"1/4"`.
pub intron: Option<String>,
/// cDNA position, e.g., `"ENST00000302118.5:c.89C>G"`.
pub hgvsc: Option<String>,
/// Protein position, e.g., `"ENSP00000302118.5:p.Thr30Arg"`.
pub hgvsp: Option<String>,
/// cDNA position, e.g., `"89/1863"`.
pub cdna_position: Option<String>,
/// CDS position, e.g., `"89/1863"`.
pub cds_position: Option<String>,
/// Protein position, e.g., `"30/620"`.
pub protein_position: Option<String>,
/// Amino acids, e.g., `"T/R"`.
pub amino_acids: Option<String>,
/// Codons, e.g., `"gCg/gGg"`.
pub codons: Option<String>,
/// Existing variation info.
pub existing_variation: Option<String>,
/// dbSNP ID, e.g., `"rs28942080"`.
pub dbsnp_id: Option<String>,
/// Distance output of VEP.
pub distance: Option<String>,
/// Strand, e.g., `"1"`.
pub strand: Option<String>,
/// Flags, e.g., `"cds_end_NF"`.
pub flags: Option<String>,
/// Variant class, e.g., `"SNV"`.
pub variant_class: Option<String>,
/// Minimised output of VEP.
pub minimised: Option<String>,
/// Symbol source, e.g., `"HGNC"`.
pub symbol_source: Option<String>,
/// HGNC ID, e.g., `"HGNC:8706"`.
pub hgnc_id: Option<String>,
/// Whether this is the canonical transcript.
pub canonical: bool,
/// Transcript support level, e.g., `"1"`.
pub tsl: Option<i32>,
/// APPRIS annotation, e.g. `"P1"`.
pub appris: Option<String>,
/// CCDS ID, e.g., `"CCDS30547.1"`.
pub ccds: Option<String>,
/// Ensembl protein ID, e.g., `"ENSP00000302118"`.
pub ensp: Option<String>,
/// SwissProt ID, e.g., `"P04114"`.
pub swissprot: Option<String>,
/// TREMBL ID, e.g., `"Q5T4W7"`.
pub trembl: Option<String>,
/// UniParc ID, e.g., `"UPI000002D4B2"`.
pub uniparc: Option<String>,
/// Gene phenotype from VEP.
pub gene_pheno: Option<String>,
/// SIFT prediction, e.g., `"tolerated(0.06)"`.
pub sift: Option<VepCommonPrediction>,
/// PolyPhen prediction, e.g., `"benign(0.001)"`.
pub polyphen: Option<VepCommonPrediction>,
/// Protein domains, e.g., `\[["2p4e", "ENSP_mappings"\], \["2qtw", "ENSP_mappings"]\]`.
pub domains: Vec<VepCommonDomain>,
/// HGVS offset.
pub hgvs_offset: Option<String>,
/// Overall minor allele frequency.
pub gmaf: Option<f32>,
/// Minor allele frequency in AFR population.
pub afr_maf: Option<f32>,
/// Minor allele frequency in AMR population.
pub amr_maf: Option<f32>,
/// Minor allele frequency in EAS population.
pub eas_maf: Option<f32>,
/// Minor allele frequency in EUR population.
pub eur_maf: Option<f32>,
/// Minor allele frequency in SAS population.
pub sas_maf: Option<f32>,
/// Minor allele frequency in AA population.
pub aa_maf: Option<f32>,
/// Minor allele frequency in EA population.
pub ea_maf: Option<f32>,
/// Minor allele frequency in ExAC.
pub exac_maf: Option<f32>,
/// Minor allele frequency EXAC ADJ population.
pub exac_adj_maf: Option<f32>,
/// Minor allele frequency in ExAC AFR population.
pub exac_afr_maf: Option<f32>,
/// Minor allele frequency in ExAC AMR population.
pub exac_amr_maf: Option<f32>,
/// Minor allele frequency in ExAC EAS population.
pub exac_eas_maf: Option<f32>,
/// Minor allele frequency in ExAC FIN population.
pub exac_fin_maf: Option<f32>,
/// Minor allele frequency in ExAC NFE population.
pub exac_nfe_maf: Option<f32>,
/// Minor allele frequency in ExAC OTH population.
pub exac_oth_maf: Option<f32>,
/// Minor allele frequency in ExAC SAS population.
pub exac_sas_maf: Option<f32>,
/// Clinical significance.
pub clin_sig: Option<String>,
/// Whether the variant is somatic.
pub somatic: Option<String>,
/// Phenotype.
pub pheno: Option<String>,
/// Pubmed ID.
pub pubmed: Option<String>,
/// Motif name.
pub motif_name: Option<String>,
/// Motif pos.
pub motif_pos: Option<String>,
/// "high inf pos" from VEP.
pub high_inf_pos: Option<String>,
/// Motif score change.
pub motif_score_change: Option<String>,
/// Loss of function prediction.
pub lof: Option<String>,
/// Loss of function filter.
pub lof_filter: Option<String>,
/// Loss of function flags.
pub lof_flags: Option<String>,
/// Loss of function info.
pub lof_info: Option<String>,
}
impl From<pbs::gnomad::vep_gnomad2::Vep> for Gnomad2Vep {
fn from(value: pbs::gnomad::vep_gnomad2::Vep) -> Self {
Gnomad2Vep {
allele: value.allele,
consequence: value.consequence,
impact: value.impact,
symbol: value.symbol,
gene: value.gene,
feature_type: value.feature_type,
feature: value.feature,
feature_biotype: value.feature_biotype,
exon: value.exon,
intron: value.intron,
hgvsc: value.hgvsc,
hgvsp: value.hgvsp,
cdna_position: value.cdna_position,
cds_position: value.cds_position,
protein_position: value.protein_position,
amino_acids: value.amino_acids,
codons: value.codons,
existing_variation: value.existing_variation,
dbsnp_id: value.dbsnp_id,
distance: value.distance,
strand: value.strand,
flags: value.flags,
variant_class: value.variant_class,
minimised: value.minimised,
symbol_source: value.symbol_source,
hgnc_id: value.hgnc_id,
canonical: value.canonical,
tsl: value.tsl,
appris: value.appris,
ccds: value.ccds,
ensp: value.ensp,
swissprot: value.swissprot,
trembl: value.trembl,
uniparc: value.uniparc,
gene_pheno: value.gene_pheno,
sift: value.sift.map(Into::into),
polyphen: value.polyphen.map(Into::into),
domains: value.domains.into_iter().map(Into::into).collect(),
hgvs_offset: value.hgvs_offset,
gmaf: value.gmaf,
afr_maf: value.afr_maf,
amr_maf: value.amr_maf,
eas_maf: value.eas_maf,
eur_maf: value.eur_maf,
sas_maf: value.sas_maf,
aa_maf: value.aa_maf,
ea_maf: value.ea_maf,
exac_maf: value.exac_maf,
exac_adj_maf: value.exac_adj_maf,
exac_afr_maf: value.exac_afr_maf,
exac_amr_maf: value.exac_amr_maf,
exac_eas_maf: value.exac_eas_maf,
exac_fin_maf: value.exac_fin_maf,
exac_nfe_maf: value.exac_nfe_maf,
exac_oth_maf: value.exac_oth_maf,
exac_sas_maf: value.exac_sas_maf,
clin_sig: value.clin_sig,
somatic: value.somatic,
pheno: value.pheno,
pubmed: value.pubmed,
motif_name: value.motif_name,
motif_pos: value.motif_pos,
high_inf_pos: value.high_inf_pos,
motif_score_change: value.motif_score_change,
lof: value.lof,
lof_filter: value.lof_filter,
lof_flags: value.lof_flags,
lof_info: value.lof_info,
}
}
}
/// Store the relevant allele counts and frequencies in a given sub cohort.
#[derive(
Debug,
Default,
Clone,
serde::Serialize,
serde::Deserialize,
utoipa::ToSchema,
utoipa::ToResponse,
)]
pub struct Gnomad2AlleleCounts {
/// Number of alternate alleles in sub cohort.
pub ac: i32,
/// Total number of alleles in the sub cohort.
pub an: i32,
/// Number of homozygous alternate alleles in the sub cohort.
pub nhomalt: i32,
/// Alternate allele frequency in the sub cohort.
pub af: f32,
}
impl From<pbs::gnomad::gnomad2::AlleleCounts> for Gnomad2AlleleCounts {
fn from(value: pbs::gnomad::gnomad2::AlleleCounts) -> Self {
Gnomad2AlleleCounts {
ac: value.ac,
an: value.an,
nhomalt: value.nhomalt,
af: value.af,
}
}
}
/// Store the allele counts for the given sub cohort and sub cohort factored by sex.
#[derive(
Debug,
Default,
Clone,
serde::Serialize,
serde::Deserialize,
utoipa::ToSchema,
utoipa::ToResponse,
)]
pub struct Gnomad2AlleleCountsBySex {
/// Overall allele counts in the sub cohort.
pub overall: Option<Gnomad2AlleleCounts>,
/// Allele counts in female/XX karyotype individuals of sub cohort.
pub xx: Option<Gnomad2AlleleCounts>,
/// Allele counts in male/XY karyotype individuals of sub cohort.
pub xy: Option<Gnomad2AlleleCounts>,
}
impl From<pbs::gnomad::gnomad2::AlleleCountsBySex> for Gnomad2AlleleCountsBySex {
fn from(value: pbs::gnomad::gnomad2::AlleleCountsBySex) -> Self {
Gnomad2AlleleCountsBySex {
overall: value.overall.map(Into::into),
xx: value.xx.map(Into::into),
xy: value.xy.map(Into::into),
}
}
}
/// Store the allele counts for the given population.
#[derive(
Debug,
Default,
Clone,
serde::Serialize,
serde::Deserialize,
utoipa::ToSchema,
utoipa::ToResponse,
)]
pub struct Gnomad2PopulationAlleleCounts {
/// Name of the population.
pub population: String,
/// The overall allele counts and the one by sex.
pub counts: Option<Gnomad2AlleleCountsBySex>,
/// The filtering allele frequency (using Poisson 95% CI).
pub faf95: Option<f32>,
/// The filtering allele frequency (using Poisson 99% CI).
pub faf99: Option<f32>,
}
impl From<pbs::gnomad::gnomad2::PopulationAlleleCounts> for Gnomad2PopulationAlleleCounts {
fn from(value: pbs::gnomad::gnomad2::PopulationAlleleCounts) -> Self {
Gnomad2PopulationAlleleCounts {
population: value.population,
counts: value.counts.map(Into::into),
faf95: value.faf95,
faf99: value.faf99,
}
}
}
/// Store the allele counts for the given cohort.
#[derive(
Debug,
Default,
Clone,
serde::Serialize,
serde::Deserialize,
utoipa::ToSchema,
utoipa::ToResponse,
)]
pub struct Gnomad2CohortAlleleCounts {
/// Name of the cohort.
pub cohort: Option<String>,
/// Allele counts for each population.
pub by_population: Vec<Gnomad2PopulationAlleleCounts>,
/// Allele counts by sex.
pub by_sex: Option<Gnomad2AlleleCountsBySex>,
/// Raw allele counts.
pub raw: Option<Gnomad2AlleleCounts>,
/// The population with maximum AF.
pub popmax: Option<String>,
/// Maximum allele frequency across populations (excluding samples of Ashkenazi, Finnish, and
/// indeterminate ancestry).
pub af_popmax: Option<f32>,
/// Allele count in population with maximum AF.
pub ac_popmax: Option<i32>,
/// Total number of alleles in population with maximum AF.
pub an_popmax: Option<i32>,
/// Total number of homozygous individuals in population with maximum AF.
pub nhomalt_popmax: Option<i32>,
}
impl From<pbs::gnomad::gnomad2::CohortAlleleCounts> for Gnomad2CohortAlleleCounts {
fn from(value: pbs::gnomad::gnomad2::CohortAlleleCounts) -> Self {
Gnomad2CohortAlleleCounts {
cohort: value.cohort,
by_population: value.by_population.into_iter().map(Into::into).collect(),
by_sex: value.by_sex.map(Into::into),
raw: value.raw.map(Into::into),
popmax: value.popmax,
af_popmax: value.af_popmax,
ac_popmax: value.ac_popmax,
an_popmax: value.an_popmax,
nhomalt_popmax: value.nhomalt_popmax,
}
}
}
/// Encapsulate VCF INFO fields related to age.
#[derive(
Debug,
Default,
Clone,
serde::Serialize,
serde::Deserialize,
utoipa::ToSchema,
utoipa::ToResponse,
)]
pub struct Gnomad2AgeInfo {
/// Histogram of ages of individuals with a homoplasmic variant; bin edges are: [30.0, 35.0,
/// 40.0, 45.0, 50.0, 55.0, 60.0, 65.0, 70.0, 75.0, 80.0].
pub age_hist_hom_bin_freq: Vec<i32>,
/// Count of age values falling below lowest histogram bin edge for individuals with a
/// homoplasmic variant.
pub age_hist_hom_n_smaller: Option<i32>,
/// Count of age values falling above highest histogram bin edge for individuals with a
/// homoplasmic variant.
pub age_hist_hom_n_larger: Option<i32>,
/// Histogram of ages of individuals with a heteroplasmic variant; bin edges are: [30.0, 35.0,
/// 40.0, 45.0, 50.0, 55.0, 60.0, 65.0, 70.0, 75.0, 80.0]
pub age_hist_het_bin_freq: Vec<i32>,
/// Count of age values falling below lowest histogram bin edge for individuals with a
/// heteroplasmic variant.
pub age_hist_het_n_smaller: Option<i32>,
/// Count of age values falling above highest histogram bin edge for individuals with a
/// heteroplasmic variant.
pub age_hist_het_n_larger: Option<i32>,
}
impl From<pbs::gnomad::gnomad2::AgeInfo> for Gnomad2AgeInfo {
fn from(value: pbs::gnomad::gnomad2::AgeInfo) -> Self {
Gnomad2AgeInfo {
age_hist_hom_bin_freq: value.age_hist_hom_bin_freq,
age_hist_hom_n_smaller: value.age_hist_hom_n_smaller,
age_hist_hom_n_larger: value.age_hist_hom_n_larger,
age_hist_het_bin_freq: value.age_hist_het_bin_freq,
age_hist_het_n_smaller: value.age_hist_het_n_smaller,
age_hist_het_n_larger: value.age_hist_het_n_larger,
}
}
}
/// Encapsulate VCF INFO fields related to depth.
#[derive(
Debug,
Default,
Clone,
serde::Serialize,
serde::Deserialize,
utoipa::ToSchema,
utoipa::ToResponse,
)]
pub struct Gnomad2DepthInfo {
/// Count of dp values falling above highest histogram bin edge for all individuals.
pub dp_hist_all_n_larger: Option<i32>,
/// Count of dp values falling above highest histogram bin edge for individuals with the
/// alternative allele
pub dp_hist_alt_n_larger: Option<i32>,
/// Histogram of dp values for all individuals; bin edges are: [0.0, 200.0, 400.0, 600.0, 800.0,
/// 1000.0, 1200.0, 1400.0, 1600.0, 1800.0, 2000.0]
pub dp_hist_all_bin_freq: Vec<i32>,
/// Histogram of dp values for individuals with the alternative allele; bin edges are: [0.0,
/// 200.0, 400.0, 600.0, 800.0, 1000.0, 1200.0, 1400.0, 1600.0, 1800.0, 2000.0]
pub dp_hist_alt_bin_freq: Vec<i32>,
}
impl From<pbs::gnomad::gnomad2::DepthInfo> for Gnomad2DepthInfo {
fn from(value: pbs::gnomad::gnomad2::DepthInfo) -> Self {
Gnomad2DepthInfo {
dp_hist_all_n_larger: value.dp_hist_all_n_larger,
dp_hist_alt_n_larger: value.dp_hist_alt_n_larger,
dp_hist_all_bin_freq: value.dp_hist_all_bin_freq,
dp_hist_alt_bin_freq: value.dp_hist_alt_bin_freq,
}
}
}
/// Encapsulate quality-related information.
#[derive(
Debug,
Default,
Clone,
serde::Serialize,
serde::Deserialize,
utoipa::ToSchema,
utoipa::ToResponse,
)]
pub struct Gnomad2QualityInfo {
/// Phred-scaled p-value of Fisher's exact test for strand bias.
pub fs: Option<f32>,
/// Inbreeding coefficient as estimated from the genotype likelihoods per-sample when compared
/// against the Hardy-Weinberg expectation.
pub inbreeding_coeff: Option<f32>,
/// Root mean square of the mapping quality of reads across all samples.
pub mq: Option<f32>,
/// Z-score from Wilcoxon rank sum test of alternate vs. reference read mapping qualities.
pub mq_rank_sum: Option<f32>,
/// Variant call confidence normalized by depth of sample reads supporting a variant.
pub qd: Option<f32>,
/// Z-score from Wilcoxon rank sum test of alternate vs. reference read position bias.
pub read_pos_rank_sum: Option<f32>,
/// Variant was used to build the positive training set of high-quality variants for VQSR.
pub vqsr_positive_train_site: bool,
/// Variant was used to build the negative training set of low-quality variants for VQSR.
pub vqsr_negative_train_site: bool,
/// Z-score from Wilcoxon rank sum test of alternate vs. reference base qualities.
pub base_q_rank_sum: Option<f32>,
/// Z-score from Wilcoxon rank sum test of alternate vs. reference number of hard clipped bases.
pub clipping_rank_sum: Option<f32>,
/// Strand bias estimated by the symmetric odds ratio test
pub sor: Option<f32>,
/// Depth of informative coverage for each sample; reads with MQ=255 or with bad mates are
/// filtered.
pub dp: Option<i32>,
/// Log-odds ratio of being a true variant versus being a false positive under the trained VQSR
/// Gaussian mixture model.
pub vqslod: Option<f32>,
/// Allele-specific worst-performing annotation in the VQSR Gaussian mixture model
pub vqsr_culprit: Option<String>,
/// Variant falls within a segmental duplication region
pub segdup: bool,
/// Variant falls within a low complexity region.
pub lcr: bool,
/// Variant falls within a reference decoy region.
pub decoy: bool,
/// Variant was a callset-wide doubleton that was transmitted within a family (i.e., a singleton
/// amongst unrelated sampes in cohort).
pub transmitted_singleton: bool,
/// Maximum p-value over callset for binomial test of observed allele balance for a heterozygous
/// genotype, given expectation of AB=0.5.
pub pab_max: Option<f32>,
}
impl From<pbs::gnomad::gnomad2::QualityInfo> for Gnomad2QualityInfo {
fn from(value: pbs::gnomad::gnomad2::QualityInfo) -> Self {
Gnomad2QualityInfo {
fs: value.fs,
inbreeding_coeff: value.inbreeding_coeff,
mq: value.mq,
mq_rank_sum: value.mq_rank_sum,
qd: value.qd,
read_pos_rank_sum: value.read_pos_rank_sum,
vqsr_positive_train_site: value.vqsr_positive_train_site,
vqsr_negative_train_site: value.vqsr_negative_train_site,
base_q_rank_sum: value.base_q_rank_sum,
clipping_rank_sum: value.clipping_rank_sum,
sor: value.sor,
dp: value.dp,
vqslod: value.vqslod,
vqsr_culprit: value.vqsr_culprit,
segdup: value.segdup,
lcr: value.lcr,
decoy: value.decoy,
transmitted_singleton: value.transmitted_singleton,
pab_max: value.pab_max,
}
}
}
/// Random forest related information.
#[derive(
Debug,
Default,
Clone,
serde::Serialize,
serde::Deserialize,
utoipa::ToSchema,
utoipa::ToResponse,
)]
pub struct Gnomad2RandomForestInfo {
/// Random forest prediction probability for a site being a true variant.
pub rf_tp_probability: f32,
/// Variant was labelled as a positive example for training of random forest model.
pub rf_positive_label: bool,
/// Variant was labelled as a negative example for training of random forest model.
pub rf_negative_label: bool,
/// Random forest training label.
pub rf_label: Option<String>,
/// Variant was used in training random forest model.
pub rf_train: bool,
}
impl From<pbs::gnomad::gnomad2::RandomForestInfo> for Gnomad2RandomForestInfo {
fn from(value: pbs::gnomad::gnomad2::RandomForestInfo) -> Self {
Gnomad2RandomForestInfo {
rf_tp_probability: value.rf_tp_probability,
rf_positive_label: value.rf_positive_label,
rf_negative_label: value.rf_negative_label,
rf_label: value.rf_label,
rf_train: value.rf_train,
}
}
}
/// Liftover related information.
#[derive(
Debug,
Default,
Clone,
serde::Serialize,
serde::Deserialize,
utoipa::ToSchema,
utoipa::ToResponse,
)]
pub struct Gnomad2LiftoverInfo {
/// The REF and the ALT alleles have been reverse complemented in liftover since the mapping from
/// the previous reference to the current one was on the negative strand.
pub reverse_complemented_alleles: bool,
/// The REF and the ALT alleles have been swapped in liftover due to changes in the reference. It
/// is possible that not all INFO annotations reflect this swap, and in the genotypes, only the
/// GT, PL, and AD fields have been modified. You should check the TAGS_TO_REVERSE parameter that
/// was used during the LiftOver to be sure.
pub swapped_alleles: bool,
/// A list of the original alleles (including REF) of the variant prior to liftover. If the
/// alleles were not changed during liftover, this attribute will be omitted.
pub original_alleles: Vec<String>,
/// The name of the source contig/chromosome prior to liftover.
pub original_contig: Option<String>,
/// The position of the variant on the source contig prior to liftover.
pub original_start: Option<String>,
}
impl From<pbs::gnomad::gnomad2::LiftoverInfo> for Gnomad2LiftoverInfo {
fn from(value: pbs::gnomad::gnomad2::LiftoverInfo) -> Self {
Gnomad2LiftoverInfo {
reverse_complemented_alleles: value.reverse_complemented_alleles,
swapped_alleles: value.swapped_alleles,
original_alleles: value.original_alleles,
original_contig: value.original_contig,
original_start: value.original_start,
}
}
}
/// Variant type related information.
#[derive(
Debug,
Default,
Clone,
serde::Serialize,
serde::Deserialize,
utoipa::ToSchema,
utoipa::ToResponse,
)]
pub struct Gnomad2VariantInfo {
/// Variant type (snv, indel, multi-snv, multi-indel, or mixed).
pub variant_type: String,
/// Allele type (snv, ins, del, or mixed).
pub allele_type: String,
/// Total number of alternate alleles observed at variant locus.
pub n_alt_alleles: i32,
/// Variant type was mixed.
pub was_mixed: bool,
/// Variant locus coincides with a spanning deletion (represented by a star) observed elsewhere
/// in the callset.
pub has_star: bool,
}
impl From<pbs::gnomad::gnomad2::VariantInfo> for Gnomad2VariantInfo {
fn from(value: pbs::gnomad::gnomad2::VariantInfo) -> Self {
Gnomad2VariantInfo {
variant_type: value.variant_type,
allele_type: value.allele_type,
n_alt_alleles: value.n_alt_alleles,
was_mixed: value.was_mixed,
has_star: value.has_star,
}
}
}
/// Protocol buffer for the gnomAD v2 VCF record.
///
/// The more specialized fields from the INFO column are stored in separate, optional fields such
/// that we don't end up with a humongous message.
#[derive(
Debug,
Default,
Clone,
serde::Serialize,
serde::Deserialize,
utoipa::ToSchema,
utoipa::ToResponse,
)]
pub struct Gnomad2Record {
/// Chromosome name.
pub chrom: String,
/// 1-based start position.
pub pos: i32,
/// Reference allele.
pub ref_allele: String,
/// Alternate allele.
pub alt_allele: String,
/// Site-level filters.
pub filters: Vec<Gnomad2Filter>,
/// VEP annotation records.
pub vep: Vec<Gnomad2Vep>,
/// Variant allele counts in the different cohorts and population.
///
/// The populations in gnomAD v2/3 are: empty for global, "controls", "non_cancer", "non_neuro",
/// and "non_topmed".
pub allele_counts: Vec<Gnomad2CohortAlleleCounts>,
/// Variant (on sex chromosome) falls outside a pseudoautosomal region
pub nonpar: bool,
/// Information on lift-over from GRCh37 to GRCh38.
pub liftover_info: Option<Gnomad2LiftoverInfo>,
/// Random forest related information.
pub rf_info: Option<Gnomad2RandomForestInfo>,
/// Variant-related information details.
pub variant_info: Option<Gnomad2VariantInfo>,
/// Summary information for variant quality interpretation.
pub quality_info: Option<Gnomad2QualityInfo>,
/// Age-related information.
pub age_info: Option<Gnomad2AgeInfo>,
/// Depth of coverage-related information.
pub depth_info: Option<Gnomad2DepthInfo>,
}
impl TryFrom<pbs::gnomad::gnomad2::Record> for Gnomad2Record {
type Error = anyhow::Error;
fn try_from(value: pbs::gnomad::gnomad2::Record) -> Result<Self, anyhow::Error> {
Ok(Gnomad2Record {
chrom: value.chrom,
pos: value.pos,
ref_allele: value.ref_allele,
alt_allele: value.alt_allele,
filters: value
.filters
.into_iter()
.map(|filter| {
Gnomad2Filter::try_from(pbs::gnomad::gnomad2::Filter::try_from(filter)?)
})
.collect::<Result<Vec<_>, _>>()?,
vep: value.vep.into_iter().map(Into::into).collect(),
allele_counts: value.allele_counts.into_iter().map(Into::into).collect(),
nonpar: value.nonpar,
liftover_info: value.liftover_info.map(Into::into),
rf_info: value.rf_info.map(Into::into),
variant_info: value.variant_info.map(Into::into),
quality_info: value.quality_info.map(Into::into),
age_info: value.age_info.map(Into::into),
depth_info: value.depth_info.map(Into::into),
})
}
}
/// Protocol buffer enum for site-level filters.
#[derive(
Clone,
Copy,
Debug,
PartialEq,
Eq,
Hash,
PartialOrd,
Ord,
serde::Serialize,
serde::Deserialize,
strum::EnumString,
utoipa::ToSchema,
)]
#[serde(rename_all = "snake_case")]
#[strum(serialize_all = "snake_case")]
pub enum Gnomad2Filter {
/// Allele count is zero after filtering out low-confidence genotypes (GQ < 20; DP < 10; and AB <
/// 0.2 for het calls).
AlleleCountIsZero = 1,
/// InbreedingCoeff < -0.3.
InbreedingCoeff = 2,
/// Passed all variant filters
Pass = 3,
/// Failed random forest filtering thresholds of 0.055272738028512555, 0.20641025579497013
/// (probabilities of being a true positive variant) for SNPs, indels
RandomForest = 4,
}
impl TryFrom<pbs::gnomad::gnomad2::Filter> for Gnomad2Filter {
type Error = anyhow::Error;
fn try_from(value: pbs::gnomad::gnomad2::Filter) -> Result<Self, Self::Error> {
Ok(match value {
pbs::gnomad::gnomad2::Filter::AlleleCountIsZero => Gnomad2Filter::AlleleCountIsZero,
pbs::gnomad::gnomad2::Filter::InbreedingCoeff => Gnomad2Filter::InbreedingCoeff,
pbs::gnomad::gnomad2::Filter::Pass => Gnomad2Filter::Pass,
pbs::gnomad::gnomad2::Filter::RandomForest => Gnomad2Filter::RandomForest,
_ => anyhow::bail!("Unknown Gnomad2Filter: {:?}", value),
})
}
}
/// Protocol buffer for the gnomAD-nuclear VEP predictions.
#[derive(
Debug,
Default,
Clone,
serde::Serialize,
serde::Deserialize,
utoipa::ToSchema,
utoipa::ToResponse,
)]
pub struct Gnomad3Vep {
/// Allele of record.
pub allele: String,
/// Consequence, e.g., `"missense_variant"`.
pub consequence: String,
/// Impact, e.g., `"MODERATE"`.
pub impact: String,
/// Gene symbol, e.g., `"PCSK9"`.
pub symbol: String,
/// Gene ID, `e.g., "ENSG00000169174"`.
pub gene: String,
/// Feature type, e.g., `"Transcript"`.
pub feature_type: String,
/// Feature ID, e.g., `"ENST00000302118"`.
pub feature: String,
/// Feature biotype, e.g., `"protein_coding"`.
pub feature_biotype: String,
/// Ranked exon number, e.g., `"1/4"`.
pub exon: Option<String>,
/// Ranked intron number, e.g., `"1/4"`.
pub intron: Option<String>,
/// cDNA position, e.g., `"ENST00000302118.5:c.89C>G"`.
pub hgvsc: Option<String>,
/// Protein position, e.g., `"ENSP00000302118.5:p.Thr30Arg"`.
pub hgvsp: Option<String>,
/// cDNA position, e.g., `"89/1863"`.
pub cdna_position: Option<String>,
/// CDS position, e.g., `"89/1863"`.
pub cds_position: Option<String>,
/// Protein position, e.g., `"30/620"`.
pub protein_position: Option<String>,
/// Amino acids, e.g., `"T/R"`.
pub amino_acids: Option<String>,
/// Codons, e.g., `"gCg/gGg"`.
pub codons: Option<String>,
/// TODO: actually is optional int32 allele_num = 18;
/// dbSNP ID, e.g., `"rs28942080"`.
pub dbsnp_id: Option<String>,
/// Distance output of VEP.
pub distance: Option<String>,
/// Strand, e.g., `"1"`.
pub strand: Option<String>,
/// Variant class, e.g., `"SNV"`.
pub variant_class: Option<String>,
/// Minimised output of VEP.
pub minimised: Option<String>,
/// Symbol source, e.g., `"HGNC"`.
pub symbol_source: Option<String>,
/// HGNC ID, e.g., `"HGNC:8706"`.
pub hgnc_id: Option<String>,
/// Whether this is the canonical transcript.
pub canonical: Option<bool>,
/// Transcript support level, e.g., `"1"`.
pub tsl: Option<i32>,
/// APPRIS annotation, e.g. `"P1"`.
pub appris: Option<String>,
/// CCDS ID, e.g., `"CCDS30547.1"`.
pub ccds: Option<String>,
/// Ensembl protein ID, e.g., `"ENSP00000302118"`.
pub ensp: Option<String>,
/// SwissProt ID, e.g., `"P04114"`.
pub swissprot: Option<String>,
/// TREMBL ID, e.g., `"Q5T4W7"`.
pub trembl: Option<String>,
/// UniParc ID, e.g., `"UPI000002D4B2"`.
pub uniparc: Option<String>,
/// Gene phenotype from VEP.
pub gene_pheno: Option<String>,
/// SIFT prediction, e.g., `"tolerated(0.06)"`.
pub sift: Option<VepCommonPrediction>,
/// PolyPhen prediction, e.g., `"benign(0.001)"`.
pub polyphen: Option<VepCommonPrediction>,
/// Protein domains, e.g., `\[["2p4e", "ENSP_mappings"\], \["2qtw", "ENSP_mappings"]\]`.
pub domains: Vec<VepCommonDomain>,
/// HGVS offset.
pub hgvs_offset: Option<String>,
/// Motif name.
pub motif_name: Option<String>,
/// Motif name.
pub motif_pos: Option<String>,
/// "high inf pos" from VEP.
pub high_inf_pos: Option<String>,
/// Motif score change.
pub motif_score_change: Option<String>,
/// Loss of function prediction.
pub lof: Option<String>,
/// Loss of function filter.
pub lof_filter: Option<String>,
/// Loss of function flags.
pub lof_flags: Option<String>,
/// Loss of function info.
pub lof_info: Option<String>,
}
impl From<pbs::gnomad::vep_gnomad3::Vep> for Gnomad3Vep {
fn from(value: pbs::gnomad::vep_gnomad3::Vep) -> Self {
Gnomad3Vep {
allele: value.allele,
consequence: value.consequence,
impact: value.impact,
symbol: value.symbol,
gene: value.gene,
feature_type: value.feature_type,
feature: value.feature,
feature_biotype: value.feature_biotype,
exon: value.exon,
intron: value.intron,
hgvsc: value.hgvsc,
hgvsp: value.hgvsp,
cdna_position: value.cdna_position,
cds_position: value.cds_position,
protein_position: value.protein_position,
amino_acids: value.amino_acids,
codons: value.codons,
dbsnp_id: value.dbsnp_id,
distance: value.distance,
strand: value.strand,
variant_class: value.variant_class,
minimised: value.minimised,
symbol_source: value.symbol_source,
hgnc_id: value.hgnc_id,
canonical: value.canonical,
tsl: value.tsl,
appris: value.appris,
ccds: value.ccds,
ensp: value.ensp,
swissprot: value.swissprot,
trembl: value.trembl,
uniparc: value.uniparc,
gene_pheno: value.gene_pheno,
sift: value.sift.map(Into::into),
polyphen: value.polyphen.map(Into::into),
domains: value.domains.into_iter().map(Into::into).collect(),
hgvs_offset: value.hgvs_offset,
motif_name: value.motif_name,
motif_pos: value.motif_pos,
high_inf_pos: value.high_inf_pos,
motif_score_change: value.motif_score_change,
lof: value.lof,
lof_filter: value.lof_filter,
lof_flags: value.lof_flags,
lof_info: value.lof_info,
}
}
}
/// Store details on variant effect predictions.
#[derive(
Debug,
Default,
Clone,
serde::Serialize,
serde::Deserialize,
utoipa::ToSchema,
utoipa::ToResponse,
)]
pub struct Gnomad3EffectInfo {
/// PrimateAI's deleteriousness score from 0 (less deleterious) to 1 (more deleterious).
pub primate_ai_score: Option<f32>,
/// dbNSFP's Revel score from 0 to 1. Variants with higher scores are predicted to be
/// more likely to be deleterious.
pub revel_score: Option<f32>,
/// Illumina's SpliceAI max delta score; interpreted as the probability of the variant
/// being splice-altering.
pub splice_ai_max_ds: Option<f32>,
/// The consequence term associated with the max delta score in 'splice_ai_max_ds'.
pub splice_ai_consequence: Option<String>,
/// Raw CADD scores are interpretable as the extent to which the annotation profile for a given variant suggests that the variant is likely to be 'observed' (negative values) vs 'simulated' (positive values). Larger values are more deleterious.
pub cadd_raw: Option<f32>,
/// Cadd Phred-like scores ('scaled C-scores') ranging from 1 to 99, based on the rank of each variant relative to all possible 8.6 billion substitutions in the human reference genome. Larger values are more deleterious.
pub cadd_phred: Option<f32>,
}
impl From<pbs::gnomad::gnomad3::EffectInfo> for Gnomad3EffectInfo {
fn from(value: pbs::gnomad::gnomad3::EffectInfo) -> Self {
Gnomad3EffectInfo {
primate_ai_score: value.primate_ai_score,
revel_score: value.revel_score,
splice_ai_max_ds: value.splice_ai_max_ds,
splice_ai_consequence: value.splice_ai_consequence,
cadd_raw: value.cadd_raw,
cadd_phred: value.cadd_phred,
}
}
}
/// Store the relevant allele counts and frequencies in a given sub cohort.
#[derive(
Debug,
Default,
Clone,
serde::Serialize,
serde::Deserialize,
utoipa::ToSchema,
utoipa::ToResponse,
)]
pub struct Gnomad3AlleleCounts {
/// Number of alternate alleles in sub cohort.
pub ac: i32,
/// Total number of alleles in the sub cohort.
pub an: i32,
/// Number of homozygous alternate alleles in the sub cohort.
pub nhomalt: i32,
/// Alternate allele frequency in the sub cohort.
pub af: f32,
}
impl From<pbs::gnomad::gnomad3::AlleleCounts> for Gnomad3AlleleCounts {
fn from(value: pbs::gnomad::gnomad3::AlleleCounts) -> Self {
Gnomad3AlleleCounts {
ac: value.ac,
an: value.an,
nhomalt: value.nhomalt,
af: value.af,
}
}
}
/// Store the allele counts for the given sub cohort and sub cohort factored by sex.
#[derive(
Debug,
Default,
Clone,
serde::Serialize,
serde::Deserialize,
utoipa::ToSchema,
utoipa::ToResponse,
)]
pub struct Gnomad3AlleleCountsBySex {
/// Overall allele counts in the sub cohort.
pub overall: Option<Gnomad3AlleleCounts>,
/// Allele counts in female/XX karyotype individuals of sub cohort.
pub xx: Option<Gnomad3AlleleCounts>,
/// Allele counts in male/XY karyotype individuals of sub cohort.
pub xy: Option<Gnomad3AlleleCounts>,
}
impl From<pbs::gnomad::gnomad3::AlleleCountsBySex> for Gnomad3AlleleCountsBySex {
fn from(value: pbs::gnomad::gnomad3::AlleleCountsBySex) -> Self {
Gnomad3AlleleCountsBySex {
overall: value.overall.map(Into::into),
xx: value.xx.map(Into::into),
xy: value.xy.map(Into::into),
}
}
}
/// Store the allele counts for the given sub cohort in the given population.
#[derive(
Debug,
Default,
Clone,
serde::Serialize,
serde::Deserialize,
utoipa::ToSchema,
utoipa::ToResponse,
)]
pub struct Gnomad3PopulationAlleleCounts {
/// Name of the population.
pub population: String,
/// The overall allele counts and the one by sex.
pub counts: Option<Gnomad3AlleleCountsBySex>,
/// The filtering allele frequency (using Poisson 95% CI).
pub faf95: Option<f32>,
/// The filtering allele frequency (using Poisson 99% CI).
pub faf99: Option<f32>,
/// The filtering allele frequency for XX samples (using Poisson 95% CI).
pub faf95_xx: Option<f32>,
/// The filtering allele frequency for XX samples (using Poisson 99% CI).
pub faf99_xx: Option<f32>,
/// The filtering allele frequency for XY samples (using Poisson 95% CI).
pub faf95_xy: Option<f32>,
/// The filtering allele frequency for XY samples (using Poisson 99% CI).
pub faf99_xy: Option<f32>,
}
impl From<pbs::gnomad::gnomad3::PopulationAlleleCounts> for Gnomad3PopulationAlleleCounts {
fn from(value: pbs::gnomad::gnomad3::PopulationAlleleCounts) -> Self {
Gnomad3PopulationAlleleCounts {
population: value.population,
counts: value.counts.map(Into::into),
faf95: value.faf95,
faf99: value.faf99,
faf95_xx: value.faf95_xx,
faf99_xx: value.faf99_xx,
faf95_xy: value.faf95_xy,
faf99_xy: value.faf99_xy,
}
}
}
/// Store the allele counts for the given cohort.
#[derive(
Debug,
Default,
Clone,
serde::Serialize,
serde::Deserialize,
utoipa::ToSchema,
utoipa::ToResponse,
)]
pub struct Gnomad3CohortAlleleCounts {
/// Name of the cohort.
pub cohort: Option<String>,
/// Allele counts for each population.
pub by_population: Vec<Gnomad3PopulationAlleleCounts>,
/// Allele counts by sex.
pub by_sex: Option<Gnomad3AlleleCountsBySex>,
/// Raw allele counts.
pub raw: Option<Gnomad3AlleleCounts>,
/// The population with maximum AF.
pub popmax: Option<String>,
/// Maximum allele frequency across populations (excluding samples of Ashkenazi, Finnish, and
/// indeterminate ancestry).
pub af_popmax: Option<f32>,
/// Allele count in population with maximum AF.
pub ac_popmax: Option<i32>,
/// Total number of alleles in population with maximum AF.
pub an_popmax: Option<i32>,
/// Total number of homozygous individuals in population with maximum AF.
pub nhomalt_popmax: Option<i32>,
}
impl From<pbs::gnomad::gnomad3::CohortAlleleCounts> for Gnomad3CohortAlleleCounts {
fn from(value: pbs::gnomad::gnomad3::CohortAlleleCounts) -> Self {
Gnomad3CohortAlleleCounts {
cohort: value.cohort,
by_population: value.by_population.into_iter().map(Into::into).collect(),
by_sex: value.by_sex.map(Into::into),
raw: value.raw.map(Into::into),
popmax: value.popmax,
af_popmax: value.af_popmax,
ac_popmax: value.ac_popmax,
an_popmax: value.an_popmax,
nhomalt_popmax: value.nhomalt_popmax,
}
}
}
/// Encapsulate VCF INFO fields related to age.
#[derive(
Debug,
Default,
Clone,
serde::Serialize,
serde::Deserialize,
utoipa::ToSchema,
utoipa::ToResponse,
)]
pub struct Gnomad3AgeInfo {
/// Histogram of ages of individuals with a homoplasmic variant; bin edges are: [30.0, 35.0,
/// 40.0, 45.0, 50.0, 55.0, 60.0, 65.0, 70.0, 75.0, 80.0].
pub age_hist_hom_bin_freq: Vec<i32>,
/// Count of age values falling below lowest histogram bin edge for individuals with a
/// homoplasmic variant.
pub age_hist_hom_n_smaller: Option<i32>,
/// Count of age values falling above highest histogram bin edge for individuals with a
/// homoplasmic variant.
pub age_hist_hom_n_larger: Option<i32>,
/// Histogram of ages of individuals with a heteroplasmic variant; bin edges are: [30.0, 35.0,
/// 40.0, 45.0, 50.0, 55.0, 60.0, 65.0, 70.0, 75.0, 80.0]
pub age_hist_het_bin_freq: Vec<i32>,
/// Count of age values falling below lowest histogram bin edge for individuals with a
/// heteroplasmic variant.
pub age_hist_het_n_smaller: Option<i32>,
/// Count of age values falling above highest histogram bin edge for individuals with a
/// heteroplasmic variant.
pub age_hist_het_n_larger: Option<i32>,
}
impl From<pbs::gnomad::gnomad3::AgeInfo> for Gnomad3AgeInfo {
fn from(value: pbs::gnomad::gnomad3::AgeInfo) -> Self {
Gnomad3AgeInfo {
age_hist_hom_bin_freq: value.age_hist_hom_bin_freq,
age_hist_hom_n_smaller: value.age_hist_hom_n_smaller,
age_hist_hom_n_larger: value.age_hist_hom_n_larger,
age_hist_het_bin_freq: value.age_hist_het_bin_freq,
age_hist_het_n_smaller: value.age_hist_het_n_smaller,
age_hist_het_n_larger: value.age_hist_het_n_larger,
}
}
}
/// Encapsulate VCF INFO fields related to depth.
#[derive(
Debug,
Default,
Clone,
serde::Serialize,
serde::Deserialize,
utoipa::ToSchema,
utoipa::ToResponse,
)]
pub struct Gnomad3DepthInfo {
/// Count of dp values falling above highest histogram bin edge for all individuals.
pub dp_hist_all_n_larger: Option<i32>,
/// Count of dp values falling above highest histogram bin edge for individuals with the
/// alternative allele
pub dp_hist_alt_n_larger: Option<i32>,
/// Histogram of dp values for all individuals; bin edges are: [0.0, 200.0, 400.0, 600.0, 800.0,
/// 1000.0, 1200.0, 1400.0, 1600.0, 1800.0, 2000.0]
pub dp_hist_all_bin_freq: Vec<i32>,
/// Histogram of dp values for individuals with the alternative allele; bin edges are: [0.0,
/// 200.0, 400.0, 600.0, 800.0, 1000.0, 1200.0, 1400.0, 1600.0, 1800.0, 2000.0]
pub dp_hist_alt_bin_freq: Vec<i32>,
}
impl From<pbs::gnomad::gnomad3::DepthInfo> for Gnomad3DepthInfo {
fn from(value: pbs::gnomad::gnomad3::DepthInfo) -> Self {
Gnomad3DepthInfo {
dp_hist_all_n_larger: value.dp_hist_all_n_larger,
dp_hist_alt_n_larger: value.dp_hist_alt_n_larger,
dp_hist_all_bin_freq: value.dp_hist_all_bin_freq,
dp_hist_alt_bin_freq: value.dp_hist_alt_bin_freq,
}
}
}
/// Encapsulate quality-related information.
#[derive(
Debug,
Default,
Clone,
serde::Serialize,
serde::Deserialize,
utoipa::ToSchema,
utoipa::ToResponse,
)]
pub struct Gnomad3QualityInfo {
/// Allele-specific phred-scaled p-value of Fisher's exact test for strand bias.
pub as_fs: Option<f32>,
/// Inbreeding coefficient as estimated from the genotype likelihoods per-sample when compared
/// against the Hardy-Weinberg expectation.
pub inbreeding_coeff: Option<f32>,
/// Allele-specific root mean square of the mapping quality of reads across all samples
pub as_mq: Option<f32>,
/// Z-score from Wilcoxon rank sum test of alternate vs. reference read mapping qualities.
pub mq_rank_sum: Option<f32>,
/// Allele-specific z-score from Wilcoxon rank sum test of alternate vs. reference read
/// mapping qualities.
pub as_mq_rank_sum: Option<f32>,
/// Allele-specific variant call confidence normalized by depth of sample reads supporting a
/// variant.
pub as_qd: Option<f32>,
/// Z-score from Wilcoxon rank sum test of alternate vs. reference read position bias.
pub read_pos_rank_sum: Option<f32>,
/// Allele-specific z-score from Wilcoxon rank sum test of alternate vs. reference read position bias.
pub as_read_pos_rank_sum: Option<f32>,
/// Allele-specific strand bias estimated by the symmetric odds ratio test.
pub as_sor: Option<f32>,
/// Variant was used to build the positive training set of high-quality variants for VQSR.
pub positive_train_site: bool,
/// Variant was used to build the negative training set of low-quality variants for VQSR.
pub negative_train_site: bool,
/// Allele-specific log-odds ratio of being a true variant versus being a false positive under the trained VQSR Gaussian mixture model.
pub as_vqslod: Option<f32>,
/// Allele-specific worst-performing annotation in the VQSR Gaussian mixture model.
pub as_culprit: Option<String>,
/// Variant falls within a segmental duplication region.
pub segdup: bool,
/// Variant falls within a low complexity region.
pub lcr: bool,
/// Variant was a callset-wide doubleton that was transmitted within a family (i.e., a singleton
/// amongst unrelated sampes in cohort).
pub transmitted_singleton: bool,
/// Maximum p-value over callset for binomial test of observed allele balance for a heterozygous genotype, given expectation of 0.5.
pub as_pab_max: Option<f32>,
/// Allele-specific sum of PL\[0\] values; used to approximate the QUAL score.
pub as_qual_approx: Option<i32>,
/// Allele-specific forward/reverse read counts for strand bias tests.
pub as_sb_table: Option<String>,
/// Strand bias estimated by the symmetric odds ratio test (v4 only).
pub sor: Option<f32>,
}
impl From<pbs::gnomad::gnomad3::QualityInfo> for Gnomad3QualityInfo {
fn from(value: pbs::gnomad::gnomad3::QualityInfo) -> Self {
Gnomad3QualityInfo {
as_fs: value.as_fs,
inbreeding_coeff: value.inbreeding_coeff,
as_mq: value.as_mq,
mq_rank_sum: value.mq_rank_sum,
as_mq_rank_sum: value.as_mq_rank_sum,
as_qd: value.as_qd,
read_pos_rank_sum: value.read_pos_rank_sum,
as_read_pos_rank_sum: value.as_read_pos_rank_sum,
as_sor: value.as_sor,
positive_train_site: value.positive_train_site,
negative_train_site: value.negative_train_site,
as_vqslod: value.as_vqslod,
as_culprit: value.as_culprit,
segdup: value.segdup,
lcr: value.lcr,
transmitted_singleton: value.transmitted_singleton,
as_pab_max: value.as_pab_max,
as_qual_approx: value.as_qual_approx,
as_sb_table: value.as_sb_table,
sor: value.sor,
}
}
}
/// Variant type related information.
#[derive(
Debug,
Default,
Clone,
serde::Serialize,
serde::Deserialize,
utoipa::ToSchema,
utoipa::ToResponse,
)]
pub struct Gnomad3VariantInfo {
/// Variant type (snv, indel, multi-snv, multi-indel, or mixed).
pub variant_type: String,
/// Allele type (snv, ins, del, or mixed).
pub allele_type: String,
/// Total number of alternate alleles observed at variant locus.
pub n_alt_alleles: i32,
/// Variant type was mixed.
pub was_mixed: bool,
/// All samples are homozygous alternate for the variant.
pub monoallelic: bool,
/// Depth over variant genotypes (does not include depth of reference samples).
pub var_dp: i32,
/// Allele-specific depth over variant genotypes (does not include depth of reference samples) (v4 only).
pub as_vardp: Option<i32>,
}
impl From<pbs::gnomad::gnomad3::VariantInfo> for Gnomad3VariantInfo {
fn from(value: pbs::gnomad::gnomad3::VariantInfo) -> Self {
Gnomad3VariantInfo {
variant_type: value.variant_type,
allele_type: value.allele_type,
n_alt_alleles: value.n_alt_alleles,
was_mixed: value.was_mixed,
monoallelic: value.monoallelic,
var_dp: value.var_dp,
as_vardp: value.as_vardp,
}
}
}
/// Protocol buffer for the gnomAD-nuclear VCF record.
///
/// The more specialized fields from the INFO column are stored in separate, optional fields such
/// that we don't end up with a humongous message.
#[derive(
Debug,
Default,
Clone,
serde::Serialize,
serde::Deserialize,
utoipa::ToSchema,
utoipa::ToResponse,
)]
pub struct Gnomad3Record {
/// Chromosome name.
pub chrom: String,
/// 1-based start position.
pub pos: i32,
/// Reference allele.
pub ref_allele: String,
/// Alternate allele.
pub alt_allele: String,
/// Site-level filters.
pub filters: Vec<Gnomad3Filter>,
/// VEP annotation records.
pub vep: Vec<Gnomad3Vep>,
/// Variant allele counts in the different cohorts and population.
///
/// The populations in gnomAD v2/3 are: empty for global, "controls", "non_cancer", "non_neuro",
/// and "non_topmed".
pub allele_counts: Vec<Gnomad3CohortAlleleCounts>,
/// Variant (on sex chromosome) falls outside a pseudoautosomal region
pub nonpar: bool,
/// Information on variant scores.
pub effect_info: Option<Gnomad3EffectInfo>,
/// Variant-related information details.
pub variant_info: Option<Gnomad3VariantInfo>,
/// Summary information for variant quality interpretation.
pub quality_info: Option<Gnomad3QualityInfo>,
/// Age-related information.
pub age_info: Option<Gnomad3AgeInfo>,
/// Depth of coverage-related information.
pub depth_info: Option<Gnomad3DepthInfo>,
}
impl TryFrom<pbs::gnomad::gnomad3::Record> for Gnomad3Record {
type Error = anyhow::Error;
fn try_from(value: pbs::gnomad::gnomad3::Record) -> Result<Self, Self::Error> {
Ok(Gnomad3Record {
chrom: value.chrom,
pos: value.pos,
ref_allele: value.ref_allele,
alt_allele: value.alt_allele,
filters: value
.filters
.into_iter()
.map(|filter| {
Gnomad3Filter::try_from(pbs::gnomad::gnomad3::Filter::try_from(filter)?)
})
.collect::<Result<Vec<_>, _>>()?,
vep: value.vep.into_iter().map(Into::into).collect(),
allele_counts: value.allele_counts.into_iter().map(Into::into).collect(),
nonpar: value.nonpar,
effect_info: value.effect_info.map(Into::into),
variant_info: value.variant_info.map(Into::into),
quality_info: value.quality_info.map(Into::into),
age_info: value.age_info.map(Into::into),
depth_info: value.depth_info.map(Into::into),
})
}
}
/// Protocol buffer enum for site-level filters.
#[derive(
Clone,
Copy,
Debug,
PartialEq,
Eq,
Hash,
PartialOrd,
Ord,
serde::Serialize,
serde::Deserialize,
strum::EnumString,
utoipa::ToSchema,
)]
#[serde(rename_all = "snake_case")]
#[strum(serialize_all = "snake_case")]
pub enum Gnomad3Filter {
/// Allele count is zero after filtering out low-confidence genotypes (GQ < 20; DP < 10; and AB <
/// 0.2 for het calls).
AlleleCountIsZero = 1,
/// Failed VQSR filtering thresholds of:
///
/// gnomAD-genomes v3: -2.7739 for SNPs and -1.0606 for indels
/// gnomAD-genomes v4: -2.502 for SNPs and -0.7156 for indels
/// gnomAD-exomes v4: -1.4526 for SNPs and 0.0717 for indels
AsVsqr = 2,
/// InbreedingCoeff < -0.3.
InbreedingCoeff = 3,
/// Passed all variant filters
Pass = 4,
}
impl TryFrom<pbs::gnomad::gnomad3::Filter> for Gnomad3Filter {
type Error = anyhow::Error;
fn try_from(value: pbs::gnomad::gnomad3::Filter) -> Result<Self, Self::Error> {
Ok(match value {
pbs::gnomad::gnomad3::Filter::AlleleCountIsZero => Gnomad3Filter::AlleleCountIsZero,
pbs::gnomad::gnomad3::Filter::AsVsqr => Gnomad3Filter::AsVsqr,
pbs::gnomad::gnomad3::Filter::InbreedingCoeff => Gnomad3Filter::InbreedingCoeff,
pbs::gnomad::gnomad3::Filter::Pass => Gnomad3Filter::Pass,
_ => anyhow::bail!("Unknown Filter: {:?}", value),
})
}
}
/// Protocol buffer for the gnomAD-nuclear VEP predictions.
#[derive(
Debug,
Default,
Clone,
serde::Serialize,
serde::Deserialize,
utoipa::ToSchema,
utoipa::ToResponse,
)]
pub struct Gnomad4Vep {
/// Allele of record.
pub allele: String,
/// Consequence, e.g., `"missense_variant"`.
pub consequence: String,
/// Impact, e.g., `"MODERATE"`.
pub impact: String,
/// Gene symbol, e.g., `"PCSK9"`.
pub symbol: String,
/// Gene ID, `e.g., "ENSG00000169174"`.
pub gene: String,
/// Feature type, e.g., `"Transcript"`.
pub feature_type: String,
/// Feature ID, e.g., `"ENST00000302118"`.
pub feature: String,
/// Feature biotype, e.g., `"protein_coding"`.
pub feature_biotype: String,
/// Ranked exon number, e.g., `"1/4"`.
pub exon: Option<String>,
/// Ranked intron number, e.g., `"1/4"`.
pub intron: Option<String>,
/// cDNA position, e.g., `"ENST00000302118.5:c.89C>G"`.
pub hgvsc: Option<String>,
/// Protein position, e.g., `"ENSP00000302118.5:p.Thr30Arg"`.
pub hgvsp: Option<String>,
/// cDNA position, e.g., `"89/1863"`.
pub cdna_position: Option<String>,
/// CDS position, e.g., `"89/1863"`.
pub cds_position: Option<String>,
/// Protein position, e.g., `"30/620"`.
pub protein_position: Option<String>,
/// Amino acids, e.g., `"T/R"`.
pub amino_acids: Option<String>,
/// Codons, e.g., `"gCg/gGg"`.
pub codons: Option<String>,
/// Allele count.
pub allele_num: Option<i32>,
/// Distance output of VEP.
pub distance: Option<String>,
/// Strand, e.g., `"1"`.
pub strand: Option<String>,
/// Flags
pub flags: Option<String>,
/// Variant class, e.g., `"SNV"`.
pub variant_class: Option<String>,
/// Symbol source, e.g., `"HGNC"`.
pub symbol_source: Option<String>,
/// HGNC ID, e.g., `"HGNC:8706"`.
pub hgnc_id: Option<String>,
/// Whether this is the canonical transcript.
pub canonical: Option<bool>,
/// Presence in MANE Select
pub mane_select: Option<bool>,
/// Presence in MANE Plus Clinical
pub mane_plus_clinical: Option<bool>,
/// Transcript support level, e.g., `"1"`.
pub tsl: Option<i32>,
/// APPRIS annotation, e.g. `"P1"`.
pub appris: Option<String>,
/// CCDS ID, e.g., `"CCDS30547.1"`.
pub ccds: Option<String>,
/// Ensembl protein ID, e.g., `"ENSP00000302118"`.
pub ensp: Option<String>,
/// Uniprot isoform.
pub uniprot_isoform: Option<String>,
/// Value of VEP "SOURCE" field.
pub source: Option<String>,
/// Protein domains, e.g., `\[["2p4e", "ENSP_mappings"\], \["2qtw", "ENSP_mappings"]\]`.
pub domains: Vec<VepCommonDomain>,
/// miRNA information.
pub mirna: Option<String>,
/// HGVS offset.
pub hgvs_offset: Option<String>,
/// PubMed IDs
pub pubmed: Option<String>,
/// Motif name.
pub motif_name: Option<String>,
/// Motif name.
pub motif_pos: Option<String>,
/// "high inf pos" from VEP.
pub high_inf_pos: Option<String>,
/// Motif score change.
pub motif_score_change: Option<String>,
/// Transcription factors.
pub transcription_factors: Option<String>,
/// Loss of function prediction.
pub lof: Option<String>,
/// Loss of function filter.
pub lof_filter: Option<String>,
/// Loss of function flags.
pub lof_flags: Option<String>,
/// Loss of function info.
pub lof_info: Option<String>,
}
impl From<pbs::gnomad::vep_gnomad4::Vep> for Gnomad4Vep {
fn from(value: pbs::gnomad::vep_gnomad4::Vep) -> Self {
Gnomad4Vep {
allele: value.allele,
consequence: value.consequence,
impact: value.impact,
symbol: value.symbol,
gene: value.gene,
feature_type: value.feature_type,
feature: value.feature,
feature_biotype: value.feature_biotype,
exon: value.exon,
intron: value.intron,
hgvsc: value.hgvsc,
hgvsp: value.hgvsp,
cdna_position: value.cdna_position,
cds_position: value.cds_position,
protein_position: value.protein_position,
amino_acids: value.amino_acids,
codons: value.codons,
allele_num: value.allele_num,
distance: value.distance,
strand: value.strand,
flags: value.flags,
variant_class: value.variant_class,
symbol_source: value.symbol_source,
hgnc_id: value.hgnc_id,
canonical: value.canonical,
mane_select: value.mane_select,
mane_plus_clinical: value.mane_plus_clinical,
tsl: value.tsl,
appris: value.appris,
ccds: value.ccds,
ensp: value.ensp,
uniprot_isoform: value.uniprot_isoform,
source: value.source,
domains: value.domains.into_iter().map(Into::into).collect(),
mirna: value.mirna,
hgvs_offset: value.hgvs_offset,
pubmed: value.pubmed,
motif_name: value.motif_name,
motif_pos: value.motif_pos,
high_inf_pos: value.high_inf_pos,
motif_score_change: value.motif_score_change,
transcription_factors: value.transcription_factors,
lof: value.lof,
lof_filter: value.lof_filter,
lof_flags: value.lof_flags,
lof_info: value.lof_info,
}
}
}
/// Store details on variant effect predictions.
#[derive(
Debug,
Default,
Clone,
serde::Serialize,
serde::Deserialize,
utoipa::ToSchema,
utoipa::ToResponse,
)]
pub struct Gnomad4EffectInfo {
/// Pangolin's largest delta score across 2 splicing consequences, which reflects the probability of the variant being splice-altering">
pub pangolin_largest_ds: Option<f32>,
/// Base-wise conservation score across the 241 placental mammals in the Zoonomia project. Score ranges from -20 to 9.28, and reflects acceleration (faster evolution than expected under neutral drift, assigned negative scores) as well as conservation (slower than expected evolution, assigned positive scores).">
pub phylop: Option<f32>,
/// Score that predicts the possible impact of an amino acid substitution on the structure and function of a human protein, ranging from 0.0 (tolerated) to 1.0 (deleterious). We prioritize max scores for MANE Select transcripts where possible and otherwise report a score for the canonical transcript.">
pub polyphen_max: Option<f32>,
/// The maximum REVEL score at a site's MANE Select or canonical transcript. It's an ensemble score for predicting the pathogenicity of missense variants (based on 13 other variant predictors). Scores ranges from 0 to 1. Variants with higher scores are predicted to be more likely to be deleterious.">
pub revel_max: Option<f32>,
/// Score reflecting the scaled probability of the amino acid substitution being tolerated, ranging from 0 to 1. Scores below 0.05 are predicted to impact protein function. We prioritize max scores for MANE Select transcripts where possible and otherwise report a score for the canonical transcript.">
pub sift_max: Option<f32>,
/// Illumina's SpliceAI max delta score; interpreted as the probability of the variant being splice-altering.">
pub spliceai_ds_max: Option<f32>,
/// Raw CADD scores are interpretable as the extent to which the annotation profile for a given variant suggests that the variant is likely to be 'observed' (negative values) vs 'simulated' (positive values). Larger values are more deleterious.
pub cadd_raw: Option<f32>,
/// Cadd Phred-like scores ('scaled C-scores') ranging from 1 to 99, based on the rank of each variant relative to all possible 8.6 billion substitutions in the human reference genome. Larger values are more deleterious.
pub cadd_phred: Option<f32>,
}
impl From<pbs::gnomad::gnomad4::EffectInfo> for Gnomad4EffectInfo {
fn from(value: pbs::gnomad::gnomad4::EffectInfo) -> Self {
Gnomad4EffectInfo {
pangolin_largest_ds: value.pangolin_largest_ds,
phylop: value.phylop,
polyphen_max: value.polyphen_max,
revel_max: value.revel_max,
sift_max: value.sift_max,
spliceai_ds_max: value.spliceai_ds_max,
cadd_raw: value.cadd_raw,
cadd_phred: value.cadd_phred,
}
}
}
/// Store the allele counts for the given sub cohort in the given ancestry group.
#[derive(
Debug,
Default,
Clone,
serde::Serialize,
serde::Deserialize,
utoipa::ToSchema,
utoipa::ToResponse,
)]
pub struct Gnomad4AncestryGroupAlleleCounts {
/// Name of the ancestry group.
pub ancestry_group: String,
/// The overall allele counts and the one by sex.
pub counts: Option<Gnomad3AlleleCountsBySex>,
/// The filtering allele frequency (using Poisson 95% CI).
pub faf95: Option<f32>,
/// The filtering allele frequency (using Poisson 99% CI).
pub faf99: Option<f32>,
/// The filtering allele frequency for XX samples (using Poisson 95% CI).
pub faf95_xx: Option<f32>,
/// The filtering allele frequency for XX samples (using Poisson 99% CI).
pub faf99_xx: Option<f32>,
/// The filtering allele frequency for XY samples (using Poisson 95% CI).
pub faf95_xy: Option<f32>,
/// The filtering allele frequency for XY samples (using Poisson 99% CI).
pub faf99_xy: Option<f32>,
}
impl From<pbs::gnomad::gnomad4::AncestryGroupAlleleCounts> for Gnomad4AncestryGroupAlleleCounts {
fn from(value: pbs::gnomad::gnomad4::AncestryGroupAlleleCounts) -> Self {
Gnomad4AncestryGroupAlleleCounts {
ancestry_group: value.ancestry_group,
counts: value.counts.map(Into::into),
faf95: value.faf95,
faf99: value.faf99,
faf95_xx: value.faf95_xx,
faf99_xx: value.faf99_xx,
faf95_xy: value.faf95_xy,
faf99_xy: value.faf99_xy,
}
}
}
/// Store the allele counts for the given cohort.
#[derive(
Debug,
Default,
Clone,
serde::Serialize,
serde::Deserialize,
utoipa::ToSchema,
utoipa::ToResponse,
)]
pub struct Gnomad4CohortAlleleCounts {
/// Name of the cohort.
pub cohort: Option<String>,
/// Allele counts for each population.
pub by_ancestry_group: Vec<Gnomad4AncestryGroupAlleleCounts>,
/// Allele counts by sex.
pub by_sex: Option<Gnomad3AlleleCountsBySex>,
/// Raw allele counts.
pub raw: Option<Gnomad3AlleleCounts>,
/// The ancestry group with maximum AF.
pub grpmax: Option<String>,
/// Maximum allele frequency across ancestry groups.
pub af_grpmax: Option<f32>,
/// Allele count in ancestry group with maximum AF.
pub ac_grpmax: Option<i32>,
/// Total number of alleles in ancestry group with maximum AF.
pub an_grpmax: Option<i32>,
/// Total number of homozygous individuals in ancestry group with maximum AF.
pub nhomalt_grpmax: Option<i32>,
}
impl From<pbs::gnomad::gnomad4::CohortAlleleCounts> for Gnomad4CohortAlleleCounts {
fn from(value: pbs::gnomad::gnomad4::CohortAlleleCounts) -> Self {
Gnomad4CohortAlleleCounts {
cohort: value.cohort,
by_ancestry_group: value
.by_ancestry_group
.into_iter()
.map(Into::into)
.collect(),
by_sex: value.by_sex.map(Into::into),
raw: value.raw.map(Into::into),
grpmax: value.grpmax,
af_grpmax: value.af_grpmax,
ac_grpmax: value.ac_grpmax,
an_grpmax: value.an_grpmax,
nhomalt_grpmax: value.nhomalt_grpmax,
}
}
}
/// VRS information
#[derive(
Debug,
Default,
Clone,
serde::Serialize,
serde::Deserialize,
utoipa::ToSchema,
utoipa::ToResponse,
)]
pub struct Gnomad4VrsInfo {
/// The computed identifiers for the GA4GH VRS Alleles corresponding to the values in the REF and ALT fields
pub allele_ids: Vec<String>,
/// Interresidue coordinates used as the location ends for the GA4GH VRS Alleles corresponding to the values in the REF and ALT fields
pub ends: Vec<i32>,
/// Interresidue coordinates used as the location starts for the GA4GH VRS Alleles corresponding to the values in the REF and ALT fields
pub starts: Vec<i32>,
/// The literal sequence states used for the GA4GH VRS Alleles corresponding to the values in the REF and ALT fields
pub states: Vec<String>,
}
impl From<pbs::gnomad::gnomad4::VrsInfo> for Gnomad4VrsInfo {
fn from(value: pbs::gnomad::gnomad4::VrsInfo) -> Self {
Gnomad4VrsInfo {
allele_ids: value.allele_ids,
ends: value.ends,
starts: value.starts,
states: value.states,
}
}
}
/// Protocol buffer for the gnomAD-nuclear VCF record.
///
/// The more specialized fields from the INFO column are stored in separate, optional fields such
/// that we don't end up with a humongous message.
#[derive(
Debug,
Default,
Clone,
serde::Serialize,
serde::Deserialize,
utoipa::ToSchema,
utoipa::ToResponse,
)]
pub struct Gnomad4Record {
/// Chromosome name.
pub chrom: String,
/// 1-based start position.
pub pos: i32,
/// Reference allele.
pub ref_allele: String,
/// Alternate allele.
pub alt_allele: String,
/// Site-level filters.
pub filters: Vec<Gnomad3Filter>,
/// VEP annotation records.
pub vep: Vec<Gnomad4Vep>,
/// Variant allele counts in the different cohorts and population.
///
/// The populations in gnomAD v4 are: empty for global, "joint" for exome+genomes.
pub allele_counts: Vec<Gnomad4CohortAlleleCounts>,
/// Variant (on sex chromosome) falls outside a pseudoautosomal region
pub nonpar: bool,
/// All samples are heterozygous for the variant
pub only_het: bool,
/// Variant falls outside of Broad exome capture regions (exomes only).
pub outside_broad_capture_region: bool,
/// Variant falls outside of UK Biobank exome capture regions(exomes only).
pub outside_ukb_capture_region: bool,
/// Variant was a callset-wide doubleton that was present only in two siblings (i.e., a singleton amongst unrelated samples in cohort) (exomes only).
pub sibling_singleton: bool,
/// Information on variant scores.
pub effect_info: Option<Gnomad4EffectInfo>,
/// Variant-related information details.
pub variant_info: Option<Gnomad3VariantInfo>,
/// Summary information for variant quality interpretation.
pub quality_info: Option<Gnomad3QualityInfo>,
/// Age-related information.
pub age_info: Option<Gnomad3AgeInfo>,
/// Depth of coverage-related information.
pub depth_info: Option<Gnomad3DepthInfo>,
/// VRS infos.
pub vrs_info: Option<Gnomad4VrsInfo>,
}
impl TryFrom<pbs::gnomad::gnomad4::Record> for Gnomad4Record {
type Error = anyhow::Error;
fn try_from(value: pbs::gnomad::gnomad4::Record) -> Result<Self, Self::Error> {
Ok(Gnomad4Record {
chrom: value.chrom,
pos: value.pos,
ref_allele: value.ref_allele,
alt_allele: value.alt_allele,
filters: value
.filters
.into_iter()
.map(|filter| {
Gnomad3Filter::try_from(pbs::gnomad::gnomad3::Filter::try_from(filter)?)
})
.collect::<Result<Vec<_>, _>>()?,
vep: value.vep.into_iter().map(Into::into).collect(),
allele_counts: value.allele_counts.into_iter().map(Into::into).collect(),
nonpar: value.nonpar,
only_het: value.only_het,
outside_broad_capture_region: value.outside_broad_capture_region,
outside_ukb_capture_region: value.outside_ukb_capture_region,
sibling_singleton: value.sibling_singleton,
effect_info: value.effect_info.map(Into::into),
variant_info: value.variant_info.map(Into::into),
quality_info: value.quality_info.map(Into::into),
age_info: value.age_info.map(Into::into),
depth_info: value.depth_info.map(Into::into),
vrs_info: value.vrs_info.map(Into::into),
})
}
}
/// Allow either a gnomAD v2/v3 or v4 record.
#[derive(
Clone, Debug, serde::Serialize, serde::Deserialize, strum::EnumString, utoipa::ToSchema,
)]
#[serde(rename_all = "snake_case")]
#[strum(serialize_all = "snake_case")]
pub enum GnomadRecord {
/// gnomAD v2 record.
Gnomad2(Gnomad2Record),
/// gnomAD v3 record.
Gnomad3(Gnomad3Record),
/// gnomAD v4 record.
Gnomad4(Gnomad4Record),
}
/// Encapsulate VCF INFO fields related to quality.
#[derive(
Debug,
Default,
Clone,
serde::Serialize,
serde::Deserialize,
utoipa::ToSchema,
utoipa::ToResponse,
)]
pub struct GnomadMtdnaQualityInfo {
/// Mean depth across all individuals for the site.
pub dp_mean: Option<f32>,
/// Mean MMQ (median mapping quality) across individuals with a variant for the site.
pub mq_mean: Option<f32>,
/// Mean TLOD (Log 10 likelihood ratio score of variant existing versus not existing) across
/// individuals with a variant for the site.
pub tlod_mean: Option<f32>,
}
impl From<pbs::gnomad::mtdna::QualityInfo> for GnomadMtdnaQualityInfo {
fn from(value: pbs::gnomad::mtdna::QualityInfo) -> Self {
GnomadMtdnaQualityInfo {
dp_mean: value.dp_mean,
mq_mean: value.mq_mean,
tlod_mean: value.tlod_mean,
}
}
}
/// Encapsulate VCF INFO fields related to heteroplasmy levels.
#[derive(
Debug,
Default,
Clone,
serde::Serialize,
serde::Deserialize,
utoipa::ToSchema,
utoipa::ToResponse,
)]
pub struct GnomadMtdnaHeteroplasmyInfo {
/// Histogram of number of individuals with a heteroplasmy level below 0.1, bin edges are: [0.0,
/// 0.1, 0.2, 0.30000000000000004, 0.4, 0.5, 0.6000000000000001, 0.7000000000000001, 0.8, 0.9,
/// 1.0]
pub heteroplasmy_below_min_het_threshold_hist: Vec<i32>,
/// Histogram of heteroplasmy levels; bin edges are: [0.0, 0.1, 0.2, 0.30000000000000004, 0.4,
/// 0.5, 0.6000000000000001, 0.7000000000000001, 0.8, 0.9, 1.0].
pub hl_hist: Vec<i32>,
/// Present if variant is found at an overall frequency of .001 across all samples with a
/// heteroplasmy level > 0 and < 0.50 (includes variants <0.01 heteroplasmy which are
/// subsequently filtered)
pub common_low_heteroplasmy: bool,
/// Maximum heteroplasmy level observed among all samples for that variant.
pub max_hl: f32,
}
impl From<pbs::gnomad::mtdna::HeteroplasmyInfo> for GnomadMtdnaHeteroplasmyInfo {
fn from(value: pbs::gnomad::mtdna::HeteroplasmyInfo) -> Self {
GnomadMtdnaHeteroplasmyInfo {
heteroplasmy_below_min_het_threshold_hist: value
.heteroplasmy_below_min_het_threshold_hist,
hl_hist: value.hl_hist,
common_low_heteroplasmy: value.common_low_heteroplasmy,
max_hl: value.max_hl,
}
}
}
/// Encapsulate VCF INFO fields related to filter failure histograms.
#[derive(
Debug,
Default,
Clone,
serde::Serialize,
serde::Deserialize,
utoipa::ToSchema,
utoipa::ToResponse,
)]
pub struct GnomadMtdnaFilterHistograms {
/// Histogram of number of individuals failing the base_qual filter (alternate allele median base
/// quality) across heteroplasmy levels, bin edges are: [0.0, 0.1, 0.2, 0.30000000000000004, 0.4,
/// 0.5, 0.6000000000000001, 0.7000000000000001, 0.8, 0.9, 1.0]
pub base_qual_hist: Vec<i32>,
/// Histogram of number of individuals failing the position filter (median distance of alternate
/// variants from end of reads) across heteroplasmy levels, bin edges are: [0.0, 0.1, 0.2, 0.
/// 30000000000000004, 0.4, 0.5, 0.6000000000000001, 0.7000000000000001, 0.8, 0.9, 1.0]
pub position_hist: Vec<i32>,
/// Histogram of number of individuals failing the strand_bias filter (evidence for alternate
/// allele comes from one read direction only) across heteroplasmy levels, bin edges are: [0.0,
/// 0.1, 0.2, 0.30000000000000004, 0.4, 0.5, 0.6000000000000001, 0.7000000000000001, 0.8, 0.9,
/// 1.0]
pub strand_bias_hist: Vec<i32>,
/// Histogram of number of individuals failing the weak_evidence filter (mutation does not meet
/// likelihood threshold) across heteroplasmy levels, bin edges are: [0.0, 0.1, 0.2,
/// 0.30000000000000004, 0.4, 0.5, 0.6000000000000001, 0.7000000000000001, 0.8, 0.9, 1.0]
pub weak_evidence_hist: Vec<i32>,
/// Histogram of number of individuals failing the contamination filter across heteroplasmy
/// levels, bin edges are: [0.0, 0.1, 0.2, 0.30000000000000004, 0.4, 0.5, 0.6000000000000001,
/// 0.7000000000000001, 0.8, 0.9, 1.0]
pub contamination_hist: Vec<i32>,
}
impl From<pbs::gnomad::mtdna::FilterHistograms> for GnomadMtdnaFilterHistograms {
fn from(value: pbs::gnomad::mtdna::FilterHistograms) -> Self {
GnomadMtdnaFilterHistograms {
base_qual_hist: value.base_qual_hist,
position_hist: value.position_hist,
strand_bias_hist: value.strand_bias_hist,
weak_evidence_hist: value.weak_evidence_hist,
contamination_hist: value.contamination_hist,
}
}
}
/// Encapsulate VCF INFO fields related to populations.
#[derive(
Debug,
Default,
Clone,
serde::Serialize,
serde::Deserialize,
utoipa::ToSchema,
utoipa::ToResponse,
)]
pub struct GnomadMtdnaPopulationInfo {
/// List of overall allele number for each population, population order: ['afr', 'ami', 'amr',
/// 'asj', 'eas', 'fin', 'nfe', 'oth', 'sas', 'mid']
pub pop_an: Vec<i32>,
/// List of AC_het for each population, population order: ['afr', 'ami', 'amr', 'asj', 'eas',
/// 'fin', 'nfe', 'oth', 'sas', 'mid']
pub pop_ac_het: Vec<i32>,
/// List of AC_hom for each population, population order: ['afr', 'ami', 'amr', 'asj', 'eas',
/// 'fin', 'nfe', 'oth', 'sas', 'mid']
pub pop_ac_hom: Vec<i32>,
/// List of AF_hom for each population, population order: ['afr', 'ami', 'amr', 'asj', 'eas',
/// 'fin', 'nfe', 'oth', 'sas', 'mid']
pub pop_af_hom: Vec<f32>,
/// List of AF_het for each population, population order: ['afr', 'ami', 'amr', 'asj', 'eas',
/// 'fin', 'nfe', 'oth', 'sas', 'mid']
pub pop_af_het: Vec<f32>,
/// Histogram of heteroplasmy levels for each population; bin edges are: [0.0, 0.1, 0.2,
/// 0.30000000000000004, 0.4, 0.5, 0.6000000000000001, 0.7000000000000001, 0.8, 0.9, 1.0],
/// population order: \['afr', 'ami', 'amr', 'asj', 'eas', 'fin', 'nfe', 'oth', 'sas', 'mid'\]
///
/// Note that we encode this by concatenating all lists here because of limitations in
/// protocolbuffers (no native nested repeated fields).
pub pop_hl_hist: Vec<i32>,
}
impl From<pbs::gnomad::mtdna::PopulationInfo> for GnomadMtdnaPopulationInfo {
fn from(value: pbs::gnomad::mtdna::PopulationInfo) -> Self {
GnomadMtdnaPopulationInfo {
pop_an: value.pop_an,
pop_ac_het: value.pop_ac_het,
pop_ac_hom: value.pop_ac_hom,
pop_af_hom: value.pop_af_hom,
pop_af_het: value.pop_af_het,
pop_hl_hist: value.pop_hl_hist,
}
}
}
/// Encapsulate VCF INFO fields related to haplogroups.
#[derive(
Debug,
Default,
Clone,
serde::Serialize,
serde::Deserialize,
utoipa::ToSchema,
utoipa::ToResponse,
)]
pub struct GnomadMtdnaHaplogroupInfo {
/// Present if variant is present as a haplogroup defining variant in PhyloTree build 17.
pub hap_defining_variant: bool,
/// List of overall allele number for each haplogroup, haplogroup order: ['A', 'B', 'C', 'D',
/// 'E', 'F', 'G', 'H', 'HV', 'I', 'J', 'K', 'L0', 'L1', 'L2', 'L3', 'L4', 'L5', 'M', 'N', 'P',
/// 'R', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
pub hap_an: Vec<i32>,
/// List of AC_het for each haplogroup, haplogroup order: ['A', 'B', 'C', 'D', 'E', 'F', 'G',
/// 'H', 'HV', 'I', 'J', 'K', 'L0', 'L1', 'L2', 'L3', 'L4', 'L5', 'M', 'N', 'P', 'R', 'T', 'U',
/// 'V', 'W', 'X', 'Y', 'Z']
pub hap_ac_het: Vec<i32>,
/// List of AC_hom for each haplogroup, haplogroup order: ['A', 'B', 'C', 'D', 'E', 'F', 'G',
/// 'H', 'HV', 'I', 'J', 'K', 'L0', 'L1', 'L2', 'L3', 'L4', 'L5', 'M', 'N', 'P', 'R', 'T', 'U',
/// 'V', 'W', 'X', 'Y', 'Z']
pub hap_ac_hom: Vec<i32>,
/// List of AF_het for each haplogroup, haplogroup order: ['A', 'B', 'C', 'D', 'E', 'F', 'G',
/// 'H', 'HV', 'I', 'J', 'K', 'L0', 'L1', 'L2', 'L3', 'L4', 'L5', 'M', 'N', 'P', 'R', 'T', 'U',
/// 'V', 'W', 'X', 'Y', 'Z']
pub hap_af_het: Vec<f32>,
/// List of AF_hom for each haplogroup, haplogroup order: ['A', 'B', 'C', 'D', 'E', 'F', 'G',
/// 'H', 'HV', 'I', 'J', 'K', 'L0', 'L1', 'L2', 'L3', 'L4', 'L5', 'M', 'N', 'P', 'R', 'T', 'U',
/// 'V', 'W', 'X', 'Y', 'Z']
pub hap_af_hom: Vec<f32>,
/// Histogram of heteroplasmy levels for each haplogroup; bin edges are: [0.0, 0.1, 0.2,
/// 0.30000000000000004, 0.4, 0.5, 0.6000000000000001, 0.7000000000000001, 0.8, 0.9, 1.0],
/// haplogroup order: ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'HV', 'I', 'J', 'K', 'L0', 'L1',
/// 'L2', 'L3', 'L4', 'L5', 'M', 'N', 'P', 'R', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
///
/// Note that we encode this by concatenating all lists here because of limitations in
/// protocolbuffers (no native nested repeated fields).
pub hap_hl_hist: Vec<i32>,
/// List of filtering allele frequency for each haplogroup restricted to homoplasmic variants,
/// haplogroup order: ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'HV', 'I', 'J', 'K', 'L0', 'L1',
/// 'L2', 'L3', 'L4', 'L5', 'M', 'N', 'P', 'R', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
pub hap_faf_hom: Vec<f32>,
/// Haplogroup with maximum AF_hom.
pub hapmax_af_hom: Option<String>,
/// Haplogroup with maximum AF_het.
pub hapmax_af_het: Option<String>,
/// Maximum filtering allele frequency across haplogroups restricted to homoplasmic variants.
pub faf_hapmax_hom: Option<f32>,
}
impl From<pbs::gnomad::mtdna::HaplogroupInfo> for GnomadMtdnaHaplogroupInfo {
fn from(value: pbs::gnomad::mtdna::HaplogroupInfo) -> Self {
GnomadMtdnaHaplogroupInfo {
hap_defining_variant: value.hap_defining_variant,
hap_an: value.hap_an,
hap_ac_het: value.hap_ac_het,
hap_ac_hom: value.hap_ac_hom,
hap_af_het: value.hap_af_het,
hap_af_hom: value.hap_af_hom,
hap_hl_hist: value.hap_hl_hist,
hap_faf_hom: value.hap_faf_hom,
hapmax_af_hom: value.hapmax_af_hom,
hapmax_af_het: value.hapmax_af_het,
faf_hapmax_hom: value.faf_hapmax_hom,
}
}
}
/// Encapsulate VCF INFO fields related to age.
#[derive(
Debug,
Default,
Clone,
serde::Serialize,
serde::Deserialize,
utoipa::ToSchema,
utoipa::ToResponse,
)]
pub struct GnomadMtdnaAgeInfo {
/// Histogram of ages of individuals with a homoplasmic variant; bin edges are: [30.0, 35.0,
/// 40.0, 45.0, 50.0, 55.0, 60.0, 65.0, 70.0, 75.0, 80.0].
pub age_hist_hom_bin_freq: Vec<i32>,
/// Count of age values falling below lowest histogram bin edge for individuals with a
/// homoplasmic variant.
pub age_hist_hom_n_smaller: Option<i32>,
/// Count of age values falling above highest histogram bin edge for individuals with a
/// homoplasmic variant.
pub age_hist_hom_n_larger: Option<i32>,
/// Histogram of ages of individuals with a heteroplasmic variant; bin edges are: [30.0, 35.0,
/// 40.0, 45.0, 50.0, 55.0, 60.0, 65.0, 70.0, 75.0, 80.0]
pub age_hist_het_bin_freq: Vec<i32>,
/// Count of age values falling below lowest histogram bin edge for individuals with a
/// heteroplasmic variant.
pub age_hist_het_n_smaller: Option<i32>,
/// Count of age values falling above highest histogram bin edge for individuals with a
/// heteroplasmic variant.
pub age_hist_het_n_larger: Option<i32>,
}
impl From<pbs::gnomad::mtdna::AgeInfo> for GnomadMtdnaAgeInfo {
fn from(value: pbs::gnomad::mtdna::AgeInfo) -> Self {
GnomadMtdnaAgeInfo {
age_hist_hom_bin_freq: value.age_hist_hom_bin_freq,
age_hist_hom_n_smaller: value.age_hist_hom_n_smaller,
age_hist_hom_n_larger: value.age_hist_hom_n_larger,
age_hist_het_bin_freq: value.age_hist_het_bin_freq,
age_hist_het_n_smaller: value.age_hist_het_n_smaller,
age_hist_het_n_larger: value.age_hist_het_n_larger,
}
}
}
/// Encapsulate VCF INFO fields related to depth.
#[derive(
Debug,
Default,
Clone,
serde::Serialize,
serde::Deserialize,
utoipa::ToSchema,
utoipa::ToResponse,
)]
pub struct GnomadMtdnaDepthInfo {
/// Count of dp values falling above highest histogram bin edge for all individuals.
pub dp_hist_all_n_larger: Option<i32>,
/// Count of dp values falling above highest histogram bin edge for individuals with the
/// alternative allele
pub dp_hist_alt_n_larger: Option<i32>,
/// Histogram of dp values for all individuals; bin edges are: [0.0, 200.0, 400.0, 600.0, 800.0,
/// 1000.0, 1200.0, 1400.0, 1600.0, 1800.0, 2000.0]
pub dp_hist_all_bin_freq: Vec<i32>,
/// Histogram of dp values for individuals with the alternative allele; bin edges are: [0.0,
/// 200.0, 400.0, 600.0, 800.0, 1000.0, 1200.0, 1400.0, 1600.0, 1800.0, 2000.0]
pub dp_hist_alt_bin_freq: Vec<i32>,
}
impl From<pbs::gnomad::mtdna::DepthInfo> for GnomadMtdnaDepthInfo {
fn from(value: pbs::gnomad::mtdna::DepthInfo) -> Self {
GnomadMtdnaDepthInfo {
dp_hist_all_n_larger: value.dp_hist_all_n_larger,
dp_hist_alt_n_larger: value.dp_hist_alt_n_larger,
dp_hist_all_bin_freq: value.dp_hist_all_bin_freq,
dp_hist_alt_bin_freq: value.dp_hist_alt_bin_freq,
}
}
}
/// Protocol buffer for the gnomAD-mtDNA VCF record.
///
/// The more specialized fields from the INFO column are stored in separate, optional fields such
/// that we don't end up with a humongous message.
#[derive(
Debug,
Default,
Clone,
serde::Serialize,
serde::Deserialize,
utoipa::ToSchema,
utoipa::ToResponse,
)]
pub struct GnomadMtdnaRecord {
/// Chromosome name.
pub chrom: String,
/// 1-based start position.
pub pos: i32,
/// Reference allele.
pub ref_allele: String,
/// Alternate allele.
pub alt_allele: String,
/// Variant in format of RefPosAlt
pub variant_collapsed: String,
/// Excluded allele count (number of individuals in which the variant was filtered out).
pub excluded_ac: i32,
/// Overall allele number (number of samples with non-missing genotype).
pub an: i32,
/// Allele count restricted to variants with a heteroplasmy level >= 0.95.
pub ac_hom: i32,
/// Allele count restricted to variants with a heteroplasmy level >= 0.10 and < 0.95.
pub ac_het: i32,
/// Allele frequency restricted to variants with a heteroplasmy level >= 0.95.
pub af_hom: f32,
/// Allele frequency restricted to variants with a heteroplasmy level >= 0.10 and < 0.95.
pub af_het: f32,
/// Site-level filters.
pub filters: Vec<GnomadMtdnaFilter>,
/// MitoTip raw score
pub mitotip_score: Option<f32>,
/// MitoTip score interpretation
pub mitotip_trna_prediction: Option<String>,
/// tRNA pathogenicity classification from PON-mt-tRNA
pub pon_mt_trna_prediction: Option<String>,
/// tRNA ML_probability_of_pathogenicity from PON-mt-tRNA
pub pon_ml_probability_of_pathogenicity: Option<String>,
/// VEP v3 annotation records.
pub vep: Vec<Gnomad3Vep>,
/// Summary information for variant quality interpretation.
pub quality_info: Option<GnomadMtdnaQualityInfo>,
/// Information related to heteroplasmy levels.
pub heteroplasmy_info: Option<GnomadMtdnaHeteroplasmyInfo>,
/// Histograms related to variant quality filters.
pub filter_histograms: Option<GnomadMtdnaFilterHistograms>,
/// Population-related information.
pub population_info: Option<GnomadMtdnaPopulationInfo>,
/// Haplogroup-related information.
pub haplogroup_info: Option<GnomadMtdnaHaplogroupInfo>,
/// Age-related information.
pub age_info: Option<GnomadMtdnaAgeInfo>,
/// Depth of coverage-related information.
pub depth_info: Option<GnomadMtdnaDepthInfo>,
}
impl TryFrom<pbs::gnomad::mtdna::Record> for GnomadMtdnaRecord {
type Error = anyhow::Error;
fn try_from(value: pbs::gnomad::mtdna::Record) -> Result<Self, Self::Error> {
Ok(GnomadMtdnaRecord {
chrom: value.chrom,
pos: value.pos,
ref_allele: value.ref_allele,
alt_allele: value.alt_allele,
variant_collapsed: value.variant_collapsed,
excluded_ac: value.excluded_ac,
an: value.an,
ac_hom: value.ac_hom,
ac_het: value.ac_het,
af_hom: value.af_hom,
af_het: value.af_het,
filters: value
.filters
.into_iter()
.map(|filter| {
GnomadMtdnaFilter::try_from(
pbs::gnomad::mtdna::Filter::try_from(filter)
.map_err(anyhow::Error::from)?,
)
})
.collect::<Result<_, _>>()?,
mitotip_score: value.mitotip_score,
mitotip_trna_prediction: value.mitotip_trna_prediction,
pon_mt_trna_prediction: value.pon_mt_trna_prediction,
pon_ml_probability_of_pathogenicity: value.pon_ml_probability_of_pathogenicity,
vep: value.vep.into_iter().map(Into::into).collect(),
quality_info: value.quality_info.map(Into::into),
heteroplasmy_info: value.heteroplasmy_info.map(Into::into),
filter_histograms: value.filter_histograms.map(Into::into),
population_info: value.population_info.map(Into::into),
haplogroup_info: value.haplogroup_info.map(Into::into),
age_info: value.age_info.map(Into::into),
depth_info: value.depth_info.map(Into::into),
})
}
}
/// Protocol buffer enum for site-level filters.
#[derive(
Clone,
Copy,
Debug,
PartialEq,
Eq,
Hash,
PartialOrd,
Ord,
serde::Serialize,
serde::Deserialize,
strum::Display,
strum::EnumString,
utoipa::ToSchema,
)]
#[serde(rename_all = "snake_case")]
#[strum(serialize_all = "snake_case")]
pub enum GnomadMtdnaFilter {
/// Variant overlaps site that is commonly reported in literature to be artifact prone.
ArtifactProneSite,
/// Allele where all samples with the variant call had at least 2 different heteroplasmic indels
/// called at the position.
IndelStack,
/// No-pass-genotypes site (no individuals were PASS for the variant).
NoPassGenotype,
}
impl TryFrom<pbs::gnomad::mtdna::Filter> for GnomadMtdnaFilter {
type Error = anyhow::Error;
fn try_from(value: pbs::gnomad::mtdna::Filter) -> Result<Self, Self::Error> {
Ok(match value {
pbs::gnomad::mtdna::Filter::ArtifactProneSite => {
GnomadMtdnaFilter::ArtifactProneSite
}
pbs::gnomad::mtdna::Filter::IndelStack => GnomadMtdnaFilter::IndelStack,
pbs::gnomad::mtdna::Filter::NoPassGenotype => GnomadMtdnaFilter::NoPassGenotype,
_ => anyhow::bail!("unknown gnomad::mtdna::Filter: {:?}", value),
})
}
}
/// A record corresponding to dbSNP VCF.
#[derive(Debug, Default, Clone, serde::Serialize, serde::Deserialize, utoipa::ToSchema)]
pub struct DbsnpRecord {
/// Chromosome name.
pub chrom: String,
/// 1-based start position.
pub pos: i32,
/// Reference allele.
pub ref_allele: String,
/// Alternate allele.
pub alt_allele: String,
/// The rs ID.
pub rs_id: i32,
}
impl From<crate::pbs::dbsnp::Record> for DbsnpRecord {
fn from(value: crate::pbs::dbsnp::Record) -> Self {
DbsnpRecord {
chrom: value.chrom,
pos: value.pos,
ref_allele: value.ref_allele,
alt_allele: value.alt_allele,
rs_id: value.rs_id,
}
}
}
/// A HelixMtDb record.
#[derive(Debug, Default, Clone, serde::Serialize, serde::Deserialize, utoipa::ToSchema)]
pub struct HelixMtDbRecord {
/// Chromosome name.
pub chrom: String,
/// 1-based start position.
pub pos: i32,
/// Reference allele.
pub ref_allele: String,
/// / Alternate allele.
pub alt_allele: String,
/// Total number of individuals.
pub num_total: i32,
/// Number of homoplasmic carriers.
pub num_het: i32,
/// Number of heteroplasmic carriers.
pub num_hom: i32,
/// Feature type.
pub feature_type: String,
/// Gene name.
pub gene_name: String,
}
impl From<crate::pbs::helixmtdb::Record> for HelixMtDbRecord {
fn from(val: crate::pbs::helixmtdb::Record) -> Self {
HelixMtDbRecord {
chrom: val.chrom,
pos: val.pos,
ref_allele: val.ref_allele,
alt_allele: val.alt_allele,
num_total: val.num_total,
num_het: val.num_het,
num_hom: val.num_hom,
feature_type: val.feature_type,
gene_name: val.gene_name,
}
}
}
/// A UCSC conservation record.
#[derive(Debug, Default, Clone, serde::Serialize, serde::Deserialize, utoipa::ToSchema)]
pub struct UcscConservationRecord {
/// Chromosome name.
pub chrom: String,
/// 1-based, inclusive start position.
pub start: i32,
/// 1-based, inclusive stop position.
pub stop: i32,
/// HGNC identifier.
pub hgnc_id: String,
/// ENST identifier.
pub enst_id: String,
/// Exon number (1-based).
pub exon_num: i32,
/// Exon count.
pub exon_count: i32,
/// Alignment.
pub alignment: String,
}
impl From<crate::pbs::cons::Record> for UcscConservationRecord {
fn from(value: crate::pbs::cons::Record) -> Self {
UcscConservationRecord {
chrom: value.chrom,
start: value.start,
stop: value.stop,
hgnc_id: value.hgnc_id,
enst_id: value.enst_id,
exon_num: value.exon_num,
exon_count: value.exon_count,
alignment: value.alignment,
}
}
}
/// List of `Record`s.
#[derive(Debug, Default, Clone, serde::Serialize, serde::Deserialize, utoipa::ToSchema)]
pub struct UcscConservationRecordList {
/// The records in the list.
pub records: Vec<UcscConservationRecord>,
}
impl From<crate::pbs::cons::RecordList> for UcscConservationRecordList {
fn from(value: crate::pbs::cons::RecordList) -> Self {
UcscConservationRecordList {
records: value.records.into_iter().map(Into::into).collect(),
}
}
}
/// List of `ClinvarExtractedVcvRecord`s.
#[derive(Debug, Default, Clone, serde::Serialize, serde::Deserialize, utoipa::ToSchema)]
pub struct ExtractedVcvRecordList {
/// The list of VCV records that may share a global variant.
pub records: Vec<ClinvarExtractedVcvRecord>,
}
impl TryFrom<crate::pbs::clinvar::minimal::ExtractedVcvRecordList> for ExtractedVcvRecordList {
type Error = anyhow::Error;
fn try_from(
value: crate::pbs::clinvar::minimal::ExtractedVcvRecordList,
) -> Result<Self, Self::Error> {
Ok(ExtractedVcvRecordList {
records: value
.records
.into_iter()
.map(TryInto::try_into)
.collect::<Result<_, _>>()?,
})
}
}
/// Annotation for a sinngle variant.
#[derive(Debug, Default, Clone, serde::Serialize, serde::Deserialize, utoipa::ToSchema)]
pub struct SeqvarsAnnoResponseRecord {
/// Annotations from CADD (TSV annotation file).
pub cadd: Option<indexmap::IndexMap<String, serde_json::Value>>,
/// Annotations from dbSNP.
pub dbsnp: Option<DbsnpRecord>,
/// Annotations from dbNSFP (TSV annotation file).
pub dbnsfp: Option<indexmap::IndexMap<String, serde_json::Value>>,
/// Annotations from dbscSNV.
pub dbscsnv: Option<indexmap::IndexMap<String, serde_json::Value>>,
/// Annotations from gnomAD-mtDNA.
pub gnomad_mtdna: Option<GnomadMtdnaRecord>,
/// Annotations from gnomAD-exomes.
pub gnomad_exomes: Option<GnomadRecord>,
/// Annotations from gnomAD-genomes.
pub gnomad_genomes: Option<GnomadRecord>,
/// Annotations from HelixMTdb.
pub helixmtdb: Option<HelixMtDbRecord>,
/// Annotations from UCSC conservation.
pub ucsc_conservation: Option<UcscConservationRecordList>,
/// Minimal extracted data from ClinVar.
pub clinvar: Option<ExtractedVcvRecordList>,
}
/// Query response for `handle_with_openapi()`.
#[derive(
Debug,
Default,
Clone,
serde::Serialize,
serde::Deserialize,
utoipa::ToSchema,
utoipa::ToResponse,
)]
pub struct SeqvarsAnnosResponse {
/// The result records.
pub result: SeqvarsAnnoResponseRecord,
}
}
use response::*;
/// Query for annotations for a single variant.
#[utoipa::path(
get,
operation_id = "seqvarsAnosQuery",
params(SeqvarsAnnosQuery),
responses(
(status = 200, description = "Annotation for a single variant.", body = SeqvarsAnnosResponse),
(status = 500, description = "Internal server error.", body = CustomError)
)
)]
#[get("/api/v1/genes/info")]
pub async fn handle_with_openapi(
data: Data<crate::server::run::WebServerData>,
_path: Path<()>,
query: web::Query<SeqvarsAnnosQuery>,
) -> actix_web::Result<Json<SeqvarsAnnosResponse>, CustomError> {
let genome_release = query
.genome_release
.parse()
.map_err(|e: strum::ParseError| {
CustomError::new(anyhow::anyhow!("problem getting genome release: {}", e))
})?;
fn json_value_to_indexmap(
value: serde_json::Value,
) -> Result<indexmap::IndexMap<String, serde_json::Value>, CustomError> {
value
.as_object()
.map(|v| {
Ok(v.iter()
.map(|(k, v)| (k.clone(), v.clone()))
.collect::<indexmap::IndexMap<_, _>>())
})
.unwrap_or_else(|| Err(CustomError::new(anyhow::anyhow!("expected object"))))
}
let result = SeqvarsAnnoResponseRecord {
cadd: data.annos[genome_release][AnnoDb::Cadd]
.as_ref()
.map(|db| {
fetch_var_tsv_json(
&db.data,
AnnoDb::Cadd.cf_name(),
query.clone().into_inner().into(),
)
})
.transpose()?
.flatten()
.map(json_value_to_indexmap)
.transpose()?,
dbsnp: data.annos[genome_release][AnnoDb::Dbsnp]
.as_ref()
.map(|db| {
fetch_var_protobuf::<crate::dbsnp::pbs::Record>(
&db.data,
AnnoDb::Dbsnp.cf_name(),
query.clone().into_inner().into(),
)
})
.transpose()?
.flatten()
.map(Into::into),
dbnsfp: data.annos[genome_release][AnnoDb::Dbnsfp]
.as_ref()
.map(|db| {
fetch_var_tsv_json(
&db.data,
AnnoDb::Dbnsfp.cf_name(),
query.clone().into_inner().into(),
)
})
.transpose()?
.flatten()
.map(json_value_to_indexmap)
.transpose()?,
dbscsnv: data.annos[genome_release][AnnoDb::Dbscsnv]
.as_ref()
.map(|db| {
fetch_var_tsv_json(
&db.data,
AnnoDb::Dbscsnv.cf_name(),
query.clone().into_inner().into(),
)
})
.transpose()?
.flatten()
.map(json_value_to_indexmap)
.transpose()?,
gnomad_mtdna: data.annos[genome_release][AnnoDb::GnomadMtdna]
.as_ref()
.map(|db| {
fetch_var_protobuf::<crate::pbs::gnomad::mtdna::Record>(
&db.data,
AnnoDb::GnomadMtdna.cf_name(),
query.clone().into_inner().into(),
)?
.map(TryInto::<GnomadMtdnaRecord>::try_into)
.transpose()
.map_err(CustomError::new)
})
.transpose()?
.flatten()
.map(Into::into),
// gnomad_exomes: Option<bool>,
// gnomad_genomes: Option<bool>,
helixmtdb: data.annos[genome_release][AnnoDb::Helixmtdb]
.as_ref()
.map(|db| {
Ok(fetch_var_protobuf::<crate::pbs::helixmtdb::Record>(
&db.data,
AnnoDb::Helixmtdb.cf_name(),
query.clone().into_inner().into(),
)?
.map(Into::into))
})
.transpose()?
.flatten(),
ucsc_conservation: data.annos[genome_release][AnnoDb::UcscConservation]
.as_ref()
.map(|db| {
let start: keys::Pos = query.clone().into_inner().into();
let start = keys::Pos {
chrom: start.chrom,
pos: start.pos - 2,
};
let stop = query.clone().into_inner().into();
Ok(fetch_pos_protobuf::<crate::pbs::cons::RecordList>(
&db.data,
AnnoDb::UcscConservation.cf_name(),
start,
stop,
)?
.into_iter()
.next()
.map(Into::into))
})
.transpose()?
.flatten(),
clinvar: data.annos[genome_release][AnnoDb::Clinvar]
.as_ref()
.map(|db| {
fetch_var_protobuf::<crate::pbs::clinvar::minimal::ExtractedVcvRecordList>(
&db.data,
AnnoDb::Clinvar.cf_name(),
query.clone().into_inner().into(),
)?
.map(TryInto::<ExtractedVcvRecordList>::try_into)
.transpose()
.map_err(CustomError::new)
})
.transpose()?
.flatten(),
..Default::default()
};
Ok(Json(SeqvarsAnnosResponse { result }))
}