/
interaction2.js
229 lines (174 loc) · 8.69 KB
/
interaction2.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
// Exclude the interaction in the same chain
// usage: node interaction2.js 6M0J E 501 Y
/*
Please install the following three packages in your directory with the file interaction.js
npm install three
npm install jquery
npm install icn3d
npm install axios
npm install querystring
*/
// https://github.com/Jam3/three-buffer-vertex-data/issues/2
global.THREE = require('three');
let jsdom = require('jsdom');
global.$ = require('jquery')(new jsdom.JSDOM().window);
let icn3d = require('icn3d');
let me = new icn3d.iCn3DUI({});
let https = require('https');
let axios = require('axios');
let qs = require('querystring');
//let utils = require('./utils.js');
let myArgs = process.argv.slice(2);
if(myArgs.length != 4) {
console.log("Usage: node interaction2.js [PDB ID] [Chain ID] [Residue number] [One letter mutant]");
return;
}
let pdbid = myArgs[0].toUpperCase(); //'6jxr'; //myArgs[0];
let chain = myArgs[1];
let resi = myArgs[2];
let mutant = myArgs[3];
let baseUrlMmdb = "https://www.ncbi.nlm.nih.gov/Structure/mmdb/mmdb_strview.cgi?v=2&program=icn3d&b=1&s=1&ft=1&bu=0&complexity=2&uid=";
let urlMmdb = baseUrlMmdb + pdbid;
https.get(urlMmdb, async function(res1) {
let response1 = [];
res1.on('data', function (chunk) {
response1.push(chunk);
});
res1.on('end', async function(){
let dataStr1 = response1.join('');
let dataJson = JSON.parse(dataStr1);
me.setIcn3d();
let ic = me.icn3d;
ic.bRender = false;
await ic.mmdbParserCls.parseMmdbData(dataJson);
// find PDB in 10 angstrom around the SNP
let chainid = pdbid + '_' + chain + '_' + resi;
if(!ic.residues.hasOwnProperty(chainid)) {
console.error("Error: This residue " + chainid + " has no 3D coordinates...");
return;
}
let pdbStr = getPdbStr(ic, pdbid, chain, resi);
if(mutant == '-') { // deletion
let pdbData = pdbStr;
//console.log("free energy (kcal/mol): deletion");
let bAddition = true;
// all atoms, including the mutant
ic.loadPDBCls.loadPDB(pdbData, pdbid, false, false, bAddition);
let type = 'save1';
let resid = pdbid + '_' + chain + '_' + resi;
let atomSet2 = ic.residues[resid];
let atomSet = me.hashUtilsCls.exclHash(ic.atoms, atomSet2);
// prepare names for two sets
let command2 = resid;
let residArray2 = [resid];
ic.selectionCls.addCustomSelection(residArray2, command2, command2, 'select ' + command2, true);
let nameArray2 = [command2];
var residueHash = ic.firstAtomObjCls.getResiduesFromAtoms(atomSet);
let command = 'other';
let residArray = Object.keys(residueHash);
ic.selectionCls.addCustomSelection(residArray, command, command, 'select ' + command, true);
let nameArray = [command];
let result = await ic.viewInterPairsCls.viewInteractionPairs(nameArray2, nameArray, false, type,
true, true, true, true, true, true);
let bondCntWild = result.bondCnt;
let resn = ic.residueId2Name[resid];
console.log(pdbid + ", " + pdbid + "_" + chain + ", " + resi + ", " + resn + ", " + mutant + ", " + (- bondCntWild[0].cntHbond).toString() + ", " + (- bondCntWild[0].cntIonic).toString() + ", " + (- bondCntWild[0].cntContact).toString() + ", " + (- bondCntWild[0].cntHalegen).toString() + ", " + (- bondCntWild[0].cntPication).toString() + ", " + (- bondCntWild[0].cntPistacking).toString());
}
else {
let snpStr = chain + ',' + resi + ',' + mutant;
let dataObj = {'pdb': pdbStr, 'snp': snpStr, 'pdbid': pdbid, 'json': 1};
//https://attacomsian.com/blog/node-http-post-request
// 'https' didn't work for posting PDB data, use 'application/x-www-form-urlencoded'
const config = { headers: { 'Content-Type': 'application/x-www-form-urlencoded' } };
axios.post('https://www.ncbi.nlm.nih.gov/Structure/scap/scap.cgi', qs.stringify(dataObj), config)
.then(async function(res) {
//console.log(`Status: ${res.status}`);
//console.log('Body: ', res.data);
let mutantPDB = res.data.data.replace(/\\n/g, '\n');
await showInteractionChange(ic, mutantPDB, pdbid, chain, resi);
})
// the following caused error as described at https://stackoverflow.com/questions/53940043/unhandledpromiserejectionwarning-this-error-originated-either-by-throwing-insid
// .catch(function(err) {
// //utils.dumpError(err);
// console.log(err.stack);
// });
}
});
}).on('error', function(e) {
console.error("Error: " + pdbid + " has no MMDB data...");
});
function getPdbStr(ic, pdbid, chain, resi) {
let atoms = ic.atoms;
let residues = ic.residues;
// find neighboring residues
let resid = pdbid + '_' + chain + '_' + resi;
let radius = 10;
let bGetPairs = false;
let bSphereCalc = true;
let bInteraction = false;
let type = 'view';
let result = ic.showInterCls.pickCustomSphere_base(radius, residues[resid], atoms, bSphereCalc, bInteraction, type, 'select zone', bGetPairs);
let residueArray = Object.keys(result.residues);
let hAtoms = {};
for(let index = 0, indexl = residueArray.length; index < indexl; ++index) {
let residTmp = residueArray[index];
for(let i in residues[residTmp]) {
hAtoms[i] = 1;
}
}
hAtoms = me.hashUtilsCls.unionHash(hAtoms, residues[resid]);
let pdbStr = ic.saveFileCls.getPDBHeader() + ic.saveFileCls.getAtomPDB(hAtoms);
return pdbStr;
}
async function showInteractionChange(ic, data, pdbid, chain, resi) {
let pos = data.indexOf('\n');
let energy = data.substr(0, pos);
let pdbData = data.substr(pos + 1);
// console.log("free energy (kcal/mol): " + energy);
let bMutation = true;
let bAddition = true;
// all atoms, including the mutant
ic.loadPDBCls.loadPDB(pdbData, pdbid, false, false, bMutation, bAddition);
let type = 'save1';
let resid = pdbid + '_' + chain + '_' + resi, residMutant = pdbid + '2_' + chain + '_' + resi;
let mutantSet = {};
let chainidArray = ic.structures[pdbid + '2'];
for(let i = 0, il = chainidArray.length; i < il; ++i) {
mutantSet = me.hashUtilsCls.unionHash(mutantSet, ic.chains[chainidArray[i]]);
}
let atomSet2 = ic.residues[resid];
let tmpSet = me.hashUtilsCls.exclHash(ic.atoms, mutantSet);
// only for interaction in different chain
let atomSet = me.hashUtilsCls.exclHash(tmpSet, ic.chains[pdbid + '_' + chain]);
// prepare names for two sets
let command2 = resid;
let residArray2 = [resid];
ic.selectionCls.addCustomSelection(residArray2, command2, command2, 'select ' + command2, true);
let nameArray2 = [command2];
var residueHash = ic.firstAtomObjCls.getResiduesFromAtoms(atomSet);
let command = 'other-wild';
let residArray = Object.keys(residueHash);
ic.selectionCls.addCustomSelection(residArray, command, command, 'select ' + command, true);
let nameArray = [command];
let result = await ic.viewInterPairsCls.viewInteractionPairs(nameArray2, nameArray, false, type,
true, true, true, true, true, true);
let bondCntWild = result.bondCnt;
let atomSetMutant2 = ic.residues[residMutant];
// only for interaction in different chain
let atomSetMutant = me.hashUtilsCls.exclHash(mutantSet, ic.chains[pdbid + '2_' + chain]);
// prepare names for two sets
command2 = residMutant;
residArray2 = [residMutant];
ic.selectionCls.addCustomSelection(residArray2, command2, command2, 'select ' + command2, true);
nameArray2 = [command2];
residueHash = ic.firstAtomObjCls.getResiduesFromAtoms(atomSetMutant);
command = 'other-mutant';
residArray = Object.keys(residueHash);
ic.selectionCls.addCustomSelection(residArray, command, command, 'select ' + command, true);
nameArray = [command];
let resultMutant = await ic.viewInterPairsCls.viewInteractionPairs(nameArray2, nameArray, false, type,
true, true, true, true, true, true);
let bondCntMutant = resultMutant.bondCnt;
let resn = ic.residueId2Name[resid];
console.log(pdbid + ", " + pdbid + "_" + chain + ", " + resi + ", " + resn + ", " + mutant + ", " + (bondCntMutant[0].cntHbond - bondCntWild[0].cntHbond).toString() + ", " + (bondCntMutant[0].cntIonic - bondCntWild[0].cntIonic).toString() + ", " + (bondCntMutant[0].cntContact - bondCntWild[0].cntContact).toString() + ", " + (bondCntMutant[0].cntHalegen - bondCntWild[0].cntHalegen).toString() + ", " + (bondCntMutant[0].cntPication - bondCntWild[0].cntPication).toString() + ", " + (bondCntMutant[0].cntPistacking - bondCntWild[0].cntPistacking).toString());
}