@datagrok/bio 2.25.5 → 2.25.7

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.25.5",
8
+ "version": "2.25.7",
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",
@@ -186,6 +186,13 @@ export namespace funcs {
186
186
  return await grok.functions.call('Bio:MoleculesToHelmTopMenu', { table, molecules });
187
187
  }
188
188
 
189
+ /**
190
+ Converts a single molecule to HELM notation without requiring a table or column
191
+ */
192
+ export async function moleculeToHelmSingle(molecule: string ): Promise<string> {
193
+ return await grok.functions.call('Bio:MoleculeToHelmSingle', { molecule });
194
+ }
195
+
189
196
  /**
190
197
  Converts sequences to molblocks
191
198
  */
@@ -201,6 +208,13 @@ export namespace funcs {
201
208
  return await grok.functions.call('Bio:ToAtomicLevelPanel', { sequence });
202
209
  }
203
210
 
211
+ /**
212
+ Converts a single sequence to molblock
213
+ */
214
+ export async function toAtomicLevelSingleSeq(sequence: string ): Promise<string> {
215
+ return await grok.functions.call('Bio:ToAtomicLevelSingleSeq', { sequence });
216
+ }
217
+
204
218
  export async function sequence3dStructureWidget(sequence: any ): Promise<any> {
205
219
  return await grok.functions.call('Bio:Sequence3dStructureWidget', { sequence });
206
220
  }
package/src/package.g.ts CHANGED
@@ -273,6 +273,14 @@ export async function moleculesToHelmTopMenu(table: DG.DataFrame, molecules: DG.
273
273
  await PackageFunctions.moleculesToHelmTopMenu(table, molecules);
274
274
  }
275
275
 
276
+ //name: Molecule to HELM Single
277
+ //description: Converts a single molecule to HELM notation without requiring a table or column
278
+ //input: string molecule { semType: Molecule; description: Input molecule }
279
+ //output: string result { semType: Macromolecule; units: helm }
280
+ export async function moleculeToHelmSingle(molecule: string) : Promise<string> {
281
+ return await PackageFunctions.moleculeToHelmSingle(molecule);
282
+ }
283
+
276
284
  //name: To Atomic Level
277
285
  //description: Converts sequences to molblocks
278
286
  //input: dataframe table { description: Input data table }
@@ -299,6 +307,14 @@ export async function toAtomicLevelPanel(sequence: DG.SemanticValue) : Promise<a
299
307
  return await PackageFunctions.toAtomicLevelPanel(sequence);
300
308
  }
301
309
 
310
+ //name: To Atomic Level Single sequence
311
+ //description: Converts a single sequence to molblock
312
+ //input: string sequence { semType: Macromolecule }
313
+ //output: string result
314
+ export async function toAtomicLevelSingleSeq(sequence: string) : Promise<string> {
315
+ return await PackageFunctions.toAtomicLevelSingleSeq(sequence);
316
+ }
317
+
302
318
  //name: Molecular 3D Structure
303
319
  //tags: panel, bio, widgets
304
320
  //input: semantic_value sequence { semType: Macromolecule }
package/src/package.ts CHANGED
@@ -74,7 +74,7 @@ import {matchMoleculesWithMonomers, MonomerManager, standardizeMonomerLibrary} f
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';
77
- import {molecular3DStructureWidget, toAtomicLevelWidget} from './widgets/to-atomic-level-widget';
77
+ import {molecular3DStructureWidget, toAtomicLevelWidget, toAtomicLevelSingle} from './widgets/to-atomic-level-widget';
78
78
  import {handleSequenceHeaderRendering} from './widgets/sequence-scrolling-widget';
79
79
  import {PolymerType} from '@datagrok-libraries/js-draw-lite/src/types/org';
80
80
  import {BilnNotationProvider} from './utils/biln';
@@ -642,6 +642,20 @@ export class PackageFunctions {
642
642
  }
643
643
  }
644
644
 
645
+ @grok.decorators.func({name: 'Molecule to HELM Single', description: 'Converts a single molecule to HELM notation without requiring a table or column', outputs: [{name: 'result', type: 'string', options: {semType: 'Macromolecule', units: 'helm'}}]})
646
+ static async moleculeToHelmSingle(
647
+ @grok.decorators.param({name: 'molecule', options: {semType: 'Molecule', description: 'Input molecule'}})molecule: string,
648
+ ): Promise<string> {
649
+ // create temporary dataframe
650
+ const tempCol = DG.Column.fromStrings('molecule', [molecule]);
651
+ tempCol.semType = DG.SEMTYPE.MOLECULE;
652
+ const tempDF = DG.DataFrame.fromColumns([tempCol]);
653
+ // call converter
654
+ await PackageFunctions.moleculesToHelmTopMenu(tempDF, tempCol);
655
+ // get result
656
+ const result = tempDF.columns.toList().find((c) => c.name.toLowerCase().includes('regenerated sequence'))?.get(0);
657
+ return result ?? '';
658
+ }
645
659
 
646
660
  @grok.decorators.func({
647
661
  name: 'To Atomic Level',
@@ -690,6 +704,47 @@ export class PackageFunctions {
690
704
  return toAtomicLevelWidget(sequence);
691
705
  }
692
706
 
707
+ @grok.decorators.func({
708
+ name: 'To Atomic Level Single sequence',
709
+ description: 'Converts a single sequence to molblock'
710
+ })
711
+ static async toAtomicLevelSingleSeq(
712
+ @grok.decorators.param({name: 'sequence', type: 'string', options: {semType: 'Macromolecule'}}) sequence: string,
713
+ ) : Promise<string> {
714
+ // create temporary column and table
715
+ const isHelm = sequence.includes('$$');
716
+ const isSeparator = sequence.split('').filter((c) => c == '/').length > 2;
717
+ const isBiln = sequence.split('').filter((c) => c == '-').length > 2; // biln is super separator basically :D
718
+ // const isFasta = !isHelm && !isSeparator && !isBiln;
719
+ const tempCol = DG.Column.fromStrings('sequence', [sequence]);
720
+ tempCol.semType = DG.SEMTYPE.MACROMOLECULE;
721
+ tempCol.meta.units = isHelm ? NOTATION.HELM : isSeparator ? NOTATION.SEPARATOR : isBiln ? NOTATION.BILN : NOTATION.FASTA;
722
+ tempCol.setTag(bioTAGS.aligned, 'SEQ');
723
+ if (isSeparator)
724
+ tempCol.setTag(bioTAGS.separator, '/');
725
+ if (isBiln)
726
+ tempCol.setTag(bioTAGS.separator, '-');
727
+ // detect alphabet
728
+ const dnaAlphabet = 'AGCT';
729
+ const RNAAlphabet = 'AGCU';
730
+ const isDNA = sequence.split('').every((c) => dnaAlphabet.includes(c) || c === '/' || c === '-');
731
+ const isRNA = !isDNA && sequence.split('').every((c) => RNAAlphabet.includes(c) || c === '/' || c === '-');
732
+
733
+ tempCol.setTag(bioTAGS.alphabet, isDNA ? ALPHABET.DNA : isRNA ? ALPHABET.RNA : 'UN');
734
+ tempCol.setTag(bioTAGS.alphabetIsMultichar, 'true');
735
+
736
+ const tempDF = DG.DataFrame.fromColumns([tempCol]);
737
+
738
+ // get the sell as semantic value
739
+ const cell = tempDF.cell(0, 'sequence');
740
+ const semValue = DG.SemanticValue.fromTableCell(cell);
741
+
742
+ const res = await toAtomicLevelSingle(semValue);
743
+ if (res.errorText || !res.mol)
744
+ throw new Error(res.errorText);
745
+ return res.mol;
746
+ }
747
+
693
748
  @grok.decorators.panel({
694
749
  name: 'Molecular 3D Structure',
695
750
  tags: ['bio', 'widgets']
@@ -1277,22 +1332,7 @@ export class PackageFunctions {
1277
1332
  nonlinear: boolean
1278
1333
  ): Promise<string | undefined> {
1279
1334
  if (!(seq.trim())) return '';
1280
- try {
1281
- const seqCol = DG.Column.fromList(DG.COLUMN_TYPE.STRING, `helm`, [seq]);
1282
- const df = DG.DataFrame.fromColumns([seqCol]);
1283
- const semType = await grok.functions.call('Bio:detectMacromolecule', {col: seqCol});
1284
- if (semType) seqCol.semType = semType;
1285
-
1286
- const monomerLib = (await PackageFunctions.getMonomerLibHelper()).getMonomerLib();
1287
- const seqHelper = _package.seqHelper;
1288
- const rdKitModule = await getRdKitModule();
1289
- const res = (await sequenceToMolfile(df, seqCol, nonlinear, false, monomerLib, seqHelper, rdKitModule))?.molCol?.get(0);
1290
- return res ?? undefined;
1291
- } catch (err: any) {
1292
- const [errMsg, errStack] = errInfo(err);
1293
- _package.logger.error(errMsg, undefined, errStack);
1294
- throw err;
1295
- }
1335
+ return PackageFunctions.toAtomicLevelSingleSeq(seq);
1296
1336
  }
1297
1337
 
1298
1338
  // //description: Gets similarity to a reference sequence