@datagrok/bio 1.5.8 → 1.6.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.
- package/detectors.js +24 -12
- package/dist/package-test.js +627 -500
- package/dist/package.js +385 -474
- package/files/samples/sample_FASTA.csv +0 -1
- package/files/samples/sample_FASTA.fasta +0 -3
- package/files/samples/testDemog.csv +5851 -0
- package/files/samples/testHelm.csv +6 -0
- package/files/samples/{id.csv → testId.csv} +0 -0
- package/files/samples/{sar-small.csv → testSmiles.csv} +0 -0
- package/files/samples/testSmiles2.csv +12248 -0
- package/package.json +2 -2
- package/src/package-test.ts +1 -0
- package/src/package.ts +86 -19
- package/src/tests/convert-test.ts +8 -8
- package/src/tests/detectors-test.ts +48 -6
- package/src/tests/renderer-test.ts +40 -18
- package/src/utils/cell-renderer.ts +24 -60
- package/src/utils/convert.ts +10 -14
- package/src/utils/multiple-sequence-alignment.ts +4 -2
- package/src/utils/notation-converter.ts +215 -55
- package/{test-Bio-34f75e5127b8-c4c5a3dc.html → test-Bio-34f75e5127b8-95c6fae9.html} +17 -20
- package/src/utils/chem-palette.ts +0 -280
- package/src/utils/misc.ts +0 -29
|
@@ -1,280 +0,0 @@
|
|
|
1
|
-
import * as grok from 'datagrok-api/grok';
|
|
2
|
-
import * as ui from 'datagrok-api/ui';
|
|
3
|
-
import * as DG from 'datagrok-api/dg';
|
|
4
|
-
|
|
5
|
-
import {StringDictionary} from '@datagrok-libraries/utils/src/type-declarations';
|
|
6
|
-
import {MonomerLibrary} from '../monomer-library';
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
export class ChemPalette {
|
|
10
|
-
cp: StringDictionary = {};
|
|
11
|
-
isInit: boolean = false;
|
|
12
|
-
monomerLib: MonomerLibrary | null = null;
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Creates an instance of ChemPalette.
|
|
16
|
-
*
|
|
17
|
-
* @param {string} scheme Color scheme to use.
|
|
18
|
-
* @param {boolean} [grouping=false] Is grouping enabled.
|
|
19
|
-
* @memberof ChemPalette
|
|
20
|
-
*/
|
|
21
|
-
private constructor(scheme: string, grouping = false) {
|
|
22
|
-
if (scheme == 'grok')
|
|
23
|
-
this.cp = ChemPalette.getDatagrok(grouping);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Renders 2D representation of a amino acid residue in a tooltip.
|
|
28
|
-
*
|
|
29
|
-
* @param {DG.GridCell} cell Grid cell to show tooltip over.
|
|
30
|
-
* @param {number} x x coordinate of the mouse pointer.
|
|
31
|
-
* @param {number} y y coordinate of the mouse pointer.
|
|
32
|
-
* @param {MonomerLibrary} monomerLib Monomer Library instance
|
|
33
|
-
*/
|
|
34
|
-
static showTooltip(cell: DG.GridCell, x: number, y: number, monomerLib: MonomerLibrary): void {
|
|
35
|
-
const s = cell.cell.value as string;
|
|
36
|
-
let toDisplay = [ui.divText(s)];
|
|
37
|
-
const [, aarOuter, aarInner] = ChemPalette.getColorAAPivot(s);
|
|
38
|
-
for (const aar of [aarOuter, aarInner]) {
|
|
39
|
-
if (monomerLib.monomerNames.includes(aar)) {
|
|
40
|
-
if (aar in ChemPalette.AANames)
|
|
41
|
-
toDisplay = [ui.divText(ChemPalette.AANames[aar])];
|
|
42
|
-
|
|
43
|
-
if (aar in ChemPalette.AAFullNames)
|
|
44
|
-
toDisplay = [ui.divText(ChemPalette.AANames[ChemPalette.AAFullNames[aar]])];
|
|
45
|
-
|
|
46
|
-
const options = {
|
|
47
|
-
autoCrop: true,
|
|
48
|
-
autoCropMargin: 0,
|
|
49
|
-
suppressChiralText: true,
|
|
50
|
-
};
|
|
51
|
-
const sketch = grok.chem.svgMol(monomerLib.getMonomerMol(aar), undefined, undefined, options);
|
|
52
|
-
if (toDisplay.length == 2)
|
|
53
|
-
toDisplay.push(ui.divText('Modified'));
|
|
54
|
-
|
|
55
|
-
toDisplay.push(sketch);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
ui.tooltip.show(ui.divV(toDisplay), x, y);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Retursn divided amino with its content in the bracket, if the conetent is number, then its omitted
|
|
63
|
-
*
|
|
64
|
-
* @param {string} c raw amino
|
|
65
|
-
* @return {[string, string]} outer and inner content
|
|
66
|
-
*/
|
|
67
|
-
static getInnerOuter(c: string): [string, string] {
|
|
68
|
-
let isInner = 0;
|
|
69
|
-
let inner = '';
|
|
70
|
-
let outer = '';
|
|
71
|
-
|
|
72
|
-
for (const char of c) {
|
|
73
|
-
if (char == '(')
|
|
74
|
-
isInner++;
|
|
75
|
-
else if (char == ')')
|
|
76
|
-
isInner--;
|
|
77
|
-
else if (isInner)
|
|
78
|
-
inner += char;
|
|
79
|
-
else
|
|
80
|
-
outer += char;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
return !isNaN(parseInt(inner)) ? [outer, ''] : [outer, inner];
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
static getColorAAPivot(monomer: string = '', scheme: 'grok' = 'grok'): [string, string, string, number] {
|
|
87
|
-
const chemPaletteInstance = ChemPalette.getPalette(scheme);
|
|
88
|
-
let [outerMonomer, innerMonomer] = ChemPalette.getInnerOuter(monomer);
|
|
89
|
-
outerMonomer = (outerMonomer.length > 6 ? `${outerMonomer.slice(0, 3)}...` : outerMonomer);
|
|
90
|
-
innerMonomer = (innerMonomer.length > 6 ? `${innerMonomer.slice(0, 3)}...` : innerMonomer);
|
|
91
|
-
|
|
92
|
-
if (monomer.length == 1 || monomer[1] == '(') {
|
|
93
|
-
const amino = monomer[0]?.toUpperCase()!;
|
|
94
|
-
return amino in chemPaletteInstance ?
|
|
95
|
-
[chemPaletteInstance[amino], amino, innerMonomer, 1]:
|
|
96
|
-
[ChemPalette.undefinedColor, outerMonomer, innerMonomer, 1];
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
if (monomer[0] == 'd' && monomer[1]! in chemPaletteInstance) {
|
|
100
|
-
if (monomer.length == 2 || monomer[2] == '(') {
|
|
101
|
-
const amino = monomer[1]?.toUpperCase()!;
|
|
102
|
-
return amino in chemPaletteInstance ?
|
|
103
|
-
[chemPaletteInstance[amino], amino, innerMonomer, 2]:
|
|
104
|
-
[ChemPalette.undefinedColor, outerMonomer, innerMonomer, 2];
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
if (monomer.substring(0, 3) in ChemPalette.AAFullNames) {
|
|
109
|
-
if (monomer.length == 3 || monomer[3] == '(') {
|
|
110
|
-
const amino = ChemPalette.AAFullNames[monomer.substring(0, 3)];
|
|
111
|
-
return amino in chemPaletteInstance ?
|
|
112
|
-
[chemPaletteInstance[amino], amino, innerMonomer, 3]:
|
|
113
|
-
[ChemPalette.undefinedColor, outerMonomer, innerMonomer, 3];
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
if (monomer[0]?.toLowerCase() == monomer[0]) {
|
|
118
|
-
if (monomer.substring(1, 3) in ChemPalette.AAFullNames) {
|
|
119
|
-
if (monomer.length == 4 || monomer[4] == '(') {
|
|
120
|
-
const amino = ChemPalette.AAFullNames[monomer.substring(1, 3)];
|
|
121
|
-
return amino in chemPaletteInstance ?
|
|
122
|
-
[chemPaletteInstance[amino], amino, innerMonomer, 4]:
|
|
123
|
-
[ChemPalette.undefinedColor, outerMonomer, innerMonomer, 4];
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
return [ChemPalette.undefinedColor, outerMonomer, innerMonomer, 0];
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
static colourPalette: {[key: string]: string[]} = {
|
|
132
|
-
'orange': ['rgb(255,187,120)', 'rgb(245,167,100)', 'rgb(235,137,70)', 'rgb(205, 111, 71)'],
|
|
133
|
-
'all_green': ['rgb(44,160,44)', 'rgb(74,160,74)', 'rgb(23,103,57)', 'rgb(30,110,96)', 'rgb(60,131,95)',
|
|
134
|
-
'rgb(24,110,79)', 'rgb(152,223,138)', 'rgb(182, 223, 138)', 'rgb(152, 193, 138)'],
|
|
135
|
-
'all_blue': ['rgb(31,119,180)', 'rgb(23,190,207)', 'rgb(122, 102, 189)', 'rgb(158,218,229)', 'rgb(141, 124, 217)',
|
|
136
|
-
'rgb(31, 120, 150)'],
|
|
137
|
-
'magenta': ['rgb(162,106,192)', 'rgb(197,165,224)', 'rgb(208,113,218)'],
|
|
138
|
-
'red': ['rgb(214,39,40)', 'rgb(255,152,150)'],
|
|
139
|
-
'st_blue': ['rgb(23,190,207)', 'rgb(158,218,229)', 'rgb(31,119,180)'],
|
|
140
|
-
'dark_blue': ['rgb(31,119,180)', 'rgb(31, 120, 150)'],
|
|
141
|
-
'light_blue': ['rgb(23,190,207)', 'rgb(158,218,229)', 'rgb(108, 218, 229)', 'rgb(23,190,227)'],
|
|
142
|
-
'lilac_blue': ['rgb(124,102,211)', 'rgb(149,134,217)', 'rgb(97, 81, 150)'],
|
|
143
|
-
'dark_green': ['rgb(23,103,57)', 'rgb(30,110,96)', 'rgb(60,131,95)', 'rgb(24,110,79)'],
|
|
144
|
-
'green': ['rgb(44,160,44)', 'rgb(74,160,74)'],
|
|
145
|
-
'light_green': ['rgb(152,223,138)', 'rgb(182, 223, 138)', 'rgb(152, 193, 138)'],
|
|
146
|
-
'st_green': ['rgb(44,160,44)', 'rgb(152,223,138)', 'rgb(39, 174, 96)', 'rgb(74,160,74)'],
|
|
147
|
-
'pink': ['rgb(247,182,210)'],
|
|
148
|
-
'brown': ['rgb(140,86,75)', 'rgb(102, 62, 54)'],
|
|
149
|
-
'gray': ['rgb(127,127,127)', 'rgb(199,199,199)', 'rgb(196,156,148)', 'rgb(222, 222, 180)'],
|
|
150
|
-
'yellow': ['rgb(188,189,34)'],
|
|
151
|
-
'white': ['rgb(230,230,230)'],
|
|
152
|
-
};
|
|
153
|
-
|
|
154
|
-
static grokGroups: {[key: string]: string[]} = {
|
|
155
|
-
'yellow': ['C', 'U'],
|
|
156
|
-
'red': ['G', 'P'],
|
|
157
|
-
'all_green': ['A', 'V', 'I', 'L', 'M', 'F', 'Y', 'W'],
|
|
158
|
-
'light_blue': ['R', 'H', 'K'],
|
|
159
|
-
'dark_blue': ['D', 'E'],
|
|
160
|
-
'orange': ['S', 'T', 'N', 'Q'],
|
|
161
|
-
};
|
|
162
|
-
|
|
163
|
-
static undefinedColor = 'rgb(100,100,100)';
|
|
164
|
-
|
|
165
|
-
static makePalette(dt: {[key: string]: string[]}, simplified = false, grouping = false): StringDictionary {
|
|
166
|
-
const palette: { [key: string]: string } = {};
|
|
167
|
-
const groups = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
|
168
|
-
let currentGroup = 0;
|
|
169
|
-
for (const [color, monomers] of Object.entries(dt)) {
|
|
170
|
-
monomers.forEach((monomer, index) => {
|
|
171
|
-
palette[grouping ? groups[currentGroup] : monomer] = ChemPalette.colourPalette[color][simplified ? 0 : index];
|
|
172
|
-
});
|
|
173
|
-
currentGroup++;
|
|
174
|
-
}
|
|
175
|
-
return palette;
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
static AANames: StringDictionary = {
|
|
179
|
-
'G': 'Glycine',
|
|
180
|
-
'L': 'Leucine',
|
|
181
|
-
'Y': 'Tyrosine',
|
|
182
|
-
'S': 'Serine',
|
|
183
|
-
'E': 'Glutamic acid',
|
|
184
|
-
'Q': 'Glutamine',
|
|
185
|
-
'D': 'Aspartic acid',
|
|
186
|
-
'N': 'Asparagine',
|
|
187
|
-
'F': 'Phenylalanine',
|
|
188
|
-
'A': 'Alanine',
|
|
189
|
-
'K': 'Lysine',
|
|
190
|
-
'R': 'Arginine',
|
|
191
|
-
'H': 'Histidine',
|
|
192
|
-
'C': 'Cysteine',
|
|
193
|
-
'V': 'Valine',
|
|
194
|
-
'P': 'Proline',
|
|
195
|
-
'W': 'Tryptophan',
|
|
196
|
-
'I': 'Isoleucine',
|
|
197
|
-
'M': 'Methionine',
|
|
198
|
-
'T': 'Threonine',
|
|
199
|
-
};
|
|
200
|
-
|
|
201
|
-
static AASmiles: StringDictionary = {
|
|
202
|
-
'G': 'NCC(=O)O',
|
|
203
|
-
'L': 'N[C@H](CC(C)C)C(=O)O',
|
|
204
|
-
'Y': 'NC(CC1=CC=C(O)C=C1)C(=O)O',
|
|
205
|
-
'S': 'NC(CO)C(=O)O',
|
|
206
|
-
'E': 'N[C@@H](CCC(O)=O)C(=O)O',
|
|
207
|
-
'Q': 'N[C@@H](CCC(N)=O)C(=O)O',
|
|
208
|
-
'D': 'N[C@@H](CC(O)=O)C(=O)O',
|
|
209
|
-
'N': 'N[C@@H](CC(N)=O)C(=O)O',
|
|
210
|
-
'F': 'NC(CC1=CC=CC=C1)C(=O)O',
|
|
211
|
-
'A': 'N[C@H](C)C(=O)O',
|
|
212
|
-
'K': 'NC(CCCCN)C(=O)O',
|
|
213
|
-
'R': 'N[C@H](CCCNC(=N)C)C(=O)O',
|
|
214
|
-
'H': 'NC(CC1=CN=C[N]1)C(=O)O',
|
|
215
|
-
'C': 'N[C@@H](CS)C(=O)O',
|
|
216
|
-
'V': 'NC(C(C)C)C(=O)O',
|
|
217
|
-
'P': 'N(CCC1)C1C(=O)O',
|
|
218
|
-
'W': 'N[C@@H](Cc1c2ccccc2n([H])c1)C(=O)O',
|
|
219
|
-
'I': 'N[C@H]([C@H](C)CC)C(=O)O',
|
|
220
|
-
'M': 'NC(CCSC)C(=O)O',
|
|
221
|
-
'T': 'NC(C(O)C)C(=O)O',
|
|
222
|
-
};
|
|
223
|
-
|
|
224
|
-
static AASmilesTruncated: StringDictionary = {
|
|
225
|
-
'G': '*C*',
|
|
226
|
-
'L': 'CC(C)C[C@H](*)*',
|
|
227
|
-
'Y': 'C1=CC(=CC=C1CC(*)*)O',
|
|
228
|
-
'S': 'OCC(*)C*',
|
|
229
|
-
'E': '*[C@@H](CCC(O)=O)*',
|
|
230
|
-
'Q': '*N[C@@H](CCC(N)=O)*',
|
|
231
|
-
'D': '*[C@@H](CC(O)=O)*',
|
|
232
|
-
'N': '*[C@@H](CC(N)=O)*',
|
|
233
|
-
'F': 'C1=CC=C(C=C1)CC(*)*',
|
|
234
|
-
'A': 'C[C@H](*)*',
|
|
235
|
-
'K': 'C(CCN)CC(*)*',
|
|
236
|
-
'R': '*[C@H](CCCNC(=N)C)*',
|
|
237
|
-
'H': 'C1=C(NC=N1)CC(*)*',
|
|
238
|
-
'C': 'C([C@@H](*)*)S',
|
|
239
|
-
'V': 'CC(C)C(*)*',
|
|
240
|
-
'P': 'C1CCN(*)C1*',
|
|
241
|
-
'W': '*[C@@H](Cc1c2ccccc2n([H])c1)*',
|
|
242
|
-
'I': 'CC[C@H](C)[C@H](*)*',
|
|
243
|
-
'M': 'CSCCC(*)*',
|
|
244
|
-
'T': 'CC(O)C(*)*',
|
|
245
|
-
};
|
|
246
|
-
|
|
247
|
-
static AAFullNames: StringDictionary = {
|
|
248
|
-
'Ala': 'A',
|
|
249
|
-
'Arg': 'R',
|
|
250
|
-
'Asn': 'N',
|
|
251
|
-
'Asp': 'D',
|
|
252
|
-
'Cys': 'C',
|
|
253
|
-
'Gln': 'Q',
|
|
254
|
-
'Glu': 'E',
|
|
255
|
-
'Gly': 'G',
|
|
256
|
-
'His': 'H',
|
|
257
|
-
'Ile': 'I',
|
|
258
|
-
'Leu': 'L',
|
|
259
|
-
'Lys': 'K',
|
|
260
|
-
'Met': 'M',
|
|
261
|
-
'Phe': 'F',
|
|
262
|
-
'Pro': 'P',
|
|
263
|
-
'Ser': 'S',
|
|
264
|
-
'Thr': 'T',
|
|
265
|
-
'Trp': 'W',
|
|
266
|
-
'Tyr': 'Y',
|
|
267
|
-
'Val': 'V',
|
|
268
|
-
};
|
|
269
|
-
|
|
270
|
-
static getDatagrok(grouping = false): StringDictionary {
|
|
271
|
-
return ChemPalette.makePalette(ChemPalette.grokGroups, false, grouping);
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
static getPalette(scheme: 'grok'): StringDictionary {
|
|
275
|
-
if (scheme == 'grok')
|
|
276
|
-
return ChemPalette.getDatagrok();
|
|
277
|
-
else
|
|
278
|
-
throw new Error(`ChemPalette: scheme \`${scheme}\` does not exist`);
|
|
279
|
-
}
|
|
280
|
-
}
|
package/src/utils/misc.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import * as DG from 'datagrok-api/dg';
|
|
2
|
-
|
|
3
|
-
import * as C from './constants';
|
|
4
|
-
|
|
5
|
-
export function stringToBool(str: string): boolean {
|
|
6
|
-
return str === 'true' ? true : false;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export function getSeparator(col: DG.Column<string>): string {
|
|
10
|
-
const separator = col.tags[C.TAGS.SEPARATOR];
|
|
11
|
-
if (separator)
|
|
12
|
-
return separator as string;
|
|
13
|
-
|
|
14
|
-
const defaultSeparators = ['.', '-', ' '];
|
|
15
|
-
const categories = col.categories;
|
|
16
|
-
const catLen = categories.length;
|
|
17
|
-
for (const potentialSeparator of defaultSeparators) {
|
|
18
|
-
if (categories.filter((sequence) => sequence.includes(potentialSeparator)).length == catLen)
|
|
19
|
-
return potentialSeparator;
|
|
20
|
-
}
|
|
21
|
-
return separator as string ?? '';
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export function getTypedArrayConstructor(
|
|
25
|
-
maxNum: number): Uint8ArrayConstructor | Uint16ArrayConstructor | Uint32ArrayConstructor {
|
|
26
|
-
return maxNum < 256 ? Uint8Array :
|
|
27
|
-
maxNum < 65536 ? Uint16Array :
|
|
28
|
-
Uint32Array;
|
|
29
|
-
}
|