@datagrok/peptides 1.27.5 → 1.27.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
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@datagrok/peptides",
3
3
  "friendlyName": "Peptides",
4
- "version": "1.27.5",
4
+ "version": "1.27.7",
5
5
  "author": {
6
6
  "name": "Davit Rizhinashvili",
7
7
  "email": "drizhinashvili@datagrok.ai"
@@ -13,7 +13,7 @@
13
13
  "directory": "packages/Peptides"
14
14
  },
15
15
  "dependencies": {
16
- "@datagrok-libraries/bio": "^5.61.3",
16
+ "@datagrok-libraries/bio": "^5.63.2",
17
17
  "@datagrok-libraries/math": "^1.2.6",
18
18
  "@datagrok-libraries/ml": "^6.10.7",
19
19
  "@datagrok-libraries/statistics": "^1.2.12",
@@ -21,7 +21,7 @@
21
21
  "@datagrok-libraries/utils": "^4.6.9",
22
22
  "@webgpu/types": "^0.1.40",
23
23
  "cash-dom": "^8.1.5",
24
- "datagrok-api": "^1.25.0",
24
+ "datagrok-api": "^1.26.0",
25
25
  "file-loader": "^6.2.0",
26
26
  "rxjs": "^6.5.5",
27
27
  "uuid": "^10.0.0",
@@ -31,11 +31,11 @@
31
31
  "devDependencies": {
32
32
  "@datagrok-libraries/helm-web-editor": "^1.1.16",
33
33
  "@datagrok-libraries/js-draw-lite": "^0.0.5",
34
- "@datagrok/bio": "^2.24.0",
35
- "@datagrok/chem": "^1.13.0",
34
+ "@datagrok/bio": "^2.26.4",
35
+ "@datagrok/chem": "^1.17.1",
36
36
  "@datagrok/dendrogram": "^1.2.33",
37
37
  "@datagrok/eda": "^1.3.1",
38
- "@datagrok/helm": "^2.7.0",
38
+ "@datagrok/helm": "^2.13.0",
39
39
  "@types/uuid": "^10.0.0",
40
40
  "@types/wu": "^2.1.44",
41
41
  "@typescript-eslint/eslint-plugin": "^8.8.1",
package/src/package.g.ts CHANGED
@@ -14,8 +14,8 @@ export function Peptides() : any {
14
14
 
15
15
  //name: Bio Peptides
16
16
  //top-menu: Bio | Analyze | SAR...
17
- export function peptidesDialog() : any {
18
- return PackageFunctions.peptidesDialog();
17
+ export async function peptidesDialog() : Promise<any> {
18
+ return await PackageFunctions.peptidesDialog();
19
19
  }
20
20
 
21
21
  //input: viewer v
@@ -28,8 +28,8 @@ export async function testInitFunctionPeptides(v: any) : Promise<void> {
28
28
  //input: column col { semType: Macromolecule }
29
29
  //output: widget result
30
30
  //meta.role: widgets,panel
31
- export function peptidesPanel(col: DG.Column) : any {
32
- return PackageFunctions.peptidesPanel(col);
31
+ export async function peptidesPanel(col: DG.Column) : Promise<any> {
32
+ return await PackageFunctions.peptidesPanel(col);
33
33
  }
34
34
 
35
35
  //name: Sequence Variability Map
package/src/package.ts CHANGED
@@ -128,7 +128,7 @@ export class PackageFunctions {
128
128
  'name': 'Bio Peptides',
129
129
  'outputs': [],
130
130
  })
131
- static peptidesDialog(): DG.Dialog | null {
131
+ static async peptidesDialog(): Promise<DG.Dialog | null> {
132
132
  if (!grok.shell.t || !grok.shell.t.columns.bySemType('Macromolecule')?.length) {
133
133
  grok.shell.warning('SAR Analysis requires an active table with Macromolecule column');
134
134
  return null;
@@ -139,7 +139,7 @@ export class PackageFunctions {
139
139
  return null;
140
140
  }
141
141
 
142
- const analyzeObject = analyzePeptidesUI(grok.shell.t);
142
+ const analyzeObject = await analyzePeptidesUI(grok.shell.t);
143
143
  const dialog = ui.dialog('Analyze Peptides').add(analyzeObject.host).onOK(async () => {
144
144
  const startSuccess = analyzeObject.callback();
145
145
  if (!startSuccess)
@@ -163,11 +163,11 @@ export class PackageFunctions {
163
163
  meta: {role: 'widgets'},
164
164
  tags: ['widgets', 'panel'],
165
165
  })
166
- static peptidesPanel(
167
- @grok.decorators.param({'options': {'semType': 'Macromolecule'}}) col: DG.Column): DG.Widget {
166
+ static async peptidesPanel(
167
+ @grok.decorators.param({'options': {'semType': 'Macromolecule'}}) col: DG.Column): Promise<DG.Widget> {
168
168
  if (!col.dataFrame || !DG.Utils.firstOrNull(col.dataFrame.columns.numerical))
169
169
  return new DG.Widget(ui.divText('SAR Analysis requires an active table with at least one numerical column for activity'));
170
- const analyzeObject = analyzePeptidesUI(col.dataFrame, col);
170
+ const analyzeObject = await analyzePeptidesUI(col.dataFrame, col);
171
171
  return new DG.Widget(analyzeObject.host);
172
172
  }
173
173
 
@@ -42,6 +42,8 @@ import {getMonomerLibHelper} from '@datagrok-libraries/bio/src/types/monomer-lib
42
42
  import {PolymerTypes} from '@datagrok-libraries/bio/src/helm/consts';
43
43
  import {PeptideUtils} from '../peptideUtils';
44
44
  import {StringDictionary} from '@datagrok-libraries/utils/src/type-declarations';
45
+ import {SeqTemps} from '@datagrok-libraries/bio/src/utils/macromolecule/seq-handler';
46
+ import {getSeparator} from '../utils/misc';
45
47
 
46
48
  export enum SELECTION_MODE {
47
49
  MUTATION_CLIFFS = 'Mutation Cliffs',
@@ -543,6 +545,152 @@ export abstract class SARViewer extends DG.JsViewer implements ISARViewer {
543
545
  throw new Error('Not implemented');
544
546
  }
545
547
 
548
+ /** Shows a dialog to choose extra columns, then exports all unique mutation cliffs as a new table view. */
549
+ exportMutationCliffs(): void {
550
+ if (!this.mutationCliffs) {
551
+ grok.shell.warning('Mutation cliffs have not been calculated yet.');
552
+ return;
553
+ }
554
+
555
+ const available = this.dataFrame.columns.toList()
556
+ .filter((col) => col.name !== this.activityColumnName && col.name !== this.sequenceColumnName &&
557
+ !this.positionColumns.some((pc) => pc.name === col.name))
558
+ .map((col) => col.name);
559
+
560
+ const columnsInput = ui.input.columns('Extra columns', {table: this.dataFrame, value: [], available, nullable: true});
561
+
562
+ ui.dialog('Export Mutation Cliffs')
563
+ .add(columnsInput.root)
564
+ .onOK(() => this._doExportMutationCliffs(columnsInput.value ?? []))
565
+ .show();
566
+ }
567
+
568
+ private _doExportMutationCliffs(extraColumns: DG.Column[]): void {
569
+ const mc = this.mutationCliffs!;
570
+ const alignedSeqCol = this.dataFrame.getCol(this.sequenceColumnName);
571
+ const alignedSeqColCategories = alignedSeqCol.categories;
572
+ const alignedSeqColData = alignedSeqCol.getRawData();
573
+ const activityCol = this.dataFrame.getCol(this.activityColumnName);
574
+ const activityColData = activityCol.getRawData();
575
+
576
+ const seq1Array: string[] = [];
577
+ const seq2Array: string[] = [];
578
+ const diffArray: string[] = [];
579
+ const act1Array: (number | null)[] = [];
580
+ const act2Array: (number | null)[] = [];
581
+ const deltaArray: (number | null)[] = [];
582
+ const extraData1: any[][] = extraColumns.map(() => []);
583
+ const extraData2: any[][] = extraColumns.map(() => []);
584
+
585
+ const seenPairs = new Set<string>();
586
+
587
+ for (const [_monomer, posMap] of mc.entries()) {
588
+ for (const [_position, indexMap] of posMap.entries()) {
589
+ for (const [refIdx, subIndexes] of indexMap.entries()) {
590
+ for (const subIdx of subIndexes) {
591
+ const pairKey = refIdx < subIdx ? `${refIdx}-${subIdx}` : `${subIdx}-${refIdx}`;
592
+ if (seenPairs.has(pairKey))
593
+ continue;
594
+ seenPairs.add(pairKey);
595
+
596
+ const seq1 = alignedSeqColCategories[alignedSeqColData[refIdx]];
597
+ const seq2 = alignedSeqColCategories[alignedSeqColData[subIdx]];
598
+ seq1Array.push(seq1);
599
+ seq2Array.push(seq2);
600
+ diffArray.push(`${seq1}#${seq2}`);
601
+
602
+ const a1 = activityCol.isNone(refIdx) ? null : activityColData[refIdx];
603
+ const a2 = activityCol.isNone(subIdx) ? null : activityColData[subIdx];
604
+ act1Array.push(a1);
605
+ act2Array.push(a2);
606
+ deltaArray.push(a1 == null || a2 == null ? null : a1 - a2);
607
+
608
+ for (let e = 0; e < extraColumns.length; e++) {
609
+ const eCol = extraColumns[e];
610
+ extraData1[e].push(eCol.isNone(refIdx) ? null : eCol.get(refIdx));
611
+ extraData2[e].push(eCol.isNone(subIdx) ? null : eCol.get(subIdx));
612
+ }
613
+ }
614
+ }
615
+ }
616
+ }
617
+
618
+ if (seq1Array.length === 0) {
619
+ grok.shell.warning('No mutation cliffs found to export.');
620
+ return;
621
+ }
622
+
623
+ const seq1Col = DG.Column.fromStrings('Seq 1', seq1Array);
624
+ const seq2Col = DG.Column.fromStrings('Seq 2', seq2Array);
625
+ const diffCol = DG.Column.fromStrings('Mutation', diffArray);
626
+
627
+ // Copy sequence tags (without notation provider) so the platform detects the same semtype
628
+ for (const col of [seq1Col, seq2Col]) {
629
+ for (const tag of alignedSeqCol.tags.keys()) {
630
+ if (tag !== '.notationProvider')
631
+ col.setTag(tag, alignedSeqCol.getTag(tag)!);
632
+ }
633
+ col.semType = alignedSeqCol.semType;
634
+ }
635
+
636
+ // Set up macromolecule difference column
637
+ diffCol.semType = C.SEM_TYPES.MACROMOLECULE_DIFFERENCE;
638
+ diffCol.setTag(C.TAGS.SEPARATOR, getSeparator(alignedSeqCol));
639
+ diffCol.setTag(DG.TAGS.UNITS, alignedSeqCol.getTag(DG.TAGS.UNITS) ?? '');
640
+ diffCol.setTag(DG.TAGS.CELL_RENDERER, 'MacromoleculeDifference');
641
+ diffCol.temp[SeqTemps.notationProvider] = alignedSeqCol.temp[SeqTemps.notationProvider];
642
+
643
+ const act1Col = DG.Column.fromList(DG.COLUMN_TYPE.FLOAT, `Seq 1 ${this.activityColumnName}`, act1Array);
644
+ const act2Col = DG.Column.fromList(DG.COLUMN_TYPE.FLOAT, `Seq 2 ${this.activityColumnName}`, act2Array);
645
+ const deltaCol = DG.Column.fromList(DG.COLUMN_TYPE.FLOAT, 'Delta', deltaArray);
646
+
647
+ const columns: DG.Column[] = [seq1Col, seq2Col, diffCol, act1Col, act2Col, deltaCol];
648
+
649
+ // Add extra columns (two per extra column: one for seq1, one for seq2)
650
+ for (let e = 0; e < extraColumns.length; e++) {
651
+ const eName = extraColumns[e].name;
652
+ const eType = extraColumns[e].type;
653
+ columns.push(DG.Column.fromList(eType as DG.COLUMN_TYPE, `Seq 1 ${eName}`, extraData1[e]));
654
+ columns.push(DG.Column.fromList(eType as DG.COLUMN_TYPE, `Seq 2 ${eName}`, extraData2[e]));
655
+ }
656
+
657
+ const df = DG.DataFrame.fromColumns(columns);
658
+ df.name = 'Mutation Cliffs';
659
+ grok.shell.addTableView(df);
660
+ }
661
+
662
+ /** Exports the invariant map as a new table view: monomer × position counts. */
663
+ exportInvariantMap(): void {
664
+ const stats = this.monomerPositionStats;
665
+ const uniqueMonomers = new Set<string>();
666
+ const positionNames: string[] = [];
667
+ for (const pos of Object.keys(stats)) {
668
+ if (pos === 'general')
669
+ continue;
670
+ positionNames.push(pos);
671
+ const posStats = stats[pos]!;
672
+ for (const monomer of Object.keys(posStats)) {
673
+ if (monomer === 'general')
674
+ continue;
675
+ uniqueMonomers.add(monomer);
676
+ }
677
+ }
678
+
679
+ const monomersArray = Array.from(uniqueMonomers).sort();
680
+ const monomerCol = DG.Column.fromStrings(C.COLUMNS_NAMES.MONOMER, monomersArray);
681
+ const columns: DG.Column[] = [monomerCol];
682
+
683
+ for (const pos of positionNames) {
684
+ const posStats = stats[pos]!;
685
+ const counts = monomersArray.map((m) => posStats[m]?.count ?? 0);
686
+ columns.push(DG.Column.fromList(DG.COLUMN_TYPE.INT, pos, counts));
687
+ }
688
+
689
+ const df = DG.DataFrame.fromColumns(columns);
690
+ df.name = 'Invariant Map';
691
+ grok.shell.addTableView(df);
692
+ }
693
+
546
694
  /** Removes all the active subscriptions. */
547
695
  detach(): void {
548
696
  this.subs.forEach((sub) => sub.unsubscribe());
@@ -567,6 +715,9 @@ export abstract class SARViewer extends DG.JsViewer implements ISARViewer {
567
715
  if (!a || !a.causedBy || !a.args || !a.args.menu || !a.causedBy.target || !(a.causedBy.target instanceof HTMLElement) || !this.root.contains(a.causedBy.target))
568
716
  return;
569
717
  const menu = a.args.menu as DG.Menu;
718
+ const exportGroup = menu.group('Export');
719
+ exportGroup.item('Export Mutation Cliffs...', () => this.exportMutationCliffs());
720
+ exportGroup.item('Export Invariant Map', () => this.exportInvariantMap());
570
721
  getMonomerLibHelper().then((lh) => {
571
722
  const lib = lh.getMonomerLib();
572
723
  const mSymbols = lib.getMonomerSymbolsByType(PolymerTypes.PEPTIDE);
@@ -12,6 +12,7 @@ import {ALIGNMENT, NOTATION, TAGS as bioTAGS} from '@datagrok-libraries/bio/src/
12
12
  import {ILogoSummaryTable, LogoSummaryTable} from '../viewers/logo-summary';
13
13
  import {MmDistanceFunctionsNames} from '@datagrok-libraries/ml/src/macromolecule-distance-functions';
14
14
  import {MCL_INPUTS} from './settings';
15
+ import {createSequenceColumnInput, ISequenceColumnInput} from '@datagrok-libraries/bio/src/utils/sequence-column-input';
15
16
  //@ts-ignore
16
17
  import '../styles.css';
17
18
  export type DialogParameters = { host: HTMLElement, callback: () => Promise<boolean> };
@@ -22,10 +23,10 @@ export type DialogParameters = { host: HTMLElement, callback: () => Promise<bool
22
23
  * @param [col] - Peptides column
23
24
  * @return - UI host and analysis start callback
24
25
  */
25
- export function analyzePeptidesUI(df: DG.DataFrame, col?: DG.Column<string>): DialogParameters {
26
+ export async function analyzePeptidesUI(df: DG.DataFrame, col?: DG.Column<string>): Promise<DialogParameters> {
26
27
  const mclOptions = new type.MCLSettings();
27
28
  const logoHost = ui.div();
28
- let seqColInput: DG.InputBase | null = null;
29
+ let sequenceColInput: ISequenceColumnInput | null = null;
29
30
  if (typeof col === 'undefined') {
30
31
  // Building UI for starting analysis from dialog (top menu)
31
32
  const potentialCol = DG.Utils.firstOrNull(
@@ -36,7 +37,7 @@ export function analyzePeptidesUI(df: DG.DataFrame, col?: DG.Column<string>): Di
36
37
  grok.shell.info('Sequences column contains missing values. They will be ignored during analysis');
37
38
 
38
39
 
39
- seqColInput = ui.input.column('Sequence', {table: df, value: potentialCol, onValueChanged: (value) => {
40
+ sequenceColInput = await createSequenceColumnInput('Sequence', {table: df, value: potentialCol, onValueChanged: (value) => {
40
41
  $(logoHost).empty().append(ui.wait(async () => {
41
42
  const viewer = await df.plot.fromType('WebLogo', {sequenceColumnName: value.name});
42
43
  viewer.root.style.setProperty('height', '130px');
@@ -45,7 +46,7 @@ export function analyzePeptidesUI(df: DG.DataFrame, col?: DG.Column<string>): Di
45
46
  if (value.stats.missingValueCount !== 0)
46
47
  grok.shell.info('Sequences column contains missing values. They will be ignored during analysis');
47
48
  }, filter: (col: DG.Column) => col.semType === DG.SEMTYPE.MACROMOLECULE, nullable: false});
48
- seqColInput.setTooltip('Macromolecule column in FASTA, HELM or separated format');
49
+ sequenceColInput.inputBase.setTooltip('Macromolecule column in FASTA, HELM or separated format');
49
50
  }
50
51
 
51
52
  let funcs = DG.Func.find({package: 'Bio', name: 'webLogoViewer'});
@@ -117,8 +118,8 @@ export function analyzePeptidesUI(df: DG.DataFrame, col?: DG.Column<string>): Di
117
118
 
118
119
 
119
120
  const inputsList = [activityColumnChoice, activityScalingMethod, clustersColumnChoice, generateClustersInput];
120
- if (seqColInput !== null)
121
- inputsList.splice(0, 0, seqColInput);
121
+ if (sequenceColInput !== null)
122
+ inputsList.splice(0, 0, sequenceColInput.inputBase);
122
123
 
123
124
  // ### MCL INPUTS ###
124
125
  const similarityThresholdInput = ui.input.float(MCL_INPUTS.THRESHOLD, {
@@ -188,7 +189,7 @@ export function analyzePeptidesUI(df: DG.DataFrame, col?: DG.Column<string>): Di
188
189
  const bitsetChanged = df.filter.onChanged.subscribe(() => activityScalingMethodState());
189
190
 
190
191
  const startAnalysisCallback = async (): Promise<boolean> => {
191
- const sequencesCol = col ?? seqColInput!.value;
192
+ const sequencesCol = col ?? sequenceColInput!.value;
192
193
  bitsetChanged.unsubscribe();
193
194
  if (sequencesCol) {
194
195
  const model = await startAnalysis(activityColumnChoice.value!, sequencesCol, clustersColumnChoice.value, df,
@@ -210,7 +211,7 @@ export function analyzePeptidesUI(df: DG.DataFrame, col?: DG.Column<string>): Di
210
211
  }
211
212
 
212
213
  $(logoHost).empty().append(ui.wait(async () => {
213
- const viewer = await df.plot.fromType('WebLogo', {sequenceColumnName: col?.name ?? seqColInput!.value!.name});
214
+ const viewer = await df.plot.fromType('WebLogo', {sequenceColumnName: col?.name ?? sequenceColInput!.value!.name});
214
215
  viewer.root.style.setProperty('height', '130px');
215
216
  return viewer.root;
216
217
  }));
@@ -218,9 +219,9 @@ export function analyzePeptidesUI(df: DG.DataFrame, col?: DG.Column<string>): Di
218
219
  const mainHost = ui.divV([
219
220
  logoHost,
220
221
  ui.splitH([
221
- ui.splitV(inputElements),
222
+ ui.splitV(inputElements, {style: {flex: '0 1 auto'}}),
222
223
  histogramHost,
223
- ], {style: {height: bottomHeight, minWidth: '500px', maxWidth: '600px'}}),
224
+ ], {style: {height: bottomHeight, minWidth: '600px', maxWidth: '750px'}}),
224
225
  mclInputsHost,
225
226
  ]);
226
227
  return {host: mainHost, callback: startAnalysisCallback};