@datagrok/bio 2.11.2 → 2.11.5

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.
@@ -0,0 +1,125 @@
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 {HELM_POLYMER_TYPE} from '@datagrok-libraries/bio/src/utils/const';
7
+ import {MonomerLibHelper} from '../../utils/monomer-lib';
8
+ import {ALL_MONOMERS, CYCLIZATION_TYPE, TRANSFORMATION_TYPE} from './const';
9
+ import {addTransformedColumn} from './transformation';
10
+ import * as rxjs from 'rxjs';
11
+ import {MetaData} from './types';
12
+
13
+ export function getPolyToolDialog(): DG.Dialog {
14
+ function getMonomerList(cyclizationType: CYCLIZATION_TYPE): string[] {
15
+ if (cyclizationType === cyclizationTypes[0]) {
16
+ return [ALL_MONOMERS].concat(
17
+ monomerLib.getMonomerSymbolsByType(HELM_POLYMER_TYPE.PEPTIDE)
18
+ );
19
+ }
20
+ if (cyclizationType === cyclizationTypes[1]) {
21
+ return [ALL_MONOMERS].concat(
22
+ monomerLib.getMonomerSymbolsByRGroup(3, HELM_POLYMER_TYPE.PEPTIDE)
23
+ );
24
+ }
25
+ return ['C'];
26
+ }
27
+
28
+ function updateMonomerList(): void {
29
+ if (cyclizationTypeChoice.value === CYCLIZATION_TYPE.NCys) {
30
+ monomerList1 = getMonomerList(CYCLIZATION_TYPE.NO);
31
+ monomerList2 = getMonomerList(CYCLIZATION_TYPE.NCys);
32
+ } else {
33
+ monomerList1 = getMonomerList(cyclizationTypeChoice.value as CYCLIZATION_TYPE);
34
+ monomerList2 = [...monomerList1];
35
+ }
36
+
37
+ leftTerminalChoice = ui.choiceInput(
38
+ 'R1:', monomerList1[0], monomerList1, () => { onRGroupValueChange.next(); }
39
+ );
40
+ rightTerminalChoice = ui.choiceInput('R2:', monomerList2[0], monomerList2, () => { onRGroupValueChange.next(); });
41
+ onRGroupValueChange.next();
42
+ ui.empty(terminalControls);
43
+ [leftTerminalChoice, rightTerminalChoice].forEach((el) => { terminalControls.appendChild(el.root); });
44
+ }
45
+
46
+ function updateMeta() {
47
+ meta.cyclizationType = cyclizationTypeChoice.value!;
48
+ meta.leftTerminal = leftTerminalChoice.value!;
49
+ meta.rightTerminal = rightTerminalChoice.value!;
50
+ meta.transformationType = transformationChoice.value!;
51
+ }
52
+
53
+
54
+ const onCyclizationChoice = new rxjs.Subject<string>();
55
+ const onRGroupValueChange = new rxjs.Subject<string>();
56
+ onCyclizationChoice.subscribe(() => {
57
+ meta.cyclizationType = cyclizationTypeChoice.value!;
58
+ updateMonomerList();
59
+ });
60
+ onRGroupValueChange.subscribe(() => {
61
+ meta.rightTerminal = rightTerminalChoice.value!;
62
+ meta.leftTerminal = leftTerminalChoice.value!;
63
+ });
64
+
65
+ const meta = {} as MetaData;
66
+ const transformations = [TRANSFORMATION_TYPE.CYCLIZATION];
67
+ const transformationChoice = ui.choiceInput(
68
+ 'Modification', transformations[0], transformations, () => meta.transformationType = transformationChoice.value!
69
+ );
70
+
71
+ const cyclizationTypes = [CYCLIZATION_TYPE.NO, CYCLIZATION_TYPE.R3, CYCLIZATION_TYPE.NCys];
72
+ const cyclizationTypeChoice = ui.choiceInput(
73
+ 'Type', cyclizationTypes[2], cyclizationTypes, () => { onCyclizationChoice.next(); }
74
+ );
75
+
76
+ const monomerLib = MonomerLibHelper.instance.getBioLib();
77
+ let monomerList1: string[] = [];
78
+ let monomerList2: string[] = [];
79
+ let leftTerminalChoice = ui.choiceInput(
80
+ 'R1:', monomerList1[0], monomerList1, () => {
81
+ meta.leftTerminal = leftTerminalChoice.value!;
82
+ }
83
+ );
84
+ let rightTerminalChoice = ui.choiceInput('R2:', monomerList2[0], monomerList2, () => {
85
+ meta.rightTerminal = rightTerminalChoice.value!;
86
+ });
87
+ const terminalControls = ui.divV([leftTerminalChoice.root, rightTerminalChoice.root]);
88
+ updateMonomerList();
89
+
90
+ updateMeta();
91
+
92
+ const targetColumns = grok.shell.t.columns.bySemTypeAll(DG.SEMTYPE.MACROMOLECULE);
93
+ if (!targetColumns)
94
+ throw new Error('No dataframe with maceomolecule columns open');
95
+
96
+ const targetColumnInput = ui.columnInput(
97
+ 'Column', grok.shell.t, targetColumns[0], null,
98
+ {filter: (col: DG.Column) => col.semType === DG.SEMTYPE.MACROMOLECULE}
99
+ );
100
+
101
+ const generateHelmChoiceInput = ui.boolInput('Get HELM', true);
102
+ ui.tooltip.bind(generateHelmChoiceInput.root, 'Add HELM column');
103
+
104
+ const div = ui.div([
105
+ targetColumnInput,
106
+ transformationChoice,
107
+ cyclizationTypeChoice,
108
+ terminalControls,
109
+ generateHelmChoiceInput,
110
+ ]);
111
+
112
+ const dialog = ui.dialog('Poly Tool')
113
+ .add(div)
114
+ .onOK(async () => {
115
+ const molCol = targetColumnInput.value;
116
+ if (!molCol) {
117
+ grok.shell.warning('No marcomolecule column chosen!');
118
+ return;
119
+ }
120
+ addTransformedColumn(molCol!, meta, generateHelmChoiceInput.value!);
121
+ }
122
+ );
123
+
124
+ return dialog;
125
+ }