-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUSI.js
232 lines (202 loc) · 6.55 KB
/
USI.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
/*
interpretation```
https://www.psidev.info/usi
```;
''`
https://pubs.acs.org/doi/10.1021/acs.jproteome.7b00851
```;
interpretatio
Unimod Interim Names
ProForma (Proteoform and Peptidoform Notation)
support subset of the Proforma specification
Unimod
name parsing by
4.2.5 delta mass notation
it does not support the fixed modification
also not
EMEVEESPEK/2+ELVISLIVER/3
This does not define as Base Level Support
*/
/*
mzspec:<collection>:<msRun>:<indexType>:<indexNumber>:<optionalInterpretation>
*/
USI = class USI {
constructor(baseString) {
this.baseString = baseString;
this.proForma = '';
this.parse();
}
/**
* @return {string} returns the ProForma string
*/
parse() {
const usiSplit = this.baseString.split(':');
// const proFormaString = this.baseString.slice(usiSplitPosition + 1);
// if (proFormaString.lastIndexOf('/') === -1) {
if (usiSplit.length <= 5) {
throw 'missing an interpretation';
} else {
let i = 0;
let position = 0;
// hard copy
let _baseString = this.baseString.slice();
while (i < 5) {
position = _baseString.indexOf(':');
_baseString = _baseString.slice(position + 1);
i++;
}
// this.proForma = ;
this.proForma = _baseString;
}
}
};
ProForma = class ProForma {
constructor(baseString) {
this.baseString = baseString;
this.precursorCharge = -1;
this.modifications = [];
this.baseSequence = '';
this.modString = '';
}
parse() {
this.modString = this.generateModString();
this.baseSequence = this.generateBaseSequence();
this.modString = this.removeAdditionalInformation();
this.modString = this.removePrefixTag();
this.modifications = this.parseModification();
}
generateModString() {
const baseStringSplit = this.baseString.split('/');
this.precursorCharge = parseInt(baseStringSplit[1]);
return baseStringSplit[0];
}
// remove Additional information
removeAdditionalInformation() {
return this.modString.replace(/\[info:.+?\]/g, '');
}
generateBaseSequence() {
const modStringWithoutMods = this.modString.replace(/\[.+?\]/g, '');
// notation rule 6
const modStringWithoutMods6 = modStringWithoutMods.replace(/\+/g, '');
// notation rule 7
return modStringWithoutMods6.replace(/-/g, '');
}
removePrefixTag() {
return this.modString.replace(/^\[.+?\]\+/g, '');
}
parseNterminalModifications(annotation, beforeChar, afterChar) {
}
parseModification() {
// deepCopy
const modifications = [];
let modString = this.modString.slice();
let skip = 0; // marks jumps
while (modString.indexOf('[', 0) !== -1) { // if -1 we have modifications
const positionBracketOpen = modString.indexOf('[', 0);
const positionBracketClose = modString.indexOf(']', 0);
// N terminus
if (positionBracketOpen === 0) {
const modification = modString.substring(positionBracketOpen + 1, positionBracketClose);
const m = {
name: modification,
index: -1,
site: 'N-terminus',
};
modifications.push(m);
if (modString[positionBracketClose + 1] === '[') {
// another n terminal modification
skip = 1;
} else {
skip = 2;
}
}
// inside
if (positionBracketOpen !== 0 && modString[positionBracketOpen - 1] !== '-') {
const modification = modString.substring(positionBracketOpen + 1, positionBracketClose);
const m = {
name: modification,
index: positionBracketOpen - 1,
site: modString[positionBracketOpen - 1],
};
modifications.push(m);
skip = 1;
}
if (positionBracketOpen !== 0 && modString[positionBracketOpen - 1] === '-') {
// now parse all the rest
let cTerminalModstring = modString.substring(positionBracketOpen);
while (cTerminalModstring.indexOf('[', 0) !== -1) { // if -1 we have modifications
const cTerminalpositionBracketOpen = cTerminalModstring.indexOf('[', 0);
const cTerminalpositionBracketClose = cTerminalModstring.indexOf(']', 0);
const modification = cTerminalModstring.substring(cTerminalpositionBracketOpen + 1,
cTerminalpositionBracketClose);
const m = {
name: modification,
index: this.baseSequence.length - 1,
site: 'C-terminus',
};
modifications.push(m);
cTerminalModstring = cTerminalModstring.substring(positionBracketClose + skip);
skip = 1;
}
}
modString = modString.slice(0, positionBracketOpen)
+ modString.slice(positionBracketClose + skip);
}
return modifications;
}
getModifications() {
let { modString } = this;
let nTerminalModification = false;
let cTerminalModification;
cTerminalModification = false;
let modifications = [];
if (modString[0] === '[') {
nTerminalModification = true;
}
let positionTracker = 0;
if (nTerminalModification) {
const position = modString.indexOf(']', 0); // returns -1 if false
const modification = modString.substring(1, position);
const m = {
name: modification,
index: -1,
site: 'N-terminus',
};
modifications.push(m);
positionTracker = position + 2; // + 2 to get over ']-'
}
modString = modString.substring(positionTracker);
const check = modString.indexOf('-[', 0);
if (check !== -1) {
const modification = modString.substring(check + 2, modString.length - 1); // +2 to remove '-[' and length -1 for ']'
const m = {
name: modification,
index: this.sequence.length,
site: 'C-terminus',
};
modifications.push(m);
modString = modString.substring(0, check);
}
// parse Modifications within peptide
while (modString.indexOf('[', 0) !== -1) { // LHFFMPGFAPLTSR
const check = modString.indexOf('[', 0);
const position = modString.indexOf(']', 0); // returns -1 if false
const modification = modString.substring(check + 1, position);
positionTracker = position + 2; // + 2 to get over ']-'
const m = {
name: modification,
index: check,
site: modString[check - 1],
};
modifications.push(m);
modString = modString.substring(0, check)
+ modString.substring(position + 1);
}
modifications = modifications.map((el) => {
el.index += -1;
return el;
});
return modifications;
}
};
module.exports = { USI, ProForma };