-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadd_psa_interface.js
156 lines (145 loc) · 5.21 KB
/
add_psa_interface.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
"use strict";
var add_asa_residues = require('./add_asa_residues');
var add_binding_residues = require('./add_binding_residues');
var highlight_all = require('./highlight_all');
var add_molprobity = require('./add_molprobity');
var add_highlight_all = highlight_all.add_highlight_all;
var add_psa_interface = function(){
var $LOG = { 'protein':{}, 'gene':{}, 'interaction:':{} };
if(top.$LOG){
$LOG = top.$LOG;
}
var alignment = JSON.parse(getParameterByName("alignment"));
var pdb = alignment['pdb'];
if(!pdb){
console.log("%c /compute/biopython/interface/<PDB> PDB code is null", 'color:red;');
$LOG.protein['psa'] = {
'description':'Computing ASA and binding sites data',
'command':'GET '+interface_url,
'status':'error',
'error': '/compute/biopython/interface/<PDB> PDB code is null',
'cost':'NA'
};
console.log("%c /compute/molprobity/<PDB> PDB code is null", 'color:red;');
$LOG.protein['molprobity'] = {
'description':'Computing ASA and binding sites data',
'command':'GET '+interface_url,
'status':'error',
'error': '/compute/molprobity/<PDB> PDB code is null',
'cost':'NA'
};
if("n_sources" in $LOG.protein){
$LOG.protein['n_sources']-=2;
if($LOG.protein['n_sources']==0)remove_loading_icon();
}
return;
}
var path = null;
if('path' in alignment){
path = alignment['path'];
}
if( top.$COMPUTED_FEATURES[pdb] ){
top.binding_residues = top.$COMPUTED_FEATURES[pdb]['binding_residues'];
top.asa_residues = top.$COMPUTED_FEATURES[pdb]['asa_residues'];
var asa = add_asa_residues();
var bs = add_binding_residues();
if(bs){
feature_viewer.drawCategories([asa,bs],feature_viewer);
feature_viewer.data.push(asa);
feature_viewer.data.push(bs);
}else{
feature_viewer.drawCategories([asa],feature_viewer);
feature_viewer.data.push(asa);
}
if("n_sources" in $LOG.protein){
$LOG.protein['n_sources']--;
if($LOG.protein['n_sources']==0)remove_loading_icon();
}
add_highlight_all();
if( top.$COMPUTED_FEATURES[pdb]['molprobity'] ){
add_molprobity();
}else{
if("n_sources" in $LOG.protein){
$LOG.protein['n_sources']--;
if($LOG.protein['n_sources']==0)remove_loading_icon();
}
}
}else{
var interface_url = "/compute/biopython/interface/"+pdb;
$LOG.protein['psa'] = {
'description':'Computing ASA and binding sites data',
'command':'GET '+interface_url,
'status':'running'
};
if(path){
interface_url = "/compute/biopython/interface/"+path+"/"+pdb.replace(/\./g,"__");
}
interface_url = encodeURI(interface_url);
console.log("%c Loading "+interface_url, 'color:#c60;');
var t1 = performance.now();
$j.ajax({
url: interface_url,
dataType: 'json',
success: function(data){
if(!top.$COMPUTED_FEATURES[pdb])top.$COMPUTED_FEATURES[pdb] = {};
if("error" in data){
top.binding_residues = null;
top.asa_residues = null;
$LOG.protein['psa']['status'] = 'error';
var t2 = performance.now();
var time_ = (t2-t1)/1000;
console.log("%c Finished "+interface_url+" "+time_.toString().substring(0,4)+"s", 'color:red;');
return;
}
top.binding_residues = data['interface'];
top.$COMPUTED_FEATURES[pdb]['binding_residues'] = top.binding_residues;
top.asa_residues = data['asa'];
top.$COMPUTED_FEATURES[pdb]['asa_residues'] = top.asa_residues;
top.rri_residues = data['rri'];
top.$COMPUTED_FEATURES[pdb]['rri'] = data['rri'];
var asa = add_asa_residues();
var bs = add_binding_residues();
if(bs){
feature_viewer.drawCategories([asa,bs],feature_viewer);
feature_viewer.data.push(asa);
feature_viewer.data.push(bs);
}else{
feature_viewer.drawCategories([asa],feature_viewer);
feature_viewer.data.push(asa);
}
add_highlight_all();
$LOG.protein['psa']['status'] = 'success';
},
error: function(){
top.binding_residues = null;
top.asa_residues = null;
$LOG.protein['psa']['status'] = 'error';
}
}).always(function(){
var t2 = performance.now();
var time_ = (t2-t1)/1000;
if($LOG.protein['psa']['status'] == 'success')console.log("%c Finished "+interface_url+" "+time_.toString().substring(0,4)+"s", 'color:green;');
$LOG.protein['psa']['cost'] = time_.toString().substring(0,4);
if("n_sources" in $LOG.protein){
$LOG.protein['n_sources']--;
if($LOG.protein['n_sources']==0)remove_loading_icon();
}
add_molprobity();
});
}
};
function remove_loading_icon(){
$j("#annotations_loading_icon").remove();
}
function getParameterByName(name, url) {
if (!url) {
url = window.location.href;
}
name = name.replace(/[\[\]]/g, "\\$&");
var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
results = regex.exec(url);
if (!results) return null;
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, " "));
}
module.exports = add_psa_interface;