@datagrok/bio 2.15.3 → 2.15.6

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 (69) hide show
  1. package/CHANGELOG.md +40 -0
  2. package/detectors.js +9 -2
  3. package/dist/284.js +1 -1
  4. package/dist/284.js.map +1 -1
  5. package/dist/455.js +2 -0
  6. package/dist/455.js.map +1 -0
  7. package/dist/980.js +1 -1
  8. package/dist/980.js.map +1 -1
  9. package/dist/package-test.js +3 -3
  10. package/dist/package-test.js.map +1 -1
  11. package/dist/package.js +2 -2
  12. package/dist/package.js.map +1 -1
  13. package/files/monomer-libraries/polytool-lib.json +52 -0
  14. package/files/tests/to-atomic-level-msa-fasta-output.csv +683 -683
  15. package/files/tests/to-atomic-level-msa-separator-output.csv +104 -104
  16. package/package.json +9 -9
  17. package/src/analysis/sequence-activity-cliffs.ts +3 -1
  18. package/src/calculations/monomerLevelMols.ts +2 -1
  19. package/src/demo/bio03-atomic-level.ts +1 -1
  20. package/src/package-test.ts +2 -1
  21. package/src/package.ts +151 -38
  22. package/src/tests/WebLogo-positions-test.ts +1 -1
  23. package/src/tests/activity-cliffs-tests.ts +2 -3
  24. package/src/tests/bio-tests.ts +1 -1
  25. package/src/tests/detectors-custom-notation-tests.ts +37 -0
  26. package/src/tests/detectors-tests.ts +20 -69
  27. package/src/tests/detectors-weak-and-likely-tests.ts +2 -2
  28. package/src/tests/monomer-libraries-tests.ts +31 -6
  29. package/src/tests/pepsea-tests.ts +1 -1
  30. package/src/tests/renderers-monomer-placer-tests.ts +2 -4
  31. package/src/tests/scoring.ts +2 -3
  32. package/src/tests/seq-handler-get-helm-tests.ts +2 -4
  33. package/src/tests/seq-handler-splitted-tests.ts +6 -2
  34. package/src/tests/splitters-test.ts +6 -6
  35. package/src/tests/substructure-filters-tests.ts +2 -3
  36. package/src/tests/to-atomic-level-tests.ts +22 -17
  37. package/src/tests/to-atomic-level-ui-tests.ts +76 -38
  38. package/src/tests/types.ts +0 -2
  39. package/src/tests/utils/detectors-utils.ts +63 -0
  40. package/src/tests/utils.ts +2 -2
  41. package/src/utils/cell-renderer-custom.ts +62 -0
  42. package/src/utils/cell-renderer.ts +58 -126
  43. package/src/utils/cyclized.ts +28 -14
  44. package/src/utils/dimerized.ts +0 -2
  45. package/src/utils/helm-to-molfile/converter/converter.ts +75 -54
  46. package/src/utils/helm-to-molfile/converter/monomer-wrapper.ts +2 -2
  47. package/src/utils/helm-to-molfile/converter/polymer.ts +23 -16
  48. package/src/utils/helm-to-molfile/converter/types.ts +0 -10
  49. package/src/utils/helm-to-molfile/utils.ts +10 -7
  50. package/src/utils/monomer-lib/consts.ts +18 -0
  51. package/src/utils/monomer-lib/lib-manager.ts +13 -3
  52. package/src/utils/monomer-lib/library-file-manager/file-manager.ts +1 -2
  53. package/src/utils/monomer-lib/monomer-colors.ts +68 -0
  54. package/src/utils/monomer-lib/monomer-lib-base.ts +165 -0
  55. package/src/utils/monomer-lib/monomer-lib.ts +44 -72
  56. package/src/utils/monomer-lib/monomer-manager/monomer-manager.ts +1 -1
  57. package/src/utils/monomer-lib/web-editor-monomer-dummy.ts +121 -0
  58. package/src/utils/monomer-lib/web-editor-monomer-of-library.ts +102 -0
  59. package/src/utils/pepsea.ts +1 -1
  60. package/src/utils/save-as-fasta.ts +1 -1
  61. package/src/utils/seq-helper/seq-helper.ts +20 -49
  62. package/src/utils/sequence-to-mol.ts +24 -28
  63. package/src/viewers/web-logo-viewer.ts +2 -1
  64. package/src/widgets/composition-analysis-widget.ts +4 -3
  65. package/src/widgets/representations.ts +8 -10
  66. package/dist/248.js +0 -2
  67. package/dist/248.js.map +0 -1
  68. package/src/utils/cell-renderer-consts.ts +0 -31
  69. package/src/utils/monomer-lib/library-file-manager/consts.ts +0 -1
package/src/package.ts CHANGED
@@ -4,8 +4,7 @@ import * as ui from 'datagrok-api/ui';
4
4
  import * as DG from 'datagrok-api/dg';
5
5
 
6
6
  import {Options} from '@datagrok-libraries/utils/src/type-declarations';
7
- import {DimReductionBaseEditor, PreprocessFunctionReturnType}
8
- from '@datagrok-libraries/ml/src/functionEditors/dimensionality-reduction-editor';
7
+ import {DimReductionBaseEditor, PreprocessFunctionReturnType} from '@datagrok-libraries/ml/src/functionEditors/dimensionality-reduction-editor';
9
8
  import {getActivityCliffs} from '@datagrok-libraries/ml/src/viewers/activity-cliffs';
10
9
  import {MmDistanceFunctionsNames} from '@datagrok-libraries/ml/src/macromolecule-distance-functions';
11
10
  import {BitArrayMetrics, KnownMetrics} from '@datagrok-libraries/ml/src/typed-metrics';
@@ -14,50 +13,38 @@ import {SeqHandler, SeqTemps} from '@datagrok-libraries/bio/src/utils/seq-handle
14
13
  import {IMonomerLib, IMonomerSet} from '@datagrok-libraries/bio/src/types';
15
14
  import {SeqPalette} from '@datagrok-libraries/bio/src/seq-palettes';
16
15
  import {FastaFileHandler} from '@datagrok-libraries/bio/src/utils/fasta-handler';
17
- import {_toAtomicLevel} from '@datagrok-libraries/bio/src/monomer-works/to-atomic-level';
18
- import {SCORE, calculateScores} from '@datagrok-libraries/bio/src/utils/macromolecule/scoring';
19
- import {
20
- createJsonMonomerLibFromSdf, IMonomerLibHelper
21
- } from '@datagrok-libraries/bio/src/monomer-works/monomer-utils';
16
+ import {SCORE} from '@datagrok-libraries/bio/src/utils/macromolecule/scoring';
17
+ import {createJsonMonomerLibFromSdf, IMonomerLibHelper} from '@datagrok-libraries/bio/src/monomer-works/monomer-utils';
22
18
  import {errInfo} from '@datagrok-libraries/bio/src/utils/err-info';
23
19
  import {ActivityCliffsEditor} from '@datagrok-libraries/ml/src/functionEditors/activity-cliffs-function-editor';
24
20
  import BitArray from '@datagrok-libraries/utils/src/bit-array';
25
21
  import {BYPASS_LARGE_DATA_WARNING} from '@datagrok-libraries/ml/src/functionEditors/consts';
26
- import {
27
- getEmbeddingColsNames, multiColReduceDimensionality
28
- } from '@datagrok-libraries/ml/src/multi-column-dimensionality-reduction/reduce-dimensionality';
22
+ import {getEmbeddingColsNames, multiColReduceDimensionality} from '@datagrok-libraries/ml/src/multi-column-dimensionality-reduction/reduce-dimensionality';
29
23
  import {DimReductionMethods} from '@datagrok-libraries/ml/src/multi-column-dimensionality-reduction/types';
30
- import {
31
- ITSNEOptions, IUMAPOptions
32
- } from '@datagrok-libraries/ml/src/multi-column-dimensionality-reduction/multi-column-dim-reducer';
24
+ import {ITSNEOptions, IUMAPOptions} from '@datagrok-libraries/ml/src/multi-column-dimensionality-reduction/multi-column-dim-reducer';
33
25
  import {generateLongSequence, generateLongSequence2} from '@datagrok-libraries/bio/src/utils/generator';
34
26
  import {getUserLibSettings, setUserLibSettings} from '@datagrok-libraries/bio/src/monomer-works/lib-settings';
35
27
  import {ISeqHelper} from '@datagrok-libraries/bio/src/utils/seq-helper';
36
28
  import {RDModule} from '@datagrok-libraries/chem-meta/src/rdkit-api';
37
29
  import {getRdKitModule} from '@datagrok-libraries/bio/src/chem/rdkit-module';
38
- import {getHelmHelper, IHelmHelper} from '@datagrok-libraries/bio/src/helm/helm-helper';
39
30
 
40
31
  import {getMacromoleculeColumns} from './utils/ui-utils';
41
- import {
42
- MacromoleculeDifferenceCellRenderer, MacromoleculeSequenceCellRenderer,
43
- } from './utils/cell-renderer';
32
+ import {MacromoleculeDifferenceCellRenderer, MacromoleculeSequenceCellRenderer,} from './utils/cell-renderer';
33
+ import {MacromoleculeCustomCellRenderer} from './utils/cell-renderer-custom';
44
34
  import {VdRegionsViewer} from './viewers/vd-regions-viewer';
45
35
  import {SequenceAlignment} from './seq_align';
46
36
  import {getEncodedSeqSpaceCol} from './analysis/sequence-space';
47
- import {
48
- createLinesGrid, createPropPanelElement, createTooltipElement,
49
- } from './analysis/sequence-activity-cliffs';
37
+ import {createLinesGrid, createPropPanelElement, createTooltipElement,} from './analysis/sequence-activity-cliffs';
50
38
  import {SequenceSimilarityViewer} from './analysis/sequence-similarity-viewer';
51
39
  import {SequenceDiversityViewer} from './analysis/sequence-diversity-viewer';
52
- import {MONOMERIC_COL_TAGS, SubstructureSearchDialog, invalidateMols} from './substructure-search/substructure-search';
40
+ import {invalidateMols, MONOMERIC_COL_TAGS, SubstructureSearchDialog} from './substructure-search/substructure-search';
53
41
  import {convert} from './utils/convert';
54
42
  import {getMacromoleculeColumnPropertyPanel} from './widgets/representations';
55
43
  import {saveAsFastaUI} from './utils/save-as-fasta';
56
44
  import {BioSubstructureFilter} from './widgets/bio-substructure-filter';
57
45
  import {WebLogoViewer} from './viewers/web-logo-viewer';
58
46
  import {MonomerLibManager} from './utils/monomer-lib/lib-manager';
59
- import {getMonomerLibraryManagerLink, showManageLibrariesDialog,
60
- showManageLibrariesView} from './utils/monomer-lib/library-file-manager/ui';
47
+ import {getMonomerLibraryManagerLink, showManageLibrariesDialog, showManageLibrariesView} from './utils/monomer-lib/library-file-manager/ui';
61
48
  import {demoBio01UI} from './demo/bio01-similarity-diversity';
62
49
  import {demoBio01aUI} from './demo/bio01a-hierarchical-clustering-and-sequence-space';
63
50
  import {demoBio01bUI} from './demo/bio01b-hierarchical-clustering-and-activity-cliffs';
@@ -115,8 +102,17 @@ export class SeqPaletteCustom implements SeqPalette {
115
102
  let monomerLib: IMonomerLib | null = null;
116
103
  let monomerSets: IMonomerSet | null = null;
117
104
 
105
+ let initBioPromise: Promise<void> | null = null;
106
+
118
107
  //tags: init
119
- export async function initBio() {
108
+ export async function initBio(): Promise<void> {
109
+ if (initBioPromise === null) {
110
+ initBioPromise = initBioInt();
111
+ }
112
+ await initBioPromise;
113
+ }
114
+
115
+ async function initBioInt() {
120
116
  const logPrefix = 'Bio: _package.initBio()';
121
117
  _package.logger.debug(`${logPrefix}, start`);
122
118
  let rdKitModule!: RDModule;
@@ -195,7 +191,7 @@ export function getBioLib(): IMonomerLib {
195
191
  }
196
192
 
197
193
  // For sync internal use, on initialized package
198
- export function getMonomerLib(): IMonomerLib | null {
194
+ export function getMonomerLib(): IMonomerLib {
199
195
  return monomerLib!;
200
196
  }
201
197
 
@@ -326,6 +322,15 @@ export function SeqActivityCliffsEditor(call: DG.FuncCall) {
326
322
 
327
323
  // -- Cell renderers --
328
324
 
325
+ //name: customSequenceCellRenderer
326
+ //tags: cellRenderer
327
+ //meta.cellType: sequence
328
+ //meta.columnTags: quality=Macromolecule, units=custom
329
+ //output: grid_cell_renderer result
330
+ export function customSequenceCellRenderer(): DG.GridCellRenderer {
331
+ return new MacromoleculeCustomCellRenderer();
332
+ }
333
+
329
334
  //name: fastaSequenceCellRenderer
330
335
  //tags: cellRenderer
331
336
  //meta.cellType: sequence
@@ -335,6 +340,15 @@ export function fastaSequenceCellRenderer(): MacromoleculeSequenceCellRenderer {
335
340
  return new MacromoleculeSequenceCellRenderer();
336
341
  }
337
342
 
343
+ //name: separatorSequenceCellRenderer
344
+ //tags: cellRenderer
345
+ //meta.cellType: sequence
346
+ //meta.columnTags: quality=Macromolecule, units=separator
347
+ //output: grid_cell_renderer result
348
+ export function separatorSequenceCellRenderer(): MacromoleculeSequenceCellRenderer {
349
+ return new MacromoleculeSequenceCellRenderer();
350
+ }
351
+
338
352
  // -- Property panels --
339
353
 
340
354
  //name: Bioinformatics | Sequence Renderer
@@ -353,15 +367,6 @@ export function compositionAnalysisWidget(sequence: DG.SemanticValue): DG.Widget
353
367
  return getCompositionAnalysisWidget(sequence);
354
368
  }
355
369
 
356
- //name: separatorSequenceCellRenderer
357
- //tags: cellRenderer
358
- //meta.cellType: sequence
359
- //meta.columnTags: quality=Macromolecule, units=separator
360
- //output: grid_cell_renderer result
361
- export function separatorSequenceCellRenderer(): MacromoleculeSequenceCellRenderer {
362
- return new MacromoleculeSequenceCellRenderer();
363
- }
364
-
365
370
  //name: MacromoleculeDifferenceCellRenderer
366
371
  //tags: cellRenderer
367
372
  //meta.cellType: MacromoleculeDifference
@@ -621,13 +626,17 @@ export async function sequenceSpaceTopMenu(table: DG.DataFrame, molecules: DG.Co
621
626
  //description: Converts sequences to molblocks
622
627
  //input: dataframe table [Input data table]
623
628
  //input: column seqCol {caption: Sequence; semType: Macromolecule}
624
- //input: bool nonlinear =false {caption: Non linear; description: Slower mode for cycling/branching HELM structures}
629
+ //input: bool nonlinear =false {caption: Non-linear; description: Slower mode for cycling/branching HELM structures}
630
+ //input: bool highlight =false {caption: Highlight monomers; description: Highlight monomers' substructures of the molecule }
625
631
  //output:
626
- export async function toAtomicLevel(table: DG.DataFrame, seqCol: DG.Column, nonlinear: boolean): Promise<void> {
632
+ export async function toAtomicLevel(
633
+ table: DG.DataFrame, seqCol: DG.Column, nonlinear: boolean, highlight: boolean = false
634
+ ): Promise<void> {
627
635
  const pi = DG.TaskBarProgressIndicator.create('Converting to atomic level ...');
628
636
  try {
637
+ await initBioPromise;
629
638
  const monomerLib = (await getMonomerLibHelper()).getMonomerLib();
630
- await sequenceToMolfile(table, seqCol, nonlinear, monomerLib);
639
+ await sequenceToMolfile(table, seqCol, nonlinear, highlight, monomerLib, _package.rdKitModule);
631
640
  } finally {
632
641
  pi.close();
633
642
  }
@@ -751,6 +760,31 @@ export function convertDialog() {
751
760
  convert(col);
752
761
  }
753
762
 
763
+ //top-menu: Bio | Convert | TestConvert
764
+ //name: convertSeqNotation
765
+ //description: RDKit-based conversion for SMILES, SMARTS, InChi, Molfile V2000 and Molfile V3000
766
+ //input: string sequence {semType: Macromolecule}
767
+ //input: string targetNotation
768
+ //input: string separator
769
+ //output: string result
770
+ export async function convertSeqNotation(sequence: string, targetNotation: NOTATION, separator?: string): Promise<string | undefined | null> {
771
+ try {
772
+ const col = DG.Column.fromStrings('sequence', [sequence]);
773
+ const df = DG.DataFrame.fromColumns([col]);
774
+ const semType = await grok.functions.call('Bio:detectMacromolecule', {col: col});
775
+ if (semType)
776
+ col.semType = semType;
777
+ const converterSh = SeqHandler.forColumn(col);
778
+ const newColumn = converterSh.convert(targetNotation, separator);
779
+ return newColumn.get(0);
780
+ } catch (err: any) {
781
+ const [errMsg, errStack] = errInfo(err);
782
+ _package.logger.error(errMsg, undefined, errStack);
783
+ throw err;
784
+ }
785
+ }
786
+
787
+
754
788
  //name: monomerCellRenderer
755
789
  //tags: cellRenderer
756
790
  //meta.cellType: Monomer
@@ -1098,6 +1132,76 @@ export async function sdfToJsonLib(table: DG.DataFrame) {
1098
1132
 
1099
1133
  // -- Utils --
1100
1134
 
1135
+ //name: seq2atomic
1136
+ //friendlyName: seq2atomic
1137
+ //description: Converts a `Macromolecule` sequence to its atomic level `Molecule` representation
1138
+ //input: string seq { semType: Macromolecule }
1139
+ //input: bool nonlinear
1140
+ //output: string molfile { semType: Molecule }
1141
+ //meta.role: converter
1142
+ export async function seq2atomic(seq: string, nonlinear: boolean): Promise<string | undefined> {
1143
+ if (!(seq.trim())) return '';
1144
+ try {
1145
+ const seqCol = DG.Column.fromList(DG.COLUMN_TYPE.STRING, `helm`, [seq]);
1146
+ const df = DG.DataFrame.fromColumns([seqCol]);
1147
+ const semType = await grok.functions.call('Bio:detectMacromolecule', {col: seqCol});
1148
+ if (semType) seqCol.semType = semType;
1149
+
1150
+ const monomerLib = (await getMonomerLibHelper()).getMonomerLib();
1151
+ const res = (await sequenceToMolfile(df, seqCol, nonlinear, false, monomerLib, _package.rdKitModule))?.molCol?.get(0);
1152
+ return res ?? undefined;
1153
+ } catch (err: any) {
1154
+ const [errMsg, errStack] = errInfo(err);
1155
+ _package.logger.error(errMsg, undefined, errStack);
1156
+ throw err;
1157
+ }
1158
+ }
1159
+
1160
+ // //description: Gets similarity to a reference sequence
1161
+ // //input: string seq { semType: Macromolecule }
1162
+ // //input: string ref { semType: Macromolecule }
1163
+ // //output: double result
1164
+ // export async function seqSimilarity(seq: string, ref: string): Promise<number> {
1165
+ // // if (!(seq.trim())) return null;
1166
+ // try {
1167
+ // const seqCol = DG.Column.fromList(DG.COLUMN_TYPE.STRING, `seq`, [seq]);
1168
+ // const df = DG.DataFrame.fromColumns([seqCol]);
1169
+ // const semType = await grok.functions.call('Bio:detectMacromolecule', {col: seqCol});
1170
+ // if (semType) seqCol.semType = semType;
1171
+ //
1172
+ // const resCol = await calculateScoresWithEmptyValues(df, seqCol, ref, SCORE.SIMILARITY);
1173
+ // return resCol.get(0)!;
1174
+ // } catch (err: any) {
1175
+ // const [errMsg, errStack] = errInfo(err);
1176
+ // _package.logger.error(errMsg, undefined, errStack);
1177
+ // throw err;
1178
+ // }
1179
+ // }
1180
+
1181
+ //name: seqIdentity
1182
+ //friendlyName: seqIdentity
1183
+ //description: Gets identity to a reference sequence
1184
+ //input: string seq { semType: Macromolecule }
1185
+ //input: string ref { semType: Macromolecule }
1186
+ //output: double result
1187
+ export async function seqIdentity(seq: string, ref: string): Promise<number | null> {
1188
+ if (!(seq.trim())) return null;
1189
+ try {
1190
+ const seqCol = DG.Column.fromList(DG.COLUMN_TYPE.STRING, `seq`, [seq]);
1191
+ const df = DG.DataFrame.fromColumns([seqCol]);
1192
+ const semType = await grok.functions.call('Bio:detectMacromolecule', {col: seqCol});
1193
+ if (!semType) throw new Error('Macromolecule required');
1194
+
1195
+ const resCol = await calculateScoresWithEmptyValues(df, seqCol, ref, SCORE.IDENTITY);
1196
+ return resCol.get(0);
1197
+ } catch (err: any) {
1198
+ const [errMsg, errStack] = errInfo(err);
1199
+ _package.logger.error(errMsg, undefined, errStack);
1200
+ throw err;
1201
+ }
1202
+ }
1203
+
1204
+
1101
1205
  //name: detectMacromoleculeProbe
1102
1206
  //input: file file
1103
1207
  //input: string colName = ''
@@ -1121,7 +1225,7 @@ export async function getSeqHelper(): Promise<ISeqHelper> {
1121
1225
  export function getMolFromHelm(
1122
1226
  df: DG.DataFrame, helmCol: DG.Column<string>, chiralityEngine: boolean
1123
1227
  ): Promise<DG.Column<string>> {
1124
- return getMolColumnFromHelm(df, helmCol, chiralityEngine);
1228
+ return getMolColumnFromHelm(df, helmCol, chiralityEngine, getMonomerLib());
1125
1229
  }
1126
1230
 
1127
1231
  // -- Custom notation providers --
@@ -1130,6 +1234,7 @@ export function getMolFromHelm(
1130
1234
  //input: column col
1131
1235
  //input: string separator
1132
1236
  export function applyNotationProviderForCyclized(col: DG.Column<string>, separator: string) {
1237
+ col.meta.units = NOTATION.CUSTOM;
1133
1238
  col.temp[SeqTemps.notationProvider] = new CyclizedNotationProvider(separator);
1134
1239
  }
1135
1240
 
@@ -1137,5 +1242,13 @@ export function applyNotationProviderForCyclized(col: DG.Column<string>, separat
1137
1242
  //input: column col
1138
1243
  //input: string separator
1139
1244
  export function applyNotationProviderForDimerized(col: DG.Column<string>, separator: string) {
1245
+ col.meta.units = NOTATION.CUSTOM;
1140
1246
  col.temp[SeqTemps.notationProvider] = new DimerizedNotationProvider(separator);
1141
1247
  }
1248
+
1249
+ //name: test1
1250
+ //output: object result
1251
+ export function test1(): any {
1252
+ _package.logger.debug('Bio:test1() function');
1253
+ return {value: 'value1'};
1254
+ }
@@ -4,7 +4,6 @@ import * as DG from 'datagrok-api/dg';
4
4
  import {category, expect, expectArray, test, testEvent} from '@datagrok-libraries/utils/src/test';
5
5
  import {ALPHABET, NOTATION, TAGS as bioTAGS} from '@datagrok-libraries/bio/src/utils/macromolecule';
6
6
  import {SeqHandler} from '@datagrok-libraries/bio/src/utils/seq-handler';
7
- import {GAP_SYMBOL} from '@datagrok-libraries/bio/src/utils/macromolecule/types';
8
7
 
9
8
  import {
10
9
  countForMonomerAtPosition,
@@ -12,6 +11,7 @@ import {
12
11
  PositionMonomerInfo as PMI,
13
12
  WebLogoViewer,
14
13
  } from '../viewers/web-logo-viewer';
14
+ import {GAP_SYMBOL} from '@datagrok-libraries/bio/src/utils/macromolecule/consts';
15
15
 
16
16
  const g: string = GAP_SYMBOL;
17
17
 
@@ -10,7 +10,7 @@ import {MmDistanceFunctionsNames} from '@datagrok-libraries/ml/src/macromolecule
10
10
  import {BitArrayMetricsNames} from '@datagrok-libraries/ml/src/typed-metrics';
11
11
  import {getMonomerLibHelper, IMonomerLibHelper} from '@datagrok-libraries/bio/src/monomer-works/monomer-utils';
12
12
  import {
13
- getUserLibSettings, setUserLibSettings, setUserLibSettingsForTests
13
+ getUserLibSettings, setUserLibSettings
14
14
  } from '@datagrok-libraries/bio/src/monomer-works/lib-settings';
15
15
  import {UserLibSettings} from '@datagrok-libraries/bio/src/monomer-works/types';
16
16
  import {DimReductionMethods} from '@datagrok-libraries/ml/src/multi-column-dimensionality-reduction/types';
@@ -32,8 +32,7 @@ category('activityCliffs', async () => {
32
32
  userLibSettings = await getUserLibSettings();
33
33
 
34
34
  // Test 'helm' requires default monomer library loaded
35
- await setUserLibSettingsForTests();
36
- await monomerLibHelper.loadMonomerLib(true); // load default libraries
35
+ await monomerLibHelper.loadMonomerLibForTests();
37
36
  });
38
37
 
39
38
  after(async () => {
@@ -10,7 +10,7 @@ import {Nucleotides, NucleotidesPalettes} from '@datagrok-libraries/bio/src/nucl
10
10
  import {AminoacidsPalettes} from '@datagrok-libraries/bio/src/aminoacids';
11
11
  import {UnknownSeqPalette} from '@datagrok-libraries/bio/src/unknown';
12
12
  import {getStatsForCol} from '@datagrok-libraries/bio/src/utils/macromolecule/utils';
13
- import {GAP_SYMBOL} from '@datagrok-libraries/bio/src/utils/macromolecule/types';
13
+ import {GAP_SYMBOL} from '@datagrok-libraries/bio/src/utils/macromolecule/consts';
14
14
 
15
15
  /** GAP_SYMBOL */
16
16
  const g: string = GAP_SYMBOL;
@@ -0,0 +1,37 @@
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 {category, test} from '@datagrok-libraries/utils/src/test';
6
+ import {ALIGNMENT, ALPHABET, NOTATION} from '@datagrok-libraries/bio/src/utils/macromolecule';
7
+
8
+ import {_testNeg, _testPos, DetectorTestData, DfReaderFunc, PosCol} from './utils/detectors-utils';
9
+
10
+ category('detectors: custom', () => {
11
+ const tests: DetectorTestData = {
12
+ 'cyclized1': {
13
+ csv: `n,seq
14
+ 1,R-F-C(1)-T-G-H-F-Y-G-H-F-Y-G-H-F-Y-P-C(1)-meI
15
+ 2,C(1)-T-G-H-F-Y-P-C(1)-meI
16
+ 3,R-F-C(1)-T-G-H-F-Y-P-C(1)
17
+ 4,C(1)-T-G-H-F-H-P-C(1)
18
+ 5,R-F-D(2)-T-G-H-F-Y-P-NH2(2)
19
+ 6,R-F-aG(3)-T-G-H-F-Y-P-azG(3)-meI`,
20
+ pos: {'seq': new PosCol(NOTATION.CUSTOM, ALIGNMENT.SEQ, ALPHABET.UN, 13, true, '-')}
21
+ },
22
+ };
23
+
24
+ for (const [testName, testData] of Object.entries(tests)) {
25
+ test(`${testName}`, async () => {
26
+ const reader: DfReaderFunc = async (): Promise<DG.DataFrame> => {
27
+ return DG.DataFrame.fromCsv(testData.csv);
28
+ };
29
+ for (const negColName of testData.neg ?? [])
30
+ await _testNeg(reader, negColName);
31
+ for (const [posColName, posCol] of Object.entries(testData.pos ?? {})) {
32
+ await _testPos(reader, posColName, posCol.units, posCol.aligned,
33
+ posCol.alphabet, posCol.alphabetSize, posCol.alphabetIsMultichar, posCol.separator);
34
+ }
35
+ });
36
+ }
37
+ });
@@ -4,10 +4,12 @@ import * as DG from 'datagrok-api/dg';
4
4
 
5
5
  import {category, test, expect} from '@datagrok-libraries/utils/src/test';
6
6
 
7
- import {importFasta} from '../package';
8
7
  import {ALIGNMENT, ALPHABET, NOTATION, TAGS as bioTAGS} from '@datagrok-libraries/bio/src/utils/macromolecule';
9
8
  import {SeqHandler} from '@datagrok-libraries/bio/src/utils/seq-handler';
10
9
 
10
+ import {_testNeg, _testPos, DetectorTestData, DfReaderFunc, PosCol} from './utils/detectors-utils';
11
+ import {importFasta} from '../package';
12
+
11
13
  /*
12
14
  // snippet to list df columns of semType='Macromolecule' (false positive)
13
15
  const df = grok.shell.tableByName('SPGI');
@@ -19,20 +21,6 @@ for (let i = 0; i < df.columns.length; i++) {
19
21
  }
20
22
  */
21
23
 
22
- type DfReaderFunc = () => Promise<DG.DataFrame>;
23
-
24
-
25
- class PosCol {
26
- constructor(
27
- public readonly units: string,
28
- public readonly aligned: string | null,
29
- public readonly alphabet: string | null,
30
- public readonly alphabetSize: number,
31
- public readonly alphabetIsMultichar?: boolean,
32
- public readonly separator?: string,
33
- ) { };
34
- }
35
-
36
24
  category('detectors', () => {
37
25
  const enum csvTests {
38
26
  fastaDna1 = 'csvFastaDna1',
@@ -57,7 +45,7 @@ category('detectors', () => {
57
45
  helmSameLength = 'helmSameLength',
58
46
  }
59
47
 
60
- const csvData2: { [testName: string]: { csv: string, neg?: string[], pos?: { [colName: string]: PosCol } } } = {
48
+ const csvData2: DetectorTestData = {
61
49
  'negEmpty': {
62
50
  csv: `id,col1
63
51
  1,
@@ -147,16 +135,16 @@ YN[Re]VYNR[Ac]WYV
147
135
  },
148
136
  'sepSameLength': {
149
137
  csv: `seq
150
- Ac(1)-A-A-A-A-A-A-A-A-A-A-A-A-A-C(1)-G-NH2
151
- Ac(1)-A-A-A-A-A-A-A-A-A-A-A-A-A-C(1)-G-NH2
152
- Ac(1)-A-A-A-A-A-A-A-A-A-A-A-A-A-C(1)-G-NH2`,
138
+ Aca-A-A-A-A-A-A-A-A-A-A-A-A-A-C-G-NH2
139
+ Aca-A-A-A-A-A-A-A-A-A-A-A-A-A-C-G-NH2
140
+ Aca-A-A-A-A-A-A-A-A-A-A-A-A-A-C-G-NH2`,
153
141
  pos: {'seq': new PosCol(NOTATION.SEPARATOR, ALIGNMENT.SEQ_MSA, ALPHABET.UN, 5, true, '-')}
154
142
  },
155
143
  'sepMsaSameLength': {
156
144
  csv: `seq
157
- Ac(1)-A-A-A-A-A-A-A-A-A-A-A-A-A-C(1)-G-NH2
158
- Ac(1)-A-A(2)-A-A-A-C(2)-A-A-A-A-C(1)-G-NH2
159
- Ac(1)-A-A-A-A-A-A-A-A-A-A-A-A-A-C(1)-G-NH2`,
145
+ Aca-A-A-A-A-A-A-A-A-A-A-A-A-A-Aca-G-NH2
146
+ Aca-A-Aca-A-A-A-meI-A-A-A-A-A-Aca-G-NH2
147
+ Aca-A-A-A-A-A-A-A-A-A-A-A-A-A-Aca-G-NH2`,
160
148
  pos: {'seq': new PosCol(NOTATION.SEPARATOR, ALIGNMENT.SEQ, ALPHABET.UN, 5, true, '-')}
161
149
  },
162
150
  'helmSameLength': {
@@ -166,6 +154,12 @@ PEPTIDE1{Ab(1).Y.V.K.H.P.F.W.R.W.Y.A.A.A.C(1).G.NH2}$$$$
166
154
  PEPTIDE1{Ad(1).S.W.Y.C.K.H.P.M.W.A.A.A.A.C(1)-G-NH2}$$$$`,
167
155
  pos: {'seq': new PosCol(NOTATION.HELM, null, null, 19, undefined, undefined)}
168
156
  },
157
+ 'fastaNonDigitAlphabet': {
158
+ csv: `flagC
159
+ "NMe-pyridazineH"
160
+ "Pyrrolo[2,3-c]pyridazineH"`,
161
+ neg: ['flagC']
162
+ }
169
163
  };
170
164
 
171
165
  const readCsv2: (key: keyof typeof csvData2) => DfReaderFunc = (key: keyof typeof csvData2) => {
@@ -237,9 +231,9 @@ m1-mon2-m3-mon4-mon5-Num--MON8-N9-m1-mon2-m3-mon4-mon5-Num--MON8-N9
237
231
 
238
232
  mon1-M-mon3-mon4-mon5---MON8-N9-mon1-M-mon3-mon4-mon5---MON8-N9`;
239
233
  [csvTests.sepComplex]: string = `seq
240
- Ac(1)-F-K(AEEA-AEEA-R-Ac)-L-mF-V-Y-mNle-D-W-N-mF-C(1)-G-NH2
241
- Ac(1)-F-K(AEEA-ARRA-W-Ac)-L-mF-V-Y-mNle-D-W-N-mF-C(1)-G-NH2
242
- Ac(1)-F-K(AEEA-AEEA-Ac)-L-mF-V-Y-mNle-D-W-N-mF-C(1)-G-NH2`;
234
+ Aca-F-K(AEEA-AEEA-R-Ac)-L-mF-V-Y-mNle-D-W-N-mF-Aca-G-NH2
235
+ Aca-F-K(AEEA-ARRA-W-Ac)-L-mF-V-Y-mNle-D-W-N-mF-Aca-G-NH2
236
+ Aca-F-K(AEEA-AEEA-Ac)-L-mF-V-Y-mNle-D-W-N-mF-Aca-G-NH2`;
243
237
  [csvTests.fastaMsaDna1]: string = `seq
244
238
  AC-GT-CTAC-GT-CT
245
239
  CAC-T-GTCAC-T-GT
@@ -406,7 +400,7 @@ MWRSWY-CKHPMWRSWY-CKHP`;
406
400
 
407
401
  test('SepComplex', async () => {
408
402
  await _testPos(readCsv(csvTests.sepComplex), 'seq',
409
- NOTATION.SEPARATOR, ALIGNMENT.SEQ, ALPHABET.UN, 18, true);
403
+ NOTATION.SEPARATOR, ALIGNMENT.SEQ, ALPHABET.UN, 17, true);
410
404
  });
411
405
 
412
406
  test('samplesFastaCsv', async () => {
@@ -517,20 +511,6 @@ export async function _testNegList(list: string[]): Promise<void> {
517
511
  }
518
512
  }
519
513
 
520
- export async function _testNeg(readDf: DfReaderFunc, colName: string) {
521
- const df: DG.DataFrame = await readDf();
522
- const col: DG.Column = df.getCol(colName)!;
523
- const semType: string = await grok.functions
524
- .call('Bio:detectMacromolecule', {col: col}) as unknown as string;
525
- if (semType)
526
- col.semType = semType;
527
-
528
- if (col.semType === DG.SEMTYPE.MACROMOLECULE) {
529
- const msg = `Negative test detected semType='${col.semType}', units='${col.meta.units}'.`;
530
- throw new Error(msg);
531
- }
532
- }
533
-
534
514
  export async function _testPosList(list: string[], units: NOTATION,
535
515
  aligned: ALIGNMENT, alphabet: ALPHABET, alphabetSize: number, alphabetIsMultichar: boolean,
536
516
  separator: string | null = null
@@ -556,35 +536,6 @@ export async function _testPosList(list: string[], units: NOTATION,
556
536
  }
557
537
  }
558
538
 
559
- export async function _testPos(
560
- readDf: DfReaderFunc, colName: string, units: string, aligned: string | null,
561
- alphabet: string | null, alphabetSize: number, alphabetIsMultichar?: boolean,
562
- separator: string | null = null,
563
- ) {
564
- const df: DG.DataFrame = await readDf();
565
- const col: DG.Column = df.col(colName)!;
566
- const semType: string = await grok.functions
567
- .call('Bio:detectMacromolecule', {col: col}) as unknown as string;
568
- if (semType)
569
- col.semType = semType;
570
-
571
- expect(col.semType, DG.SEMTYPE.MACROMOLECULE);
572
- expect(col.meta.units, units);
573
- expect(col.getTag(bioTAGS.aligned), aligned);
574
- expect(col.getTag(bioTAGS.alphabet), alphabet);
575
- if (separator)
576
- expect(col.getTag(bioTAGS.separator), separator);
577
-
578
- const sh = SeqHandler.forColumn(col);
579
- expect(sh.getAlphabetSize(), alphabetSize);
580
- expect(sh.getAlphabetIsMultichar(), alphabetIsMultichar);
581
- if (!sh.isHelm()) {
582
- expect(sh.aligned, aligned);
583
- expect(sh.alphabet, alphabet);
584
- }
585
- }
586
-
587
-
588
539
  export async function _testDf(readDf: DfReaderFunc, posCols: { [colName: string]: PosCol }): Promise<void> {
589
540
  const df: DG.DataFrame = await readDf();
590
541
  const errList: string[] = [];
@@ -4,8 +4,8 @@ import * as DG from 'datagrok-api/dg';
4
4
 
5
5
  import {category, test} from '@datagrok-libraries/utils/src/test';
6
6
  import {ALIGNMENT, ALPHABET, NOTATION} from '@datagrok-libraries/bio/src/utils/macromolecule';
7
- import {_testNeg, _testPos} from './detectors-tests';
8
- import {DfReaderFunc} from './types';
7
+
8
+ import {_testNeg, _testPos, DfReaderFunc} from './utils/detectors-utils';
9
9
 
10
10
 
11
11
  category('detectors:weak-and-likely', () => {
@@ -2,12 +2,16 @@ 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 {test, after, before, category, expect} from '@datagrok-libraries/utils/src/test';
5
+ import {test, after, before, category, expect, expectObject} from '@datagrok-libraries/utils/src/test';
6
6
  import {getMonomerLibHelper, IMonomerLibHelper} from '@datagrok-libraries/bio/src/monomer-works/monomer-utils';
7
7
  import {
8
- getUserLibSettings, setUserLibSettings, setUserLibSettingsForTests
8
+ getUserLibSettings, setUserLibSettings
9
9
  } from '@datagrok-libraries/bio/src/monomer-works/lib-settings';
10
10
  import {expectMonomerLib} from '@datagrok-libraries/bio/src/tests/monomer-lib-tests';
11
+ import {MonomerTypes, PolymerTypes} from '@datagrok-libraries/bio/src/helm/consts';
12
+ import {Monomer} from '@datagrok-libraries/bio/src/types/index';
13
+
14
+ import {monomerLibForTestsSummary} from '../utils/monomer-lib/consts';
11
15
 
12
16
 
13
17
  category('monomerLibraries', () => {
@@ -27,7 +31,7 @@ category('monomerLibraries', () => {
27
31
  test('default', async () => {
28
32
  // Clear settings to test default
29
33
  await setUserLibSettings({exclude: [], explicit: [], duplicateMonomerPreferences: {}});
30
- await monomerLibHelper.loadLibraries(true); // test defaultLib
34
+ await monomerLibHelper.loadMonomerLib(true); // test defaultLib
31
35
 
32
36
  // Currently default monomer lib set is of all files at LIB_PATH (at least HELMCoreLibrary.json)
33
37
  const currentMonomerLib = monomerLibHelper.getMonomerLib();
@@ -35,13 +39,12 @@ category('monomerLibraries', () => {
35
39
  });
36
40
 
37
41
  test('forTests', async () => {
38
- await setUserLibSettingsForTests();
39
- await monomerLibHelper.loadMonomerLib(true); // test defaultLib
42
+ await monomerLibHelper.loadMonomerLibForTests(); // test defaultLib
40
43
 
41
44
  // Currently default monomer lib set is of all files at LIB_PATH (at least HELMCoreLibrary.json)
42
45
  const currentMonomerLib = monomerLibHelper.getMonomerLib();
43
46
  // HELMCoreLibrary.json checks
44
- expectMonomerLib(currentMonomerLib);
47
+ expectMonomerLib(currentMonomerLib, monomerLibForTestsSummary);
45
48
  });
46
49
 
47
50
  test('empty', async () => {
@@ -62,4 +65,26 @@ category('monomerLibraries', () => {
62
65
  const polymerTypes = currentMonomerLib.getPolymerTypes();
63
66
  expect(polymerTypes.length === 0, true);
64
67
  });
68
+
69
+ test('override', async () => {
70
+ const overMon: Monomer = {
71
+ symbol: 'over1',
72
+ name: 'Test override monomer 1',
73
+ molfile: '',
74
+ author: 'Test Author',
75
+ id: 0,
76
+ rgroups: [],
77
+ smiles: '',
78
+ polymerType: PolymerTypes.PEPTIDE,
79
+ monomerType: MonomerTypes.BACKBONE,
80
+ createDate: null,
81
+ };
82
+ const monomerLib = monomerLibHelper.getMonomerLib();
83
+ const absentOverrideMonomer = monomerLib.getMonomer(overMon.polymerType, overMon.symbol);
84
+ expect(absentOverrideMonomer === null, true, `Unexpectedly found monomer '${overMon.symbol}' `);
85
+
86
+ const overriddenMonomerLib = monomerLib.override({[overMon.polymerType]: {[overMon.symbol]: overMon}});
87
+ const resOverMon = overriddenMonomerLib.getMonomer(overMon.polymerType, overMon.symbol);
88
+ expectObject(resOverMon as any, overMon);
89
+ });
65
90
  });
@@ -63,5 +63,5 @@ category('PepSeA', () => {
63
63
  logger.error(errMsg, undefined, errStack);
64
64
  }
65
65
  expect(logger.errorList[0].message, pepseaErrorError);
66
- },{skipReason: 'GROK-16699'});
66
+ });
67
67
  });
@@ -10,7 +10,7 @@ import {monomerToShort} from '@datagrok-libraries/bio/src/utils/macromolecule';
10
10
  import {SeqHandler} from '@datagrok-libraries/bio/src/utils/seq-handler';
11
11
  import {getMonomerLibHelper, IMonomerLibHelper} from '@datagrok-libraries/bio/src/monomer-works/monomer-utils';
12
12
  import {
13
- getUserLibSettings, setUserLibSettings, setUserLibSettingsForTests
13
+ getUserLibSettings, setUserLibSettings
14
14
  } from '@datagrok-libraries/bio/src/monomer-works/lib-settings';
15
15
  import {UserLibSettings} from '@datagrok-libraries/bio/src/monomer-works/types';
16
16
 
@@ -24,9 +24,7 @@ category('renderers: monomerPlacer', () => {
24
24
  libHelper = await getMonomerLibHelper();
25
25
  libSettings = await getUserLibSettings();
26
26
 
27
- await setUserLibSettingsForTests();
28
- await libHelper.awaitLoaded();
29
- await libHelper.loadMonomerLib(true);
27
+ await libHelper.loadMonomerLibForTests();
30
28
  });
31
29
 
32
30
  after(async () => {