PageSourceSearch

https://www.swissdock.ch/js/main/pdbSearch.js

js swissdock.ch collected 2026-10-03 19:08:46 UTC 8,523 bytes, 274 lines download raw bytes

1// -----------------------------------
2// functions to search in pdb
3// -----------------------------------
4
5function pdbSearch() { 
6
7  var database = document.getElementById('selectTargetDatabase').value;
8  var search = '';
9
10  if (database == 'pdbe') {
11    var title = document.getElementById('titlePDB').value;
12    var organism = document.getElementById('organismPDB').value;
13    var method = document.getElementById('methodPDB').value;
14
15    search = search + '?pdbe'
16
17    if (title == '') {
18      alert('You must specify a molecule name.');
19      return;
20    } else {
21      search = search + '&title=' + title.replace(' ', '_');
22    }
23  
24    if (organism != '') {
25      search = search + '&organism=' + organism.replace(' ', '_');
26    }
27  
28    if (method != '') {
29      search = search + '&method=' + method.replace(' ', '_');
30    }
31  } else if (database == 'swissmodel') {
32    var accession = document.getElementById('accession').value;
33    var template = document.getElementById('template').value;
34
35    search = search + '?swissmodel'
36
37    if (accession == '') {
38      alert('You must specify an accession number or a query name.');
39      return;
40    } else {
41      search = search + '&accession=' + accession.replace(' ', '_');
42    }
43  
44    if (template != '') {
45      if (template.length === 4 ) {
46        search = search + '&template=' + template.replace(' ', '_');
47      } else {
48        alert('Your template should be a 4 letters PDB code.')
49        return;
50      }
51    }
52  } else if (database == 'alphafold') {
53    var accession = document.getElementById('accessionAF').value;
54
55    search = search + '?alphafold'
56
57    if (accession == '') {
58      alert('You must specify an accession number.');
59      return;
60    } else {
61      search = search + '&accession=' + accession.replace(' ', '_');
62    }
63  }
64
65  $.ajax({
66    type:"GET",
67    crossDomain:true,
68    url : server + "/searchPDB" + search,
69    success: function(res) {
70      table = JSON.parse(res)['table'].replaceAll('_', ' ');
71      error = JSON.parse(res)['error'];
72      if (error !== '') {
73        if (error == 'No pdb found.') {
74          document.getElementById('searchTargetMessage').style.display = 'inline-block';
75        } else {
76          alert(error);
77        }
78      } else {
79          var obj = jQuery.parseJSON(table);
80          createPdbTable(obj);
81      }	
82    },
83    error: function() {
84      alert('The Webserver is not available. Please contact the SwissDock team.');
85    }
86  });
87}
88
89function createPdbTable(data) {
90
91  $("#pdbTable tbody").remove(); 
92  $("#pdbTable thead").remove();
93
94  var table = document.getElementById('pdbTable');
95
96  var keys = Object.keys(data[0]);
97  
98  if (keys.indexOf('pdbUrl') >= 0) {
99    keys.splice(keys.indexOf('pdbUrl'), 1);
100  }
101
102  var header = document.createElement('thead');
103  var headerRow = document.createElement('tr');
104  headerRow.role = 'row';
105
106  // Create table header row
107  for (var key of keys) {
108    // console.log(key)
109    var headerCell = document.createElement('th');
110
111    if (key !== 'exp. method') {
112      headerCell.id = keys.indexOf(key);
113      headerCell.className = 'sorting';
114      headerCell.onclick = function(e) {sortTable(this)};
115    }
116    
117    headerCell.textContent = key.charAt(0).toUpperCase() + key.slice(1);
118    // headerCell.class = 'sorting';
119    var l = 10*headerCell.textContent.length
120    if (key == 'title') {
121      var l = 25*headerCell.textContent.length
122    }
123    if (key == 'uniprot ID') {
124      var l = 25*headerCell.textContent.length
125    }
126    headerCell.style.minWidth = l.toString() + 'px';
127    headerRow.appendChild(headerCell);
128  }
129  header.appendChild(headerRow);
130  table.appendChild(header);
131
132  // Create table data rows
133  var n = 0;
134  var body = document.createElement('tbody');
135  for (var obj of data) {
136    var dataRow = document.createElement('tr');
137    dataRow.role = 'row';
138    
139    if (n % 2 === 0) {
140      dataRow.className="odd";
141    } else {
142      dataRow.className="evn";
143    }
144
145    for (var key of keys) {
146      var dataCell = document.createElement('td');
147      if (obj[key]) {
148
149        if (key.includes('uniprot ID') || key.includes('uniprot AC')) {
150          var url = 'https://www.uniprot.org/uniprotkb?query=';
151          if (obj[key].includes(',')) {
152            var links = obj[key].split(',');
153            let iterations = links.length;
154            for (var link of links) {
155              var cellLink = document.createElement('a');
156              if (!--iterations) {
157                cellLink.innerText = link;
158              } else {
159                cellLink.innerText = link + ', ';
160              }
161              cellLink.setAttribute('href', url + link.replace(' ', '_'));
162              // cellLink.setAttribute('class', "niceLinks");
163              cellLink.setAttribute('target', "_blank");
164              dataCell.appendChild(cellLink);
165            }
166          } else {
167            var cellLink = document.createElement('a');
168            cellLink.innerText = obj[key];
169            cellLink.setAttribute('href', url + obj[key].replace(' ', '_'));
170            cellLink.setAttribute('class', "niceLinks");
171            cellLink.setAttribute('target', "_blank");
172            dataCell.appendChild(cellLink);
173          }
174        } else {
175          dataCell.textContent = obj[key];
176        }
177      }
178      dataRow.appendChild(dataCell);
179    }
180
181    if (document.getElementById('selectTargetDatabase').value == 'pdbe') {
182      dataRow.id = obj['pdb id'];
183      table.style.maxHeight = '400px';
184      table.style.width = '900px';
185    } else if (document.getElementById('selectTargetDatabase').value == 'swissmodel'){
186      dataRow.id = obj['pdbUrl'].replace(' ', '_');
187      table.style.maxHeight = '430px';
188      table.style.maxWidth = '650px';
189    } else if (document.getElementById('selectTargetDatabase').value == 'alphafold'){
190      dataRow.id = obj['pdbUrl'].replace(' ', '_');
191      table.style.maxHeight = '430px';
192      table.style.maxWidth = '900px';
193    } 
194    
195    dataRow.addEventListener('click', function() {
196      var tds = document.getElementsByClassName('selected');
197      while(tds.length > 0) {
198          tds[0].className = '';  
199      }
200      if(tds.length == 0) {
201        document.getElementById('applyTargetSearch').disabled = false;
202      }
203      for (let td of this.children) {
204          td.className='selected';
205      }
206      var tmp = this.getAttribute('id');
207      console.log(tmp);
208      document.getElementById('applyTargetSearch').disabled = false;
209      document.getElementById('applyTargetSearch').onclick = function() {applyPdb(tmp)};
210    });
211
212    body.appendChild(dataRow);
213
214    n = n + 1;
215  }
216  table.appendChild(body);
217
218  document.getElementById('targetSearchPopup').style.maxHeight = '680px';
219  table.style.display = 'block';
220}
221
222function applyPdb(id) {
223  targetPopupWindow.style.display = "none";
224  popupBackground.style = "display: block;";
225
226  if (document.getElementById('selectTargetDatabase').value == 'pdbe') {
227    document.getElementById("pdbBox").value = id;
228    document.getElementById("pdbBox").dispatchEvent(new Event('change'));
229  } else if (document.getElementById('selectTargetDatabase').value == 'swissmodel'){
230    $.ajax({
231      type:"GET",
232      url : id,
233      success: function(res) {
234        console.log(res);
235        if (res !== '') {
236          pdbContent = res;
237          pdbModified = pdbContent;
238          targetFileName = document.getElementById('accession').value + '_modified.pdb';
239          document.getElementById("pdbBox").value = '';
240          document.getElementById("pdbBox").dispatchEvent(new Event('change'));
241          startNGL(pdbContent);
242          showSelection();
243        } else {
244          alert('It was impossible to get the model.');
245        }	
246      },
247      error: function() {
248        alert('It was impossible to get the model.');
249      }
250    });
251  } else if (document.getElementById('selectTargetDatabase').value == 'alphafold'){
252    $.ajax({
253      type:"GET",
254      url : id,
255      success: function(res) {
256        console.log(res);
257        if (res !== '') {
258          pdbContent = res;
259          pdbModified = pdbContent;
260          targetFileName = id.split('/').pop();
261          document.getElementById("pdbBox").value = '';
262          document.getElementById("pdbBox").dispatchEvent(new Event('change'));
263          startNGL(pdbContent);
264          showSelection();
265        } else {
266          alert('It was impossible to get the model.');
267        }	
268      },
269      error: function() {
270        alert('It was impossible to get the model.');
271      }
272    });
273  }
274}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.