@datagrok/bio 1.7.9 → 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.
@@ -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,28 +26,30 @@ 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);
32
33
 
33
34
  // hide the separator input for non-SEPARATOR target notations
34
- if (targetNotationInput.value !== NOTATION.SEPARATOR)
35
- $(separatorInput.root).hide();
36
- else
37
- $(separatorInput.root).show();
38
-
39
- targetNotationInput.onChanged(async () => {
35
+ const toggleSeparator = () => {
40
36
  if (targetNotationInput.value !== NOTATION.SEPARATOR)
41
37
  $(separatorInput.root).hide();
42
38
  else
43
39
  $(separatorInput.root).show();
40
+ };
41
+
42
+ // set correct visibility on init
43
+ toggleSeparator();
44
+
45
+ targetNotationInput.onChanged( () => {
46
+ toggleSeparator();
44
47
  });
45
48
 
46
49
  if (convertDialog == null) {
47
50
  convertDialog = ui.dialog('Convert sequence notation')
48
51
  .add(ui.div([
49
- ui.h1('Current notation: ' + current),
52
+ ui.h1('Current notation: ' + currentNotation),
50
53
  targetNotationInput.root,
51
54
  separatorInput.root
52
55
  ]))
@@ -2,7 +2,7 @@ import * as DG from 'datagrok-api/dg';
2
2
  import {WebLogo, SplitterFunc} from '@datagrok-libraries/bio/src/viewers/web-logo';
3
3
  import * as grok from 'datagrok-api/grok';
4
4
  import {
5
- CAP_GROUP_NAME, CAP_GROUP_SMILES, jsonSdfMonomerLibDict, MONOMER_SYMBOL,
5
+ CAP_GROUP_NAME, CAP_GROUP_SMILES, jsonSdfMonomerLibDict, MONOMER_ENCODE_MAX, MONOMER_ENCODE_MIN, MONOMER_SYMBOL,
6
6
  RGROUP_ALTER_ID, RGROUP_FIELD, RGROUP_LABEL, SDF_MONOMER_NAME
7
7
  } from '../const';
8
8
 
@@ -11,6 +11,33 @@ export const HELM_CORE_LIB_MONOMER_SYMBOL = 'symbol';
11
11
  export const HELM_CORE_LIB_MOLFILE = 'molfile';
12
12
  export const HELM_CORE_FIELDS = ['symbol', 'molfile', 'rgroups', 'name'];
13
13
 
14
+
15
+ export function encodeMonomers(col: DG.Column): DG.Column | null {
16
+ let encodeSymbol = MONOMER_ENCODE_MIN;
17
+ const monomerSymbolDict: { [key: string]: number }= {};
18
+ const units = col.tags[DG.TAGS.UNITS];
19
+ const sep = col.getTag('separator');
20
+ const splitterFunc: SplitterFunc = WebLogo.getSplitter(units, sep);
21
+ const encodedStringArray = [];
22
+ for (let i = 0; i < col.length; ++i) {
23
+ let encodedMonomerStr = '';
24
+ const monomers = splitterFunc(col.get(i));
25
+ monomers.forEach(m => {
26
+ if(!monomerSymbolDict[m]) {
27
+ if(encodeSymbol > MONOMER_ENCODE_MAX) {
28
+ grok.shell.error(`Not enougth symbols to encode monomers`);
29
+ return null;
30
+ }
31
+ monomerSymbolDict[m] = encodeSymbol;
32
+ encodeSymbol++;
33
+ }
34
+ encodedMonomerStr += String.fromCodePoint(monomerSymbolDict[m]);
35
+ })
36
+ encodedStringArray.push(encodedMonomerStr);
37
+ }
38
+ return DG.Column.fromStrings('encodedMolecules', encodedStringArray);
39
+ }
40
+
14
41
  export function getMolfilesFromSeq(col: DG.Column, monomersLibObject: any[]): any[][] | null {
15
42
  const units = col.tags[DG.TAGS.UNITS];
16
43
  const sep = col.getTag('separator');
@@ -18,7 +45,8 @@ export function getMolfilesFromSeq(col: DG.Column, monomersLibObject: any[]): an
18
45
  const monomersDict = createMomomersMolDict(monomersLibObject);
19
46
  const molFiles = [];
20
47
  for (let i = 0; i < col.length; ++i) {
21
- const monomers = splitterFunc(col.get(i));
48
+ const macroMolecule = col.get(i);
49
+ const monomers = splitterFunc(macroMolecule);
22
50
  const molFilesForSeq = [];
23
51
  for (let j = 0; j < monomers.length; ++j) {
24
52
  if (monomers[j]) {
@@ -34,6 +62,28 @@ export function getMolfilesFromSeq(col: DG.Column, monomersLibObject: any[]): an
34
62
  return molFiles;
35
63
  }
36
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
+
37
87
  export function createMomomersMolDict(lib: any[]): { [key: string]: string | any } {
38
88
  const dict: { [key: string]: string | any } = {};
39
89
  lib.forEach((it) => {
@@ -79,4 +129,4 @@ export function createJsonMonomerLibFromSdf(table: DG.DataFrame): any {
79
129
  resultLib.push(monomer);
80
130
  }
81
131
  return resultLib;
82
- }
132
+ }
@@ -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 0a8a5821.</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,10 +229,8 @@ 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 0a8a5821.</h1></header><div id="metadata-container"><div id="timestamp">Started: 2022-07-19 13:18:04</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">189.946s</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">177.683s</div></div><div class="failureMessages"> <pre class="failureMsg">Error: Test result : Bio.MSA.is_correct : TypeError: Cannot read properties of undefined (reading 'split')
233
- Test result : Bio.splitters.testHelm1 : Error: Expected R(U)P at position 0, got U
234
- Test result : Bio.splitters.testHelm2 : Error: Expected R(U)P at position 1, got U
235
- Test result : Bio.splitters.testHelm3 : Error: Expected R(U) at position 1, got U)
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
+ Test result : Bio.activityCliffs.activityCliffsOpen : Error: Expected "105 cliffs", got "2362 cliffs"
236
234
 
237
235
  at /home/runner/work/public/public/packages/Bio/src/__jest__/remote.test.ts:67:20
238
236
  at Generator.next (&lt;anonymous&gt;)
@@ -306,12 +304,19 @@ Test result : Bio.detectors.samplesTestSmiles2NegativeSmiles : OK
306
304
  Test result : Bio.detectors.samplesTestActivityCliffsNegativeSmiles : OK
307
305
  Test result : Bio.detectors.samplesFastaPtPosSequence : OK
308
306
  Test result : Bio.detectors.samplesTestCerealNegativeCerealName : OK
307
+ Test result : Bio.detectors.samplesTestSpgi100NegativeStereoCategory : OK
308
+ Test result : Bio.detectors.samplesTestSpgi100NegativeScaffoldNames : OK
309
+ Test result : Bio.detectors.samplesTestSpgi100NegativePrimaryScaffoldName : OK
310
+ Test result : Bio.detectors.samplesTestUnichemSourcesNegativeSrcUrl : OK
311
+ Test result : Bio.detectors.samplesTestUnichemSourcesNegativeBaseIdUrl : OK
309
312
  Test result : Bio.MSA.test_table.is_not_empty : OK
310
313
  Test result : Bio.sequenceSpace.sequenceSpaceOpens : OK
311
- Test result : Bio.activityCliffs.activityCliffsOpen : OK
312
314
  Test result : Bio.splitters.helm1 : OK
313
315
  Test result : Bio.splitters.helm2 : OK
314
316
  Test result : Bio.splitters.helm3-multichar : OK
317
+ Test result : Bio.splitters.testHelm1 : OK
318
+ Test result : Bio.splitters.testHelm2 : OK
319
+ Test result : Bio.splitters.testHelm3 : OK
315
320
  Test result : Bio.renderers.afterMsa : OK
316
321
  Test result : Bio.renderers.afterConvert : OK
317
322
  Test result : Bio.converters.testFastaPtToSeparator : OK
@@ -330,10 +335,13 @@ Test result : Bio.converters.testSeparatorPtToHelm : OK
330
335
  Test result : Bio.converters.testSeparatorDnaToHelm : OK
331
336
  Test result : Bio.converters.testSeparatorRnaToHelm : OK
332
337
  Test result : Bio.converters.testSeparatorGapsToHelm : OK
333
- Test result : Bio.converters.HelmDnaToFasta : OK
334
- Test result : Bio.converters.HelmRnaToFasta : OK
335
- Test result : Bio.converters.HelmPtToFasta : OK
336
- Test result : Bio.converters.HelmDnaToSeparator : OK
337
- Test result : Bio.converters.HelmRnaToSeparator : OK
338
- Test result : Bio.converters.HelmPtToSeparator : OK
338
+ Test result : Bio.converters.testHelmDnaToFasta : OK
339
+ Test result : Bio.converters.testHelmRnaToFasta : OK
340
+ Test result : Bio.converters.testHelmPtToFasta : OK
341
+ Test result : Bio.converters.testHelmDnaToSeparator : OK
342
+ Test result : Bio.converters.testHelmRnaToSeparator : OK
343
+ Test result : Bio.converters.testHelmPtToSeparator : OK
344
+ Test result : Bio.converters.testHelmLoneRibose : OK
345
+ Test result : Bio.converters.testHelmLoneDeoxyribose : OK
346
+ Test result : Bio.converters.testHelmLonePhosphorus : OK
339
347
  </pre></div></div></div></div></body></html>