-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathrenderer.js
1169 lines (1065 loc) · 33.2 KB
/
renderer.js
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
const loadJsonFile = require('load-json-file');
const ipcRenderer = require('electron').ipcRenderer;
const clipboard = require('electron').clipboard;
const {
app
} = require('electron').remote;
window.$ = window.jQuery = require('jquery');
require('datatables.net')(window, $);
require('./assets/js/ellipsis.js');
window.Bootstrap = require('bootstrap');
require('./assets/js/jquery.flexdatalist.min.js');
var ProtVista = require('ProtVista');
var speciesObj = null;
var expObj = null;
var xmlParser = new DOMParser();
var currentHit = null;
var species = [];
var hitsTable;
var expTable;
var diseaseTable;
var idMap = {};
var hits;
var currentExp = null;
var basepath = app.getAppPath();
document.addEventListener('DOMContentLoaded', function(event) {
retrieveSpeciesJSON();
retrieveExpList();
ipcRenderer.send('loaded');
// Listen for command to read from clipboard.
ipcRenderer.on('queryFromClipboard', function(event, clipboardContents) {
document.getElementById('query').value = clipboardContents;
newQuery(clipboardContents);
});
// Used for tooltip to tell user text has been copied to clipboard.
$('.text').tooltip({
trigger: 'click',
placement: 'top',
title: 'Copied!',
delay: {
show: 0,
hide: 500
}
});
// Help tooltip functionality.
$('[data-toggle="tooltip"]').tooltip({
placement: 'top',
delay: {
show: 300,
hide: 300
}
});
function hideTooltip(x) {
setTimeout(function() {
x.tooltip('hide');
}, 1000);
}
// Table initializations.
hitsTable = $('#hits-table').DataTable({
scrollY: '150px',
scrollX: false,
scrollCollapse: true,
paging: false,
language: {
'search': 'Search Hits:'
},
columns: [{
title: 'Symbol'
}, {
title: 'ID'
}, {
title: 'Species'
}, {
title: 'Score'
}],
order: [
[3, 'desc']
],
columnDefs: [{
targets: 1,
render: $.fn.dataTable.render.ellipsis(9)
}]
});
expTable = $('#exp-table').DataTable({
scrollY: '150px',
scrollX: false,
scrollCollapse: true,
paging: false,
language: {
'search': 'Search Experiments:'
},
columns: [{
title: 'ID',
width: '20%'
}, {
title: 'Description'
}, {
title: 'Type'
}]
});
diseaseTable = $('#disease-table').DataTable({
scrollY: '150px',
scrollX: false,
scrollCollapse: true,
paging: false,
columns: [{
title: 'Disease'
}, {
title: 'Disease ID'
}, {
title: 'PubMed/OMIM IDs'
}, {
title: 'CTDbase'
}]
});
// Handle switching which hit is displayed.
document.querySelector('#hits-table tbody').addEventListener('click',
function(event) {
var td = event.target;
var tbl = document.getElementById('hits-table');
while (td !== this && !td.matches('td')) {
td = td.parentNode;
}
if (td === this) {
console.log('No table cell found');
} else {
// Use row and cell indices to get the hit data for row clicked on.
var row = td.parentNode.rowIndex;
var hitID = tbl.rows[row].cells[1].innerHTML;
// Deal with possible ellipses in content.
if (hitID.includes('span')) {
var s = $(hitID);
hitID = s[0].title;
}
parseGeneData(hits[idMap[hitID]]).then(function(results) {
displayData(results);
});
}
});
// Handle switching which expression experiment is displayed.
document.querySelector('#exp-table tbody').addEventListener('click',
function(event) {
var td = event.target;
var tbl = document.getElementById('exp-table');
while (td !== this && !td.matches('td')) {
td = td.parentNode;
}
if (td === this) {
console.log('No table cell found');
} else {
// Use row and cell indices to get the hit data for row clicked on.
var row = td.parentNode.rowIndex;
var hitID = tbl.rows[row].cells[0].innerHTML;
currentExp = {
species: currentHit.species,
experiment: hitID
};
renderSingleExperiment(hitID);
}
});
// Species search input setup.
$('.flexdatalist').flexdatalist({
minLength: 1,
searchIn: 'name',
textProperty: 'name',
valueProperty: 'id',
data: 'species_search.json'
});
$('.flexdatalist').on('change:flexdatalist', function() {
species = $('.flexdatalist').flexdatalist('value');
});
// Ensure tables are properly adjusted on window resize.
window.onresize = function() {
hitsTable.columns.adjust().draw();
expTable.columns.adjust().draw();
}
// Reset expression widget to default view on button press.
document.querySelector('#reset-button').addEventListener('click',
function() {
renderExpression([currentHit.ensembl, currentHit.species], true);
});
// Used for header collapse.
$('#summary-div').on('hide.bs.collapse', function() {
$('#function-header').html(
'<span class="glyphicon glyphicon-collapse-down"></span>Function'
);
});
$('#summary-div').on('show.bs.collapse', function() {
$('#function-header').html(
'<span class="glyphicon glyphicon-collapse-up"></span>Function'
);
});
$('#basics').on('hide.bs.collapse', function() {
$('#basics-header').html(
'<span class="glyphicon glyphicon-collapse-down"></span>Gene Basics'
);
});
$('#basics').on('show.bs.collapse', function() {
$('#basics-header').html(
'<span class="glyphicon glyphicon-collapse-up"></span>Gene Basics'
);
});
$('#accessions').on('hide.bs.collapse', function() {
$('#accessions-header').html(
'<span class="glyphicon glyphicon-collapse-down"></span>Accessions'
);
});
$('#accessions').on('show.bs.collapse', function() {
$('#accessions-header').html(
'<span class="glyphicon glyphicon-collapse-up"></span>Accessions'
);
});
$('#expression').on('hide.bs.collapse', function() {
$('#expression-header').html(
'<span class="glyphicon glyphicon-collapse-down"></span>Expression'
);
expTable.columns.adjust().draw();
});
$('#expression').on('show.bs.collapse', function() {
$('#expression-header').html(
'<span class="glyphicon glyphicon-collapse-up"></span>Expression'
);
expTable.columns.adjust().draw();
});
$('#protein').on('hide.bs.collapse', function() {
$('#protein-header').html(
'<span class="glyphicon glyphicon-collapse-down"></span>Protein Viewer'
);
});
$('#protein').on('show.bs.collapse', function() {
$('#protein-header').html(
'<span class="glyphicon glyphicon-collapse-up"></span>Protein Viewer'
);
});
$('#diseases').on('hide.bs.collapse', function() {
$('#diseases-header').html(
'<span class="glyphicon glyphicon-collapse-down"></span>Disease Associations'
);
diseaseTable.columns.adjust().draw();
});
$('#diseases').on('show.bs.collapse', function() {
$('#diseases-header').html(
'<span class="glyphicon glyphicon-collapse-up"></span>Disease Associations'
);
diseaseTable.columns.adjust().draw();
});
// Copies a clicked div element text to the clipboard.
var copyToClipboard = function() {
var pop = $(this);
var text = this.textContent;
clipboard.writeText(text);
$(this).tooltip('show');
hideTooltip($(this));
};
var textDivs = document.getElementsByClassName('text');
for (var i = 0; i < textDivs.length; i++) {
textDivs[i].addEventListener('click', copyToClipboard, false);
}
// Listen for search button click or enter key press to initiate query.
document.getElementById('search-button').addEventListener('click',
newQuery);
document.getElementById('query').addEventListener('keypress', function(e) {
var key = e.which || e.keyCode;
if (key === 13) {
newQuery(term = document.getElementById('query').value);
}
});
});
// Grab the JSON file with species/TaxID mappings.
function retrieveSpeciesJSON() {
loadJsonFile(basepath + '/species.json').then(function(json) {
speciesObj = json;
});
}
// Grab the list of all expression experiments.
function retrieveExpList() {
$.getJSON('https://www.ebi.ac.uk/gxa/json/experiments', function(data) {
expObj = data.aaData;
});
}
function newQuery(term = null) {
if (speciesObj === null) {
return;
}
// Check if no term was passed and pull it from the input value if so.
// Also does an ugly check to make sure click event itself isn't passed as the term if
// search button used.
if (term == null || term instanceof MouseEvent) {
term = document.getElementById('query').value;
}
var queryUrl = 'https://mygene.info/v3/query?q=' + term +
'&fields=all&size=1000';
var querySpecies = '';
if (species.length > 0) {
querySpecies = species[0]
for (var i = 1; i < species.length; i++) {
querySpecies = querySpecies + '%2C' + species[i]
}
queryUrl = 'https://mygene.info/v3/query?q=' + term + '&species=' +
querySpecies + '&fields=all&size=1000';
}
fetch(queryUrl).then(function(response) {
if (response.status !== 200) {
console.log('Fetch Query Error. Status Code: ' + response.status);
return;
}
response.json().then(function(data) {
console.log(data);
if (data.total !== 0 && data.success !== false) {
hits = data.hits;
topHit = hits[0];
for (var i = 0; i < hits.length; i++) {
idMap[hits[i]._id] = i;
};
var basics = {
'hits': hits.length
};
// Display all info for the top hit.
displayData(basics);
displayHits(data);
displayHeadings();
parseGeneData(topHit).then(function(topHit) {
displayData(topHit);
});
} else {
// Empty hits list.
$('#hitbody').empty();
var empty = {
'hits': 'No hits',
'match-score': 0
};
// Wipe the rest of the fields.
displayData(empty);
hideData(document.getElementById('info-div'));
hideData(document.getElementById('loc-div'));
hideData(document.getElementById('summary-div'));
hideData(document.getElementById('expression'));
hideData(document.getElementById('protein'));
hideData(document.getElementById('diseases'));
hideData(document.getElementById('hits-div'));
hideData(document.getElementById('species-div'));
hideData(document.getElementById('db-div'));
hideData(document.getElementById('db2-div'));
hideHeadings();
}
});
})
.catch(function(err) {
console.error('Fetch Query Error', err);
});
}
// Adds all hits to the hit table.
function displayHits(hitsList) {
var dataSet = [];
hitsTable.clear();
for (i in hitsList.hits) {
var hit = hitsList.hits[i];
var spec = 'NA';
var symbol = 'NA';
// Check if species is in our list.
if (speciesObj[hit.taxid] !== undefined) {
spec = speciesObj[hit.taxid];
}
// Check if symbol is part of the hit.
if (hit.symbol !== undefined) {
symbol = hit.symbol;
}
dataSet.push([
symbol,
hit._id,
spec,
hit._score.toFixed(2)
]);
}
hitsTable.rows.add(
dataSet
).draw();
}
function renderExpression(data, reset) {
// Renders the interactive widget initially.
var targ = document.getElementById('highchartsContainer');
if (data[0] === null || data[1] === null) {
targ.innerHTML = 'No expression data available for this species.';
return;
};
var expGene = data[0].ident;
var expSpecies = data[1];
// Render previously selected experiment if top hit from new search is of same species.
// Much more convenient than continously going back and selecting the same experiment.
if (currentExp !== null && reset !== true) {
if (currentExp.species === data[1]) {
renderSingleExperiment(currentExp.experiment);
return;
}
}
expressionAtlasHeatmapHighcharts.render({
query: {
gene: expGene,
species: expSpecies,
},
target: targ,
disableGoogleAnalytics: true,
fail: function() {
targ.innerHTML = 'No expression data available for this species.'
}
});
// Creates the experiment table.
displayExpers();
}
// Display a single experiment chosen from the experiment list.
// Tries several different gene identifiers if ENSEMBL ID fails.
function renderSingleExperiment(expID) {
var targ = document.getElementById('highchartsContainer');
expressionAtlasHeatmapHighcharts.render({
experiment: expID,
query: {
gene: [{
'value': currentHit.ensembl.ident
}]
},
target: targ,
disableGoogleAnalytics: true,
fail: function() {
expressionAtlasHeatmapHighcharts.render({
experiment: expID,
query: {
gene: [{
'value': currentHit.uniprot.ident
}]
},
target: targ,
disableGoogleAnalytics: true,
fail: function() {
expressionAtlasHeatmapHighcharts.render({
experiment: expID,
query: {
gene: [{
'value': currentHit['gene-symbol']
}]
},
target: targ,
disableGoogleAnalytics: true,
fail: function() {
targ.innerHTML =
'No expression data available for this gene in this experiment.'
}
})
}
})
}
});
}
// Populate the expression experiment table.
function displayExpers() {
var dataSet = [];
expTable.clear();
for (i in expObj) {
var exper = expObj[i];
var exID = exper.experimentAccession;
var exDesc = exper.experimentDescription;
var exType;
if (exper.experimentType === 'MICROARRAY_ANY') {
exType = 'Microarray';
} else if (exper.experimentType === 'RNASEQ_MRNA_DIFFERENTIAL') {
exType = 'RNA-seq Differential'
} else {
exType = 'RNA-seq Baseline'
};
if (exper.species === currentHit.species) {
dataSet.push([
exID,
exDesc,
exType
]);
}
}
expTable.rows.add(
dataSet
).draw();
}
// Renders the ProtVista widget.
function renderProtein(data) {
var targ = document.getElementById('proteinContainer');
if (data[0] === null) {
targ.innerHTML = 'No data available for this protein.';
return;
};
//Snag only first Uniprot ID if multiple in array.
if (Array.isArray(data)) {
data = data[0]
};
var instance = new ProtVista({
el: targ,
uniprotacc: data
});
instance.getDispatcher().on("noDataAvailable", function(obj) {
targ.innerHTML = 'No data available for this protein.';
});
instance.getDispatcher().on("noDataRetrieved", function(obj) {
targ.innerHTML = 'No data available for this protein.';
});
}
// Display all text fields.
function displayData(dataObj) {
// dataObj is a single search hit with all gene info as a dict.
currentHit = dataObj;
for (data in dataObj) {
if (dataObj.hasOwnProperty(data) && dataObj[data]) {
// Check/call expression widget rendering.
var currentData = document.getElementById(data);
if (currentData.id === 'expression') {
currentData.classList.remove('hidden');
renderExpression(dataObj[data], false);
continue;
} else if (currentData.id === 'protein') {
currentData.classList.remove('hidden');
renderProtein(dataObj[data]);
continue;
} else if (currentData.id === "species" && dataObj[data].toLowerCase() ===
"homo sapiens") {
getCTDAssociations(dataObj['gene-id'].ident);
diseaseData = document.getElementById('diseases');
diseaseData.classList.remove('hidden');
currentData.classList.remove('hidden');
currentLabel = document.getElementById(data + '-label');
currentLabel.classList.remove('hidden');
} else if (currentData.id === "species" && dataObj[data].toLowerCase() !==
"homo sapiens") {
diseaseTable.clear().draw();
} else {
currentData.classList.remove('hidden');
currentLabel = document.getElementById(data + '-label');
currentLabel.classList.remove('hidden');
}
// Add new/remove old links and linebreaks from appropriate divs.
if (currentData.classList.contains('add-link')) {
var oldLinks = currentData.getElementsByTagName('a');
var oldBreaks = currentData.getElementsByTagName('br');
while (oldLinks.length > 0) {
oldLinks[0].parentNode.removeChild(oldLinks[0]);
}
while (oldBreaks.length > 0) {
oldBreaks[0].parentNode.removeChild(oldBreaks[0]);
}
var linkData = dataObj[data];
// Handle potential multiple links that needs to be added.
// And special cases like GO terms. Kind of messy.
if (linkData['ident'].constructor === Array) {
// Used to potentially check for redundant GO terms.
var old = [];
for (i in linkData['ident']) {
if (currentData.classList.contains('interpro')) {
var link = linkData['db'] + linkData['ident'][i].id;
var aTag = document.createElement('a');
aTag.setAttribute('href', link);
aTag.textContent = linkData['ident'][i].desc;
} else if (currentData.classList.contains('go')) {
// Skip redundant GO terms.
if (old.includes(linkData['ident'][i].term)) {
continue;
}
var link = linkData['db'] + linkData['ident'][i].id;
var aTag = document.createElement('a');
aTag.setAttribute('href', link);
aTag.textContent = linkData['ident'][i].term;
old.push(linkData['ident'][i].term);
} else {
var link = linkData['db'] + linkData['ident'][i];
var aTag = document.createElement('a');
aTag.setAttribute('href', link);
aTag.textContent = linkData['ident'][i];
}
var spacer = document.createElement('br');
currentData.appendChild(aTag);
currentData.appendChild(spacer);
}
} else {
if (currentData.classList.contains('go')) {
var link = linkData['db'] + linkData['ident'].id;
var aTag = document.createElement('a');
aTag.setAttribute('href', link);
aTag.textContent = linkData['ident'].term;
currentData.appendChild(aTag);
} else if (currentData.classList.contains('interpro')) {
var link = linkData['db'] + linkData['ident'].id;
var aTag = document.createElement('a');
aTag.setAttribute('href', link);
aTag.textContent = linkData['ident'].desc;
currentData.appendChild(aTag);
} else {
var link = linkData['db'] + linkData['ident'];
var aTag = document.createElement('a');
aTag.setAttribute('href', link);
aTag.textContent = linkData['ident'];
currentData.appendChild(aTag);
}
}
} else {
currentData.textContent = dataObj[data];
}
} else {
// Hide and clear any previous results.
currentData = document.getElementById(data);
if (currentData !== null && !currentData.classList.contains(
'hidden')) {
currentData.classList.add('hidden');
}
// Remove links of previous results.
if (currentData !== null && currentData.classList.contains(
'add-link')) {
var oldLinks = currentData.getElementsByTagName('a');
while (oldLinks.length > 0) {
oldLinks[0].parentNode.removeChild(oldLinks[0]);
}
}
// Hide labels too.
currentLabel = document.getElementById(data + '-label');
if (currentLabel !== null && !currentLabel.classList.contains(
'hidden')) {
currentLabel.classList.add('hidden');
}
}
}
}
// Hide all data in child nodes of given div element.
function hideData(divObj) {
var labels = divObj.querySelectorAll('label');
var links = divObj.querySelectorAll('a');
var i;
var textDivs = divObj.getElementsByClassName('text');
if (divObj.id === 'diseases') {
diseaseTable.clear().draw();
}
if (divObj.id === 'hits-div') {
hitsTable.clear().draw();
return;
}
// Handle the expression data.
if (divObj.id === 'expression' || divObj.id === 'protein') {
divObj.classList.add('hidden');
expTable.clear().draw();
return;
}
for (i = 0; i < labels.length; i++) {
var childData = labels[i];
if (!(childData.classList.contains('hidden'))) {
childData.classList.add('hidden');
}
}
for (i = 0; i < textDivs.length; i++) {
var childData = textDivs[i];
if (!(childData.classList.contains('hidden'))) {
childData.classList.add('hidden');
childData.textContent = '';
}
}
// Delete any links if necessary.
for (i = 0; i < links.length; i++) {
var childData = links[i];
childData.remove();
}
}
// Parses all gene data from a given hit into an Object.
function parseGeneData(data) {
return new Promise(function(resolve, reject) {
var aliases = null;
var hgnc = null;
var coords = null;
var hg19coords = null;
var mm9coords = null;
var names = null;
var uniprotSum = null;
var wiki = null;
var omim = null;
var ensembl = null;
var pfam = null;
var uniprot = null;
var protein = null;
var pharmgkb = null;
var expression = null;
var prosite = null;
var interpro = null;
var wormbaseSum = null;
var gobp = null;
var gomf = null;
var gocc = null;
var symbol = null;
if (data.hasOwnProperty('go')) {
if (data.go.hasOwnProperty('BP')) {
gobp = {
db: 'https://www.ebi.ac.uk/QuickGO/term/',
ident: data.go.BP
}
};
if (data.go.hasOwnProperty('MF')) {
gomf = {
db: 'https://www.ebi.ac.uk/QuickGO/term/',
ident: data.go.MF
}
};
if (data.go.hasOwnProperty('CC')) {
gocc = {
db: 'https://www.ebi.ac.uk/QuickGO/term/',
ident: data.go.CC
}
};
}
if (data.hasOwnProperty('HGNC')) {
hgnc = {
db: 'https://www.genenames.org/cgi-bin/gene_symbol_report?hgnc_id=',
ident: data.HGNC
};
}
if (data.hasOwnProperty('wikipedia')) {
wiki = {
db: 'https://en.wikipedia.org/wiki/',
ident: data.wikipedia['url_stub'].replace(/ /g, '_')
};
}
if (data.hasOwnProperty('MIM')) {
omim = {
db: 'http://omim.org/entry/',
ident: data.MIM
};
}
if (data.hasOwnProperty('ensembl')) {
if (data.ensembl.constructor === Array) {
ensembl = {
db: 'https://www.ensembl.org/Gene/Summary?g=',
ident: data.ensembl[0].gene
};
} else {
ensembl = {
db: 'https://www.ensembl.org/Gene/Summary?g=',
ident: data.ensembl['gene']
};
}
}
if (data.hasOwnProperty('pfam')) {
pfam = {
db: 'http://pfam.xfam.org/family/',
ident: data.pfam
};
}
if (data.hasOwnProperty('pharmgkb')) {
pharmgkb = {
db: 'https://www.pharmgkb.org/gene/',
ident: data.pharmgkb
};
}
if (data.hasOwnProperty('prosite')) {
prosite = {
db: 'https://prosite.expasy.org/',
ident: data.prosite
};
}
if (data.hasOwnProperty('interpro')) {
interpro = {
db: 'http://www.ebi.ac.uk/interpro/entry/',
ident: data.interpro
};
}
if (data.hasOwnProperty('alias')) {
if (typeof data.alias === 'string') {
aliases = data.alias;
} else {
aliases = data.alias.join(', ');
}
}
if (data.hasOwnProperty('genomic_pos')) {
if (data.genomic_pos.constructor === Array) {
coords = 'chr' + data.genomic_pos[0].chr + ':' + data.genomic_pos[
0]
.start +
'-' + data.genomic_pos[0].end;
} else {
coords = 'chr' + data.genomic_pos.chr + ':' + data.genomic_pos
.start +
'-' + data.genomic_pos.end;
}
}
if (data.hasOwnProperty('genomic_pos_hg19')) {
if (data.genomic_pos_hg19.constructor === Array) {
hg19coords = {
db: "http://genome.ucsc.edu/cgi-bin/hgTracks?org=human&db=hg19&position=",
ident: 'chr' + data.genomic_pos_hg19[0].chr + ':' + data.genomic_pos_hg19[
0]
.start + '-' + data.genomic_pos_hg19[0].end
};
} else {
hg19coords = {
db: "http://genome.ucsc.edu/cgi-bin/hgTracks?org=human&db=hg19&position=",
ident: 'chr' + data.genomic_pos_hg19.chr + ':' + data.genomic_pos_hg19
.start + '-' + data.genomic_pos_hg19.end
};
}
}
if (data.hasOwnProperty('genomic_pos_mm9')) {
if (data.genomic_pos_mm9.constructor === Array) {
mm9coords = {
db: "http://genome.ucsc.edu/cgi-bin/hgTracks?org=mouse&db=mm9&position=",
ident: 'chr' + data.genomic_pos_mm9[0].chr + ':' + data.genomic_pos_mm9[
0]
.start + '-' + data.genomic_pos_mm9[0].end
};
} else {
mm9coords = {
db: "http://genome.ucsc.edu/cgi-bin/hgTracks?org=mouse&db=mm9&position=",
ident: 'chr' + data.genomic_pos_mm9.chr + ':' + data.genomic_pos_mm9
.start + '-' + data.genomic_pos_mm9.end
};
}
}
if (data.hasOwnProperty('other_names') && typeof data.other_names ===
'string') {
names = data.other_names;
} else if (data.hasOwnProperty('other_names')) {
names = data.other_names.join(', ');
}
if (data.hasOwnProperty('WormBase')) {
wormbaseSum = getWormbaseSummary(data.WormBase);
}
if (data.hasOwnProperty('uniprot') && data.uniprot['Swiss-Prot'] !==
undefined) {
if (Array.isArray(data.uniprot['Swiss-Prot'])) {
uniprot = {
db: 'http://www.uniprot.org/uniprot/',
ident: data.uniprot['Swiss-Prot'][0]
};
} else {
uniprot = {
db: 'http://www.uniprot.org/uniprot/',
ident: data.uniprot['Swiss-Prot']
};
}
uniprotSum = getUniprotSummary(data.uniprot['Swiss-Prot']);
protein = data.uniprot['Swiss-Prot'];
}
if (data.hasOwnProperty('symbol') !== undefined) {
symbol = data.symbol;
} else {
symbol = "NA"
}
if (data.hasOwnProperty('WormBase') || data.hasOwnProperty(
'uniprot')) {
Promise.all([wormbaseSum, uniprotSum]).then(function(values) {
wormbaseSum = values[0];
uniprotSum = values[1];
// Resolve original promise.
resolve({
'entrez-summary': data.summary,
'alias': aliases,
'hgnc-id': hgnc,
'location': data.map_location,
'gen-pos': coords,
'19gen-pos': hg19coords,
'mm9gen-pos': mm9coords,
'tax-id': data.taxid,
'species': speciesObj[data.taxid],
'expression': [ensembl, speciesObj[data.taxid]],
'other-names': names,
'gene-type': data.type_of_gene,
'wikipedia': wiki,
'omim': omim,
'ensembl': ensembl,
'uniprot': uniprot,
'protein': protein,
'pfam': pfam,
'pharmgkb': pharmgkb,
'prosite': prosite,
'interpro': interpro,
'gobp': gobp,
'gomf': gomf,
'gocc': gocc,
'uniprot-summary': uniprotSum,
'wormbase-summary': wormbaseSum,
'gene-symbol': symbol,
'gene-name': data.name,
'gene-id': {
db: 'https://www.ncbi.nlm.nih.gov/gene/',
ident: data._id
},
'match-score': data._score
})
});
} else {
// Resolve original promise.
resolve({
'entrez-summary': data.summary,
'alias': aliases,
'hgnc-id': hgnc,
'location': data.map_location,
'gen-pos': coords,
'19gen-pos': hg19coords,
'mm9gen-pos': mm9coords,
'tax-id': data.taxid,
'species': speciesObj[data.taxid],
'expression': [ensembl, speciesObj[data.taxid]],
'other-names': names,
'gene-type': data.type_of_gene,
'wikipedia': wiki,
'omim': omim,
'ensembl': ensembl,
'uniprot': uniprot,
'protein': protein,
'pfam': pfam,
'pharmgkb': pharmgkb,
'prosite': prosite,
'interpro': interpro,
'gobp': gobp,
'gomf': gomf,
'gocc': gocc,
'uniprot-summary': uniprotSum,