@datagrok/sequence-translator 1.4.8 → 1.5.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.
Files changed (34) hide show
  1. package/.eslintrc.json +1 -1
  2. package/CHANGELOG.md +24 -0
  3. package/dist/package-test.js +1 -1
  4. package/dist/package-test.js.map +1 -1
  5. package/dist/package.js +1 -1
  6. package/dist/package.js.map +1 -1
  7. package/files/polytool-rules/rules_example.json +35 -38
  8. package/package.json +9 -9
  9. package/src/apps/common/model/oligo-toolkit-package.ts +13 -7
  10. package/src/package.ts +8 -7
  11. package/src/polytool/const.ts +1 -0
  12. package/src/polytool/{pt-conversion.ts → conversion/pt-chain.ts} +118 -285
  13. package/src/polytool/conversion/pt-conversion.ts +26 -0
  14. package/src/polytool/conversion/pt-misc.ts +193 -0
  15. package/src/polytool/conversion/pt-rules.ts +231 -0
  16. package/src/polytool/conversion/rule-manager.ts +205 -0
  17. package/src/polytool/pt-convert-editor.ts +1 -1
  18. package/src/polytool/pt-dialog.ts +133 -6
  19. package/src/polytool/{pt-enumeration-helm-dialog.ts → pt-enumerate-seq-dialog.ts} +243 -114
  20. package/src/polytool/pt-enumeration-helm.ts +2 -2
  21. package/src/polytool/pt-placeholders-breadth-input.ts +80 -39
  22. package/src/polytool/pt-placeholders-input.ts +96 -35
  23. package/src/polytool/pt-unrule-dialog.ts +1 -1
  24. package/src/polytool/pt-unrule.ts +2 -2
  25. package/src/polytool/types.ts +5 -1
  26. package/src/tests/polytool-chain-from-notation-tests.ts +9 -18
  27. package/src/tests/polytool-chain-parse-notation-tests.ts +3 -2
  28. package/src/tests/polytool-convert-tests.ts +5 -3
  29. package/src/tests/polytool-unrule-tests.ts +1 -1
  30. package/src/tests/toAtomicLevel-tests.ts +5 -6
  31. package/src/utils/cell-renderer-cyclized.ts +37 -0
  32. package/src/utils/context-menu.ts +1 -1
  33. package/src/utils/cyclized.ts +23 -26
  34. package/src/polytool/pt-rules.ts +0 -93
@@ -13,11 +13,12 @@ import {CellRendererBackBase} from '@datagrok-libraries/bio/src/utils/cell-rende
13
13
  import {MonomerPlacer} from '@datagrok-libraries/bio/src/utils/cell-renderer-monomer-placer';
14
14
  import {monomerToShort, StringListSeqSplitted} from '@datagrok-libraries/bio/src/utils/macromolecule/utils';
15
15
  import {errInfo} from '@datagrok-libraries/bio/src/utils/err-info';
16
- import {getHelmHelper} from '@datagrok-libraries/bio/src/helm/helm-helper';
16
+ import {getHelmHelper, IHelmHelper} from '@datagrok-libraries/bio/src/helm/helm-helper';
17
17
 
18
- import {Chain} from '../polytool/pt-conversion';
18
+ import {Chain} from '../polytool/conversion/pt-chain';
19
19
 
20
20
  import {_package} from '../package';
21
+ import {CyclizedCellRendererBack} from './cell-renderer-cyclized';
21
22
 
22
23
  /* eslint-enable max-len */
23
24
 
@@ -25,14 +26,18 @@ export class CyclizedNotationProvider implements INotationProvider {
25
26
  private readonly separatorSplitter: SplitterFunc;
26
27
  public readonly splitter: SplitterFunc;
27
28
 
29
+ get defaultGapOriginal(): string { return ''; }
30
+
28
31
  constructor(
29
32
  public readonly separator: string,
30
- protected readonly seqHelper: ISeqHelper
33
+ protected readonly helmHelper: IHelmHelper
31
34
  ) {
32
35
  this.separatorSplitter = getSplitterWithSeparator(this.separator);
33
36
  this.splitter = this._splitter.bind(this);
34
37
  }
35
38
 
39
+ setUnits(): void {}
40
+
36
41
  private _splitter(seq: string): ISeqSplitted {
37
42
  const baseSS: ISeqSplitted = this.separatorSplitter(seq);
38
43
  return new CyclizedSeqSplitted(
@@ -40,25 +45,17 @@ export class CyclizedNotationProvider implements INotationProvider {
40
45
  GapOriginals[NOTATION.SEPARATOR]);
41
46
  }
42
47
 
43
- public async getHelm(seq: string, options?: any): Promise<string> {
44
- const helmHelper = await getHelmHelper();
45
- const seqChain = await Chain.parseNotation(seq, helmHelper);
48
+ public getHelm(seq: string, options?: any): string {
49
+ const seqChain = Chain.parseNotation(seq, this.helmHelper);
46
50
  const resPseudoHelm = seqChain.getNotationHelm();
47
51
  return resPseudoHelm;
48
52
  }
49
53
 
50
54
  public createCellRendererBack(gridCol: DG.GridColumn | null, tableCol: DG.Column<string>): CellRendererBackBase<string> {
51
55
  let maxLengthOfMonomer: number = 4; // (_package.bioProperties ? _package.bioProperties.maxMonomerLength : 4) ?? 50;
52
- const back = new MonomerPlacer(gridCol, tableCol, _package.logger, maxLengthOfMonomer,
53
- () => {
54
- const sh = this.seqHelper.getSeqHandler(tableCol);
55
- return {
56
- seqHandler: sh,
57
- monomerCharWidth: 7,
58
- separatorWidth: 11,
59
- monomerToShort: monomerToShort,
60
- };
61
- });
56
+ const back = new CyclizedCellRendererBack(gridCol, tableCol,
57
+ maxLengthOfMonomer, this.helmHelper.seqHelper);
58
+
62
59
  back.init().then(() => {});
63
60
  return back;
64
61
  }
@@ -66,23 +63,23 @@ export class CyclizedNotationProvider implements INotationProvider {
66
63
 
67
64
  /** Gets canonical monomers for original ones with cyclization marks */
68
65
  export class CyclizedSeqSplitted extends StringListSeqSplitted {
69
- private readonly seqCList: (string | null)[];
70
-
71
66
  override getCanonical(posIdx: number): string {
72
67
  if (this.isGap(posIdx)) return GAP_SYMBOL;
73
68
 
74
- let cmRes: string | null = this.seqCList[posIdx];
75
- if (cmRes === null) {
76
- const om = this.getOriginal(posIdx);
77
- cmRes = om;
78
- if (om[om.length - 1] === ')')
79
- cmRes = this.seqCList[posIdx] = om.replace(/\(\d+\)$/, '');
80
- }
69
+ const om = this.getOriginal(posIdx);
70
+ let cmRes = om;
71
+ if (om.startsWith('{'))
72
+ cmRes = om.slice(1);
73
+ else if (om.endsWith('}'))
74
+ cmRes = om.slice(0, -1);
75
+ else if (om.startsWith('('))
76
+ cmRes = om.replace(/^\(.\d+\)/, '');
77
+ else if (om.endsWith(')'))
78
+ cmRes = om.replace(/\(\d+\)$/, '');
81
79
  return cmRes;
82
80
  }
83
81
 
84
82
  constructor(seqOList: SeqSplittedBase, gapOriginalMonomer: string) {
85
83
  super(seqOList, gapOriginalMonomer);
86
- this.seqCList = new Array<string | null>(this.length).fill(null);
87
84
  }
88
85
  }
@@ -1,93 +0,0 @@
1
- import * as DG from 'datagrok-api/dg';
2
- import * as grok from 'datagrok-api/grok';
3
- import {ActiveFiles} from '@datagrok-libraries/utils/src/settings/active-files-base';
4
-
5
- export const RULES_PATH = 'System:AppData/SequenceTranslator/polytool-rules/';
6
- export const RULES_STORAGE_NAME = 'Polytool';
7
- export const RULES_TYPE_LINK = 'link';
8
- export const RULES_TYPE_REACTION = 'reaction';
9
- export const RULES_TYPE_HOMODIMER = 'fragmentDuplication';
10
- export const RULES_TYPE_HETERODIMER = 'differentFragments';
11
-
12
- export class RuleInputs extends ActiveFiles {
13
- constructor(
14
- path: string, userStorageName: string, ext: string,
15
- options?: { onValueChanged: (value: string[]) => void }
16
- ) {
17
- super(path, userStorageName, ext, options);
18
- }
19
- }
20
-
21
- export type Rules = {
22
- homodimerCode: string | null,
23
- heterodimerCode: string | null,
24
- linkRules: RuleLink[],
25
- reactionRules: RuleReaction[]
26
- }
27
-
28
- export type RuleLink = {
29
- code: number,
30
- firstMonomer: string,
31
- secondMonomer: string,
32
- firstSubstitution: string,
33
- secondSubstitution: string,
34
- firstLinkingGroup: number,
35
- secondLinkingGroup: number
36
- }
37
-
38
- export type RuleReaction = {
39
- code: number,
40
- firstMonomer: string,
41
- secondMonomer: string,
42
- reaction: string,
43
- name: string
44
- }
45
-
46
- export async function getRules(ruleFiles: string[]): Promise<Rules> {
47
- const fileSource = new DG.FileSource(RULES_PATH);
48
- const linkRules: RuleLink[] = [];
49
- const reactionRules: RuleReaction[] = [];
50
- const rules: Rules = {homodimerCode: null, heterodimerCode: null, linkRules: linkRules, reactionRules: reactionRules};
51
-
52
- for (let i = 0; i < ruleFiles.length; i++) {
53
- const rulesRaw = await fileSource.readAsText(ruleFiles[i].replace(RULES_PATH, ''));
54
- const ruleSingle = JSON.parse(rulesRaw);
55
- for (let j = 0; j < ruleSingle.length; j++) {
56
- if (ruleSingle[j].type !== undefined && ruleSingle[j].code !== undefined) {
57
- switch (ruleSingle[j].type) {
58
- case RULES_TYPE_LINK: {
59
- const rule = ruleSingle[j].monomericSubstitution;
60
- rule['code'] = ruleSingle[j].code;
61
- linkRules.push(rule);
62
- break;
63
- }
64
- case RULES_TYPE_REACTION: {
65
- const rule = ruleSingle[j].monomericSubstitution;
66
- rule['code'] = ruleSingle[j].code;
67
- reactionRules.push(rule);
68
- break;
69
- }
70
- case RULES_TYPE_HOMODIMER: {
71
- if (rules.homodimerCode)
72
- grok.shell.warning(`PolyTool: homodimer code is duplicated in rules.`);
73
- rules.homodimerCode = ruleSingle[j].code;
74
- break;
75
- }
76
- case RULES_TYPE_HETERODIMER: {
77
- if (rules.heterodimerCode)
78
- grok.shell.warning(`PolyTool: heterodimer code is duplicated in rules.`);
79
- rules.heterodimerCode = ruleSingle[j].code;
80
- break;
81
- }
82
- default:
83
- grok.shell.warning(`PolyTool: Unexpected type - '${ruleSingle[j]}'.`);
84
- break;
85
- }
86
- } else {
87
- grok.shell.warning('Polytool: rules contain invalid rule');
88
- }
89
- }
90
- }
91
-
92
- return rules;
93
- }