@datagrok/bio 1.7.12 → 1.7.13

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
@@ -2,7 +2,7 @@
2
2
  "name": "@datagrok/bio",
3
3
  "beta": false,
4
4
  "friendlyName": "Bio",
5
- "version": "1.7.12",
5
+ "version": "1.7.13",
6
6
  "description": "Bio is a [package](https://datagrok.ai/help/develop/develop#packages) for the [Datagrok](https://datagrok.ai) platform",
7
7
  "repository": {
8
8
  "type": "git",
@@ -11,25 +11,25 @@
11
11
  },
12
12
  "dependencies": {
13
13
  "@biowasm/aioli": ">=2.4.0",
14
- "@datagrok-libraries/bio": "^2.8.5",
15
- "@datagrok-libraries/utils": "^1.0.0",
14
+ "@datagrok-libraries/bio": "^2.8.6",
16
15
  "@datagrok-libraries/ml": "^3.0.0",
16
+ "@datagrok-libraries/utils": "^1.4.0",
17
17
  "cash-dom": "latest",
18
- "datagrok-api": "^1.4.12",
19
- "dayjs": "latest",
18
+ "datagrok-api": "^1.5.1",
19
+ "dayjs": "^1.11.4",
20
+ "openchemlib": "6.0.1",
20
21
  "rxjs": "^6.5.5",
21
22
  "ts-loader": "^9.2.5",
22
- "typescript": "^4.4.2",
23
- "openchemlib": "6.0.1"
23
+ "typescript": "^4.4.2"
24
24
  },
25
25
  "devDependencies": {
26
26
  "@types/jest": "^27.0.0",
27
27
  "@typescript-eslint/eslint-plugin": "latest",
28
28
  "@typescript-eslint/parser": "latest",
29
- "eslint": "latest",
29
+ "eslint": "^8.20.0",
30
30
  "eslint-config-google": "latest",
31
31
  "jest": "^27.0.0",
32
- "jest-html-reporter": "^3.5.0",
32
+ "jest-html-reporter": "^3.6.0",
33
33
  "puppeteer": "^13.7.0",
34
34
  "ts-jest": "^27.0.0",
35
35
  "webpack": "latest",
@@ -0,0 +1,13 @@
1
+ #name: Embed
2
+ #language: python
3
+ #input: string molecule
4
+ #output: string sdf
5
+
6
+ from rdkit.Chem import AllChem
7
+ from rdkit import Chem
8
+ mol = AllChem.MolFromMolBlock(molecule) if ("M END" in molecule) else AllChem.MolFromSmiles(molecule)
9
+
10
+ AllChem.EmbedMolecule(mol, AllChem.ETKDG())
11
+ #AllChem.UFFOptimizeMolecule(mol)
12
+ #mol = Chem.RemoveHs(mol)
13
+ sdf = Chem.MolToMolBlock(mol)
package/src/package.ts CHANGED
@@ -21,6 +21,7 @@ import {getMacroMol} from './utils/atomic-works';
21
21
  import {MacromoleculeSequenceCellRenderer} from './utils/cell-renderer';
22
22
  import {convert} from './utils/convert';
23
23
  import {lru} from './utils/cell-renderer';
24
+ import {representationsWidget} from './widgets/representations';
24
25
 
25
26
  //tags: init
26
27
  export async function initBio(): Promise<void> {
@@ -37,7 +38,6 @@ export function Lru() {
37
38
  return lru;
38
39
  }
39
40
 
40
-
41
41
  //name: macromoleculeSequenceCellRenderer
42
42
  //tags: cellRenderer
43
43
  //meta.cellType: Macromolecule
@@ -280,6 +280,17 @@ function parseMacromolecule(
280
280
  return seqArray.join('');
281
281
  }
282
282
 
283
+ //name: Representations
284
+ //tags: panel, widgets
285
+ //input: cell macroMolecule {semType: Macromolecule}
286
+ //output: widget result
287
+ export async function peptideMolecule(macroMolecule: DG.Cell): Promise<DG.Widget> {
288
+ const monomersLibFile = await _package.files.readAsText(HELM_CORE_LIB_FILENAME);
289
+ const monomersLibObject: any[] = JSON.parse(monomersLibFile);
290
+
291
+ return representationsWidget(macroMolecule, monomersLibObject);
292
+ }
293
+
283
294
  //name: importFasta
284
295
  //description: Opens FASTA file
285
296
  //tags: file-handler
@@ -4,7 +4,8 @@ import * as grok from 'datagrok-api/grok';
4
4
  import * as DG from 'datagrok-api/dg';
5
5
 
6
6
  import {ConverterFunc} from './types';
7
- import {NOTATION, NotationConverter} from '@datagrok-libraries/bio/src/utils/notation-converter';
7
+ import {NotationConverter} from '@datagrok-libraries/bio/src/utils/notation-converter';
8
+ import {NOTATION} from '@datagrok-libraries/bio/src/utils/units-handler';
8
9
 
9
10
  // import {mmSemType} from '../const';
10
11
  // import {importFasta} from '../package';
@@ -5,7 +5,7 @@ import * as DG from 'datagrok-api/dg';
5
5
  import {importFasta, multipleSequenceAlignmentAny} from '../package';
6
6
  import {readDataframe} from './utils';
7
7
  import {convertDo} from '../utils/convert';
8
- import {NOTATION} from '@datagrok-libraries/bio/src/utils/notation-converter';
8
+ import {NOTATION} from '@datagrok-libraries/bio/src/utils/units-handler';
9
9
 
10
10
  category('renderers', () => {
11
11
  let tvList: DG.TableView[];
@@ -4,7 +4,8 @@ import * as grok from 'datagrok-api/grok';
4
4
  import $ from 'cash-dom';
5
5
 
6
6
  import {Subscription} from 'rxjs';
7
- import {NotationConverter, NOTATION} from '@datagrok-libraries/bio/src/utils/notation-converter';
7
+ import {NotationConverter} from '@datagrok-libraries/bio/src/utils/notation-converter';
8
+ import {NOTATION} from '@datagrok-libraries/bio/src/utils/units-handler';
8
9
 
9
10
 
10
11
  let convertDialog: DG.Dialog | null = null;
@@ -17,7 +18,7 @@ let convertDialogSubs: Subscription[] = [];
17
18
  */
18
19
  export function convert(col: DG.Column): void {
19
20
  const converter = new NotationConverter(col);
20
- const current: NOTATION = converter.sourceNotation;
21
+ const currentNotation: NOTATION = converter.notation;
21
22
  //TODO: read all notations
22
23
  const notations = [
23
24
  NOTATION.FASTA,
@@ -25,7 +26,7 @@ export function convert(col: DG.Column): void {
25
26
  NOTATION.HELM
26
27
  ];
27
28
  const separatorArray = ['-', '.', '/'];
28
- const filteredNotations = notations.filter((e) => e !== current);
29
+ const filteredNotations = notations.filter((e) => e !== currentNotation);
29
30
  const targetNotationInput = ui.choiceInput('Convert to', filteredNotations[0], filteredNotations);
30
31
 
31
32
  const separatorInput = ui.choiceInput('Separator', separatorArray[0], separatorArray);
@@ -48,7 +49,7 @@ export function convert(col: DG.Column): void {
48
49
  if (convertDialog == null) {
49
50
  convertDialog = ui.dialog('Convert sequence notation')
50
51
  .add(ui.div([
51
- ui.h1('Current notation: ' + current),
52
+ ui.h1('Current notation: ' + currentNotation),
52
53
  targetNotationInput.root,
53
54
  separatorInput.root
54
55
  ]))
@@ -45,7 +45,8 @@ export function getMolfilesFromSeq(col: DG.Column, monomersLibObject: any[]): an
45
45
  const monomersDict = createMomomersMolDict(monomersLibObject);
46
46
  const molFiles = [];
47
47
  for (let i = 0; i < col.length; ++i) {
48
- const monomers = splitterFunc(col.get(i));
48
+ const macroMolecule = col.get(i);
49
+ const monomers = splitterFunc(macroMolecule);
49
50
  const molFilesForSeq = [];
50
51
  for (let j = 0; j < monomers.length; ++j) {
51
52
  if (monomers[j]) {
@@ -61,6 +62,28 @@ export function getMolfilesFromSeq(col: DG.Column, monomersLibObject: any[]): an
61
62
  return molFiles;
62
63
  }
63
64
 
65
+ export function getMolfilesFromSingleSeq(cell: DG.Cell, monomersLibObject: any[]): any[][] | null {
66
+ const units = cell.column.tags[DG.TAGS.UNITS];
67
+ const sep = cell.column!.getTag('separator');
68
+ const splitterFunc: SplitterFunc = WebLogo.getSplitter(units, sep);
69
+ const monomersDict = createMomomersMolDict(monomersLibObject);
70
+ const molFiles = [];
71
+ const macroMolecule = cell.value;
72
+ const monomers = splitterFunc(macroMolecule);
73
+ const molFilesForSeq = [];
74
+ for (let j = 0; j < monomers.length; ++j) {
75
+ if (monomers[j]) {
76
+ if (!monomersDict[monomers[j]]) {
77
+ grok.shell.warning(`Monomer ${monomers[j]} is missing in HELM library. Structure cannot be created`);
78
+ return null;
79
+ }
80
+ molFilesForSeq.push(JSON.parse(JSON.stringify(monomersDict[monomers[j]])));
81
+ }
82
+ }
83
+ molFiles.push(molFilesForSeq);
84
+ return molFiles;
85
+ }
86
+
64
87
  export function createMomomersMolDict(lib: any[]): { [key: string]: string | any } {
65
88
  const dict: { [key: string]: string | any } = {};
66
89
  lib.forEach((it) => {
@@ -0,0 +1,54 @@
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
+ import {getMolfilesFromSingleSeq, HELM_CORE_LIB_FILENAME} from '../utils/utils';
5
+ import {getMacroMol} from '../utils/atomic-works';
6
+
7
+ /**
8
+ * 3D representation widget of macromolecule.
9
+ *
10
+ * @export
11
+ * @param {DG.Cell} macroMolecule macromolecule cell.
12
+ * @return {Promise<DG.Widget>} Widget.
13
+ */
14
+ export async function representationsWidget(macroMolecule: DG.Cell, monomersLibObject: any[]): Promise<DG.Widget> {
15
+ const pi = DG.TaskBarProgressIndicator.create('Creating 3D view');
16
+
17
+ let widgetHost;
18
+ let molBlock3D = '';
19
+ try {
20
+ try {
21
+ const atomicCodes = getMolfilesFromSingleSeq(macroMolecule, monomersLibObject);
22
+ const result = await getMacroMol(atomicCodes!);
23
+ const molBlock2D = result[0];
24
+ molBlock3D = (await grok.functions.call('Bio:Embed', {molBlock2D})) as string;
25
+ } catch (e) {
26
+ console.warn(e);
27
+ }
28
+
29
+ try {
30
+ molBlock3D = molBlock3D.replaceAll('\\n', '\n');
31
+ const stringBlob = new Blob([molBlock3D], {type: 'text/plain'});
32
+ const nglHost = ui.div([], {classes: 'd4-ngl-viewer', id: 'ngl-3d-host'});
33
+
34
+ //@ts-ignore
35
+ const stage = new NGL.Stage(nglHost, {backgroundColor: 'white'});
36
+ //@ts-ignore
37
+ stage.loadFile(stringBlob, {ext: 'sdf'}).then(function(comp: NGL.StructureComponent) {
38
+ stage.setSize(300, 300);
39
+ comp.addRepresentation('ball+stick');
40
+ comp.autoView();
41
+ });
42
+ const sketch = grok.chem.svgMol(molBlock3D);
43
+ const panel = ui.divH([sketch]);
44
+
45
+ widgetHost = ui.div([panel, nglHost]);
46
+ } catch (e) {
47
+ widgetHost = ui.divText('Couldn\'t get peptide structure');
48
+ }
49
+ } catch (e) {
50
+ widgetHost = ui.divText('Couldn\'t get peptide structure');
51
+ }
52
+ pi.close();
53
+ return new DG.Widget(widgetHost);
54
+ }
@@ -1,4 +1,4 @@
1
- <html><head><meta charset="utf-8"/><title>Bio Test Report. Datagrok version datagrok/datagrok:latest SHA=34f75e5127b8. Commit 6fa72ec4.</title><style type="text/css">html,
1
+ <html><head><meta charset="utf-8"/><title>Bio Test Report. Datagrok version datagrok/datagrok:latest SHA=34f75e5127b8. Commit 781e9df9.</title><style type="text/css">html,
2
2
  body {
3
3
  font-family: Arial, Helvetica, sans-serif;
4
4
  font-size: 1rem;
@@ -229,7 +229,7 @@ header {
229
229
  font-size: 1rem;
230
230
  padding: 0 0.5rem;
231
231
  }
232
- </style></head><body><div id="jesthtml-content"><header><h1 id="title">Bio Test Report. Datagrok version datagrok/datagrok:latest SHA=34f75e5127b8. Commit 6fa72ec4.</h1></header><div id="metadata-container"><div id="timestamp">Started: 2022-07-22 13:03:45</div><div id="summary"><div id="suite-summary"><div class="summary-total">Suites (1)</div><div class="summary-passed summary-empty">0 passed</div><div class="summary-failed">1 failed</div><div class="summary-pending summary-empty">0 pending</div></div><div id="test-summary"><div class="summary-total">Tests (1)</div><div class="summary-passed summary-empty">0 passed</div><div class="summary-failed">1 failed</div><div class="summary-pending summary-empty">0 pending</div></div></div></div><div id="suite-1" class="suite-container"><div class="suite-info"><div class="suite-path">/home/runner/work/public/public/packages/Bio/src/__jest__/remote.test.ts</div><div class="suite-time warn">213.603s</div></div><div class="suite-tests"><div class="test-result failed"><div class="test-info"><div class="test-suitename"> </div><div class="test-title">TEST</div><div class="test-status">failed</div><div class="test-duration">199.146s</div></div><div class="failureMessages"> <pre class="failureMsg">Error: Test result : Bio.MSA.is_correct : TypeError: Cannot read properties of undefined (reading 'split')
232
+ </style></head><body><div id="jesthtml-content"><header><h1 id="title">Bio Test Report. Datagrok version datagrok/datagrok:latest SHA=34f75e5127b8. Commit 781e9df9.</h1></header><div id="metadata-container"><div id="timestamp">Started: 2022-07-27 13:06:16</div><div id="summary"><div id="suite-summary"><div class="summary-total">Suites (1)</div><div class="summary-passed summary-empty">0 passed</div><div class="summary-failed">1 failed</div><div class="summary-pending summary-empty">0 pending</div></div><div id="test-summary"><div class="summary-total">Tests (1)</div><div class="summary-passed summary-empty">0 passed</div><div class="summary-failed">1 failed</div><div class="summary-pending summary-empty">0 pending</div></div></div></div><div id="suite-1" class="suite-container"><div class="suite-info"><div class="suite-path">/home/runner/work/public/public/packages/Bio/src/__jest__/remote.test.ts</div><div class="suite-time warn">213.765s</div></div><div class="suite-tests"><div class="test-result failed"><div class="test-info"><div class="test-suitename"> </div><div class="test-title">TEST</div><div class="test-status">failed</div><div class="test-duration">199.116s</div></div><div class="failureMessages"> <pre class="failureMsg">Error: Test result : Bio.MSA.is_correct : TypeError: Cannot read properties of undefined (reading 'split')
233
233
  Test result : Bio.activityCliffs.activityCliffsOpen : Error: Expected "105 cliffs", got "2362 cliffs"
234
234
 
235
235
  at /home/runner/work/public/public/packages/Bio/src/__jest__/remote.test.ts:67:20