@datagrok/peptides 0.0.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,6 @@
1
1
  import {ChemPalette} from './chem-palette';
2
2
  import * as DG from 'datagrok-api/dg';
3
+
3
4
  const cp = new ChemPalette('grok');
4
5
 
5
6
  export function expandColumn(col:DG.Column,
@@ -22,35 +23,24 @@ export function expandColumn(col:DG.Column,
22
23
  timeout);
23
24
  }
24
25
 
25
- export function setAARRenderer(
26
- col:DG.Column,
27
- grid:DG.Grid|null = null,
28
- ) {
26
+ export function setAARRenderer(col:DG.Column, grid:DG.Grid|null = null) {
29
27
  col.semType = 'aminoAcids';
30
28
  col.setTag('cell.renderer', 'aminoAcids');
31
- if (grid) {
32
- expandColumn(col, grid, (ent) => measureAAR(ent, true));
33
- }
29
+ if (grid)
30
+ expandColumn(col, grid, (ent) => measureAAR(ent));
34
31
  }
35
32
 
36
- export function measureAAR(s:string,
37
- hideMod = false):number {
33
+ export function measureAAR(s: string): number {
38
34
  const end = s.lastIndexOf(')');
39
35
  const beg = s.indexOf('(');
40
36
  return end == beg ? s.length:s.length - (end-beg)+1;
41
37
  }
38
+
42
39
  function printLeftCentered(
43
- x: number,
44
- y: number,
45
- w: number,
46
- h: number,
47
- g: CanvasRenderingContext2D,
48
- s: string,
49
- color = ChemPalette.undefinedColor,
50
- pivot: number = 0,
51
- left = false,
52
- hideMod = false,
53
- ) {
40
+ x: number, y: number, w: number, h: number,
41
+ g: CanvasRenderingContext2D, s: string, color = ChemPalette.undefinedColor,
42
+ pivot: number = 0, left = false, hideMod = false) {
43
+
54
44
  g.textAlign = 'start';
55
45
  let colorPart = pivot == -1 ? s.substring(0) : s.substring(0, pivot);
56
46
  if (colorPart.length == 1) {
@@ -60,7 +50,7 @@ function printLeftCentered(
60
50
  if (colorPart.substring(0, 3) in ChemPalette.AAFullNames) {
61
51
  colorPart = ChemPalette.AAFullNames[s.substring(0, 3)] + colorPart.substr(3);
62
52
  } else if (colorPart.substring(1, 4) in ChemPalette.AAFullNames) {
63
- colorPart = colorPart.at(0) + ChemPalette.AAFullNames[s.substring(1, 4)] + colorPart.substr(4);
53
+ colorPart = colorPart[0] + ChemPalette.AAFullNames[s.substring(1, 4)] + colorPart.substr(4);
64
54
  }
65
55
  }
66
56
  let grayPart = pivot == -1 ? '' : s.substr(pivot);
@@ -80,66 +70,48 @@ function printLeftCentered(
80
70
  const textSize = g.measureText(colorPart + grayPart);
81
71
  const indent = 5;
82
72
 
83
-
84
73
  const colorTextSize = g.measureText(colorPart);
85
- if (left || textSize.width > w) {
74
+
75
+ function draw(dx1: number, dx2: number) {
86
76
  g.fillStyle = color;
87
77
  g.fillText(
88
78
  colorPart,
89
- x + indent,
79
+ x + dx1,
90
80
  y + (textSize.fontBoundingBoxAscent + textSize.fontBoundingBoxDescent) / 2,
91
81
  );
92
82
  g.fillStyle = ChemPalette.undefinedColor;
93
83
  g.fillText(
94
84
  grayPart,
95
- x + indent + colorTextSize.width,
85
+ x + dx2,
96
86
  y + (textSize.fontBoundingBoxAscent + textSize.fontBoundingBoxDescent) / 2,
97
87
  );
88
+ }
89
+
90
+
91
+ if (left || textSize.width > w) {
92
+ draw(indent, indent + colorTextSize.width);
98
93
  return x + colorTextSize.width + g.measureText(grayPart).width;
99
- } else {
100
- g.fillStyle = color;
101
- g.fillText(
102
- colorPart,
103
- x + (w - textSize.width) / 2,
104
- y + (textSize.fontBoundingBoxAscent + textSize.fontBoundingBoxDescent) / 2,
105
- );
106
- g.fillStyle = ChemPalette.undefinedColor;
107
- g.fillText(
108
- grayPart,
109
- x + (w - textSize.width) / 2 + colorTextSize.width,
110
- y + (textSize.fontBoundingBoxAscent + textSize.fontBoundingBoxDescent) / 2,
111
- );
94
+ }
95
+ else {
96
+ draw((w - textSize.width) / 2, (w - textSize.width) / 2 + colorTextSize.width);
112
97
  return x + (w - textSize.width) / 2 + colorTextSize.width;
113
98
  }
114
99
  }
115
100
 
116
- export class AminoAcidsCellRenderer extends DG.GridCellRenderer {
117
- private fontSize = 15;
118
-
119
101
 
120
- get name() {
121
- return 'aminoAcidsCR';
122
- }
102
+ export class AminoAcidsCellRenderer extends DG.GridCellRenderer {
123
103
 
124
- get cellType() {
125
- return 'aminoAcids';
126
- }
104
+ get name() { return 'aminoAcidsCR'; }
127
105
 
106
+ get cellType() { return 'aminoAcids'; }
128
107
 
129
- render(
130
- g: CanvasRenderingContext2D,
131
- x: number,
132
- y: number,
133
- w: number,
134
- h: number,
135
- gridCell: DG.GridCell,
136
- cellStyle: DG.GridCellStyle,
137
- ) {
108
+ render(g: CanvasRenderingContext2D, x: number, y: number, w: number, h: number,
109
+ gridCell: DG.GridCell, cellStyle: DG.GridCellStyle) {
138
110
  g.save();
139
111
  g.beginPath();
140
112
  g.rect(x, y, w, h);
141
113
  g.clip();
142
- g.font = `${this.fontSize}px monospace`;
114
+ g.font = `14px monospace`;
143
115
  g.textBaseline = 'top';
144
116
  const s: string = gridCell.cell.value ? gridCell.cell.value : '-';
145
117
  const [color, pivot] = cp.getColorPivot(s);
@@ -148,46 +120,29 @@ export class AminoAcidsCellRenderer extends DG.GridCellRenderer {
148
120
  }
149
121
  }
150
122
 
151
- export class AlignedSequenceCellRenderer extends DG.GridCellRenderer {
152
- private maxCellWidth = 200;
153
123
 
124
+ export class AlignedSequenceCellRenderer extends DG.GridCellRenderer {
154
125
 
155
- constructor() {
156
- super();
157
- }
158
-
159
-
160
- get name() {
161
- return 'alignedSequenceCR';
162
- }
163
-
164
- get cellType() {
165
- return 'alignedSequence';
166
- }
126
+ get name() { return 'alignedSequenceCR'; }
167
127
 
128
+ get cellType() { return 'alignedSequence'; }
168
129
 
169
- render(
170
- g: CanvasRenderingContext2D,
171
- x: number,
172
- y: number,
173
- w: number,
174
- h: number,
175
- gridCell: DG.GridCell,
176
- cellStyle: DG.GridCellStyle,
177
- ) {
178
- w = Math.min(gridCell.grid.canvas.width-x, w);
130
+ render(g: CanvasRenderingContext2D, x: number, y: number, w: number, h: number,
131
+ gridCell: DG.GridCell, cellStyle: DG.GridCellStyle ) {
132
+ w = Math.min(gridCell.grid.canvas.width - x, w);
179
133
  g.save();
180
134
  g.beginPath();
181
135
  g.rect(x, y, w, h);
182
136
  g.clip();
183
- g.font = '15px monospace';
137
+ g.font = '14px monospace';
184
138
  g.textBaseline = 'top';
185
- const s: string = gridCell.cell.value;
139
+ const s: string = gridCell.cell.value ?? '';
186
140
 
187
141
  const subParts = s.split('-');
188
142
  const [text, simplified] = processSequence(subParts);
189
143
  const textSize = g.measureText(text.join(''));
190
- x = Math.max(x, x+(w-textSize.width)/2);
144
+ x = Math.max(x, x + (w - textSize.width) / 2);
145
+
191
146
  subParts.forEach((amino: string, index) => {
192
147
  const [color, pivot] = cp.getColorPivot(amino);
193
148
  g.fillStyle = ChemPalette.undefinedColor;
@@ -197,15 +152,19 @@ export class AlignedSequenceCellRenderer extends DG.GridCellRenderer {
197
152
  }
198
153
  x = printLeftCentered(x, y, w, h, g, amino, color, pivot, true);
199
154
  });
155
+
200
156
  g.restore();
201
157
  }
202
158
  }
159
+
160
+
203
161
  export function processSequence(subParts:string[]) : [string[], boolean] {
204
- const simplified = !subParts.some((amino, index)=>{
205
- return amino.length>1 &&
206
- index !=0 &&
207
- index != subParts.length-1;
208
- });
162
+
163
+ const simplified = !subParts.some((amino, index) =>
164
+ amino.length > 1 &&
165
+ index != 0 &&
166
+ index != subParts.length - 1);
167
+
209
168
  const text:string[] = [];
210
169
  subParts.forEach((amino: string, index) => {
211
170
  if (index < subParts.length) {
@@ -215,5 +174,4 @@ export function processSequence(subParts:string[]) : [string[], boolean] {
215
174
  text.push(amino);
216
175
  });
217
176
  return [text, simplified];
218
- }
219
-
177
+ }
@@ -1,8 +1,11 @@
1
1
  import * as grok from 'datagrok-api/grok';
2
2
  import * as ui from 'datagrok-api/ui';
3
3
  import * as DG from 'datagrok-api/dg';
4
+
5
+
4
6
  export class ChemPalette {
5
- cp:{ [Key: string]: string; } = {};
7
+ cp: {[key: string]: string} = {};
8
+
6
9
  constructor(scheme: string) {
7
10
  if (scheme == 'grok') {
8
11
  this.cp = ChemPalette.getDatagrok();
@@ -32,32 +35,36 @@ export class ChemPalette {
32
35
  const [color, _] = this.getColorPivot(c);
33
36
  return color;
34
37
  }
38
+
35
39
  getColorAAPivot(c = ''): [string, string, number] {
36
- if (c.length == 1 || c.at(1) == '(') {
37
- const amino = c.at(0)?.toUpperCase()!;
40
+ if (c.length == 1 || c[1] == '(') {
41
+ const amino = c[0]?.toUpperCase()!;
38
42
  return amino in this.cp?
39
43
  [this.cp[amino], amino, 1]:
40
44
  [ChemPalette.undefinedColor, '', 1];
41
45
  }
42
- if (c.at(0) == 'd' && c.at(1)! in this.cp) {
43
- if (c.length == 2 || c.at(2) == '(') {
44
- const amino = c.at(1)?.toUpperCase()!;
46
+
47
+ if (c[0] == 'd' && c[1]! in this.cp) {
48
+ if (c.length == 2 || c[2] == '(') {
49
+ const amino = c[1]?.toUpperCase()!;
45
50
  return amino in this.cp?
46
51
  [this.cp[amino], amino, 2]:
47
52
  [ChemPalette.undefinedColor, '', 2];
48
53
  }
49
54
  }
55
+
50
56
  if (c.substr(0, 3) in ChemPalette.AAFullNames) {
51
- if (c.length == 3 || c.at(3) == '(') {
57
+ if (c.length == 3 || c[3] == '(') {
52
58
  const amino = ChemPalette.AAFullNames[c.substr(0, 3)];
53
59
  return amino in this.cp?
54
60
  [this.cp[amino], amino, 3]:
55
61
  [ChemPalette.undefinedColor, '', 3];
56
62
  }
57
63
  }
58
- if (c.at(0)?.toLowerCase() == c.at(0)) {
64
+
65
+ if (c[0]?.toLowerCase() == c[0]) {
59
66
  if (c.substr(1, 3) in ChemPalette.AAFullNames) {
60
- if (c.length == 4 || c.at(4) == '(') {
67
+ if (c.length == 4 || c[4] == '(') {
61
68
  const amino = ChemPalette.AAFullNames[c.substr(1, 3)];
62
69
  return amino in this.cp?
63
70
  [this.cp[amino], amino, 4]:
@@ -65,16 +72,17 @@ export class ChemPalette {
65
72
  }
66
73
  }
67
74
  }
75
+
68
76
  return [ChemPalette.undefinedColor, '', 0];
69
- //return c ? DG.Color.toRgb(this.colorScale(c)) : 'rgb(127,127,127)'
70
77
  }
78
+
71
79
  getColorPivot(c = ''): [string, number] {
72
80
  // eslint-disable-next-line no-unused-vars
73
81
  const [color, _, pivot] = this.getColorAAPivot(c);
74
82
  return [color, pivot];
75
83
  };
76
84
 
77
- static colourPalette: { [key: string]: string[] } = {
85
+ static colourPalette: {[key: string]: string[]} = {
78
86
  'orange': ['rgb(255,187,120)', 'rgb(245,167,100)', 'rgb(235,137,70)', 'rgb(205, 111, 71)'],
79
87
  'all_green': ['rgb(44,160,44)', 'rgb(74,160,74)', 'rgb(23,103,57)', 'rgb(30,110,96)', 'rgb(60,131,95)',
80
88
  'rgb(24,110,79)', 'rgb(152,223,138)', 'rgb(182, 223, 138)', 'rgb(152, 193, 138)'],
@@ -97,29 +105,44 @@ export class ChemPalette {
97
105
  'white': ['rgb(230,230,230)'],
98
106
  }
99
107
 
100
- static grokGroups: [string[], string][] = [
101
- [['C', 'U'], 'yellow'],
102
- [['G', 'P'], 'red'],
103
- [['A', 'V', 'I', 'L', 'M', 'F', 'Y', 'W'], 'all_green'],
104
- [['R', 'H', 'K'], 'light_blue'],
105
- [['D', 'E'], 'dark_blue'],
106
- [['S', 'T', 'N', 'Q'], 'orange'],
107
- ];
108
+ // static grokGroups: [string[], string][] = [
109
+ // [['C', 'U'], 'yellow'],
110
+ // [['G', 'P'], 'red'],
111
+ // [['A', 'V', 'I', 'L', 'M', 'F', 'Y', 'W'], 'all_green'],
112
+ // [['R', 'H', 'K'], 'light_blue'],
113
+ // [['D', 'E'], 'dark_blue'],
114
+ // [['S', 'T', 'N', 'Q'], 'orange'],
115
+ // ];
116
+ static grokGroups: {[key: string]: string[]} = {
117
+ 'yellow': ['C', 'U'],
118
+ 'red': ['G', 'P'],
119
+ 'all_green': ['A', 'V', 'I', 'L', 'M', 'F', 'Y', 'W'],
120
+ 'light_blue': ['R', 'H', 'K'],
121
+ 'dark_blue': ['D', 'E'],
122
+ 'orange': ['S', 'T', 'N', 'Q'],
123
+ }
124
+
125
+ static leskGroups: {[key: string]: string[]} = {
126
+ 'orange': ['G', 'A', 'S', 'T'],
127
+ 'all_green': ['C', 'V', 'I', 'L', 'P', 'F', 'Y', 'M', 'W'],
128
+ 'magenta': ['N', 'Q', 'H'],
129
+ 'red': ['D', 'E'],
130
+ 'all_blue': ['K', 'R'],
131
+ }
132
+
108
133
  static undefinedColor = 'rgb(100,100,100)'
109
134
 
110
- static makePalette(dt: [string[], string][], simplified = false) {
135
+ static makePalette(dt: {[key: string]: string[]}, simplified = false) {
111
136
  const palette: { [key: string]: string } = {};
112
- dt.forEach((cp) => {
113
- const objList = cp[0];
114
- const colour = cp[1];
115
- objList.forEach((obj, ind) => {
116
- palette[obj] = ChemPalette.colourPalette[colour][simplified ? 0 : ind];
137
+ for (const [color, monomers] of Object.entries(dt)) {
138
+ monomers.forEach((monomer, index) => {
139
+ palette[monomer] = ChemPalette.colourPalette[color][simplified ? 0 : index];
117
140
  });
118
- });
141
+ }
119
142
  return palette;
120
143
  }
121
144
 
122
- static AANames:{ [Key: string]: string; } = {
145
+ static AANames: {[key: string]: string} = {
123
146
  'G': 'Glycine',
124
147
  'L': 'Leucine',
125
148
  'Y': 'Tyrosine',
@@ -141,7 +164,8 @@ export class ChemPalette {
141
164
  'M': 'Methionine',
142
165
  'T': 'Threonine',
143
166
  }
144
- static AASmiles: { [Key: string]: string; } = {
167
+
168
+ static AASmiles: {[key: string]: string} = {
145
169
  'G': 'NCC(=O)O',
146
170
  'L': 'N[C@H](CC(C)C)C(=O)O',
147
171
  'Y': 'NC(CC1=CC=C(O)C=C1)C(=O)O',
@@ -153,7 +177,7 @@ export class ChemPalette {
153
177
  'F': 'NC(CC1=CC=CC=C1)C(=O)O',
154
178
  'A': 'N[C@H](C)C(=O)O',
155
179
  'K': 'NC(CCCCN)C(=O)O',
156
- 'R': 'N[C(=O)OH](CCCNC(N)=N)C(=O)O',
180
+ 'R': 'N[C@H](CCCNC(=N)C)C(=O)O',
157
181
  'H': 'NC(CC1=CN=C[N]1)C(=O)O',
158
182
  'C': 'N[C@@H](CS)C(=O)O',
159
183
  'V': 'NC(C(C)C)C(=O)O',
@@ -163,7 +187,8 @@ export class ChemPalette {
163
187
  'M': 'NC(CCSC)C(=O)O',
164
188
  'T': 'NC(C(O)C)C(=O)O',
165
189
  }
166
- static AASmilesTruncated: { [Key: string]: string; } = {
190
+
191
+ static AASmilesTruncated: {[key: string]: string} = {
167
192
  'G': '*C*',
168
193
  'L': 'CC(C)C[C@H](*)*',
169
194
  'Y': 'C1=CC(=CC=C1CC(*)*)O',
@@ -175,7 +200,7 @@ export class ChemPalette {
175
200
  'F': 'C1=CC=C(C=C1)CC(*)*',
176
201
  'A': 'C[C@H](*)*',
177
202
  'K': 'C(CCN)CC(*)*',
178
- 'R': '*[C(=O)OH](CCCNC(N)=N)*',
203
+ 'R': '*[C@H](CCCNC(=N)C)*',
179
204
  'H': 'C1=C(NC=N1)CC(*)*',
180
205
  'C': 'C([C@@H](*)*)S',
181
206
  'V': 'CC(C)C(*)*',
@@ -186,7 +211,7 @@ export class ChemPalette {
186
211
  'T': 'CC(O)C(*)*',
187
212
  }
188
213
 
189
- static AAFullNames: { [Key: string]: string; } = {
214
+ static AAFullNames: {[key: string]: string} = {
190
215
  'Ala': 'A',
191
216
  'Arg': 'R',
192
217
  'Asn': 'N',
@@ -207,16 +232,13 @@ export class ChemPalette {
207
232
  'Trp': 'W',
208
233
  'Tyr': 'Y',
209
234
  'Val': 'V',
210
- };
235
+ }
211
236
 
212
- static getDatagrok = ():{ [Key: string]: string; } => {
237
+ static getDatagrok() {
213
238
  return ChemPalette.makePalette(ChemPalette.grokGroups);
214
- };
239
+ }
215
240
 
216
- getLesk = () => ChemPalette.makePalette([
217
- [['G', 'A', 'S', 'T'], 'orange'],
218
- [['C', 'V', 'I', 'L', 'P', 'F', 'Y', 'M', 'W'], 'all_green'],
219
- [['N', 'Q', 'H'], 'magenta'],
220
- [['D', 'E'], 'red'],
221
- [['K', 'R'], 'all_blue']])
241
+ static getLesk() {
242
+ return ChemPalette.makePalette(ChemPalette.leskGroups);
243
+ }
222
244
  }
@@ -0,0 +1,175 @@
1
+ /**
2
+ * Library of molecular weights.
3
+ * @link https://worldwide.promega.com/resources/tools/amino-acid-chart-amino-acid-structure */
4
+ const _lib = [
5
+ {
6
+ 'Name': 'Alanine',
7
+ 'Three-letter': 'Ala',
8
+ 'One-letter': 'A',
9
+ 'Weight': '89Da',
10
+ },
11
+ {
12
+ 'Name': 'Arginine',
13
+ 'Three-letter': 'Arg',
14
+ 'One-letter': 'R',
15
+ 'Weight': '174Da',
16
+ },
17
+ {
18
+ 'Name': 'Asparagine',
19
+ 'Three-letter': 'Asn',
20
+ 'One-letter': 'N',
21
+ 'Weight': '132Da',
22
+ },
23
+ {
24
+ 'Name': 'Aspartic acid',
25
+ 'Three-letter': 'Asp',
26
+ 'One-letter': 'D',
27
+ 'Weight': '133Da',
28
+ },
29
+ {
30
+ 'Name': 'Asparagine or aspartic acid',
31
+ 'Three-letter': 'Asx',
32
+ 'One-letter': 'B',
33
+ 'Weight': '133Da',
34
+ },
35
+ {
36
+ 'Name': 'Cysteine',
37
+ 'Three-letter': 'Cys',
38
+ 'One-letter': 'C',
39
+ 'Weight': '121Da',
40
+ },
41
+ {
42
+ 'Name': 'Glutamine',
43
+ 'Three-letter': 'Gln',
44
+ 'One-letter': 'Q',
45
+ 'Weight': '146Da',
46
+ },
47
+ {
48
+ 'Name': 'Glutamic acid',
49
+ 'Three-letter': 'Glu',
50
+ 'One-letter': 'E',
51
+ 'Weight': '147Da',
52
+ },
53
+ {
54
+ 'Name': 'Glutamine or glutamic acid',
55
+ 'Three-letter': 'Glx',
56
+ 'One-letter': 'Z',
57
+ 'Weight': '147Da',
58
+ },
59
+ {
60
+ 'Name': 'Glycine',
61
+ 'Three-letter': 'Gly',
62
+ 'One-letter': 'G',
63
+ 'Weight': '75Da',
64
+ },
65
+ {
66
+ 'Name': 'Histidine',
67
+ 'Three-letter': 'His',
68
+ 'One-letter': 'H',
69
+ 'Weight': '155Da',
70
+ },
71
+ {
72
+ 'Name': 'Isoleucine',
73
+ 'Three-letter': 'Ile',
74
+ 'One-letter': 'I',
75
+ 'Weight': '131Da',
76
+ },
77
+ {
78
+ 'Name': 'Leucine',
79
+ 'Three-letter': 'Leu',
80
+ 'One-letter': 'L',
81
+ 'Weight': '131Da',
82
+ },
83
+ {
84
+ 'Name': 'Lysine',
85
+ 'Three-letter': 'Lys',
86
+ 'One-letter': 'K',
87
+ 'Weight': '146Da',
88
+ },
89
+ {
90
+ 'Name': 'Methionine',
91
+ 'Three-letter': 'Met',
92
+ 'One-letter': 'M',
93
+ 'Weight': '149Da',
94
+ },
95
+ {
96
+ 'Name': 'Phenylalanine',
97
+ 'Three-letter': 'Phe',
98
+ 'One-letter': 'F',
99
+ 'Weight': '165Da',
100
+ },
101
+ {
102
+ 'Name': 'Proline',
103
+ 'Three-letter': 'Pro',
104
+ 'One-letter': 'P',
105
+ 'Weight': '115Da',
106
+ },
107
+ {
108
+ 'Name': 'Serine',
109
+ 'Three-letter': 'Ser',
110
+ 'One-letter': 'S',
111
+ 'Weight': '105Da',
112
+ },
113
+ {
114
+ 'Name': 'Threonine',
115
+ 'Three-letter': 'Thr',
116
+ 'One-letter': 'T',
117
+ 'Weight': '119Da',
118
+ },
119
+ {
120
+ 'Name': 'Tryptophan',
121
+ 'Three-letter': 'Trp',
122
+ 'One-letter': 'W',
123
+ 'Weight': '204Da',
124
+ },
125
+ {
126
+ 'Name': 'Tyrosine',
127
+ 'Three-letter': 'Tyr',
128
+ 'One-letter': 'Y',
129
+ 'Weight': '181Da',
130
+ },
131
+ {
132
+ 'Name': 'Valine',
133
+ 'Three-letter': 'Val',
134
+ 'One-letter': 'V',
135
+ 'Weight': '117Da',
136
+ },
137
+ ];
138
+
139
+ /**
140
+ * Selection of the molecular weights of amino acid residues.
141
+ * @type {*} */
142
+ const weightsLib : {[name: string]: number} = {};
143
+
144
+ // Create a dictionary linking one-letter code with the corresponding residues weight.
145
+ for (const d of _lib) {
146
+ weightsLib[d['One-letter']] = parseFloat(d.Weight.substring(0, d.Weight.length-2));
147
+ }
148
+
149
+ /**
150
+ * Calculates molecular weight of the given peptide in daltons.
151
+ *
152
+ * @export
153
+ * @param {string} sequence Peptide sequence.
154
+ * @return {number} Molecular weight in Da.
155
+ */
156
+ export function getSequenceMolecularWeight(sequence: string): number {
157
+ let sum = 0;
158
+
159
+ if (sequence.startsWith('NH2')) {
160
+ sum += 16.02;
161
+ sequence = sequence.substring(3);
162
+ }
163
+
164
+ if (sequence.endsWith('COOH')) {
165
+ sum += 45.02;
166
+ sequence = sequence.substring(0, sequence.length-4);
167
+ }
168
+
169
+ for (const i of sequence) {
170
+ if (i in weightsLib) {
171
+ sum += weightsLib[i];
172
+ }
173
+ }
174
+ return sum;
175
+ }