@datagrok/sequence-translator 1.2.7 → 1.3.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 (107) hide show
  1. package/.eslintrc.json +5 -5
  2. package/CHANGELOG.md +14 -0
  3. package/dist/package-test.js +2 -1
  4. package/dist/package-test.js.LICENSE.txt +8 -0
  5. package/dist/package-test.js.map +1 -1
  6. package/dist/package.js +2 -1
  7. package/dist/package.js.LICENSE.txt +8 -0
  8. package/dist/package.js.map +1 -1
  9. package/files/pattern-app-data.json +80 -0
  10. package/package.json +22 -14
  11. package/src/{model → apps/common/model}/const.ts +1 -1
  12. package/src/{model/data-loading-utils → apps/common/model/data-loader}/const.ts +7 -2
  13. package/src/apps/common/model/data-loader/json-loader.ts +48 -0
  14. package/src/{model/data-loading-utils → apps/common/model/data-loader}/types.ts +13 -6
  15. package/src/{model → apps/common/model}/monomer-lib/lib-wrapper.ts +9 -12
  16. package/src/apps/common/model/oligo-toolkit-package.ts +30 -0
  17. package/src/{model → apps/common/model}/parsing-validation/format-detector.ts +5 -5
  18. package/src/{model → apps/common/model}/parsing-validation/format-handler.ts +18 -19
  19. package/src/{model → apps/common/model}/parsing-validation/sequence-validator.ts +1 -1
  20. package/src/apps/common/view/app-ui-base.ts +28 -0
  21. package/src/apps/common/view/combined-app-ui.ts +66 -0
  22. package/src/{view/utils → apps/common/view/components}/colored-input/colored-text-input.ts +1 -1
  23. package/src/{view/utils → apps/common/view/components}/draw-molecule.ts +1 -1
  24. package/src/{view/utils → apps/common/view/components}/molecule-img.ts +3 -3
  25. package/src/{view/const/ui.ts → apps/common/view/const.ts} +4 -4
  26. package/src/apps/common/view/isolated-app-ui.ts +43 -0
  27. package/src/{view/monomer-lib-viewer/viewer.ts → apps/common/view/monomer-lib-viewer.ts} +2 -2
  28. package/src/apps/common/view/utils.ts +29 -0
  29. package/src/apps/pattern/model/const.ts +121 -0
  30. package/src/apps/pattern/model/data-manager.ts +297 -0
  31. package/src/apps/pattern/model/event-bus.ts +487 -0
  32. package/src/apps/pattern/model/router.ts +46 -0
  33. package/src/apps/pattern/model/subscription-manager.ts +21 -0
  34. package/src/apps/pattern/model/translator.ts +94 -0
  35. package/src/apps/pattern/model/types.ts +52 -0
  36. package/src/apps/pattern/model/utils.ts +110 -0
  37. package/src/apps/pattern/view/components/bulk-convert/column-input.ts +79 -0
  38. package/src/apps/pattern/view/components/bulk-convert/table-controls.ts +38 -0
  39. package/src/apps/pattern/view/components/bulk-convert/table-input.ts +95 -0
  40. package/src/apps/pattern/view/components/edit-block-controls.ts +196 -0
  41. package/src/apps/pattern/view/components/left-section.ts +44 -0
  42. package/src/apps/pattern/view/components/load-block-controls.ts +200 -0
  43. package/src/apps/pattern/view/components/numeric-label-visibility-controls.ts +69 -0
  44. package/src/apps/pattern/view/components/right-section.ts +148 -0
  45. package/src/apps/pattern/view/components/strand-editor/dialog.ts +79 -0
  46. package/src/apps/pattern/view/components/strand-editor/header-controls.ts +105 -0
  47. package/src/apps/pattern/view/components/strand-editor/strand-controls.ts +159 -0
  48. package/src/apps/pattern/view/components/terminal-modification-editor.ts +127 -0
  49. package/src/apps/pattern/view/components/translation-examples-block.ts +139 -0
  50. package/src/{view/style/pattern-app.css → apps/pattern/view/style.css} +4 -0
  51. package/src/apps/pattern/view/svg-utils/const.ts +77 -0
  52. package/src/apps/pattern/view/svg-utils/legend-block.ts +92 -0
  53. package/src/apps/pattern/view/svg-utils/strands-block.ts +335 -0
  54. package/src/apps/pattern/view/svg-utils/svg-block-base.ts +37 -0
  55. package/src/apps/pattern/view/svg-utils/svg-display-manager.ts +44 -0
  56. package/src/apps/pattern/view/svg-utils/svg-element-factory.ts +94 -0
  57. package/src/apps/pattern/view/svg-utils/svg-renderer.ts +51 -0
  58. package/src/apps/pattern/view/svg-utils/text-dimensions-calculator.ts +29 -0
  59. package/src/apps/pattern/view/svg-utils/title-block.ts +53 -0
  60. package/src/apps/pattern/view/svg-utils/utils.ts +37 -0
  61. package/src/apps/pattern/view/types.ts +14 -0
  62. package/src/apps/pattern/view/ui.ts +61 -0
  63. package/src/{model/structure-app → apps/structure/model}/mol-transformations.ts +3 -3
  64. package/src/{model/structure-app → apps/structure/model}/monomer-code-parser.ts +9 -10
  65. package/src/{model/structure-app → apps/structure/model}/oligo-structure.ts +4 -4
  66. package/src/{model/structure-app → apps/structure/model}/sequence-to-molfile.ts +2 -2
  67. package/src/{view/apps/oligo-structure.ts → apps/structure/view/ui.ts} +31 -17
  68. package/src/{model/translator-app → apps/translator/model}/conversion-utils.ts +25 -7
  69. package/src/{model/translator-app → apps/translator/model}/format-converter.ts +7 -12
  70. package/src/{view/const/oligo-translator.ts → apps/translator/view/const.ts} +1 -1
  71. package/src/{view/apps/oligo-translator.ts → apps/translator/view/ui.ts} +88 -42
  72. package/src/demo/demo-st-ui.ts +12 -32
  73. package/src/package.ts +91 -55
  74. package/src/plugins/mermade.ts +9 -9
  75. package/src/polytool/const.ts +28 -0
  76. package/src/polytool/csv-to-json-monomer-lib-converter.ts +40 -0
  77. package/src/polytool/cyclized.ts +56 -0
  78. package/src/polytool/monomer-lib-handler.ts +115 -0
  79. package/src/polytool/pt-conversion.ts +307 -0
  80. package/src/polytool/pt-dialog.ts +115 -0
  81. package/src/polytool/pt-enumeration.ts +127 -0
  82. package/src/polytool/pt-rules.ts +73 -0
  83. package/src/polytool/utils.ts +27 -0
  84. package/src/tests/const.ts +5 -5
  85. package/src/tests/formats-support.ts +6 -6
  86. package/src/tests/formats-to-helm.ts +5 -5
  87. package/src/tests/helm-to-nucleotides.ts +5 -10
  88. package/tsconfig.json +3 -9
  89. package/webpack.config.js +3 -0
  90. package/files/axolabs-style.json +0 -97
  91. package/src/model/data-loading-utils/json-loader.ts +0 -38
  92. package/src/model/pattern-app/const.ts +0 -33
  93. package/src/model/pattern-app/draw-svg.ts +0 -193
  94. package/src/model/pattern-app/helpers.ts +0 -96
  95. package/src/model/pattern-app/oligo-pattern.ts +0 -111
  96. package/src/view/app-ui.ts +0 -193
  97. package/src/view/apps/oligo-pattern.ts +0 -759
  98. /package/src/{model → apps/common/model}/helpers.ts +0 -0
  99. /package/src/{model → apps/common/model}/monomer-lib/const.ts +0 -0
  100. /package/src/{view/utils → apps/common/view/components}/app-info-dialog.ts +0 -0
  101. /package/src/{view/utils → apps/common/view/components}/colored-input/input-painters.ts +0 -0
  102. /package/src/{view/style/colored-text-input.css → apps/common/view/components/colored-input/style.css} +0 -0
  103. /package/src/{view/utils → apps/common/view/components}/router.ts +0 -0
  104. /package/src/{model/structure-app → apps/structure/model}/const.ts +0 -0
  105. /package/src/{view/style/structure-app.css → apps/structure/view/style.css} +0 -0
  106. /package/src/{model/translator-app → apps/translator/model}/const.ts +0 -0
  107. /package/src/{view/style/translator-app.css → apps/translator/view/style.css} +0 -0
@@ -1,111 +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
- // @ts-ignore
5
- import * as svg from 'save-svg-as-png';
6
- import $ from 'cash-dom';
7
-
8
- import {isOverhang} from './helpers';
9
- import {axolabsStyleMap} from '../data-loading-utils/json-loader';
10
-
11
- export function generateExample(sequenceLength: number, sequenceBasis: string): string {
12
- const AXOLABS_MAP = axolabsStyleMap;
13
- const uniqueSymbols = AXOLABS_MAP[sequenceBasis].symbols.join('');
14
- return uniqueSymbols.repeat(Math.floor(sequenceLength / 4)) + uniqueSymbols.slice(0, sequenceLength % 4);
15
- }
16
-
17
- export function findDuplicates(data: Int32Array | Float32Array | Float64Array | Uint32Array): number[] {
18
- return Array.from(new Set(data)).filter((value) => data.indexOf(value) !== data.lastIndexOf(value));
19
- }
20
-
21
- export async function isCurrentUserCreatedThisPattern(patternName: string): Promise<boolean> {
22
- return await grok.dapi.users.current().then((user) => {
23
- const [firstName, lastName] = getUserName(patternName);
24
- return (user.firstName !== firstName || user.lastName !== lastName);
25
- });
26
- }
27
-
28
- export function getShortName(patternName: string): string {
29
- let first = patternName.length + 1;
30
- for (let i = 0; i < patternName.length; i++) {
31
- if (patternName[i] === '(') {
32
- first = i;
33
- break;
34
- }
35
- }
36
- return patternName.slice(0, first - 1);
37
- }
38
-
39
- function getUserName(patternName: string): string[] {
40
- let first = -1;
41
- for (let i = 0; i < patternName.length; i++) {
42
- if (patternName[i] === '(') {
43
- first = i;
44
- break;
45
- }
46
- }
47
- return (first === -1) ? ['', ''] : patternName.slice(first + 9, patternName.length - 1).split(' ').slice(1);
48
- }
49
-
50
- export function translateSequence(
51
- sequence: string,
52
- bases: DG.InputBase[],
53
- ptoLinkages: DG.InputBase[],
54
- startModification: DG.InputBase,
55
- endModification: DG.InputBase,
56
- firstPtoExist: boolean): string {
57
- let i: number = -1;
58
- let mainSequence = sequence.replace(/[AUGC]/g, function(x: string) {
59
- i++;
60
- const AXOLABS_MAP = axolabsStyleMap;
61
-
62
- const baseChoices: string[] = Object.keys(AXOLABS_MAP);
63
- // const defaultBase: string = baseChoices[0];
64
- const indexOfSymbol = AXOLABS_MAP['RNA']['symbols'].indexOf(x);
65
- let symbol = AXOLABS_MAP[bases[i].value]['symbols'][indexOfSymbol];
66
- if (isOverhang(bases[i].value)) {
67
- if (i < sequence.length / 2 && !isOverhang(bases[i + 1].value))
68
- symbol = symbol + x + 'f';
69
- else if (i > sequence.length / 2 && !isOverhang(bases[i - 1].value))
70
- symbol = x + 'f' + symbol;
71
- }
72
- return (ptoLinkages[i].value) ? symbol + 's' : symbol;
73
- });
74
- if (mainSequence.slice(0, 5).split('mU').length === 3)
75
- mainSequence = '(uu)' + mainSequence.slice(4);
76
- if (mainSequence.slice(mainSequence.length - 7).split('mU').length === 3)
77
- mainSequence = mainSequence.slice(0, mainSequence.length - 4) + '(uu)';
78
- return startModification.value + (firstPtoExist ? 's' : '') + mainSequence + endModification.value;
79
- }
80
-
81
- export function addColumnWithIds(tableName: string, columnName: string, patternName: string) {
82
- const nameOfNewColumn = 'ID ' + patternName;
83
- const columns = grok.shell.table(tableName).columns;
84
- if (columns.contains(nameOfNewColumn))
85
- columns.remove(nameOfNewColumn);
86
- const columnWithIds = columns.byName(columnName);
87
- return columns.addNewString(nameOfNewColumn).init((i: number) => {
88
- return (columnWithIds.getString(i) === '') ? '' : columnWithIds.get(i) + '_' + patternName;
89
- });
90
- }
91
-
92
- export function addColumnWithTranslatedSequences(
93
- tableName: string,
94
- columnName: string,
95
- bases: DG.InputBase[],
96
- ptoLinkages: DG.InputBase[],
97
- startModification: DG.InputBase,
98
- endModification: DG.InputBase,
99
- firstPtoExist: boolean) {
100
- const nameOfNewColumn = 'Axolabs ' + columnName;
101
- const columns = grok.shell.table(tableName).columns;
102
- if (columns.contains(nameOfNewColumn))
103
- columns.remove(nameOfNewColumn);
104
- const columnWithInputSequences = columns.byName(columnName);
105
- return columns.addNewString(nameOfNewColumn).init((i: number) => {
106
- return columnWithInputSequences.getString(i) === '' ?
107
- '' :
108
- translateSequence(columnWithInputSequences.getString(i), bases, ptoLinkages, startModification, endModification,
109
- firstPtoExist);
110
- });
111
- }
@@ -1,193 +0,0 @@
1
- /* Do not change these import lines to match external modules in webpack configuration */
2
- import * as grok from 'datagrok-api/grok';
3
- import * as ui from 'datagrok-api/ui';
4
- import * as DG from 'datagrok-api/dg';
5
-
6
- import {TAB, APP} from './const/ui';
7
- import {TranslatorLayoutHandler} from './apps/oligo-translator';
8
- import {StructureLayoutHandler} from './apps/oligo-structure';
9
- import {PatternLayoutHandler} from './apps/oligo-pattern';
10
- import {MonomerLibViewer} from './monomer-lib-viewer/viewer';
11
- import {_package} from '../package';
12
- import {tryCatch} from '../model/helpers';
13
-
14
- type ViewFactories = {[name: string]: () => DG.View};
15
-
16
- export abstract class AppUIBase {
17
- constructor(protected appName: string, protected parentAppName?: string) { }
18
- abstract addView(): Promise<void>;
19
-
20
- async createAppLayout(): Promise<void> {
21
- const pi: DG.TaskBarProgressIndicator = DG.TaskBarProgressIndicator.create(`Loading ${this.appName}...`);
22
-
23
- let currentView = grok.shell.v?.root;
24
- if (currentView)
25
- ui.setUpdateIndicator(currentView, true);
26
-
27
- await tryCatch(async () => {
28
- await this.addView();
29
- }, () => pi.close());
30
-
31
- if (currentView)
32
- ui.setUpdateIndicator(currentView, false);
33
- }
34
- }
35
-
36
- abstract class SimpleAppUIBase extends AppUIBase {
37
- constructor(appName: string) {
38
- super(appName);
39
- this.view = DG.View.create();
40
- this.setupView();
41
- }
42
-
43
- protected view: DG.View;
44
- async addView(): Promise<void> {
45
- await this.initView();
46
- const name = this.parentAppName ? this.parentAppName + '/' + this.appName : this.appName;
47
- this.view.path = `/apps/${_package.name}/${name.replace(/\s/g, '')}/`;
48
- grok.shell.addView(this.view);
49
- }
50
-
51
- protected abstract getHtml(): Promise<HTMLDivElement>;
52
- async initView(): Promise<void> {
53
- const html = await this.getHtml();
54
- this.view.append(html);
55
- }
56
-
57
- protected setupView(): void {
58
- this.view.box = true;
59
- this.view.name = this.appName;
60
-
61
- const windows = grok.shell.windows;
62
- windows.showProperties = false;
63
- windows.showToolbox = false;
64
- windows.showHelp = false;
65
- }
66
-
67
- getView(): DG.View {
68
- return this.view;
69
- }
70
- }
71
-
72
- export class CombinedAppUI extends AppUIBase {
73
- constructor(externalViewFactories: ViewFactories) {
74
- super(APP.COMBINED)
75
- this.externalViewFactories = externalViewFactories;
76
- const factories = this.getViewFactories();
77
- this.multiView = new DG.MultiView({viewFactories: factories});
78
- }
79
-
80
- private multiView: DG.MultiView;
81
- private externalViewFactories?: ViewFactories;
82
-
83
- private getViewFactories(): ViewFactories {
84
- function viewFactory(uiConstructor: new (view: DG.View) => SimpleAppUIBase): () => DG.View {
85
- const view = DG.View.create();
86
- const translateUI = new uiConstructor(view);
87
- // intentonally don't await for the promise
88
- translateUI.initView();
89
- return () => translateUI.getView();
90
- }
91
-
92
- let result: {[key: string]: () => DG.View } = {
93
- [TAB.TRANSLATOR]: viewFactory(OligoTranslatorUI),
94
- [TAB.PATTERN]: viewFactory(OligoPatternUI),
95
- [TAB.STRUCTRE]: viewFactory(OligoStructureUI),
96
- }
97
-
98
- if (this.externalViewFactories)
99
- result = Object.assign({}, result, this.externalViewFactories);
100
-
101
- return result
102
- }
103
-
104
- private getPath(): string {
105
- let name = this.multiView.tabs.currentPane.name;
106
- name = name.charAt(0).toUpperCase() + name.substring(1).toLowerCase();
107
- const path = `/apps/${_package.name}/OligoToolkit/${name}`;
108
- return path;
109
- }
110
-
111
- private setUrl(): void {
112
- this.multiView.path = this.getPath();
113
- }
114
-
115
- async addView(): Promise<void> {
116
- this.multiView.tabs.onTabChanged.subscribe(() => this.setUrl());
117
- this.setUrl();
118
- grok.shell.addView(this.multiView);
119
- }
120
- }
121
-
122
- /** For plugins from external packages */
123
- export class ExternalPluginUI extends SimpleAppUIBase {
124
- constructor(viewName: string, layout: HTMLDivElement) {
125
- super(viewName);
126
- this.layout = layout;
127
- }
128
- private layout: HTMLDivElement;
129
-
130
- protected getHtml(): Promise<HTMLDivElement> {
131
- return Promise.resolve(this.layout);
132
- }
133
- }
134
-
135
- export class AppUIFactory {
136
- private constructor() {}
137
-
138
- static getUI(appName: string): SimpleAppUIBase {
139
- switch (appName) {
140
- case APP.TRANSLATOR:
141
- return new OligoTranslatorUI();
142
- case APP.PATTERN:
143
- return new OligoPatternUI();
144
- case APP.STRUCTRE:
145
- return new OligoStructureUI();
146
- default:
147
- throw new Error(`Unknown app name: ${appName}`);
148
- }
149
- }
150
- }
151
-
152
- class OligoTranslatorUI extends SimpleAppUIBase {
153
- constructor() {
154
- super(APP.TRANSLATOR);
155
-
156
- const viewMonomerLibIcon = ui.iconFA('book', MonomerLibViewer.view, 'View monomer library');
157
- this.topPanel = [
158
- viewMonomerLibIcon,
159
- ];
160
- this.view.setRibbonPanels([this.topPanel]);
161
- this.ui = new TranslatorLayoutHandler();
162
- }
163
-
164
- private readonly topPanel: HTMLElement[];
165
- private readonly ui: TranslatorLayoutHandler;
166
-
167
- protected getHtml(): Promise<HTMLDivElement> {
168
- return this.ui.getHtmlElement();
169
- };
170
- }
171
-
172
- class OligoPatternUI extends SimpleAppUIBase {
173
- constructor() {
174
- super(APP.PATTERN);
175
- this.ui = new PatternLayoutHandler();
176
- }
177
- private readonly ui: PatternLayoutHandler;
178
- protected getHtml(): Promise<HTMLDivElement> {
179
- return Promise.resolve(this.ui.htmlDivElement);
180
- }
181
- }
182
-
183
- class OligoStructureUI extends SimpleAppUIBase {
184
- constructor() {
185
- super(APP.STRUCTRE)
186
- this.ui = new StructureLayoutHandler();
187
- }
188
- private readonly ui: StructureLayoutHandler;
189
-
190
- protected getHtml(): Promise<HTMLDivElement> {
191
- return this.ui.getHtmlDivElement();
192
- }
193
- }