@datagrok/sequence-translator 1.3.12 → 1.3.14
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/CHANGELOG.md +19 -1
- package/dist/package-test.js +1 -1
- package/dist/package-test.js.map +1 -1
- package/dist/package.js +1 -1
- package/dist/package.js.map +1 -1
- package/package.json +6 -6
- package/src/apps/common/view/components/colored-input/style.css +1 -0
- package/src/apps/structure/view/style.css +14 -19
- package/src/apps/structure/view/ui.ts +9 -25
- package/src/package.ts +6 -6
- package/src/polytool/pt-dialog.ts +3 -70
- package/src/polytool/pt-enumeration-helm-dialog.ts +366 -169
- package/src/polytool/pt-enumeration-helm.ts +41 -33
- package/src/polytool/pt-placeholders-input.ts +23 -9
- package/src/polytool/types.ts +2 -0
- package/src/tests/polytool-enumerate-tests.ts +41 -24
- package/src/utils/context-menu.ts +5 -3
- package/src/utils/err-info.ts +2 -1
- package/src/polytool/cyclized.ts +0 -56
|
@@ -2,7 +2,11 @@ import * as ui from 'datagrok-api/ui';
|
|
|
2
2
|
import * as grok from 'datagrok-api/grok';
|
|
3
3
|
import * as DG from 'datagrok-api/dg';
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
HelmType, HelmMol,
|
|
7
|
+
JSDraw2ModuleType, OrgType
|
|
8
|
+
} from '@datagrok-libraries/bio/src/helm/types';
|
|
9
|
+
|
|
6
10
|
|
|
7
11
|
import {Chain} from './pt-conversion';
|
|
8
12
|
import {getAvailableMonomers} from './utils';
|
|
@@ -17,9 +21,14 @@ declare const org: OrgType;
|
|
|
17
21
|
function polyToolEnumeratorCore(m: HelmMol, position: number, monomerList: string[]): HelmMol[] {
|
|
18
22
|
const resMolList: HelmMol[] = new Array<HelmMol>(monomerList.length);
|
|
19
23
|
for (let i = 0; i < monomerList.length; i++) {
|
|
20
|
-
const
|
|
21
|
-
const resM = resMolList[i] = m.clone();
|
|
22
|
-
resM.atoms[position].elem
|
|
24
|
+
const newSymbol = monomerList[i];
|
|
25
|
+
const resM = resMolList[i] = m.clone() as HelmMol;
|
|
26
|
+
const oldSymbol = resM.atoms[position].elem;
|
|
27
|
+
resM.atoms[position].elem = newSymbol;
|
|
28
|
+
|
|
29
|
+
const idOldSymbol = oldSymbol?.length > 1 ? `[${oldSymbol}]` : oldSymbol;
|
|
30
|
+
const idNewSymbol = newSymbol?.length > 1 ? `[${newSymbol}]` : newSymbol;
|
|
31
|
+
resM.name = `${m.name}-${idOldSymbol}${position + 1}${idNewSymbol}`;
|
|
23
32
|
}
|
|
24
33
|
return resMolList;
|
|
25
34
|
}
|
|
@@ -29,46 +38,45 @@ function polyToolEnumeratorCore(m: HelmMol, position: number, monomerList: strin
|
|
|
29
38
|
* @param placeholders Placeholders by zero-based position key
|
|
30
39
|
* @returns {string[]} List of enumerated molecules in Helm format
|
|
31
40
|
*/
|
|
32
|
-
function getPtEnumeratorSingle(
|
|
33
|
-
const molHandler = new JSDraw2.MolHandler<HelmType>();
|
|
34
|
-
const plugin = new org.helm.webeditor.Plugin(molHandler);
|
|
35
|
-
const io = org.helm.webeditor.IO;
|
|
36
|
-
|
|
37
|
-
const origin = new JSDraw2.Point(0, 0);
|
|
38
|
-
io.parseHelm(plugin, helm, origin, undefined);
|
|
39
|
-
|
|
41
|
+
function getPtEnumeratorSingle(m: HelmMol, placeholders: PolyToolPlaceholders): HelmMol[] {
|
|
40
42
|
const coreResList: HelmMol[][] = Object.entries(placeholders)
|
|
41
|
-
.map(([p, monomerList]: [string, string[]]) => polyToolEnumeratorCore(
|
|
43
|
+
.map(([p, monomerList]: [string, string[]]) => polyToolEnumeratorCore(m, parseInt(p), monomerList));
|
|
42
44
|
const resMolList = coreResList.reduce((acc, posList) => acc.concat(posList), []);
|
|
43
|
-
|
|
44
|
-
const resHelmList = resMolList.map((m: HelmMol) => org.helm.webeditor.IO.getHelm(m)!);
|
|
45
|
-
return resHelmList;
|
|
45
|
+
return resMolList;
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
function getPtEnumeratorMatrix(
|
|
49
|
-
|
|
50
|
-
const plugin = new org.helm.webeditor.Plugin(molHandler);
|
|
51
|
-
const io = org.helm.webeditor.IO;
|
|
52
|
-
|
|
53
|
-
const origin = new JSDraw2.Point(0, 0);
|
|
54
|
-
io.parseHelm(plugin, helm, origin, undefined);
|
|
55
|
-
|
|
56
|
-
let resMolList = [molHandler.m];
|
|
48
|
+
function getPtEnumeratorMatrix(m: HelmMol, placeholders: PolyToolPlaceholders): HelmMol[] {
|
|
49
|
+
let resMolList = [m];
|
|
57
50
|
for (const [p, monomerList] of Object.entries(placeholders)) {
|
|
58
51
|
const pos: number = parseInt(p);
|
|
59
52
|
const posResMolList: HelmMol[][] = resMolList.map((m: HelmMol) => polyToolEnumeratorCore(m, pos, monomerList));
|
|
60
53
|
resMolList = posResMolList.reduce((acc, l) => acc.concat(l), []);
|
|
61
54
|
}
|
|
62
|
-
|
|
63
|
-
const resHelmList = resMolList.map((m: HelmMol) => org.helm.webeditor.IO.getHelm(m)!);
|
|
64
|
-
return resHelmList;
|
|
55
|
+
return resMolList;
|
|
65
56
|
}
|
|
66
57
|
|
|
67
|
-
export function getPtEnumeratorHelm(helm: string, params: PolyToolEnumeratorParams): string[] {
|
|
58
|
+
export function getPtEnumeratorHelm(helm: string, id: string, params: PolyToolEnumeratorParams): [string, string][] {
|
|
59
|
+
const molHandler = new JSDraw2.MolHandler<HelmType>();
|
|
60
|
+
const plugin = new org.helm.webeditor.Plugin(molHandler);
|
|
61
|
+
org.helm.webeditor.IO.parseHelm(plugin, helm, new JSDraw2.Point(0, 0), undefined);
|
|
62
|
+
const m = molHandler.m;
|
|
63
|
+
m.name = id;
|
|
64
|
+
|
|
65
|
+
let resMolList: HelmMol[];
|
|
68
66
|
switch (params.type) {
|
|
69
|
-
case PolyToolEnumeratorTypes.Single:
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
67
|
+
case PolyToolEnumeratorTypes.Single: {
|
|
68
|
+
resMolList = getPtEnumeratorSingle(molHandler.m, params.placeholders);
|
|
69
|
+
break;
|
|
70
|
+
}
|
|
71
|
+
case PolyToolEnumeratorTypes.Matrix: {
|
|
72
|
+
resMolList = getPtEnumeratorMatrix(molHandler.m, params.placeholders);
|
|
73
|
+
break;
|
|
74
|
+
}
|
|
73
75
|
}
|
|
76
|
+
|
|
77
|
+
if (params.keepOriginal)
|
|
78
|
+
resMolList = [m, ...resMolList];
|
|
79
|
+
|
|
80
|
+
const resList = resMolList.map<[string, string]>((m: HelmMol) => { return [org.helm.webeditor.IO.getHelm(m)!, m.name!]; });
|
|
81
|
+
return resList;
|
|
74
82
|
}
|
|
@@ -2,6 +2,8 @@ import * as ui from 'datagrok-api/ui';
|
|
|
2
2
|
import * as grok from 'datagrok-api/grok';
|
|
3
3
|
import * as DG from 'datagrok-api/dg';
|
|
4
4
|
|
|
5
|
+
import {Unsubscribable} from 'rxjs';
|
|
6
|
+
|
|
5
7
|
import {PolyToolPlaceholders} from './types';
|
|
6
8
|
|
|
7
9
|
export class PolyToolPlaceholdersInput extends DG.JsInputBase<DG.DataFrame> {
|
|
@@ -34,6 +36,8 @@ export class PolyToolPlaceholdersInput extends DG.JsInputBase<DG.DataFrame> {
|
|
|
34
36
|
private readonly gridHost: HTMLDivElement;
|
|
35
37
|
public readonly grid: DG.Grid;
|
|
36
38
|
|
|
39
|
+
private subs: Unsubscribable[] = [];
|
|
40
|
+
|
|
37
41
|
protected constructor(name: string | undefined, grid: DG.Grid, heightRowCount?: number) {
|
|
38
42
|
super();
|
|
39
43
|
|
|
@@ -41,7 +45,7 @@ export class PolyToolPlaceholdersInput extends DG.JsInputBase<DG.DataFrame> {
|
|
|
41
45
|
|
|
42
46
|
this.gridHost = ui.div([], {
|
|
43
47
|
classes: 'ui-input-editor',
|
|
44
|
-
style: {width: '100%', height: '100%', marginTop: '-8px'},
|
|
48
|
+
style: {width: '100%', height: '100%', marginTop: '-8px', marginBottom: '8px', paddingBottom: '4px'},
|
|
45
49
|
});
|
|
46
50
|
|
|
47
51
|
this.grid = grid;
|
|
@@ -51,25 +55,34 @@ export class PolyToolPlaceholdersInput extends DG.JsInputBase<DG.DataFrame> {
|
|
|
51
55
|
this.updateGridHeight(heightRowCount + 0.7);
|
|
52
56
|
} else {
|
|
53
57
|
this.updateGridHeight(this.grid.dataFrame.rowCount + 0.6);
|
|
54
|
-
this.grid.dataFrame.onRowsAdded
|
|
55
|
-
.subscribe(() => { this.updateGridHeight(this.grid.dataFrame.rowCount + 0.6); });
|
|
58
|
+
this.subs.push(this.grid.dataFrame.onRowsAdded
|
|
59
|
+
.subscribe(() => { this.updateGridHeight(this.grid.dataFrame.rowCount + 0.6); }));
|
|
56
60
|
}
|
|
57
61
|
this.grid.root.style.width = `100%`;
|
|
58
62
|
|
|
59
|
-
|
|
63
|
+
this.subs.push(this.grid.dataFrame.onDataChanged.subscribe(() => {
|
|
64
|
+
this.fireChanged();
|
|
65
|
+
}));
|
|
66
|
+
|
|
67
|
+
this.subs.push(ui.onSizeChanged(this.grid.root).subscribe(() => {
|
|
60
68
|
this.grid.columns.byIndex(2)!.width = this.grid.root.clientWidth - this.grid.horzScroll.root.offsetWidth -
|
|
61
69
|
this.grid.columns.byIndex(0)!.width - this.grid.columns.byIndex(1)!.width - 10;
|
|
62
|
-
});
|
|
70
|
+
}));
|
|
63
71
|
|
|
64
72
|
this.root.classList.add('ui-input-polytool-pos-grid');
|
|
65
73
|
this.root.append(this.gridHost);
|
|
66
74
|
}
|
|
67
75
|
|
|
76
|
+
detach(): void {
|
|
77
|
+
for (const sub of this.subs) sub.unsubscribe();
|
|
78
|
+
}
|
|
79
|
+
|
|
68
80
|
public static async create(
|
|
69
|
-
name?: string,
|
|
81
|
+
name?: string, options?: {}, heightRowCount?: number
|
|
70
82
|
): Promise<PolyToolPlaceholdersInput> {
|
|
71
|
-
const df: DG.DataFrame =
|
|
83
|
+
const df: DG.DataFrame = DG.DataFrame.fromObjects([{Position: '', Monomers: ''}])!;
|
|
72
84
|
const grid = (await df.plot.fromType(DG.VIEWER.GRID, options)) as DG.Grid;
|
|
85
|
+
grid.sort(['Position']);
|
|
73
86
|
return new PolyToolPlaceholdersInput(name, grid, heightRowCount);
|
|
74
87
|
}
|
|
75
88
|
|
|
@@ -82,8 +95,9 @@ export class PolyToolPlaceholdersInput extends DG.JsInputBase<DG.DataFrame> {
|
|
|
82
95
|
|
|
83
96
|
// -- Handle events --
|
|
84
97
|
|
|
85
|
-
private
|
|
86
|
-
|
|
98
|
+
private gridRootOnSizeChanged(): void {
|
|
99
|
+
this.grid.columns.byIndex(2)!.width = this.grid.root.clientWidth - this.grid.horzScroll.root.offsetWidth -
|
|
100
|
+
this.grid.columns.byIndex(0)!.width - this.grid.columns.byIndex(1)!.width - 10;
|
|
87
101
|
}
|
|
88
102
|
}
|
|
89
103
|
|
package/src/polytool/types.ts
CHANGED
|
@@ -6,9 +6,7 @@ import {before, after, category, expect, test, expectArray} from '@datagrok-libr
|
|
|
6
6
|
import {getHelmHelper, IHelmHelper} from '@datagrok-libraries/bio/src/helm/helm-helper';
|
|
7
7
|
|
|
8
8
|
import {PolyToolEnumeratorParams, PolyToolEnumeratorTypes} from '../polytool/types';
|
|
9
|
-
import {polyToolEnumerateHelm} from '../package';
|
|
10
9
|
import {getPtEnumeratorHelm} from '../polytool/pt-enumeration-helm';
|
|
11
|
-
import {HelmMol} from '@datagrok-libraries/bio/src/helm/types';
|
|
12
10
|
|
|
13
11
|
category('PolyTool', () => {
|
|
14
12
|
let helmHelper: IHelmHelper;
|
|
@@ -22,27 +20,46 @@ category('PolyTool', () => {
|
|
|
22
20
|
});
|
|
23
21
|
|
|
24
22
|
const tests: {
|
|
25
|
-
[testName: string]: { src: string, params: PolyToolEnumeratorParams, tgt: string[] }
|
|
23
|
+
[testName: string]: { src: string, params: PolyToolEnumeratorParams, tgt: [string, string][] }
|
|
26
24
|
} = {
|
|
27
25
|
'single1': {
|
|
28
|
-
src: 'PEPTIDE1{[Ac(1)].F.W.G.P.L.[Tic].[C(1)].G.[NH2]}$$$$',
|
|
26
|
+
src: 'PEPTIDE1{[Ac(1)].F.W.G.P.L.[Tic].[C(1)].G.[NH2]}$$$$V2.0',
|
|
29
27
|
params: {
|
|
30
28
|
type: PolyToolEnumeratorTypes.Single,
|
|
31
29
|
placeholders: {
|
|
32
30
|
[4]: ['K', 'P', 'F4COO'],
|
|
33
31
|
[6]: ['Y', 'T'],
|
|
34
|
-
}
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
tgt: [
|
|
35
|
+
['PEPTIDE1{[Ac(1)].F.W.G.K.L.[Tic].[C(1)].G.[NH2]}$$$$V2.0', '-P5K'],
|
|
36
|
+
['PEPTIDE1{[Ac(1)].F.W.G.P.L.[Tic].[C(1)].G.[NH2]}$$$$V2.0', '-P5P'],
|
|
37
|
+
['PEPTIDE1{[Ac(1)].F.W.G.[F4COO].L.[Tic].[C(1)].G.[NH2]}$$$$V2.0', '-P5[F4COO]'],
|
|
38
|
+
['PEPTIDE1{[Ac(1)].F.W.G.P.L.Y.[C(1)].G.[NH2]}$$$$V2.0', '-[Tic]7Y'],
|
|
39
|
+
['PEPTIDE1{[Ac(1)].F.W.G.P.L.T.[C(1)].G.[NH2]}$$$$V2.0', '-[Tic]7T'],
|
|
40
|
+
]
|
|
41
|
+
},
|
|
42
|
+
'single-with-original': {
|
|
43
|
+
src: 'PEPTIDE1{[Ac(1)].F.W.G.P.L.[Tic].[C(1)].G.[NH2]}$$$$V2.0',
|
|
44
|
+
params: {
|
|
45
|
+
type: PolyToolEnumeratorTypes.Single,
|
|
46
|
+
placeholders: {
|
|
47
|
+
[4]: ['K', 'P', 'F4COO'],
|
|
48
|
+
[6]: ['Y', 'T'],
|
|
49
|
+
},
|
|
50
|
+
keepOriginal: true,
|
|
35
51
|
},
|
|
36
52
|
tgt: [
|
|
37
|
-
'PEPTIDE1{[Ac(1)].F.W.G.
|
|
38
|
-
'PEPTIDE1{[Ac(1)].F.W.G.
|
|
39
|
-
'PEPTIDE1{[Ac(1)].F.W.G.
|
|
40
|
-
'PEPTIDE1{[Ac(1)].F.W.G.
|
|
41
|
-
'PEPTIDE1{[Ac(1)].F.W.G.P.L.
|
|
53
|
+
['PEPTIDE1{[Ac(1)].F.W.G.P.L.[Tic].[C(1)].G.[NH2]}$$$$V2.0', ''],
|
|
54
|
+
['PEPTIDE1{[Ac(1)].F.W.G.K.L.[Tic].[C(1)].G.[NH2]}$$$$V2.0', '-P5K'],
|
|
55
|
+
['PEPTIDE1{[Ac(1)].F.W.G.P.L.[Tic].[C(1)].G.[NH2]}$$$$V2.0', '-P5P'],
|
|
56
|
+
['PEPTIDE1{[Ac(1)].F.W.G.[F4COO].L.[Tic].[C(1)].G.[NH2]}$$$$V2.0', '-P5[F4COO]'],
|
|
57
|
+
['PEPTIDE1{[Ac(1)].F.W.G.P.L.Y.[C(1)].G.[NH2]}$$$$V2.0', '-[Tic]7Y'],
|
|
58
|
+
['PEPTIDE1{[Ac(1)].F.W.G.P.L.T.[C(1)].G.[NH2]}$$$$V2.0', '-[Tic]7T'],
|
|
42
59
|
]
|
|
43
60
|
},
|
|
44
61
|
'matrix1': {
|
|
45
|
-
src: 'PEPTIDE1{[Ac(1)].F.W.G.P.L.[Tic].[C(1)].G.[NH2]}$$$$',
|
|
62
|
+
src: 'PEPTIDE1{[Ac(1)].F.W.G.P.L.[Tic].[C(1)].G.[NH2]}$$$$V2.0',
|
|
46
63
|
params:
|
|
47
64
|
{
|
|
48
65
|
type: PolyToolEnumeratorTypes.Matrix,
|
|
@@ -53,25 +70,25 @@ category('PolyTool', () => {
|
|
|
53
70
|
}
|
|
54
71
|
},
|
|
55
72
|
tgt: [
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
73
|
+
["PEPTIDE1{[Ac(1)].D.W.G.K.L.Y.[C(1)].G.[NH2]}$$$$V2.0", "-F2D-P5K-[Tic]7Y"],
|
|
74
|
+
["PEPTIDE1{[Ac(1)].D.W.G.K.L.T.[C(1)].G.[NH2]}$$$$V2.0", "-F2D-P5K-[Tic]7T"],
|
|
75
|
+
["PEPTIDE1{[Ac(1)].D.W.G.P.L.Y.[C(1)].G.[NH2]}$$$$V2.0", "-F2D-P5P-[Tic]7Y"],
|
|
76
|
+
["PEPTIDE1{[Ac(1)].D.W.G.P.L.T.[C(1)].G.[NH2]}$$$$V2.0", "-F2D-P5P-[Tic]7T"],
|
|
77
|
+
["PEPTIDE1{[Ac(1)].D.W.G.[F4COO].L.Y.[C(1)].G.[NH2]}$$$$V2.0", "-F2D-P5[F4COO]-[Tic]7Y"],
|
|
78
|
+
["PEPTIDE1{[Ac(1)].D.W.G.[F4COO].L.T.[C(1)].G.[NH2]}$$$$V2.0", "-F2D-P5[F4COO]-[Tic]7T"],
|
|
79
|
+
["PEPTIDE1{[Ac(1)].L.W.G.K.L.Y.[C(1)].G.[NH2]}$$$$V2.0", "-F2L-P5K-[Tic]7Y"],
|
|
80
|
+
["PEPTIDE1{[Ac(1)].L.W.G.K.L.T.[C(1)].G.[NH2]}$$$$V2.0", "-F2L-P5K-[Tic]7T"],
|
|
81
|
+
["PEPTIDE1{[Ac(1)].L.W.G.P.L.Y.[C(1)].G.[NH2]}$$$$V2.0", "-F2L-P5P-[Tic]7Y"],
|
|
82
|
+
["PEPTIDE1{[Ac(1)].L.W.G.P.L.T.[C(1)].G.[NH2]}$$$$V2.0", "-F2L-P5P-[Tic]7T"],
|
|
83
|
+
["PEPTIDE1{[Ac(1)].L.W.G.[F4COO].L.Y.[C(1)].G.[NH2]}$$$$V2.0", "-F2L-P5[F4COO]-[Tic]7Y"],
|
|
84
|
+
["PEPTIDE1{[Ac(1)].L.W.G.[F4COO].L.T.[C(1)].G.[NH2]}$$$$V2.0", "-F2L-P5[F4COO]-[Tic]7T"],
|
|
68
85
|
],
|
|
69
86
|
}
|
|
70
87
|
};
|
|
71
88
|
|
|
72
89
|
for (const [testName, testData] of Object.entries(tests)) {
|
|
73
90
|
test(`enumerator-${testName}`, async () => {
|
|
74
|
-
const res = getPtEnumeratorHelm(testData.src, testData.params);
|
|
91
|
+
const res = getPtEnumeratorHelm(testData.src, '', testData.params);
|
|
75
92
|
expectArray(res, testData.tgt);
|
|
76
93
|
});
|
|
77
94
|
}
|
|
@@ -2,11 +2,13 @@ import * as grok from 'datagrok-api/grok';
|
|
|
2
2
|
import * as DG from 'datagrok-api/dg';
|
|
3
3
|
import * as ui from 'datagrok-api/ui';
|
|
4
4
|
|
|
5
|
-
import {defaultErrorHandler} from './err-info';
|
|
6
|
-
import {_package, addContextMenu} from '../package';
|
|
7
5
|
import {SeqHandler} from '@datagrok-libraries/bio/src/utils/seq-handler';
|
|
8
6
|
import {NOTATION} from '@datagrok-libraries/bio/src/utils/macromolecule';
|
|
9
|
-
|
|
7
|
+
|
|
8
|
+
import {defaultErrorHandler} from './err-info';
|
|
9
|
+
import {polyToolEnumerateHelmUI} from '../polytool/pt-enumeration-helm-dialog';
|
|
10
|
+
|
|
11
|
+
import {_package} from '../package';
|
|
10
12
|
|
|
11
13
|
export type SequenceTranslatorWindowType = Window & {
|
|
12
14
|
$sequenceTranslator?: {
|
package/src/utils/err-info.ts
CHANGED
|
@@ -6,8 +6,9 @@ import {errInfo} from '@datagrok-libraries/bio/src/utils/err-info';
|
|
|
6
6
|
|
|
7
7
|
import {_package} from '../package';
|
|
8
8
|
|
|
9
|
-
export function defaultErrorHandler(err: any, shell: boolean = true):
|
|
9
|
+
export function defaultErrorHandler(err: any, shell: boolean = true): [string, string | undefined] {
|
|
10
10
|
const [errMsg, errStack] = errInfo(err);
|
|
11
11
|
_package.logger.error(errMsg, undefined, errStack);
|
|
12
12
|
if (shell) grok.shell.error(errMsg);
|
|
13
|
+
return [errMsg, errStack];
|
|
13
14
|
}
|
package/src/polytool/cyclized.ts
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import {GAP_SYMBOL, INotationProvider, ISeqSplitted, SeqSplittedBase, SplitterFunc}
|
|
2
|
-
from '@datagrok-libraries/bio/src/utils/macromolecule/types';
|
|
3
|
-
import {getSplitterWithSeparator, StringListSeqSplitted} from '@datagrok-libraries/bio/src/utils/macromolecule/utils';
|
|
4
|
-
import {GapOriginals} from '@datagrok-libraries/bio/src/utils/seq-handler';
|
|
5
|
-
import {NOTATION} from '@datagrok-libraries/bio/src/utils/macromolecule';
|
|
6
|
-
|
|
7
|
-
export class CyclizedNotationProvider implements INotationProvider {
|
|
8
|
-
private readonly separatorSplitter: SplitterFunc;
|
|
9
|
-
public readonly splitter: SplitterFunc;
|
|
10
|
-
|
|
11
|
-
constructor(
|
|
12
|
-
public readonly separator: string
|
|
13
|
-
) {
|
|
14
|
-
this.separatorSplitter = getSplitterWithSeparator(this.separator);
|
|
15
|
-
this.splitter = this._splitter.bind(this);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
private _splitter(seq: string): ISeqSplitted {
|
|
19
|
-
const baseSS: ISeqSplitted = this.separatorSplitter(seq);
|
|
20
|
-
return new CyclizedSeqSplitted(baseSS.originals, GapOriginals[NOTATION.SEPARATOR]);
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/** Gets canonical monomers for original ones with cyclization marks */
|
|
25
|
-
export class CyclizedSeqSplitted extends StringListSeqSplitted {
|
|
26
|
-
private readonly seqCList: (string | null)[];
|
|
27
|
-
|
|
28
|
-
private _canonicals: string[] | null = null;
|
|
29
|
-
override get canonicals(): SeqSplittedBase {
|
|
30
|
-
if (!this._canonicals) {
|
|
31
|
-
const len = this.length;
|
|
32
|
-
this._canonicals = new Array<string>(len);
|
|
33
|
-
for (let posIdx = 0; posIdx < len; ++posIdx)
|
|
34
|
-
this._canonicals[posIdx] = this.getCanonical(posIdx);
|
|
35
|
-
}
|
|
36
|
-
return this._canonicals;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
override getCanonical(posIdx: number): string {
|
|
40
|
-
if (this.isGap(posIdx)) return GAP_SYMBOL;
|
|
41
|
-
|
|
42
|
-
let cmRes: string | null = this.seqCList[posIdx];
|
|
43
|
-
if (cmRes === null) {
|
|
44
|
-
const om = this.getOriginal(posIdx);
|
|
45
|
-
cmRes = om;
|
|
46
|
-
if (om[om.length - 1] === ')')
|
|
47
|
-
cmRes = this.seqCList[posIdx] = om.replace(/\(\d+\)$/, '');
|
|
48
|
-
}
|
|
49
|
-
return cmRes;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
constructor(seqOList: SeqSplittedBase, gapOriginalMonomer: string) {
|
|
53
|
-
super(seqOList, gapOriginalMonomer);
|
|
54
|
-
this.seqCList = new Array<string | null>(this.length).fill(null);
|
|
55
|
-
}
|
|
56
|
-
}
|