@datagrok/bio 2.4.47 → 2.4.48

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": "Leonid Stolbov",
6
6
  "email": "lstolbov@datagrok.ai"
7
7
  },
8
- "version": "2.4.47",
8
+ "version": "2.4.48",
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.ts CHANGED
@@ -57,6 +57,7 @@ import {BioPackage, BioPackageProperties} from './package-types';
57
57
  import {RDModule} from '@datagrok-libraries/chem-meta/src/rdkit-api';
58
58
  import {ObjectPropertyBag} from 'datagrok-api/dg';
59
59
  import {PackageSettingsEditorWidget} from './widgets/package-settings-editor-widget';
60
+ import {getCompositionAnalysisWidget} from './widgets/composition-analysis-widget';
60
61
 
61
62
  export const _package = new BioPackage();
62
63
 
@@ -218,6 +219,14 @@ export function macroMolColumnPropertyPanel(molColumn: DG.Column): DG.Widget {
218
219
  return getMacromoleculeColumnPropertyPanel(molColumn);
219
220
  }
220
221
 
222
+ //name: Composition analysis
223
+ //tags: panel, bio, widgets
224
+ //input: semantic_value sequence { semType: Macromolecule }
225
+ //output: widget result
226
+ export function compositionAnalysisWidget(sequence: DG.SemanticValue): DG.Widget {
227
+ return getCompositionAnalysisWidget(sequence);
228
+ }
229
+
221
230
  //name: separatorSequenceCellRenderer
222
231
  //tags: cellRenderer
223
232
  //meta.cellType: sequence
@@ -0,0 +1,62 @@
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 {TAGS as bioTAGS, ALPHABET, getPaletteByType} from '@datagrok-libraries/bio/src/utils/macromolecule';
5
+ import {SeqPalette} from '@datagrok-libraries/bio/src/seq-palettes';
6
+ import {UnknownSeqPalettes} from '@datagrok-libraries/bio/src/unknown';
7
+ import '../../css/composition-analysis.css';
8
+ import {UnitsHandler} from '@datagrok-libraries/bio/src/utils/units-handler';
9
+
10
+ export function getCompositionAnalysisWidget(val: DG.SemanticValue) {
11
+ const host = ui.div();
12
+ host.classList.add('macromolecule-cell-comp-analysis-host');
13
+ const alphabet = val.cell.column.tags[bioTAGS.alphabet];
14
+ let palette: SeqPalette = UnknownSeqPalettes.Color;
15
+ switch (alphabet) {
16
+ case ALPHABET.DNA:
17
+ case ALPHABET.RNA:
18
+ palette = getPaletteByType(ALPHABET.DNA);
19
+ break;
20
+ case ALPHABET.PT:
21
+ palette = getPaletteByType(ALPHABET.PT);
22
+ break;
23
+ default:
24
+ break;
25
+ }
26
+
27
+ const counts = new Map<string, number>();
28
+ let max = 0;
29
+ const uh = UnitsHandler.getOrCreate(val.cell.column);
30
+ const splitter = uh.getSplitter();
31
+ const parts = splitter(val.value);
32
+ const len = parts.length;
33
+ parts.filter((p) => p && p !== '').forEach((c: string) => {
34
+ const count = counts.get(c) || 0;
35
+ counts.set(c, count + 1);
36
+ max = Math.max(max, count + 1);
37
+ });
38
+ max /= len;// percentage
39
+ // calculate frequencies
40
+ const compositionMap: {[key: string]: HTMLElement} = {};
41
+ const valueArray = Array.from(counts.entries());
42
+ valueArray.sort((a, b) => b[1] - a[1]);
43
+ valueArray.forEach(([key, value]) => {
44
+ const ratio = value / len;
45
+ const color = palette.get(key);
46
+ const barDiv = ui.div('', {classes: 'macromolecule-cell-comp-analysis-bar'});
47
+ barDiv.style.width = `${ratio / max * 50}px`;
48
+ const valueDiv = ui.div((ratio * 100).toFixed(2) + '%');
49
+ barDiv.style.backgroundColor = color;
50
+ compositionMap[key] = ui.div([barDiv, valueDiv], {classes: 'macromolecule-cell-comp-analysis-value'});
51
+ });
52
+
53
+ const table = ui.tableFromMap(compositionMap);
54
+ Array.from(table.rows).forEach((row) => {
55
+ const barCol = (row.getElementsByClassName('macromolecule-cell-comp-analysis-bar')[0] as HTMLDivElement)
56
+ .style.backgroundColor;
57
+ row.cells[0].style.color = barCol;
58
+ });
59
+
60
+ host.appendChild(table);
61
+ return new DG.Widget(host);
62
+ }