-
Notifications
You must be signed in to change notification settings - Fork 16
/
new_results_page.jinja2
1687 lines (1542 loc) · 82.1 KB
/
new_results_page.jinja2
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
{% extends "sitebase.jinja2" %}
{% set page_title = _("Sample Results") %}
{% set show_breadcrumbs = show_breadcrumbs %}
{% block head %}
<link rel="stylesheet" type="text/css" href="/static/vendor/css/jquery.dataTables.css" />
<link id="emperor-css" rel="stylesheet" type="text/css" href="/static/vendor/emperor/css/emperor.css">
<link rel="stylesheet" type="text/css" href="/static/vendor/emperor/vendor/css/jquery-ui.min.css">
<link rel="stylesheet" type="text/css" href="/static/vendor/emperor/vendor/css/slick.grid.min.css">
<link rel="stylesheet" type="text/css" href="/static/vendor/emperor/vendor/css/spectrum.min.css">
<link rel="stylesheet" type="text/css" href="/static/vendor/emperor/vendor/css/chosen.min.css">
<link rel="stylesheet" type="text/css" href="/static/vendor/emperor/vendor/css/jquery.contextMenu.min.css">
<link rel="stylesheet" type="text/css" href="/static/css/4_column_flex.css" />
<style>
.nav-white-bg {
background-color: #fff;
width: auto;
}
.diversity-icon {
vertical-align: middle;
width: 72px;
height: 72px;
object-fit: contain;
float:left;
}
.diversity-text {
vertical-align:middle;
display:inline;
float:left;
padding: 10px;
padding-left: 20px;
}
.diversity-header {
background-color: #EDECEF;
padding: 10px;
}
.diversity-compare {
background-color: #ffffff;
color: #747678;
border-radius: 15px;
padding: 10px;
padding-left: 20px;
border-style: solid;
border-width: 2px;
border-color: #006a96;
width: 30%;
margin: 20px;
}
.diversity-category {
color: #006a96;
}
.diversity-info {
}
.diversity-banner {
width: 100%;
max-width: 1920px;
height: auto;
border-radius: 8px;
border: 1px solid #ddd;
}
.similarity-fontstyle-same {
color: var(--ucsd-green);
}
.similarity-fontstyle-different {
color: var(--ucsd-brown);
}
/*.micromap {
min-width: 400px;
min-height: 300px;
}*/
.microinfo {
min-width: 40%;
}
/*Removes the .active, .accordion:hover effect from minimal_interface.css*/
/* Could potentially use color: initial but has less support...? */
.accordion-microbiome-map
{
background-color: #eee;
color: #000;
cursor: pointer;
padding: 5px;
width: 100%;
text-align: left;
border: none;
outline: none;
transition: 0.4s;
margin-bottom: 1%;
margin-top: 1%;
}
.accordion-panel-microbiome-map {
background-color: white;
max-height: 0;
overflow: hidden;
transition: max-height 0.2s ease-out;
}
.tab-pane {
background-color: #FFFFFF;
color: #000000;
}
.microbe-count {
font-weight: bold;
}
div.results_text {
text-align: left;
}
div.how_you_compare_section {
background-color: #f1f1f1;
color: #747678;
border-radius: 15px;
padding: 10px;
padding-left: 20px;
border-style: solid;
border-width: thin;
border-color: #006a96;
width: 70%;
}
div.how_you_compare_section h3 {
color: #006a96;
font-weight: lighter;
font-family: Mulish,sans-serif;
font-size: 36px;
}
div.how_you_compare_section h4 {
color: #006a96;
font-weight: lighter;
font-family: Mulish,sans-serif;
font-size: 20px;
}
div.how_you_compare_section p {
font: normal normal 400 14px/1.6 Muli,sans-serif;
font-variant-numeric: oldstyle-nums;
color: #747678;
}
div.how_you_compare_section a {
color: #006a96;
}
div.your_sample_diversity_inset {
background-color: #006a96;
color: #ffffff;
font-size: 20px;
border-radius: 15px;
border-style: solid;
border-width: thin;
border-color: #006a96;
width: 35%;
box-shadow: 0 4px 8px 0 rgb(0 0 0 / 20%), 0 6px 20px 0 rgb(0 0 0 / 19%);
}
.scatter-bg {
background-image: url('/static/img/scatter.png');
background: url('/static/img/scatter.png');
background-position: top 400px left 0px;
background-size: 220px;
background-origin: content-box;
background-repeat: no-repeat;
}
div.your_sample_diversity_inset .card-header {
color: #ffffff;
text-align: center;
}
div.your_sample_diversity_inset .card-body {
color: #ffffff;
font-size: 32px;
text-align: center;
}
.tooltipper {
color: #fc8900;
}
.tooltip.show {
opacity: 1;
}
.tooltip-inner {
background-color: #ffffff; !important;
color: #747678;
border: 2px solid #fc8900;
}
.bs-tooltip-auto[x-placement^=bottom] .arrow::before, .bs-tooltip-bottom .arrow::before {
border-bottom-color: #fc8900 !important;
}
.bs-tooltip-auto[x-placement^=top] .arrow::before, .bs-tooltip-top .arrow::before {
border-top-color: #fc8900 !important;
}
.bs-tooltip-auto[x-placement^=left] .arrow::before, .bs-tooltip-left .arrow::before {
border-left-color: #fc8900 !important;
}
.bs-tooltip-auto[x-placement^=right] .arrow::before, .bs-tooltip-right .arrow::before {
border-right-color: #fc8900 !important;
}
</style>
<script type="text/javascript" language="javascript" src="/static/js/ruleset.js"></script>
<!-- Datatables must precede emperor imports, they don't play nice with each other. -->
<script type="text/javascript" charset="utf8" src="/static/vendor/js/jquery.dataTables.js"></script>
<script src="/static/vendor/DataTables/Buttons-1.6.2/js/dataTables.buttons.min.js"></script>
<script src="/static/vendor/DataTables/Buttons-1.6.2/js/buttons.html5.min.js"></script>
<script src="/static/vendor/DataTables/PercentageBars-1.10.21/js/percentageBars.js"></script>
<!-- plotly must precede emperor imports as well. I'm getting the feeling
that emperor doesn't know how to play nice. -->
<script src='https://cdn.plot.ly/plotly-latest.min.js'></script>
<script src="/static/vendor/emperor/vendor/js/require-2.1.22.min.js"></script>
<script src="/static/vendor/emperor/emperor_loader.js"></script>
<script>
"use strict";
var dynamic_text_dictionary = {
"11 to 20": "{{ _('11 to 20') }}",
"21 to 30": "{{ _('21 to 30') }}",
"5-6 hours": "{{ _('5-6 hours') }}",
"6 to 10": "{{ _('6 to 10') }}",
"6-7 hours": "{{ _('6-7 hours') }}",
"7-8 hours": "{{ _('7-8 hours') }}",
"8 or more hours": "{{ _('8 or more hours') }}",
"Daily": "{{ _('Daily') }}",
"Less than 5": "{{ _('Less than 5') }}",
"Less than 5 hours": "{{ _('Less than 5 hours') }}",
"More than 30": "{{ _('More than 30') }}",
"Never": "{{ _('Never') }}",
"Not provided": "{{ _('Not provided') }}",
"Occasionally (1-2 times/week)": "{{ _('Occasionally (1-2 times/week)') }}",
"Rarely (a few times/month)": "{{ _('Rarely (a few times/month)') }}",
"Rarely (less than once/week)": "{{ _('Rarely (less than once/week)') }}",
"Regularly (3-5 times/week)": "{{ _('Regularly (3-5 times/week)') }}",
"not applicable": "{{ _('Not provided') }}",
"not collected": "{{ _('Not provided') }}",
"not provided": "{{ _('Not provided') }}"
};
function placeURLSourcedImageFromDetail(state, url, detail) {
/* this creates the following html structure off of #pcoa-div
<div id="accordion-div-id">
<button class="accordion-microbiome-map">
<h4 class="diversity-header">button_text</h4>
</button>
<div class="accordion-panel-microbiome-map" style="">
<div class="row">
<div class="col-5">
<div id="img_div_id">
<img id="imgid" src="#" alt="img" class="img-fluid"/>
</div>
</div>
<div class="col microinfo">
description
</div>
</div>
</div>
</div>
*/
var pcoa_div = document.getElementById('pcoa-div');
var img = document.createElement('img');
img.id = detail['img_id'];
img.classList.add('img-fluid');
img.setAttribute('alt', 'img');
var img_div = document.createElement('div');
img_div.id = detail['img_div_id'];
img_div.appendChild(img);
var content_div = document.createElement('div');
content_div.classList.add('accordion-panel-microbiome-map');
content_div.style = '';
var content_div_row = document.createElement('div');
content_div_row.classList.add('row');
var content_div_img = document.createElement('div');
content_div_img.classList.add('col-5');
var content_div_desc = document.createElement('div');
content_div_desc.classList.add('col');
content_div_desc.classList.add('microinfo');
content_div_desc.innerHTML = detail['description'];
content_div_img.appendChild(img_div);
content_div_row.appendChild(content_div_img);
content_div_row.appendChild(content_div_desc);
content_div.appendChild(content_div_row);
var button_text = document.createElement('h4');
button_text.classList.add('diversity-header');
button_text.innerText = detail['button_text'];
var button = document.createElement('button');
button.classList.add('accordion-microbiome-map');
button.style = '';
button.type = 'button';
button.appendChild(button_text);
var accordion = document.createElement('div')
accordion.classList.add('microbiome-map-multipop-lifestage-accordian');
accordion.appendChild(button);
accordion.appendChild(content_div);
pcoa_div.appendChild(accordion);
placeURLSourcedImage(state, url, detail['img_id']);
};
function placeURLSourcedImage(state, url, divSelector) {
$('#' + divSelector).attr('src', url);
};
var pcoa_structure = {
'tmi_16S_gut_all_samples': {
'dataset': 'tmi-16S-allsamples',
'category': 'microbial_map',
'accordion_div_id': 'microbiome-map-all-tmi-accordion',
'button_text': "{{ _('Microbiomes Across the Body') }}",
'img_div_id': 'pcoa-tmi-all-samples',
'img_id': 'pcoa-tmi-all-samples-img',
'description': "<p>{{ _('In this map, we\'ve placed your sample relative to all the other samples we have in Microsetta. As you can see, there are a few different types of samples people have contributed, and the microbial configurations present can be REALLY different.') }}</p>"},
'tmi_16S_gut_multipop': {
'dataset': 'multipop-16S-gut',
'category': 'microbial_map_region',
'accordion_div_id': 'microbiome-map-multipop-region-accordion',
'button_text': "{{ _('Microbiomes Across the World') }}",
'img_div_id': 'pcoa-multipopulation-region',
'img_id': 'pcoa-multipopulation-region-img',
'description': "<p>{{ _('Researchers have noted large differences in our microbiomes depending on where we live. The reason WHY is not well understood, but we suspect factors such as diet or environmental exposures (e.g., plants, what\'s in your house, pollution, how often you come in contact with soil, etc) may be be major factors.') }}</p><p>{{ _('Researchers do not know how much these differences matter! They certainly may.') }}</p>"},
'tmi_16S_gut_lifestage': {
'dataset': 'lifestage-16S-gut',
'category': 'microbial_map_lifestage',
'accordion_div_id': 'microbiome-map-multipop-lifestage-accordian',
'button_text': "{{ _('Microbiomes Across the Lifespan') }}",
'img_div_id': 'pcoa-multipopulation-lifestage',
'img_id': 'pcoa-multipopulation-lifestage-img',
'description': "<p>{{ _('One major factor associated with gut microbiomes is the age of the individual, emphasized here by life stages.') }}</p><p>{{ _('Interestingly, infants are relatively similar microbially regardless of where they were born. But, as individuals age, it seems like their microbiomes reflect regional or population differences.') }}</p>"},
'tmi_16S_gut_builtenv': {
'dataset': 'builtenv-16S-allsamples',
'category': 'microbial_map',
'accordion_div_id': 'microbiome-map-builtenv-accordian',
'button_text': "{{ _('Microbiomes in the Environment') }}",
'img_div_id': 'pcoa-builtenv',
'img_id': 'pcoa-builtenv-img',
'description': "<p>{{ _('Microbes are EVERYWHERE though! Using these same techniques described above, we compared your microbiome to samples collected from all over the surfaces from a brand new hospital.') }}</p><p>{{ _('As you can see, skin samples tend to more closely resemble those from the built environment, which makes sense as skin cells are constantly shedding from you.') }}</p>"},
'tmi_WGS_gut_multipop': {
'dataset': 'multipop-WGS-gut',
'category': 'microbial_map_region',
'accordion_div_id': 'microbiome-map-multipop-accordian',
'button_text': "{{ _('Microbiomes Across the World') }}",
'img_div_id': 'pcoa-multipopulation-region',
'img_id': 'pcoa-multipopulation-region-img',
'description': "<p>{{ _('Researchers have noted large differences in our microbiomes depending on where we live. The reason WHY is not well understood, but we suspect factors such as diet or environmental exposures (e.g., plants, what\'s in your house, pollution, how often you come in contact with soil, etc) may be be major factors.') }}</p><p>{{ _('Researchers do not know how much these differences matter! They certainly may.') }}</p>"},
'tmi_WGS_gut_lifestage': {
'dataset': 'lifestage-WGS-gut',
'category': 'microbial_map_lifestage',
'accordion_div_id': 'microbiome-map-multipop-lifestage-accordian',
'button_text': "{{ _('Microbiomes Across the Lifespan') }}",
'img_div_id': 'pcoa-multipopulation-lifestage',
'img_id': 'pcoa-multipopulation-lifestage-img',
'description': "<p>{{ _('One major factor associated with gut microbiomes is the age of the individual, emphasized here by life stages.') }}</p><p>{{ _('Interestingly, infants are relatively similar microbially regardless of where they were born. But, as individuals age, it seems like their microbiomes reflect regional or population differences.') }}</p>"}
};
function getMicrobiomeMapsRasterizedPlots(state) {
if(state.dataset_type.value === 'WGS') {
var pcoa_plots = ['tmi_WGS_gut_multipop', 'tmi_WGS_gut_lifestage'];
} else {
var pcoa_plots = ['tmi_16S_gut_all_samples', 'tmi_16S_gut_multipop', 'tmi_16S_gut_lifestage', 'tmi_16S_gut_builtenv'];
}
for (var key of pcoa_plots) {
let detail = pcoa_structure[key];
let url = state.public_endpoint +
'/dataset/' +
detail['dataset'] +
'/plotting/diversity/beta/' +
state.beta_metric +
'/pcoa/full-dataset/' +
'png?category=' +
detail['category'] +
'&sample_id=' +
state.barcode_prefix +
state.sample_id;
placeURLSourcedImageFromDetail(state, url, detail);
}
setupAccordions();
};
function datasets_span(label_text, span_id) {
var div = document.getElementById('datasets-used');
var label = document.createElement('h5');
label.innerText = label_text;
var list = document.createElement('ul');
var span = document.createElement('span');
span.id = span_id.substring(1);
span.classList.add('info-loader');
span.classList.add('text-success');
div.appendChild(label);
div.appendChild(list);
list.appendChild(span);
div.appendChild(document.createElement('br'));
}
function addDatasetDetail(detail) {
let name = Object.keys(detail)[0];
let info = detail[name];
let span_id = "";
let label = "";
// Qiita doesn't provide an easy way to obtain this detail
// soo... not ideal but let's provide a way to get study
// links for various datasets
let study_lookup = {'10317': ["American Gut: an Open Platform for Citizen Science Microbiome Research",
"https://msystems.asm.org/content/3/3/e00031-18"],
"850": ["Human gut microbiome viewed across age and geography",
"https://www.nature.com/articles/nature11053"],
"10297": ["Growth and Morbidity of Gambian Infants are Influenced by Maternal Milk Oligosaccharides and Infant Gut Microbiota",
"https://www.nature.com/articles/srep40466"],
"10080": ["The Fecal Microbial Community of Breast-fed Infants from Armenia and Georgia", "https://www.ncbi.nlm.nih.gov/pmc/articles/PMC5288704/"],
"10300": ["The Fecal Microbial Community of Breast-fed Infants from Armenia and Georgia", "https://www.ncbi.nlm.nih.gov/pmc/articles/PMC5288704/"],
"11076": ["Rapid change of fecal microbiome and disappearance of Clostridium difficile in a colonized infant after transition from breast milk to cow milk", "https://microbiomejournal.biomedcentral.com/articles/10.1186/s40168-016-0198-6"],
"11884": ["Natural history of the infant gut microbiome and impact of antibiotic treatment on bacterial strain diversity and stability", "https://stm.sciencemag.org/content/8/343/343ra81"],
"1454": ["Persistent gut microbiota immaturity in malnourished Bangladeshi children", "https://www.nature.com/articles/nature13421"],
"10249": ["Antibiotics, birth mode, and diet shape microbiome maturation during early life", "https://stm.sciencemag.org/content/8/343/343ra82"],
"11937": ["Gut Microbiota in the First 2 Years of Life and the Association with Body Mass Index at Age 12 in a Norwegian Birth Cohort", "https://mbio.asm.org/content/9/5/e01751-18"],
"10333": ["Walls talk: Microbial biogeography of homes spanning urbanization", "https://advances.sciencemag.org/content/2/2/e1501061"],
"10423": ["Geography and location are the primary drivers of office microbiome composition", "https://msystems.asm.org/content/1/2/e00022-16"],
"11358": ["Seasonal cycling in the gut microbiome of the Hadza hunter-gatherers of Tanzania", "https://science.sciencemag.org/content/357/6353/802"],
"2024": ["Microbiota at Multiple Body Sites during Pregnancy in a Rural Tanzanian Population and Effects of Moringa-Supplemented Probiotic Yogurt", "https://aem.asm.org/content/81/15/4965"],
"11993": ["Gut microbiota is associated with obesity and cardiometabolic disease in a population in the midst of Westernization", "https://www.nature.com/articles/s41598-018-29687-x"],
"10581": ["Cohort of human mothers and babies from El Salvador ", "https://www.ebi.ac.uk/ena/browser/view/ERP112775"],
"10352": ["Comparison of Fecal Collection Methods for Microbiota Studies in Bangladesh", "https://aem.asm.org/content/83/10/e00361-17"],
"11757": ["Regional variation limits applications of healthy gut microbiome reference ranges and disease models", "https://www.nature.com/articles/s41591-018-0164-x"],
"1481": ["Whole-grain wheat consumption reduces inflammation in a randomized controlled trial on overweight and obese subjects with unhealthy dietary and lifestyle behaviors: role of polyphenols bound to cereal dietary fiber", "https://academic.oup.com/ajcn/article/101/2/251/4494380"],
"10052": ["The microbiome of uncontacted Amerindians", "https://advances.sciencemag.org/content/1/3/e1500183"],
"1448": ["Subsistence strategies in traditional societies distinguish gut microbiomes", "https://www.nature.com/articles/ncomms7505"],
"1718": ["Infant time series", ""],
"11666": ["Gut microbiome composition in the Hispanic Community Health Study/Study of Latinos is shaped by geographic relocation, environmental factors, and obesity", "https://pubmed.ncbi.nlm.nih.gov/31672155/"],
"12142": ["The National FINRISK Study ", "https://www.nature.com/articles/s41467-021-22962-y"],
"1926": ["Structure, function and diversity of the healthy human microbiome", "https://www.nature.com/articles/nature11234"],
"11484": ["Multi-omics of the gut microbial ecosystem in inflammatory bowel diseases", "https://pubmed.ncbi.nlm.nih.gov/31142855/"],
"11405": ["The effect of legume supplementation on the gut microbiota in rural Malawian infants aged 6 to 12 months ", "https://pubmed.ncbi.nlm.nih.gov/32047925/"]
}
switch (name) {
case "builtenv-16S-allsamples":
label = '{{ _('Microbiomes in the Environment') }}';
span_id = "#dataset_links_builtenv";
break;
case "tmi-16S-gut":
label = '{{ _('The Microsetta Initiative') }}';
span_id = "#dataset_links_tmi";
break;
case "multipop-16S-gut":
case "multipop-WGS-gut":
label = '{{ _('Microbiomes Across the World') }}';
span_id = "#dataset_links_multipopgut";
break;
case "lifestage-16S-gut":
case "lifestage-WGS-gut":
label = '{{ _('Microbiomes Across the Lifespan') }}';
span_id = "#dataset_links_lifestagegut";
break;
default:
return;
};
datasets_span(label, span_id);
let study_title = "";
let study_url = "";
let to_append = "";
for (var qiita_id of info['qiita-study-ids']) {
if(qiita_id in study_lookup) {
study_title = study_lookup[qiita_id][0];
study_url = study_lookup[qiita_id][1];
to_append = '<li><h6 style="margin-bottom: 0px;">' + study_title + '</h6>'; //<span>' + study_title + '</span>';
if(study_url !== "") {
to_append = to_append + '<a href="' + study_url + '">{{ _('Publication link') }}</a><br />';
}
to_append = to_append + '<a href="https://qiita.ucsd.edu/public/?study_id=' + qiita_id + '">{{ _('Data access (Qiita study') }} ' + qiita_id + ')</a>';
to_append = to_append + '</li>';
$(span_id).append(to_append).removeClass("spinner-grow spinner-grow-sm");
}
}
//$(span_id).append('<li><h6>' + study_title + '</h6><br /><span>' + study_title + '</span>
//$(span_id).append('<li><a href="https://qiita.ucsd.edu/public/?study_id=' + qiita_id + '">Qiita Study: ' + qiita_id + '</li>').removeClass("spinner-grow spinner-grow-sm");
//if (detail['qiita-study-ids'].length > 1)
// $("#dataset_meta_analysis").text(" (which was a meta analysis that combines the data you helped collect with other public microbiome results)").removeClass("spinner-grow spinner-grow-sm");
//else
// $("#dataset_meta_analysis").text("").removeClass("spinner-grow spinner-grow-sm")
}
function refreshDatasets(state) {
let url = state.public_endpoint + '/sample/list/dataset/' + state.barcode_prefix + state.sample_id;
$.ajax({
url: url,
type: "GET",
success: function(data)
{
for (var i = 0; i < data.length; i++) {
$.ajax({
url: state.public_endpoint + "/dataset/" + data[i],
type: "GET",
success: function (detail) {
addDatasetDetail(detail);
}
});
}
var have_wgs = false;
var have_16S = false;
for (var i = 0; i < data.length; i++) {
if(data[i] === 'tmi-WGS-gut') {
have_wgs = true;
} else if(data[i] === 'tmi-16S-gut') {
have_16S = true;
}
}
if(!have_wgs && !have_16S) {
state.dataset_type.value = null
// error gracefully somehow?
} else if(have_wgs) {
state.dataset_type.value = 'WGS';
state.dataset_site.value = 'gut';
state.dataset_input.value = 'tmi-WGS-gut';
} else {
state.dataset_type.value = '16S';
state.dataset_site.value = 'gut';
state.dataset_input.value = 'tmi-16S-gut';
}
}
});
}
function populateSelect(select_selector, value_to_text, active_value){
let select = $(select_selector);
select.empty();
for (let v in value_to_text)
{
let option = $('<option></option>')
.attr("value", v)
.text(v);
// .text(value_to_text[v]); //It should be this, but public api needs to send down friendly names
if (v === active_value)
option.attr('selected','selected');
select.append(option);
}
select.prop("disabled", false);
}
function createTaxonomyTable(state)
{
$('#taxonomyTable').DataTable(
{
destroy: true, // Necessary to replace existing datatable
language: {
url: '/static/vendor/DataTables/{{ _(EN_US_KEY) }}.json'
},
ajax: {
url: state.public_endpoint + '/dataset/' + state.dataset_input.value + "/taxonomy/present/single/" + state.taxonomy + "/" + state.barcode_prefix + state.sample_id,
dataSrc: function(d){
let representatives = {};
let generaSums = {};
//Collapse to genera (Don't show separate rows per species)
for (let i = 0; i < d.data.length; i++){
//Can't just key by genus because genus can be null/undefined. Argh.
let genus_key = d.data[i].Kingdom + ";" +
d.data[i].Phylum + ";" +
d.data[i].Class + ";" +
d.data[i].Order + ";" +
d.data[i].Family + ";" +
d.data[i].Genus;
if (genus_key in generaSums)
{
generaSums[genus_key] += d.data[i].relativeAbundance;
}
else
{
representatives[genus_key] = d.data[i];
generaSums[genus_key] = d.data[i].relativeAbundance;
}
}
let newData = [];
for (let genus_key in generaSums){
let rep = representatives[genus_key];
let sum = generaSums[genus_key];
let relativeAbundance = (sum * 100)
if (relativeAbundance <= 0.001) {
continue;
}
rep.relativeAbundance = relativeAbundance.toFixed(3);
for (var key of ["Kingdom", "Phylum", "Class", "Order", "Family", "Genus"]){
if (rep[key] != null && rep[key].startsWith("[") && rep[key].endsWith("]"))
rep[key] = rep[key].substring(1,rep[key].length-1)
}
newData.push(rep);
}
return newData;
},
},
columns: [
{
data: "relativeAbundance",
render: $.fn.dataTable.render.percentBar('round','#FFF', '#269ABC', '#31B0D5', '#286090', 3, 'groove')
},
{data: "Kingdom"},
{data: "Phylum"},
{data: "Class"},
{data: "Order"},
{data: "Family"},
{data: "Genus"},
],
order: [[ 0, "desc" ]],
dom: "Bfrtip",
buttons: [{extend: 'csv', className: 'btn btn-info', text: '{{ _('Download the spreadsheet') }}'}],
initComplete: function(settings) {
$('#taxonomyTable thead th').each(function () {
let $td = $(this);
let value = $td.text();
switch (value) {
case "Kingdom":
value = "{{ _('The broadest classification like Bacteria, Archaea and Eukaryokes (what humans are!)') }}";
break;
case "Phylum":
value = "{{ _('Within the kingdom Eukarya, this is like the difference between humans and plants') }}";
break;
case "Class":
value = "{{ _('Within the phylum Chordata, this is along the lines of humans and fish') }}";
break;
case "Order":
value = "{{ _('Within the class Mammalia, this is like the difference between whales and a dogs') }}";
break;
case "Family":
value = "{{ _('With the order Carnivora are the families for dogs and cats') }}";
break;
case "Genus":
value = "{{ _('Within the family Canidae, you would find a genus for foxes and one for wolves') }}";
break;
default:
value = "";
break;
}
$td.attr('title', value);
});
/* Apply the tooltips */
$('#taxonomyTable thead th[title]').tooltip(
{
container: 'body',
placement: 'auto'
});
}
}
);
}
function retrieveNeighbors(state, k){
let url = state.public_endpoint + '/dataset/' + state.dataset_input.value + '/diversity/beta/' + state.beta_metric + '/nearest';
return $.ajax({
method: "GET",
url: url,
data: {
sample_id: state.barcode_prefix + state.sample_id,
k:k
}
}).fail(function(result, textStatus, errorThrown){
console.log("Couldn't retrieve neighbors" + textStatus)
});
}
function fillNNResults(state, categories, chooserMap, selectorMap) {
return function(samplesQueried, sampleResults) {
// Count number of responses for each answer of each question
let categoryCounts = {}
let display = {}
for (let i = 0; i < samplesQueried.length; i++) {
for (let j = 0; j < categories.length; j++) {
let cat = categories[j]
if (!(cat in categoryCounts))
categoryCounts[cat] = {}
let val = sampleResults[i][j]
if (!(val in categoryCounts[cat]))
categoryCounts[cat][val] = 0
categoryCounts[cat][val] += 1
}
}
for (let j = 0; j < categories.length; j++){
let cat = categories[j]
let sum = 0
let maxval = -1
let maxkey = null
for (let key in categoryCounts[cat]) {
let val = categoryCounts[cat][key]
sum += val
if (key !== "Not provided" && val > maxval) {
maxval = val
maxkey = key
}
}
let me = samplesQueried.indexOf(state.barcode_prefix + state.sample_id);
let my_cat = categories.indexOf(cat);
let my_value = sampleResults[me][my_cat];
let set_color = null;
let chosen = null
if (!(cat in chooserMap) || chooserMap[cat]["type"] === "max") {
chosen = maxkey
if(chosen === my_value) {
set_color = 'similarity-fontstyle-same';
} else {
set_color = 'similarity-fontstyle-different';
}
}
else if (chooserMap[cat]["type"] === "specified")
chosen = chooserMap[cat]["value"]
else if (chooserMap[cat]["type"] === "same") {
me = samplesQueried.indexOf(state.barcode_prefix + state.sample_id)
j = categories.indexOf(cat)
chosen = sampleResults[me][j]
}
display[cat] = {}
if(chosen in dynamic_text_dictionary) {
display[cat]["response"] = dynamic_text_dictionary[chosen];
} else {
display[cat]["response"] = chosen;
}
display[cat]["value"] = Math.round((categoryCounts[cat][chosen] / sum) * 100) + "%"
display[cat]["color"] = set_color;
}
for (let cat of categories) {
if (!(cat in selectorMap))
continue;
let resp_selector = selectorMap[cat][0]
let val_selector = selectorMap[cat][1]
let resp = display[cat]["response"]
let val = display[cat]["value"]
let color = display[cat]["color"]
$(val_selector).text(val).removeClass("spinner-grow spinner-grow-sm");
if(color !== null) {
$(resp_selector).text(resp).removeClass("spinner-grow spinner-grow-sm text-success").addClass(color);
} else {
$(resp_selector).text(resp).removeClass("spinner-grow spinner-grow-sm");
}
}
}
}
function queryNeighborAndSelfMetadata(state, metadata_cats){
return function(result, textStatus, jqXHR)
{
let toQuery = result;
toQuery.push(state.barcode_prefix + state.sample_id);
return $.ajax(
{
method: "POST",
url: state.public_endpoint + '/dataset/' + state.dataset_input.value + "/metadata/values?" + $.param({ cat: metadata_cats }, true), // The true indicates traditional mode, which produces cat=blah&cat=blah rather than cat[]=blah&cat[]=blah which crashes the server.
data: JSON.stringify(toQuery),
contentType: "application/json"
}).fail(function(result, textStatus, errorThrown){
console.log("Couldn't retrieve metadata for neighbors and self " + errorThrown)
}).then(function(result, textStatus, jqXHR){
let thenner = {};
thenner.then = function(func){
// Need to pass on the sample ids. Argh.
return func(toQuery, result);
};
return thenner;
});
};
}
function updateCompare(state){
// Reset all the fields to spinners
$(".info-loader").empty().addClass("spinner-grow spinner-grow-sm");
// Stuff to fill in:
// sample_type, n_bacteria, n_archaea, dataset_name,
// n_bacteria_background, n_archaea_background,
// age_nearest_neighbor, more_or_less_sweets_nearest_neighbor
function retrieveText(method, url, data){
return $.ajax({
method: method,
url: url,
data: JSON.stringify(data),
contentType: "application/json"
}).fail(function(result, textStatus, errorThrown){
console.log("Couldn't retrieve text for " + method + " " + url);
});
}
function setInfoText(resultSelector){
return function(result, textStatus, jqXHR){
return $(resultSelector).text(result).removeClass("spinner-grow spinner-grow-sm");
};
}
function fillResults(state, selectors)
{
return function(samplesQueried, sampleResults)
{
// First selector, age, Second selector, sweets
// No similarity between the two, so we just have to handle both
let me = samplesQueried.pop();
let my_data = sampleResults.pop();
if (me !== (state.barcode_prefix + state.sample_id))
console.log("Bad call to fill results, sample id mismatch");
for (let selector_index = 0; selector_index < selectors.length; selector_index++)
{
if (selectors[selector_index] === "#age_nearest_neighbor")
{
// Find age of first neighbor with age
let nearest_age = "{{ _('Unspecified') }}";
for (let i = 0; i < samplesQueried.length; i++)
{
if (sampleResults[i][selector_index] !== "{{ _('Unspecified') }}")
{
nearest_age = Math.round(sampleResults[i][selector_index]);
break;
}
}
if (nearest_age === "{{ _('Unspecified') }}")
setInfoText(selectors[selector_index])("{{ _('chose not to provide their age') }}", null, null);
else
setInfoText(selectors[selector_index])("{{ _('is') }} " + nearest_age + " {{ _('years old') }}", null, null);
}
if (selectors[selector_index] === "#more_or_less_sweets_nearest_neighbor")
{
// Find string value for first neighbor with a string value
let nearest_sweets = "{{ _('Unspecified') }}";
for (let i = 0; i < samplesQueried.length; i++)
{
if (sampleResults[i][selector_index] !== "{{ _('Unspecified') }}" &&
sampleResults[i][selector_index] !== "{{ _('Not provided') }}")
{
nearest_sweets = sampleResults[i][selector_index];
break;
}
}
// Comparing metadata is an absolute nightmare.
let possible_values = {
"{{ _('Unspecified') }}" : NaN,
"{{ _('Not provided') }}" : NaN,
"{{ _('Never') }}" : 0,
"{{ _('Rarely (less than once/week)') }}" : 1,
"{{ _('Occasionally (1-2 times/week)') }}" : 2,
"{{ _('Regularly (3-5 times/week)') }}" : 3,
"{{ _('Daily') }}": 4
}
let my_sweets = possible_values[my_data[selector_index]];
let their_sweets = possible_values[nearest_sweets];
let info_text = "";
if (isNaN(my_sweets)){
if (isNaN(their_sweets))
info_text = "{{ _('chose not to say how many sweets they eat') }}";
else
info_text = nearest_sweets.toLowerCase() + " {{ _('eats sweets') }}";
}
else{
if (my_sweets < their_sweets)
info_text = "{{ _('eats more sugary sweets than you') }}";
else if (my_sweets > their_sweets)
info_text = "{{ _('eats fewer sugary sweets than you') }}";
else if (my_sweets === their_sweets)
info_text = "{{ _('eats about the same number of sugary sweets as you') }}";
else
info_text = "{{ _('chose not to say how many sweets they eat') }}";
}
setInfoText(selectors[selector_index])(info_text, null, null);
}
}
}
}
$("#sample_type").text(state.sample_type).removeClass("spinner-grow spinner-grow-sm");
$("#dataset_name").text(state.dataset_input.value).removeClass("spinner-grow spinner-grow-sm");
// TODO: Fill in these URLs
retrieveText("GET", state.public_endpoint + "/dataset/" + state.dataset_input.value + "/taxonomy/single/" + state.taxonomy + "/" + state.barcode_prefix + state.sample_id + "/counts?level=Kingdom", null).then(
function(result, textStatus, jqXHR){
$("#n_bacteria").text(result["Bacteria"].toLocaleString()).addClass("microbe-count").removeClass("spinner-grow spinner-grow-sm");
$("#n_archaea").text(result["Archaea"].toLocaleString()).addClass("microbe-count").removeClass("spinner-grow spinner-grow-sm");
});
retrieveText(
"POST",
state.public_endpoint + "/dataset/" + state.dataset_input.value + "/taxonomy/group/" + state.taxonomy + "/counts?level=Kingdom",
{"sample_ids":[]}
).then(
function(result, textStatus, jqXHR){
$("#n_bacteria_background").text(result["Bacteria"].toLocaleString()).addClass("microbe-count").removeClass("spinner-grow spinner-grow-sm");
$("#n_archaea_background").text(result["Archaea"].toLocaleString()).addClass("microbe-count").removeClass("spinner-grow spinner-grow-sm");
});
retrieveNeighbors(state, 1)
.then(queryNeighborAndSelfMetadata(state, ["age_years", "sugary_sweets_frequency"]))
.then(fillResults(state, ["#age_nearest_neighbor", "#more_or_less_sweets_nearest_neighbor"]));
}
function updateDiversity(state){
//https://www-dev.ucsd.edu/results-api/diversity/alpha/group/faith_pd?summary_statistics=true
const more_than_30_plants =
{
"metadata_query":
{
"condition": "OR",
"rules": [
{
"id": "types_of_plants",
"operator": "equal",
"value": "More than 30"
}
]
}
};
const water_frequency =
{
"metadata_query":
{
"condition": "OR",
"rules": [
{
"id": "one_liter_of_water_a_day_frequency",
"operator": "equal",
"value": "Regularly (3-5 times/week)"
}
]
}
};
const exercise_regularly =
{
"metadata_query":
{
"condition": "OR",
"rules": [
{
"id": "exercise_frequency",
"operator": "equal",
"value": "Regularly (3-5 times/week)"
}
]
}
};
//I wish we had ordered categorical variables because this query is stupid
const sleep_more_than_6_hrs =
{
"metadata_query":
{
"condition": "OR",
"rules": [
{
"id": "sleep_duration",
"operator": "equal",
"value": "6-7 hours"
},
{
"id": "sleep_duration",
"operator": "equal",
"value": "7-8 hours"
},
{
"id": "sleep_duration",
"operator": "equal",
"value": "8 or more hours"
}
]
}
}
const POST_DATA = {
"plants": more_than_30_plants,
"water": water_frequency,
"exercise": exercise_regularly,
"sleep": sleep_more_than_6_hrs
}
const SELECTORS = {