@datagrok/bio 2.22.9 → 2.22.10

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/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "name": "Davit Rizhinashvili",
6
6
  "email": "drizhinashvili@datagrok.ai"
7
7
  },
8
- "version": "2.22.9",
8
+ "version": "2.22.10",
9
9
  "description": "Bioinformatics support (import/export of sequences, conversion, visualization, analysis). [See more](https://github.com/datagrok-ai/public/blob/master/packages/Bio/README.md) for details.",
10
10
  "repository": {
11
11
  "type": "git",
package/src/package.g.ts CHANGED
@@ -19,6 +19,12 @@ export function sequenceTooltip(col: DG.Column) : any {
19
19
  return PackageFunctions.sequenceTooltip(col);
20
20
  }
21
21
 
22
+ //input: string library
23
+ //output: string result
24
+ export async function standardiseMonomerLibrary(library: string) : Promise<string> {
25
+ return await PackageFunctions.standardiseMonomerLibrary(library);
26
+ }
27
+
22
28
  //output: object monomerLib
23
29
  export function getBioLib() : any {
24
30
  return PackageFunctions.getBioLib();
package/src/package.ts CHANGED
@@ -70,7 +70,7 @@ import {GetRegionFuncEditor} from './utils/get-region-func-editor';
70
70
  import {sequenceToMolfile} from './utils/sequence-to-mol';
71
71
  import {detectMacromoleculeProbeDo} from './utils/detect-macromolecule-probe';
72
72
  import {getMolColumnFromHelm} from './utils/helm-to-molfile/utils';
73
- import {MonomerManager} from './utils/monomer-lib/monomer-manager/monomer-manager';
73
+ import {MonomerManager, standardizeMonomerLibrary} from './utils/monomer-lib/monomer-manager/monomer-manager';
74
74
  import {calculateScoresWithEmptyValues} from './utils/calculate-scores';
75
75
  import {SeqHelper} from './utils/seq-helper/seq-helper';
76
76
  import {_toAtomicLevel} from '@datagrok-libraries/bio/src/monomer-works/to-atomic-level';
@@ -98,7 +98,6 @@ function getDecoratorFunc() {
98
98
  if (!grok.decorators)
99
99
  (grok as any).decorators = {};
100
100
 
101
-
102
101
  const decorators = [
103
102
  'func', 'init', 'param', 'panel', 'editor', 'demo', 'app',
104
103
  'appTreeBrowser', 'fileHandler', 'fileExporter', 'model', 'viewer', 'filter', 'cellRenderer', 'autostart',
@@ -139,6 +138,11 @@ export class PackageFunctions {
139
138
  return resWidget;
140
139
  }
141
140
 
141
+ @grok.decorators.func({})
142
+ static async standardiseMonomerLibrary(library: string): Promise<string> {
143
+ return await standardizeMonomerLibrary(library);
144
+ }
145
+
142
146
  // Keep for backward compatibility
143
147
  @grok.decorators.func({outputs: [{type: 'object', name: 'monomerLib'}]})
144
148
  static getBioLib(): IMonomerLib {
@@ -49,14 +49,29 @@ export const MONOMER_DF_COLUMNS = {
49
49
  [MONOMER_DF_COLUMN_NAMES.SOURCE]: DG.COLUMN_TYPE.STRING,
50
50
  } as const;
51
51
 
52
- export function getMonomersDataFrame(activeMonomerLib: IMonomerLib) {
52
+ export async function standardiseMonomers(monomers: Monomer[]) {
53
+ const df = getMonomersDataFrame(monomers);
54
+ if (monomers.length !== df.rowCount)
55
+ throw new Error(`Monomers length ${monomers.length} does not match dataframe row count ${df.rowCount}`);
56
+ const fixedMonomers = await Promise.all(new Array(monomers.length).fill(null).map(async (_, i) => monomerFromDfRow(df.rows.get(i))));
57
+ return fixedMonomers;
58
+ }
59
+
60
+ /** Standardizes the monomer library
61
+ * warning: throws error if the library is not valid or has invalid monomers
62
+ */
63
+ export async function standardizeMonomerLibrary(libraryString: string) {
64
+ const library: Monomer[] = JSON.parse(libraryString);
65
+ if (!library || !Array.isArray(library) || library.length === 0)
66
+ throw new Error('Invalid library format, expected an array of monomers');
67
+ const fixedMonomers = await standardiseMonomers(library);
68
+ const fixedLibrary = fixedMonomers.map((m) => ({...m, lib: undefined, wem: undefined}));
69
+ const libraryStringFixed = JSON.stringify(fixedLibrary, null, 2);
70
+ return libraryStringFixed;
71
+ }
72
+
73
+ export function getMonomersDataFrame(monomers: Monomer[]) {
53
74
  try {
54
- const ploymerTypes = activeMonomerLib.getPolymerTypes();
55
- const monomers = ploymerTypes.flatMap((polymerType) => {
56
- return activeMonomerLib!.getMonomerSymbolsByType(polymerType).map((symbol) => {
57
- return activeMonomerLib!.getMonomer(polymerType, symbol)!;
58
- });
59
- });
60
75
  const df = DG.DataFrame.create(monomers.length);
61
76
 
62
77
  const uniqueRgroupNamesSet = new Set<string>();
@@ -437,7 +452,14 @@ export class MonomerManager implements IMonomerManager {
437
452
  grok.shell.error(`Library ${fileName} not found`);
438
453
  return DG.DataFrame.create();
439
454
  }
440
- const df = getMonomersDataFrame(this.activeMonomerLib);
455
+
456
+ const ploymerTypes = this.activeMonomerLib.getPolymerTypes();
457
+ const monomers = ploymerTypes.flatMap((polymerType) => {
458
+ return this.activeMonomerLib!.getMonomerSymbolsByType(polymerType).map((symbol) => {
459
+ return this.activeMonomerLib!.getMonomer(polymerType, symbol)!;
460
+ });
461
+ });
462
+ const df = getMonomersDataFrame(monomers);
441
463
  return df;
442
464
  } catch (e) {
443
465
  grok.shell.error('Error creating monomers dataframe');