-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsubmitNewJob.html
992 lines (911 loc) · 57.8 KB
/
submitNewJob.html
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
<!DOCTYPE html>
<html>
<body>
<div id="submit-mid">
<div id="submit-div" class="k-header">
<h2>New Job Submit Form</h2>
<div id="submitInfo-div">
</div>
<div id="submitForm-div">
<form method="POST" id="mainForm" name="mainForm" enctype="application/x-www-form-urlencoded" action="action_page.php">
<table align="center" width="80%">
<tr>
<th align="left">Your Email:</th>
<th>
<input type="email" id="user_email" name="user_email" value="Guest" class="k-textbox" readonly required />
<!-- <input type="email" id="user_email" name="user_email" value="[email protected]" class="k-textbox" readonly required /> -->
</th>
</tr>
<tr>
<th align="left">Job Cohort:</th>
<th>
<input type="text" id="jobName" name="jobName" value="homoScan.1" class="k-textbox" readonly />
</th>
</tr>
<tr>
<th align="left">PDB ID:</th>
<th>
<input type="text" id="pdbId" onkeyup="validatePdbAndPopulateChains()" name="pdbId" value="" class="k-textbox" autofocus required />
</th>
</tr>
</table>
<br>
<p id="serverMessage"></p>
<br>
Add/remove chains to 1:<br>
<button id="addChain1Button" type="button" class="k-button" onclick="addChainRow(1)" disabled >Add chain to 1</button>
<button id="deleteChain1Button" type="button" class="k-button" onclick="deleteChainRow(1)" disabled >Remove chain from 1</button>
<br>
<!-- This table holds the chain IDs -->
<table id="chains1Table" name="chains1Table" style="" align="center"></table>
<br>
Add/remove chains to 2:<br>
<button id="addChain2Button" type="button" class="k-button" onclick="addChainRow(2)" disabled >Add chain to 2</button>
<button id="deleteChain2Button" type="button" class="k-button" onclick="deleteChainRow(2)" disabled >Remove chain from 2</button>
<br>
<!-- This table holds the chain IDs -->
<table id="chains2Table" name="chains2Table" style="" align="center"></table>
<br>
Add/remove mutations (use PDB residue numbering):<br>
<button id="addSubstitutionButton" type="button" class="k-button" onclick="addSubstitutionRow()" disabled >Add substitution</button>
<button id="deleteMutationButton" type="button" class="k-button" onclick="deleteSubstitutionRow()" disabled >Remove substitution</button>
<br>
<table id="substitutionTableHeader" name="substitutionTableHeader" style="" align="center"></table>
<table id="substitutionTable" name="substitutionTable" style="" align="center"></table>
<br>
</form>
<p align="center">
<button class="k-button" id="submit-btn" onclick="formSubmitProcedure()" disabled>Submit</button>
</p>
</div>
</div>
</div>
</body>
<script>
// Fills in the User's Email
function loadAccInfo() {
$("#loading-img").fadeIn("slow");
$.ajax({
type: "POST",
url: "calls.php",
dataType: 'json',
data: {restcall: 'getUserInfo', arguments: [user]},
success: function(accInfo_data) {
console.log("check 32 : " + accInfo_data.email);
document.getElementById("user_email").value = accInfo_data.email;
//$("#user_email").html(accInfo_data.email);
$("#loading-img").fadeOut("slow");
},
error: function(accInfo_jqXHR, accInfo_textStatus, accInfo_errorThrown) {
popupNotification.show("Error loading User info: " + accInfo_jqXHR.responseText, "error");
$("#loading-img").fadeOut("slow");
}
});
};
// Should only be called AFTER document.allPdbChains is properly populated
function populateRemainingPdbChains(){
console.log("check 27.0");
if (!(document.allPdbChains.length > 1)) {
alert("Error! Not enough chains found!");
}
document.remainingPdbChains = document.allPdbChains.slice(); // the slice() method ensures that we copy the array by value rather than by reference. https://stackoverflow.com/questions/7486085/copying-array-by-value-in-javascript
for (var h = 1; h < 3; h++){
var myTable = document.getElementById("chains" + h + "Table");
console.log("check 27.1");
console.log(document.remainingPdbChains);
console.log("check 27.2");
for (var i = 0; i < myTable.rows.length; i++) {
var myIndex = document.remainingPdbChains.indexOf(myTable.rows[i].cells[0].childNodes[0].value)
console.log("table " + h + " row " + i + " has chain " + myTable.rows[i].cells[0].childNodes[0].value);
console.log("Looking for " + myTable.rows[i].cells[0].childNodes[0].value);
if (myIndex != -1){ // If one of the user-selected chains is found in document.remainingPdbChains ..
console.log("Deleting " + myTable.rows[i].cells[0].value);
document.remainingPdbChains.splice(myIndex,1); // Remove the corresponding chain from document.remainingPdbChains
console.log("Deleting " + myTable.rows[i].cells[0].value);
} else { // Actually this should never happen.
alert("Somehow you have selected a chain which is not in the protein! Or maybe you selected the same chain more than once!");
}
}
}
}
function populateChainArrays(){
var xhttp = new XMLHttpRequest(); // May need variant to handle old IE browsers https://www.w3schools.com/js/js_ajax_http.asp
console.log("Detected 1 at your PDB ID is valid. You may now add chains.");
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
console.log(JSON.parse(this.responseText)) ;
var myTempChainIdArray = JSON.parse(this.responseText);
var myChainIdArray = []; // casting these as arrays
document.allPdbChains = []; // casting these as arrays
document.remainingPdbChains = [];
for (var i = 0; i< myTempChainIdArray.length; i++){
myChainIdArray.push(myTempChainIdArray[i].chainId);
document.allPdbChains.push(myTempChainIdArray[i].chainId); // trying to make sure the array gets passed by value not reference
//document.remainingPdbChains.push(myTempChainIdArray[i].chainId); // trying to make sure the array gets passed by value not reference
}
console.log("check 26.5");
populateRemainingPdbChains();
console.log(myChainIdArray);
document.usedPdbChains = [];
} else {
console.log(this.status) ;
}
};
xhttp.open("POST", "calls.php", false ); // Going with asynchronous as I don't want to move on until the chains are ready. Revisit this decision later.
console.log(this.status) ;
xhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); // this turns out to be crucial!
console.log(document.getElementById("pdbId").value );
// Argument is user-provided PDB ID:
// contains a system call to breeder:
xhttp.send("restcall=getPdbChains&arguments[]=" + document.getElementById("pdbId").value ); // calls.php contains a SWITCH on 'restcall'
}
function populatePdbPrimaryArray(complex1, complex2){
if (complex1 === undefined) {
complex1 = "";
}
if (complex2 === undefined) {
complex2 = "";
}
var myPdbIdArray = [];
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
console.log(JSON.parse(this.responseText)) ;
var myTempPdbPrimaryArray = JSON.parse(this.responseText);
document.pdbPrimaryArray = []; // make sure this array is empty
for (var i = 0; i< myTempPdbPrimaryArray.length; i++){
document.pdbPrimaryArray.push(myTempPdbPrimaryArray[i].pdbPrimary); // trying to make sure the array gets passed by value not reference
//alert("Check 3. document.pdbPrimaryArray.length = " + document.pdbPrimaryArray.length );
console.log(myTempPdbPrimaryArray[i]);
}
console.log(document.pdbPrimaryArray);
console.log(document.pdbPrimaryArray.join());
// moved this up from validatePdbAndPopulateChains, so it onlky happens after we are done with document.pdbPrimaryArray .
document.getElementById("pdbId").readOnly = true ;
document.getElementById("pdbId").value = document.getElementById("pdbId").value.toUpperCase();
document.getElementById("addChain1Button").disabled = false;
document.getElementById("addChain2Button").disabled = false;
function checkPdbIdMatches(thisPdbId){
return thisPdbId == document.getElementById("pdbId").value ;
}
console.log("check 25.0");
//console.log ( countAndFillSequenceTable( document.getElementById("pdbId").value ) );
//console.log("check 25.0.1");
if (!(chainTablesInCorrectOrder())){ // This function will pop up an informative alert if the tables are in the wrong order. it takes no further action.
console.log("check 25.1");
for (var numComplex = 1; numComplex < 3; numComplex++)
{
for (var i = 0; i < document.getElementById("chains"+numComplex+"Table").rows.length; i++) {deleteChainRow(numComplex);}
}
deleteSubstitutionRow();
populateChainArrays();
} else if (document.pdbPrimaryArray.length == 0){
// There is no primaryPdb associated with the user-provided PDB ID. This is a completely new protein. Do nothing special.
/*
// alert("Your specified PDB ID " + document.getElementById("pdbId").value + " is not a member of any existing family of homologous PDB IDs. This is evidently the first time this PDB ID is used. We will need to prepare the database for first time use of this PDB ID. This should take on the order of one minute, depending on protein size. Please do NOT reload or navigate away from this page!");
// console.log("no pdbPrimary found for this PDB ID. This is a new PDB ID.");
//setTimeout(populateChainArrays(),1000);
// populateChainArrays();
// alert("Done preparing the database for first time use with PDB ID " + document.getElementById("pdbId").value + "");
*/
} else if (!(document.pdbPrimaryArray.find( checkPdbIdMatches ) === undefined )) { // If one of the elements of document.pdbPrimaryArray is document.getElementById("pdbId")
if (document.pdbPrimaryArray.length > 1) {
//alert("Your specified PDB ID is already the head of more than one existing family of homologous PDB IDs. This is good, let's keep this PDB ID for now. For your information, this pdbID is a member of families headed by : " + document.pdbPrimaryArray.join());
document.getElementById("serverMessage").innerHTML = "Your specified PDB ID is already the head of more than one existing family of homologous PDB IDs. This is good, let's keep this PDB ID for now. For your information, this pdbID is a member of families headed by : " + document.pdbPrimaryArray.join() + ". <br> You may now select the chains in complexes 1 and 2.";
} else {
//alert("Your specified PDB ID "+ document.getElementById("pdbId").value + " is the head of exactly one existing family of homologous PDB IDs. That means there are already submissions for at least one mutation of this complex. This is good, let's continue.");
document.getElementById("serverMessage").innerHTML = "Your specified PDB ID "+ document.getElementById("pdbId").value + " is the head of exactly one existing family of homologous PDB IDs. That means there are already submissions for at least one mutation of this complex. This is good, let's continue. <br>";// You may now select the chains in complexes 1 and 2.";
}
////alert("Your specified PDB ID " + document.getElementById("pdbId") + " is already the head of at least one existing family of homologous PDB IDs. If at all possible we should try to do the calculations within the context of an existing family. The candidate families are headed by : " + document.pdbPrimaryArray.join());
} else {
if (!((complex1 == "") && (complex2 == ""))){
alert("Your specified PDB ID " + document.getElementById("pdbId").value + " and complex " +complex1 + "," + complex2 + " . This combination has already been submitted as a homologous family headed by PDB ID: " + document.pdbPrimaryArray.join() + " . You are now obligated to switch to PDB ID " + document.pdbPrimaryArray[0] + " . ");
for (var numComplex = 1; numComplex < 3; numComplex++)
{
for (var i = 0; i < document.getElementById("chains"+numComplex+"Table").rows.length; i++) {deleteChainRow(numComplex);}
}
deleteSubstitutionRow();
document.getElementById("pdbId").value = document.pdbPrimaryArray[0];
populateChainArrays();
//document.getElementById("pdbId").text = document.pdbPrimaryArray[0];
}
else if (confirm("Your specified PDB ID " + document.getElementById("pdbId").value + " is a member of homolog families headed by the following PDB ID(s): " + document.pdbPrimaryArray.join() + " . As you can see, it is not the head of any of these families. We STRONGLY recommend switching to one of these other PDB IDs. Press OK to make the switch to " + document.pdbPrimaryArray[0] + " . ")) {
document.getElementById("pdbId").value = document.pdbPrimaryArray[0];
populateChainArrays();
//document.getElementById("pdbId").text = document.pdbPrimaryArray[0];
};
}
} else {
console.log(this.status) ;
}
console.log(document.getElementById("pdbId").value);
};
xhttp.open("POST", "calls.php", false ); // Going with asynchronous
xhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); // this turns out to be crucial!
// Argument is user-provided PDB ID:
//xhttp.send("restcall=getPdbPrimary&arguments[]=" + document.getElementById("pdbId").value ); // calls.php contains a SWITCH on restcall
if ((complex1 == "") && (complex2 == ""))
xhttp.send("restcall=getPdbPrimary&arguments[]=" + document.getElementById("pdbId").value ); // calls.php contains a SWITCH on restcall
else if ((complex1 == "") || (complex2 == "")) {alert("One of your complexes is empty!"); return;}
else {
var myQuery = "restcall=getPdbPrimary&arguments[0]=" + document.getElementById("pdbId").value +"&arguments[1]=" + complex1 + "&arguments[2]=" + complex2;
console.log(myQuery);
xhttp.send(myQuery);
//xhttp.send("restcall=getPdbPrimary&arguments[]=" + document.getElementById("pdbId").value +"&" + complex1 + "&" + complex2);
}
}
function messagePatience(){
document.getElementById("serverMessage").innerHTML = "Please wait patiently!";
}
function validatePdbAndPopulateChains(){
var myChainIdArray = [];
if (document.allPdbChains === undefined) {
//alert("document.allPdbChains is undefined. Now initializing that as an empty array []");
console.log("document.allPdbChains is undefined. Now initializing that as an empty array []");
document.allPdbChains = [];}
//document.getElementById("serverMessage").innerHTML = "The chains have not yet been loaded..";
if (!(validatePdbIdLength())) {
document.getElementById("serverMessage").innerHTML = "";
//document.pdbPrimaryArray = []; // Make sure arrays populated from prior visits to page are cleaned out
document.allPdbChains = []; // Make sure arrays populated from prior visits to page are cleaned out
return false; // First make sure the length is right
} else {
//document.getElementById("serverMessage").innerHTML = "Please wait patiently!";
document.getElementById("pdbId").value = (document.getElementById("pdbId").value).toUpperCase() ; // we standardize to uppercase PDB IDs throughout this server.
document.pdbPrimaryArray = []; // casting these as arrays
//alert("About to call populatePdbPrimaryArray(). Currently document.pdbPrimaryArray.length = " + document.pdbPrimaryArray.length );
populatePdbPrimaryArray();
//alert("Done with populatePdbPrimaryArray(). Currently document.pdbPrimaryArray.length = " + document.pdbPrimaryArray.length );
// moved this up to populatePdbPrimaryArray() , so it onlky happens after we are done with document.pdbPrimaryArray .
console.log("Detected that your PDB ID is valid. You may now add chains.");
//alert("document.pdbPrimaryArray.length : " + document.pdbPrimaryArray.length);
if ((document.pdbPrimaryArray.length == 0) && (document.allPdbChains.length == 0)) {
//if (document.allPdbChains.length == 0)
var txt;
var r = confirm("Your specified PDB ID " + document.getElementById("pdbId").value + " has not been submitted to us before. We will need to prepare the database for first time use of this PDB ID. This could take on the order of one minute, depending on protein size. Please do NOT reload or navigate away from this page, even if your browser claims it is unresponsive! Can you wait this long?");
if (r == true) {
//var myWindow = window.open("http://pe1.scilifelab.se/patiencePdb.php", "MsgWindow", "width=800,height=400");
//myWindow.document.write("<p> Your specified PDB ID has not been submitted to us before. We will need to prepare the database for first time use. This should take on the order of one minute, depending on protein size. This window will close when that is done. Please wait patiently!</p>");
populateChainArrays();
//myWindow.close();
alert("Database has now been prepared for first time use with PDB ID " + document.getElementById("pdbId").value + "");
document.getElementById("serverMessage").innerHTML += "Ready to pick chains!";
} else {
txt = "You pressed Cancel!";
document.getElementById("pdbId").value = "";
document.getElementById("serverMessage").innerHTML = "";
//document.getElementById("serverMessage").hide();
////document.getElementById("serverMessage").show();
} // of else (meaning r == false)
} // of if (document.pdbPrimaryArray.length == 0)
else if (document.allPdbChains.length == 0){
alert("We will now load the sequence table for your specified PDB ID " + document.getElementById("pdbId").value + ". This has been submitted to us before, so it should only take a brief moment. ");
populateChainArrays();
//myWindow.close();
//alert("Database has now been prepared for first time use with PDB ID " + document.getElementById("pdbId").value + "");
document.getElementById("serverMessage").innerHTML += "Ready to pick chains!";
}
else {
document.getElementById("serverMessage").innerHTML += "Ready to pick chains!";
//document.getElementById("serverMessage").innerHTML = "Ready!";
}
} // of else (meaning validatePdbIdLength() == true)
} // of function validatePdbAndPopulateChains()
function validatePdbIdLength(){
var pdbIdElement = document.getElementById("pdbId");
var lengthPdbId = pdbIdElement.value.length;
//alert(lengthPdbId);
if (lengthPdbId == 4) {
return(true);
} else return false;
}
function sortChainRows( numComplex ){
var myTable = document.getElementById("chains"+numComplex+"Table");
console.log("check 20");
console.log(numComplex);
function compareChainRows(j,k){
console.log("check 21");
console.log(numComplex);
var myTable = document.getElementById("chains"+numComplex+"Table");
console.log(myTable.rows.length );
if (myTable.rows[j].cells[0].childNodes[0].value < myTable.rows[k].cells[0].childNodes[0].value ) {
console.log( " < " );
return 1;}
else if (myTable.rows[j].cells[0].childNodes[0].value == myTable.rows[k].cells[0].childNodes[0].value ) {
console.log( " ==" );
return 0;}
else if (myTable.rows[j].cells[0].childNodes[0].value > myTable.rows[k].cells[0].childNodes[0].value ) {
console.log( " > " );
return -1;}
}
console.log("check 20.1");
console.log(myTable.rows);
console.log("check 20.2");
console.log(myTable.rows.length);
console.log("check 20.2.1");
//console.log(myTable.rows[0].cells[0].childNodes[0].value);
//console.log(myTable.rows[1].cells[0].childNodes[0].value);
console.log("check 20.3");
var h = 1;
console.log("check 20.4");
console.log("( h)" + ( h));
for (var h = 1; h < myTable.rows.length; h++){
console.log("check 20.4.1");
console.log("( h)" + ( h));
console.log("(myTable.rows.length - h)" + (myTable.rows.length - h));
for (var i = 0; i < (myTable.rows.length - h) ; i++ )
{
console.log("check 20.5");
if (compareChainRows( i ,i + 1) == 1) {
console.log("NOT Swapping rows");
} // a<b, so do nothing
else if (compareChainRows( i ,i + 1 ) == 0) {
alert("Error! There are two identical chains! Reset the page and start over.");1
}
else if (compareChainRows( i ,i + 1 )){ // Swap these two rows
console.log("Swapping rows");
myTable.rows[i].parentNode.insertBefore(myTable.rows[i + 1] ,myTable.rows[i]);
console.log(" rows = " + myTable.rows.length);
console.log(" rows = " + myTable.rows.length);
}
}
}
console.log("check 20.7");
for (var h = 0; h < myTable.rows.length; h++) console.log("Row "+ h + " has : " + myTable.rows[h].cells[0].childNodes[0].value );
}
// This just takes all the elements of document.remainingPdbChains and creates options in the drop down list.
function repopulateOptions(localChainSelector){
console.log(document.remainingPdbChains);
document.remainingPdbChains.sort();
console.log("check 30.6 " + document.remainingPdbChains);
// depopulate the list of options, in case it is not empty:
var totalChildren = localChainSelector.childElementCount;
for (var i= 0; i < totalChildren; i++) {localChainSelector.removeChild(localChainSelector.childNodes[0]);}
console.log(localChainSelector.childElementCount);
console.log("check 30.8 localChainSelector.value = " + localChainSelector.value)
console.log(document.remainingPdbChains);
for (var i = 0 ; i< document.remainingPdbChains.length ; i++){
console.log("check 30.8 localChainSelector.value = " + localChainSelector.value)
var myChainId = document.remainingPdbChains[i];
var myOption = document.createElement("option");
console.log("check 31.0");
console.log(myChainId);
//console.log(myChainId.value); // this member does not exist
//console.log(myChainId.chainId);
console.log(document.remainingPdbChains[i]);
myOption.value = myChainId;
myOption.innerHTML = myChainId;
localChainSelector.appendChild(myOption);
}
console.log("check 30.8 localChainSelector.value = " + localChainSelector.value)
//populateRemainingPdbChains(); // Just added this, might not be necessary but seems safe.
}
function createChainSelector(numComplex){
var myTable = document.getElementById("chains"+numComplex+"Table");
// Chain ID selector:
var createdChainSelector = document.createElement("SELECT");
createdChainSelector.id = "complex" + numComplex + "ChainSelector" + (myTable.rows.length - 1); //tableNumRows is always 1 less than myTable.rows.length
createdChainSelector.name = createdChainSelector.id;
createdChainSelector.onfocus = function(){
console.log(document.remainingPdbChains);
this.previous = this.value;
console.log("check 26.4");
populateRemainingPdbChains(); // Just added this, might not be necessary but seems safe.
if (document.remainingPdbChains.indexOf(this.previous) == -1){ // This should always happen actually, as we just called populateRemainingPdbChains
document.remainingPdbChains.push(this.previous);
} // have to temporarioy add this.previous to remainingPdbChains in order to repopulate properly
else {
//alert("Problem!");
}
repopulateOptions(createdChainSelector); // This just takes all the elements of document.remainingPdbChains and creates options in the drop down list.
console.log("check 26.4.2");
populateRemainingPdbChains(); // have to remove the selected element from remainingPdbChains again
//document.remainingPdbChains.splice(document.remainingPdbChains.indexOf(this.previous),1) ; // have to remove the selected element from remainingPdbChains again
// Make the prior value the current selected value.
for (var i= 0; i < createdChainSelector.childElementCount; i++) {
if (createdChainSelector.childNodes[i].value == this.previous){
createdChainSelector.selectedIndex = i;
}
}
}
createdChainSelector.onchange = function(){
console.log(document.allPdbChains.length -1);
console.log("check 1");
populateRemainingPdbChains(); // This will remove the currently selected value
//document.remainingPdbChains.splice(document.remainingPdbChains.indexOf(this.value),1) ;
//if (document.remainingPdbChains.indexOf(this.previous) == -1){
// document.remainingPdbChains.push(this.previous);} // The prior option is now available for use again
sortChainRows(1);
sortChainRows(2);
}
return createdChainSelector;
}
function addChainRow( numComplex ){
document.getElementById("serverMessage").innerHTML = "Now select or change the chain for complex " + numComplex + " from the drop down list. You are also allowed to remove chains, or (if enough remain available) add further chains.";
document.getElementById("pdbId").readonly = true;
console.log(document.allPdbChains.length -1);
document.getElementById("deleteChain" + numComplex + "Button").disabled = false;
var myTable = document.getElementById("chains"+numComplex+"Table");
var tableNumRows = myTable.rows.length;
myTable.insertRow(tableNumRows);
myTable.rows[tableNumRows].insertCell(0);
var myChainSelector = createChainSelector(numComplex);
console.log(document.remainingPdbChains);
console.log("check 30.0");
repopulateOptions(myChainSelector);
console.log("check 30.1");
myTable.rows[tableNumRows].cells[0].appendChild(myChainSelector);
// If we reached the maximum number of rows, disable the add mutation button
if (document.remainingPdbChains.length == 1)
{
document.getElementById("addChain1Button").disabled = true;
document.getElementById("addChain2Button").disabled = true;
alert("This is the last chain left to select from. You are not allowed to make further selections without deleting a chain from one of the two complexes.");
}
else if (myTable.rows.length == (document.allPdbChains.length -1))
{// probably set to num chains in PDB minus one.
document.getElementById("addChain" + numComplex + "Button").disabled = true;
alert("You are only allowed to specify " + (document.allPdbChains.length -1) + " chains for this , based on a total number of " + document.allPdbChains.length + " available chains");
}
else if ((myTable.rows.length == 4) || (myTable.rows.length == (document.allPdbChains.length -1)))
{// probably set to num chains in PDB minus one.
document.getElementById("addChain1Button").disabled = true;
alert("You have reached the maximum number of chains: 4");
}
document.remainingPdbChains.splice(document.remainingPdbChains.indexOf(myChainSelector.value ),1) ; // have to delete the selected element
document.getElementById("addSubstitutionButton").disabled = false;
if ((document.getElementById("chains1Table").rows.length == 0) || ( document.getElementById("chains2Table").rows.length == 0)){
document.getElementById("addSubstitutionButton").disabled = true;
}
sortChainRows(numComplex);
//sortChainRows(2);
}
function deleteChainRow(numComplex){
//// Now have to add the value to be deleted, back to remainingPdbChains :
var myTable = document.getElementById("chains" + numComplex + "Table");
var selectorToDelete = "complex" + numComplex + "ChainSelector" + (myTable.rows.length - 1);
var valueOfSelectorToDelete = document.getElementById(selectorToDelete).value;
console.log(valueOfSelectorToDelete);
console.log(document.remainingPdbChains);
//document.remainingPdbChains.push(valueOfSelectorToDelete);
if (document.remainingPdbChains.indexOf(valueOfSelectorToDelete) == -1){
document.remainingPdbChains.push(valueOfSelectorToDelete);} // The prior option is now available for use again
////
console.log(document.remainingPdbChains);
var tableNumRows = myTable.rows.length;
if (tableNumRows == 0) {
// do nothing
alert("Error");
//document.getElementById("deleteMutationButton").disabled = true;
}
else {
myTable.deleteRow(myTable.rows.length - 1);
tableNumRows = myTable.rows.length;
if (tableNumRows == 0) {
document.getElementById("deleteChain" + numComplex + "Button").disabled = true;
}
}
document.getElementById("addChain" + numComplex + "Button").disabled = false; // If we removed a row, then we are definitely not at the maximum number of rows
if (document.getElementById("chains1Table").rows.length < (document.allPdbChains.length-1)){
document.getElementById("addChain1Button").disabled = false;
}
if (document.getElementById("chains2Table").rows.length < (document.allPdbChains.length-1)){
document.getElementById("addChain2Button").disabled = false;
}
if ((document.getElementById("chains1Table").rows.length == 0) || ( document.getElementById("chains2Table").rows.length == 0)){
document.getElementById("addSubstitutionButton").disabled = true;
}
}
function deleteSubstitutionRow(){
var myTable = document.getElementById("substitutionTable");
var tableNumRows = myTable.rows.length;
if (tableNumRows == 0) {
// do nothing
alert("Error");
//document.getElementById("deleteMutationButton").disabled = true;
}
else {
myTable.deleteRow(myTable.rows.length - 1);
tableNumRows = myTable.rows.length;
if (tableNumRows == 0) {
document.getElementById("deleteMutationButton").disabled = true;
document.getElementById("submit-btn").disabled = true;
}
}
document.getElementById("addSubstitutionButton").disabled = false; // If we removed a row, then we are definitely not at the maximum number of rows
}
function chainTablesInCorrectOrder(){
console.log("check 22.0");
var complex1chain0Id = document.getElementById("chains1Table").rows[0]
if ((document.getElementById("chains1Table").rows.length == 0) || (document.getElementById("chains2Table").rows.length == 0)){
console.log("At least one of the two chains tables is empty. Not valid to check chain ordering!");
return 1;
}
if (document.getElementById("chains1Table").rows[0].cells[0].childNodes[0].value > document.getElementById("chains2Table").rows[0].cells[0].childNodes[0].value){
console.log("check 23.0");
alert("Your first complex starts with chain " + document.getElementById("chains1Table").rows[0].cells[0].childNodes[0].value + " which is alphabetically higher than the first chain of the second complex, " + document.getElementById("chains2Table").rows[0].cells[0].childNodes[0].value + ". This is not allowed! Please put chain " + document.getElementById("chains2Table").rows[0].cells[0].childNodes[0].value + " in the first complex, and chain " + document.getElementById("chains1Table").rows[0].cells[0].childNodes[0].value + " in the second complex. This is a measure to avoid making redundant calculations.");
return 0;
} else {
console.log("check 24.0");
return 1;
}
console.log("check 22.1");
//var complex2chain0Id = document.getElementById("chains1Table").
/*var myOriginalTable1 = document.getElementById("chains1Table");
var myOriginalTable2 = document.getElementById("chains2Table");
//var myNewTable1 = document.getElementById("chains1Table").cloneNode(true);
//myOriginalTable1.rows[0];
document.getElementById("chains2Table").insertRow(0);
document.getElementById("chains2Table").rows[0] = document.getElementById("chains1Table").rows[0];
console.log("check 23");
console.log("check 22");
var tableNumRows = document.getElementById("chains1Table").rows.length;
document.getElementById("chains1Table").insertRow(tableNumRows);
document.getElementById("chains1Table").rows[tableNumRows].insertCell(0);
var myChainSelector = createChainSelector(1);
repopulateOptions(myChainSelector);
console.log(document.remainingPdbChains);
document.getElementById("chains1Table").rows[tableNumRows].cells[0].appendChild(myChainSelector);
console.log("check 23");
*/
}
function formSubmitProcedure(){
//sortChainTables();
sortSubstitutionRows( );
console.log(document.readyState);
console.log(document.getElementById("mainForm"));
console.log(document.forms.length);
console.log(document.forms[0] );
console.log(document.getElementById("mainForm"));
if(document.readyState === 'complete'){} ;
document.mainForm.submit();
}
function sortSubstitutionRows( ){
var mySubstitutionTable = document.getElementById("substitutionTable");
function compareSubstitutionRows(j,k){
console.log(mySubstitutionTable.rows.length );
if (mySubstitutionTable.rows[j].cells[0].childNodes[0].value < mySubstitutionTable.rows[k].cells[0].childNodes[0].value ) {
console.log( " < " );
return 1;}
else if (mySubstitutionTable.rows[j].cells[0].childNodes[0].value == mySubstitutionTable.rows[k].cells[0].childNodes[0].value ) { // The chains are the same for j,k. So check the residue numbers.
if (mySubstitutionTable.rows[j].cells[1].childNodes[0].value < mySubstitutionTable.rows[k].cells[1].childNodes[0].value ){
console.log( " < " );
return 1;
}
else if (mySubstitutionTable.rows[j].cells[1].childNodes[0].value > mySubstitutionTable.rows[k].cells[1].childNodes[0].value ){
console.log( " > " );
return -1;
}
else {
console.log( " ==" );
return 0;
}
}
else if (mySubstitutionTable.rows[j].cells[0].childNodes[0].value > mySubstitutionTable.rows[k].cells[0].childNodes[0].value ) {
console.log( " > " );
return -1;}
}
console.log(mySubstitutionTable.rows);
//mySubstitutionTable.rows.sort(sortSubstitutionRows);
for (var h = 1; h < mySubstitutionTable.rows.length; h++)
for (var i = 0; i < (mySubstitutionTable.rows.length - h) ; i++ )
{
if (compareSubstitutionRows( i ,i + 1) == 1) {
console.log("NOT Swapping rows");
} // a<b, so do nothing
else if (compareSubstitutionRows( i ,i + 1 ) == 0) {
alert("Error! There are two identical substitutions! Reset the page and start over.");1
}
else if (compareSubstitutionRows( i ,i + 1 )){ // Swap these two rows
console.log("Swapping rows");
mySubstitutionTable.rows[i].parentNode.insertBefore(mySubstitutionTable.rows[i + 1] ,mySubstitutionTable.rows[i]);
console.log(" rows = " + mySubstitutionTable.rows.length);
console.log(" rows = " + mySubstitutionTable.rows.length);
}
}
for (var h = 0; h < mySubstitutionTable.rows.length; h++) {
console.log("Row "+ h + " has : " + mySubstitutionTable.rows[h].cells[0].childNodes[0].value );
// After sorting, we need to set the .id and .name properties of these selectors.
mySubstitutionTable.rows[h].cells[0].childNodes[0].id = "chainId" + h;
mySubstitutionTable.rows[h].cells[0].childNodes[0].name = mySubstitutionTable.rows[h].cells[0].childNodes[0].id;
mySubstitutionTable.rows[h].cells[1].childNodes[0].id = "residueNumber" + h;
mySubstitutionTable.rows[h].cells[1].childNodes[0].name = mySubstitutionTable.rows[h].cells[1].childNodes[0].id;
mySubstitutionTable.rows[h].cells[2].childNodes[0].id = "substitutedResidueType" + h;
mySubstitutionTable.rows[h].cells[2].childNodes[0].name = mySubstitutionTable.rows[h].cells[2].childNodes[0].id;
}
}
function addSubstitutionRow(){
document.getElementById("submit-btn").disabled = true; // We enable the Submit button only after the user selects a substitution
var complex1 = "";
var complex2 = "";
for (var i = 0; i < document.getElementById("chains1Table").rows.length; i++) complex1 += document.getElementById("chains1Table").rows[i].cells[0].childNodes[0].value;
for (var i = 0; i < document.getElementById("chains2Table").rows.length; i++) complex2 += document.getElementById("chains2Table").rows[i].cells[0].childNodes[0].value;
console.log(" >" + complex1 + "< ");
console.log(" >" + complex2 + "< ");
// somehow populatePdbPrimaryArray was getting called here..
//populatePdbPrimaryArray(complex1, complex2);
addChain1Button.disabled = true;
addChain2Button.disabled = true;
deleteChain1Button.disabled = true;
deleteChain2Button.disabled = true;
document.getElementById("deleteMutationButton").disabled = false;
var mySubstitutionTableHeader = document.getElementById("substitutionTableHeader");
if (mySubstitutionTableHeader.rows.length == 0){
mySubstitutionTableHeader.insertRow(0);
mySubstitutionTableHeader.rows[0].insertCell(0);
mySubstitutionTableHeader.rows[0].insertCell(1);
mySubstitutionTableHeader.rows[0].insertCell(2);
mySubstitutionTableHeader.rows[0].cells[0].innerHTML = "Chain";
mySubstitutionTableHeader.rows[0].cells[1].innerHTML = "Residue";
mySubstitutionTableHeader.rows[0].cells[2].innerHTML = "Substitution";
}
var mySubstitutionTable = document.getElementById("substitutionTable");
var standardSubstitutionColumnWidth = "100000px";
mySubstitutionTable.style.columnWidth = standardSubstitutionColumnWidth;
mySubstitutionTableHeader.style.columnWidth = standardSubstitutionColumnWidth;
var tableNumRows = mySubstitutionTable.rows.length;
mySubstitutionTable.insertRow(tableNumRows);
mySubstitutionTable.rows[mySubstitutionTable.rows.length - 1].insertCell(0);
mySubstitutionTable.rows[mySubstitutionTable.rows.length - 1].insertCell(1);
mySubstitutionTable.rows[mySubstitutionTable.rows.length - 1].insertCell(2);
// If the table has any prior entries, disable modification of those:
if (mySubstitutionTable.rows.length > 1){
}
// Chain ID selector:
var myChainSelector = document.createElement("SELECT");
for (var i = 0 ; i< document.allPdbChains.length ; i++){
var myChainId = document.allPdbChains[i];
if (document.remainingPdbChains.indexOf(myChainId) == -1) {
var myOption = document.createElement("option");
myOption.value = myChainId;
myOption.innerHTML = myChainId;
myChainSelector.appendChild(myOption);}
}
mySubstitutionTable.rows[mySubstitutionTable.rows.length - 1].cells[0].appendChild(myChainSelector);
myChainSelector.onchange = function(){
updatePdbResidueIdArrayAndPopulateSelector(); // This should be dependent on the actual chain
}
// Residue number selector:
var myResidueNumberSelector = document.createElement("SELECT");
myResidueNumberSelector.id = "residueNumber" + (mySubstitutionTable.rows.length - 1);
console.log(myResidueNumberSelector.id);
myResidueNumberSelector.name = myResidueNumberSelector.id;
mySubstitutionTable.rows[mySubstitutionTable.rows.length - 1].cells[1].appendChild(myResidueNumberSelector);
var xhttp = new XMLHttpRequest();
updatePdbResidueIdArrayAndPopulateSelector(); // This should ultimately be dependent on the actual chain chosen. So we populate based on the default chain here, and above in the myChainSelector.onchange event we repopulate upon change of chain choice.
var myTempResidueIdArray = []; // casting these as arrays
var myResidueIdArray = []; // casting these as arrays
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
var myTempResidueIdArray = JSON.parse(this.responseText);
console.log(myTempResidueIdArray.length);
for (var i = 0; i < (mySubstitutionTable.rows.length - 1); i++){ // Note that this will not count the current row. If there is only one row in substitutionTable, then this loop will not run at all.
console.log(i);
// If the chain in substitution i matches the chain of the current substitution, then we need to remove a residue Id from the current myTempResidueIdArray so it cannot be selected again:
var valueToDelete = "" ; // cast as string
if ( mySubstitutionTable.rows[i].cells[0].childNodes[0].value == mySubstitutionTable.rows[mySubstitutionTable.rows.length - 1].cells[0].childNodes[0].value) {
valueToDelete = mySubstitutionTable.rows[i].cells[1].childNodes[0].value;
residueIdIndexToDelete = myTempResidueIdArray.indexOf(valueToDelete);
for (var j = 0; j < myTempResidueIdArray.length; j++){
//console.log(" >" + myTempResidueIdArray[j].residueId + "< compared to >" + valueToDelete +"<");
if (myTempResidueIdArray[j].residueId == valueToDelete) {residueIdIndexToDelete = j;}
}
myTempResidueIdArray.splice(residueIdIndexToDelete,1); // Remove the already-used residue ID.
console.log(mySubstitutionTable.rows[i].cells[1].childNodes[0].value);
console.log(residueIdIndexToDelete);
}
}
console.log(myTempResidueIdArray.length);
myResidueIdArray = [];
for (var i = 0; i< myTempResidueIdArray.length; i++){
var myResidueId = ""; // let's cast the elements as strings early on
myResidueId = myTempResidueIdArray[i].residueId;
myResidueIdArray.push(myResidueId); // This should be an ordinary array, rather than an array of key-values .
}
} else {
}
populateResidueNumberSelector();
};
myResidueNumberSelector.onchange = function(){
//sortSubstitutionRows();
//updatePdbResidueIdArrayAndPopulateSelector(); // This should be dependent on the actual chain chosen! Right now it seems to populate based on the first chain on the list. --SCF
}
function updatePdbResidueIdArrayAndPopulateSelector(){
console.log("check 1");
xhttp.open("POST", "calls.php", true ); // Going with asynchronous as I don't want to move on until the chains are ready. Revisit this decision later.
xhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); // this turns out to be crucial!
// Argument is user-provided PDB ID:
var myChainId = myChainSelector.value;
console.log(myChainId);
xhttp.send("restcall=getPdbResidueIds&arguments[0]=" + document.getElementById("pdbId").value + "&" + "arguments[1]=" + myChainId ) ; // calls.php contains a SWITCH on 'restcall'
}
function populateResidueNumberSelector(){
var totalChildren = myResidueNumberSelector.childElementCount;
for (var i= 0; i < totalChildren; i++) {
//console.log(i);
myResidueNumberSelector.removeChild(myResidueNumberSelector.childNodes[0]);}
console.log(myResidueIdArray.length);
for (var i = 0 ; i< myResidueIdArray.length ; i++){
//console.log(i);
var myResidueId = myResidueIdArray[i];
var myOption = document.createElement("option");
myOption.value = myResidueId;
myOption.innerHTML = myResidueId;
myResidueNumberSelector.appendChild(myOption);
}
}
// Substituted residue type selector
var mySubstitutedResidueTypeSelector = document.createElement("SELECT");
// best to set the name and id properties after sorting. Could also set them here, can revisit decision later.
//mySubstitutedResidueTypeSelector.id = "substitutedResidueType" + (mySubstitutionTable.rows.length - 1);
//mySubstitutedResidueTypeSelector.name = mySubstitutedResidueTypeSelector.id ;
// myResidueNumberSelector.id = "residueNumber" + (mySubstitutionTable.rows.length - 1);
//myResidueNumberSelector.name = myResidueNumberSelector.id;
function populatemySubstitutedResidueTypeSelector(){
var aminoAcidTypes = ["?","A","R","N","D","C","E","Q","G","H","I","L","K","M","F","P","S","T","W","Y","V"];
for (var i = 0; i < aminoAcidTypes.length ; i++){
var mySubstitutedResidueTypeOption = document.createElement("option");
mySubstitutedResidueTypeOption.value = aminoAcidTypes[i];
mySubstitutedResidueTypeOption.innerHTML = aminoAcidTypes[i];
mySubstitutedResidueTypeSelector.appendChild(mySubstitutedResidueTypeOption);
};
}
populatemySubstitutedResidueTypeSelector();
mySubstitutionTable.rows[mySubstitutionTable.rows.length - 1].cells[2].appendChild(mySubstitutedResidueTypeSelector);
/*if (mySubstitutionTable.rows.length == 1){
mySubstitutionTable.rows[mySubstitutionTable.rows.length - 1].cells[0].innerHTML = "Chain<br>";
mySubstitutionTable.rows[mySubstitutionTable.rows.length - 1].cells[1].innerHTML = "Residue<br>";
mySubstitutionTable.rows[mySubstitutionTable.rows.length - 1].cells[2].innerHTML = "Substitution<br>";
}*/
console.log(myResidueNumberSelector.value);
mySubstitutedResidueTypeSelector.onfocus = function(){repopulateSubstitutedAminoAcidTypeOptions(mySubstitutedResidueTypeSelector.parentNode.parentNode.rowIndex);}
mySubstitutedResidueTypeSelector.onchange= function(){
document.getElementById("submit-btn").disabled = false; // We enable the Submit button only after the user selects a substitution
}
// If we reached the maximum number of rows, disable the add mutation button
if (mySubstitutionTable.rows.length == 4){
document.getElementById("addSubstitutionButton").disabled = true;
alert("You have reached the maximum number of mutations: 4");
}
}
function repopulateSubstitutedAminoAcidTypeOptions(rowIndex){
//function repopulateSubstitutedAminoAcidTypeOptions(localSubstitutedResidueTypeSelector, pdbId, chainId, residueId){
/*
var mySubstitutionTable = document.getElementById("substitutionTable");
var pdbId = "1AXI"; //document.getElementById("pdbId").value;
var localSubstitutedResidueTypeSelector = mySubstitutionTable.rows[ rowIndex ].cells[2].childNodes[0];
//var rowIndex = localSubstitutedResidueTypeSelector.parentNode.parentNode.rowIndex;
//console.log(localSubstitutedResidueTypeSelector, pdbId, chainId, residueId);
var aminoAcidTypes = ["?","A","R","N","D","C","E","Q","G","H","I","L","K","M","F","P","S","T","W","Y","V"];
var chainId = mySubstitutionTable.rows[ rowIndex ].cells[0].childNodes[0].value;
console.log(chainId);
var residueId = mySubstitutionTable.rows[ rowIndex ].cells[1].childNodes[0].value;
console.log(residueId);
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
console.log((this.responseText)) ;
console.log(JSON.parse(this.responseText)) ;
var myTempAminoAcidTypeArray = JSON.parse(this.responseText);
//return (myTempAminoAcidTypeArray[0].aminoAcidType);
while (localSubstitutedResidueTypeSelector.hasChildNodes()) {
localSubstitutedResidueTypeSelector.removeChild(node.lastChild);
}
for (var i = 0; i < aminoAcidTypes.length ; i++){
if (myTempAminoAcidTypeArray[0].aminoAcidType != aminoAcidTypes[i]) {
var mySubstitutedResidueTypeOption = document.createElement("option");
mySubstitutedResidueTypeOption.value = aminoAcidTypes[i];
mySubstitutedResidueTypeOption.innerHTML = aminoAcidTypes[i];
localSubstitutedResidueTypeSelector.appendChild(mySubstitutedResidueTypeOption);
}
};
} else {
console.log(this.status) ;
console.log(this.readystate) ;
console.log((this.responseText)) ;
}
}
xhttp.open("POST", "calls.php", true );
xhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); // this turns out to be crucial!
var callString ="restcall=getPdbChains&arguments[0]=" + pdbId ; // + "&arguments[1]=" + chainId + "&arguments[2]=" + residueId;
//var callString ="restcall=getWildTypeAminoAcidType&arguments[0]=" + pdbId + "&arguments[1]=" + chainId + "&arguments[2]=" + residueId;
console.log(callString);
xhttp.send("callString");
*/
var mySubstitutionTable = document.getElementById("substitutionTable");
var localSubstitutedResidueTypeSelector = mySubstitutionTable.rows[ rowIndex ].cells[2].childNodes[0];
var xhttp = new XMLHttpRequest(); // May need variant to handle old IE browsers https://www.w3schools.com/js/js_ajax_http.asp
console.log("Detected 1 at your PDB ID is valid. You may now add chains.");
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
console.log(JSON.parse(this.responseText)) ;
var myWildTypeResidueType = JSON.parse(this.responseText);
while (localSubstitutedResidueTypeSelector.hasChildNodes()) {
localSubstitutedResidueTypeSelector.removeChild(localSubstitutedResidueTypeSelector.childNodes[0]);
}
var aminoAcidTypes = ["?","A","R","N","D","C","E","Q","G","H","I","L","K","M","F","P","S","T","W","Y","V"];
for (var i = 0; i< aminoAcidTypes.length; i++){
console.log(myWildTypeResidueType[0].aminoAcidType);
console.log(aminoAcidTypes[i]);
//document.allPdbChains.push(myWildTypeResidueType[i].chainId); // trying to make sure the array gets passed by value not reference
//document.remainingPdbChains.push(myWildTypeResidueType[i].chainId); // trying to make sure the array gets passed by value not reference
if (aminoAcidTypes[i] != myWildTypeResidueType[0].aminoAcidType){
var mySubstitutedResidueTypeOption = document.createElement("option");
mySubstitutedResidueTypeOption.value = aminoAcidTypes[i];
mySubstitutedResidueTypeOption.innerHTML = aminoAcidTypes[i];
localSubstitutedResidueTypeSelector.appendChild(mySubstitutedResidueTypeOption);
}
}
} else {
console.log(this.status) ;
}
};
xhttp.open("POST", "calls.php", true ); // Going with asynchronous as I don't want to move on until the chains are ready. Revisit this decision later.
console.log(this.status) ;
xhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); // this turns out to be crucial!
console.log(document.getElementById("pdbId").value );
var pdbId = document.getElementById("pdbId").value;
var chainId = mySubstitutionTable.rows[ rowIndex ].cells[0].childNodes[0].value;
var residueId = mySubstitutionTable.rows[ rowIndex ].cells[1].childNodes[0].value;
// Argument is user-provided PDB ID:
var callString ="restcall=getWildTypeAminoAcidType&arguments[0]=" + pdbId + "&arguments[1]=" + chainId + "&arguments[2]=" + residueId;
//var callString ="restcall=getPdbChains&arguments[]=" + document.getElementById("pdbId").value;
console.log(callString);
xhttp.send(callString);
//xhttp.send("restcall=getWildTypeAminoAcidType&arguments[]=" + document.getElementById("pdbId").value ); // calls.php contains a SWITCH on 'restcall'
//xhttp.send("restcall=getPdbChains&arguments[]=" + document.getElementById("pdbId").value ); // calls.php contains a SWITCH on 'restcall'
}
$(document).ready(function() {
if (user != "Guest") {
loadAccInfo();
console.log("check 33 " );
}else {
console.log("check 34 " );
document.getElementById("submit-div").innerHTML = "The job submitting process is only allowed to registered users. Please register or Log-in first.";
}
});
</script>
<style>
html {
}
html,body {
height:100%;
width: 100%;
margin: 0;
padding: 0;
}
#submit-mid {
font-size: 75%;
margin: 0;
height: 100%;
background: url("images/WAL-5.jpg") no-repeat center center fixed;
background-size: cover;
text-align:center;
}
#submit-div {
border-radius: 10px 10px 10px 10px;
border-style: solid;
border-width: 1px;
overflow: visible;
width: 400px;
margin: auto;
padding: 10px 20px;
opacity: 0.85;
position: relative;
top: 20%;
overflow: auto;
}
#submitInfo-div {
}
#submitForm-div {
}
table tr th input {
width: 100% !important;
}
#submit-btn {
width: 100px;
height: 30px;
font-size: 14px;
}
</style>
</html>