-
Notifications
You must be signed in to change notification settings - Fork 43
/
alignSeq.js
240 lines (191 loc) · 11.7 KB
/
alignSeq.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
/**
* @author Jiyao Wang <wangjiy@ncbi.nlm.nih.gov> / https://github.com/ncbi/icn3d
*/
class AlignSeq {
constructor(icn3dui) {
this.icn3dui = icn3dui;
}
//Set up the sequence display with the aligned sequences. Either chains in "alignChainArray" or residues
//in "residueArray" will be highlighted. "bUpdateHighlightAtoms" is a flag to update the highlight atoms
//or not. "bShowHighlight" is a flag to show highlight or not.
getAlignSequencesAnnotations(alignChainArray, bUpdateHighlightAtoms, residueArray, bShowHighlight, bOnechain, bReverse) {
let me = this.icn3dui,
ic = me.icn3d;
let sequencesHtml = '';
alignChainArray = Object.keys(ic.alnChains);
if (bReverse) alignChainArray = alignChainArray.reverse();
let maxSeqCnt = 0;
let chainHash = {}
if (alignChainArray !== undefined) {
for (let i = 0, il = alignChainArray.length; i < il; ++i) {
let chainid = alignChainArray[i];
// make sure some residues are aligned
if(ic.alnChainsSeq[chainid] && ic.alnChainsSeq[chainid].length > 0) {
chainHash[chainid] = 1;
}
else {
return { "sequencesHtml": sequencesHtml, "maxSeqCnt": maxSeqCnt };
}
}
}
// let bModifyHAtoms = Object.keys(ic.hAtoms).length == Object.keys(ic.atoms).length && bHighlightChain &&(bUpdateHighlightAtoms === undefined || bUpdateHighlightAtoms);
// let bModifyHAtoms = Object.keys(ic.hAtoms).length == Object.keys(ic.atoms).length &&(bUpdateHighlightAtoms === undefined || bUpdateHighlightAtoms);
let bModifyHAtoms = (bUpdateHighlightAtoms === undefined || bUpdateHighlightAtoms);
if (bModifyHAtoms) {
ic.hAtoms = {}
}
let bHighlightChain;
let index = 0, prevResCnt2nd = 0;
let firstChainid, oriChainid;
// for(let i in ic.alnChains) {
for (let m = 0, ml = alignChainArray.length; m < ml; ++m) {
let i = alignChainArray[m];
if (index == 0) firstChainid = i;
if (bOnechain && index > 0) {
oriChainid = firstChainid;
} else {
oriChainid = i;
}
//bHighlightChain =(alignChainArray !== undefined && chainHash.hasOwnProperty(oriChainid)) ? true : false;
//if( bHighlightChain &&(bUpdateHighlightAtoms === undefined || bUpdateHighlightAtoms) ) {
// do not update isa subset is selected already
if (bModifyHAtoms) {
ic.hAtoms = me.hashUtilsCls.unionHash(ic.hAtoms, ic.alnChains[i]);
}
let resiHtmlArray = [], seqHtml = "";
let seqLength = (ic.alnChainsSeq[i] !== undefined) ? ic.alnChainsSeq[i].length : 0;
if (seqLength > maxSeqCnt) maxSeqCnt = seqLength;
let dashPos = oriChainid.indexOf('_');
let structure = oriChainid.substr(0, dashPos);
let chain = oriChainid.substr(dashPos + 1);
//let startResi = (ic.alnChainsSeq[i][0] !== undefined) ? ic.alnChainsSeq[i][0].resi : '';
let startResi, endResi;
for (let k = 0, kl = seqLength; k < kl; ++k) {
if(ic.alnChainsSeq[i][k].resn != '-') {
startResi = ic.alnChainsSeq[i][k].resi;
break;
}
}
for (let k = seqLength - 1; k >= 0; --k) {
if(ic.alnChainsSeq[i][k].resn != '-') {
endResi = ic.alnChainsSeq[i][k].resi;
break;
}
}
seqHtml += "<span class='icn3d-residueNum' title='starting residue number'>" + startResi + "</span>";
bHighlightChain = (alignChainArray !== undefined && chainHash.hasOwnProperty(oriChainid)) ? true : false;
for (let k = 0, kl = seqLength; k < kl; ++k) {
// resiId is empty if it's gap
let resiId = 'N/A', resIdFull = '', color = '#000';
//if (ic.alnChainsSeq[i][k].resi !== '' && !isNaN(ic.alnChainsSeq[i][k].resi)) {
if (ic.alnChainsSeq[i][k].resi !== '') {
resiId = ic.alnChainsSeq[i][k].resi;
resIdFull = structure + "_" + chain + "_" + resiId;
color = ic.alnChainsSeq[i][k].color;
}
let classForAlign = "class='icn3d-residue"; // used to identify a residue when clicking a residue in sequence
//if((bShowHighlight === undefined || bShowHighlight) &&(bHighlightChain ||(ic.alnChainsSeq[i][k].aligned === 2 && residueArray !== undefined && resIdFull !== '' && residueArray.indexOf(resIdFull) !== -1) ) ) {
if ((bShowHighlight === undefined || bShowHighlight) && (bHighlightChain || (residueArray !== undefined && resIdFull !== '' && residueArray.indexOf(resIdFull) !== -1))) {
classForAlign = "class='icn3d-residue icn3d-highlightSeq";
}
// class for alignment: cons, ncons, nalign
if (resIdFull === '') {
classForAlign += "'";
} else {
classForAlign += " " + ic.alnChainsSeq[i][k].class + "'";
}
let colorRes;
if (!ic.residues.hasOwnProperty(resIdFull)) {
colorRes = '#000000;';
} else {
let firstAtom = ic.firstAtomObjCls.getFirstCalphaAtomObj(ic.residues[resIdFull]);
colorRes = (firstAtom.color !== undefined) ? '#' + firstAtom.color.getHexString() + ';' : '#000000;';
}
if (colorRes.toUpperCase() === '#FFFFFF;') colorRes = me.htmlCls.GREYD;
let bWithCoord = (resIdFull !== '') ? true : false;
if (bOnechain && k == 0) {
let letterSpace = 10;
let empthWidth = prevResCnt2nd * letterSpace;
seqHtml += "<span style='width:" + empthWidth + "px'></span>";
}
if (bWithCoord) {
if (ic.alnChainsSeq[i][k].resi != -1) {
// add "align" in front of id so that full sequence and aligned sequence will not conflict
seqHtml += "<span id='align_" + me.pre + resIdFull + "' " + classForAlign + " style='color:" + colorRes + "' title='" + ic.alnChainsSeq[i][k].resn + ic.alnChainsSeq[i][k].resi + "'>" + ic.alnChainsSeq[i][k].resn + "</span>";
} else {
seqHtml += "<span>" + ic.alnChainsSeq[i][k].resn + "</span>";
}
} else {
seqHtml += "<span title='" + ic.alnChainsSeq[i][k].resn + ic.alnChainsSeq[i][k].resi + "'>" + ic.alnChainsSeq[i][k].resn + "</span>";
}
}
//let endResi = (ic.alnChainsSeq[i][seqLength - 1] !== undefined) ? ic.alnChainsSeq[i][seqLength - 1].resi : '';
seqHtml += "<span class='icn3d-residueNum' title='ending residue number'>" + endResi + "</span>";
let n = alignChainArray.length;
// the first chain stores all annotations
// secondary: n, labels: 2, title: n, empty line: 1
let annoLength = (ic.alnChainsAnno[i] !== undefined) ? ic.alnChainsAnno[i].length : 0;
for (let j = 0, jl = annoLength; j < jl; ++j) {
resiHtmlArray[j] = "";
//let chainid = (j == 0 && annoLength >= 7) ? ic.alnChainsAnTtl[i][4][0] : oriChainid; // bottom secondary, j == 0: chain2, next secondary, j == 1: chain1,
let chainid = (j < n) ? alignChainArray[n - 1 - j] : oriChainid; // bottom secondary, j == 0: chain2, next secondary, j == 1: chain1,
resiHtmlArray[j] += "<span class='icn3d-residueNum'></span>"; // a spot corresponding to the starting and ending residue number
for (let k = 0, kl = ic.alnChainsAnno[i][j].length; k < kl; ++k) {
let text = ic.alnChainsAnno[i][j][k];
if (text == 'H' || text == 'E' || text == 'c' || text == 'o') {
if (text == 'H') {
if (k % 2 == 0) {
resiHtmlArray[j] += '<span class="icn3d-helix"> </span>';
} else {
resiHtmlArray[j] += '<span class="icn3d-helix2"> </span>';
}
} else if (text == 'E') {
if (ic.alnChainsSeq[chainid][k] !== undefined) {
let resiId = ic.alnChainsSeq[chainid][k].resi;
let resIdFull = chainid + "_" + resiId;
if (ic.residues.hasOwnProperty(resIdFull)) {
let atom = ic.firstAtomObjCls.getFirstCalphaAtomObj(ic.residues[resIdFull]);
if (atom.ssend) {
resiHtmlArray[j] += '<span class="icn3d-sheet2"> </span>';
} else {
resiHtmlArray[j] += '<span class="icn3d-sheet"> </span>';
}
}
else {
resiHtmlArray[j] += '<span class="icn3d-sheet"> </span>';
}
}
else {
resiHtmlArray[j] += '<span class="icn3d-sheet"> </span>';
}
} else if (text == 'c') {
resiHtmlArray[j] += '<span class="icn3d-coil"> </span>';
} else if (text == 'o') {
resiHtmlArray[j] += '<span class="icn3d-other"> </span>';
} else {
resiHtmlArray[j] += "<span></span>";
}
} else {
resiHtmlArray[j] += "<span>" + text + "</span>";
}
//resiHtmlArray[j] += "<span>" + ic.alnChainsAnno[i][j][k] + "</span>";
}
resiHtmlArray[j] += "<span class='icn3d-residueNum'></span>"; // a spot corresponding to the starting and ending residue number
}
let chainidTmp = i,
title = (ic.pdbid_chain2title !== undefined) ? ic.pdbid_chain2title[oriChainid] : '';
// add markers and residue numbers
for (let j = annoLength - 1; j >= 0; --j) {
let annotitle = ic.alnChainsAnTtl[i][j][0];
if (annotitle == 'SS') annotitle = '';
//sequencesHtml += "<div class='icn3d-residueLine' style='white-space:nowrap;'><div class='icn3d-seqTitle' chain='" + i + "' anno='" + j + "'>" + annotitle + "</div>" + resiHtmlArray[j] + "<br/></div>";
sequencesHtml += "<div class='icn3d-residueLine' style='white-space:nowrap;'><div class='icn3d-seqTitle' anno='" + j + "'>" + annotitle + "</div>" + resiHtmlArray[j] + "<br/></div>";
}
sequencesHtml += '<div class="icn3d-seqTitle icn3d-link icn3d-blue" chain="' + i + '" anno="sequence" title="' + title + '">' + chainidTmp + ' </div><span class="icn3d-seqLine">' + seqHtml + '</span><br/>';
if (index > 0) prevResCnt2nd += seqLength;
++index;
}
return { "sequencesHtml": sequencesHtml, "maxSeqCnt": maxSeqCnt }
}
}
export { AlignSeq }