@datagrok/peptides 1.13.2 → 1.13.3

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.13.2",
4
+ "version": "1.13.3",
5
5
  "author": {
6
6
  "name": "Volodymyr Dyma",
7
7
  "email": "vdyma@datagrok.ai"
package/src/model.ts CHANGED
@@ -535,13 +535,27 @@ export class PeptidesModel {
535
535
  sourceGrid.columns.setOrder([scaledCol.name]);
536
536
  }
537
537
 
538
- calculateMonomerPositionStatistics(): MonomerPositionStats {
539
- const positionColumns = this.splitSeqDf.columns.toList();
540
- const sourceDfLen = this.df.rowCount;
538
+ calculateMonomerPositionStatistics(options: {isFiltered?: boolean, columns?: string[]} = {}): MonomerPositionStats {
539
+ options.isFiltered ??= false;
541
540
  const monomerPositionObject = {general: {}} as MonomerPositionStats & { general: SummaryStats };
542
- const activityColData = this.df.getCol(C.COLUMNS_NAMES.ACTIVITY_SCALED).getRawData();
541
+ let activityColData: Float64Array = this.df.getCol(C.COLUMNS_NAMES.ACTIVITY_SCALED).getRawData() as Float64Array;
542
+ let positionColumns = this.splitSeqDf.columns.toList();
543
+ let sourceDfLen = this.df.rowCount;
544
+
545
+ if (options.isFiltered) {
546
+ sourceDfLen = this.df.filter.trueCount;
547
+ const tempActivityData = new Float64Array(sourceDfLen);
548
+ const selectedIndexes = this.df.filter.getSelectedIndexes();
549
+ for (let i = 0; i < sourceDfLen; ++i)
550
+ tempActivityData[i] = activityColData[selectedIndexes[i]];
551
+ activityColData = tempActivityData;
552
+ positionColumns = this.splitSeqDf.clone(this.df.filter).columns.toList();
553
+ }
554
+ options.columns ??= positionColumns.map((col) => col.name);
543
555
 
544
556
  for (const posCol of positionColumns) {
557
+ if (!options.columns.includes(posCol.name))
558
+ continue;
545
559
  const posColData = posCol.getRawData();
546
560
  const posColCateogries = posCol.categories;
547
561
  const currentPositionObject = {general: {}} as PositionStats & {general: SummaryStats};
@@ -740,10 +754,8 @@ export class PeptidesModel {
740
754
  const bar = `${monomerPosition.positionOrClusterType} = ${monomerPosition.monomerOrCluster}`;
741
755
  if (this.cachedWebLogoTooltip.bar === bar)
742
756
  ui.tooltip.show(this.cachedWebLogoTooltip.tooltip!, ev.clientX, ev.clientY);
743
- else {
744
- this.cachedWebLogoTooltip = {bar: bar,
745
- tooltip: this.showTooltipAt(monomerPosition, ev.clientX, ev.clientY)};
746
- }
757
+ else
758
+ this.cachedWebLogoTooltip = {bar: bar, tooltip: this.showTooltipAt(monomerPosition, ev.clientX, ev.clientY)};
747
759
  }
748
760
  }
749
761
 
@@ -763,20 +775,22 @@ export class PeptidesModel {
763
775
 
764
776
  //TODO: optimize
765
777
  if (gcArgs.cell.isColHeader && col?.semType === C.SEM_TYPES.MONOMER) {
766
- const stats = this.monomerPositionStats[col.name];
778
+ const isDfFiltered = this.df.filter.anyFalse;
779
+ const stats = (isDfFiltered ? this.calculateMonomerPositionStatistics({isFiltered: true, columns: [col.name]}) :
780
+ this.monomerPositionStats)[col.name];
767
781
  if (!stats)
768
782
  return;
769
783
  //TODO: precalc on stats creation
770
784
  const sortedStatsOrder = Object.keys(stats).sort((a, b) => {
771
785
  if (a === '' || a === '-')
772
- return -1;
773
- else if (b === '' || b === '-')
774
786
  return +1;
787
+ else if (b === '' || b === '-')
788
+ return -1;
775
789
  return 0;
776
790
  }).filter((v) => v !== 'general');
777
791
 
778
792
  this.webLogoBounds[col.name] = CR.drawLogoInBounds(ctx, bounds, stats, col.name, sortedStatsOrder,
779
- this.df.rowCount, this.cp, this.headerSelectedMonomers[col.name]);
793
+ this.df.filter.trueCount, this.cp, this.headerSelectedMonomers[col.name]);
780
794
  gcArgs.preventDefault();
781
795
  }
782
796
  } catch (e) {
package/src/utils/misc.ts CHANGED
@@ -44,7 +44,8 @@ export function scaleActivity(activityCol: DG.Column<number>, scaling: C.SCALING
44
44
  export function calculateSelected(df: DG.DataFrame): type.SelectionStats {
45
45
  const monomerColumns: DG.Column<string>[] = df.columns.bySemTypeAll(C.SEM_TYPES.MONOMER);
46
46
  const selectedObj: type.SelectionStats = {};
47
- for (const idx of df.selection.getSelectedIndexes()) {
47
+ const selectedIndexes = df.filter.clone().and(df.selection).getSelectedIndexes();
48
+ for (const idx of selectedIndexes) {
48
49
  for (const col of monomerColumns) {
49
50
  const monomer = col.get(idx);
50
51
  if (!monomer)
@@ -165,9 +165,9 @@ export function getDistributionWidget(table: DG.DataFrame, model: PeptidesModel)
165
165
  const hist = getActivityDistribution(prepareTableForHistogram(distributionTable));
166
166
  const bitArray = BitArray.fromString(table.selection.toBinaryString());
167
167
  const mask = DG.BitSet.create(rowCount,
168
- bitArray.allFalse ? (_): boolean => true : (i): boolean => bitArray.getBit(i));
168
+ bitArray.allFalse || bitArray.allTrue ? (_): boolean => true : (i): boolean => bitArray.getBit(i));
169
169
  const aggregatedColMap = model.getAggregatedColumnValues({filterDf: true, mask});
170
- const stats = bitArray.allFalse ? {count: rowCount, pValue: null, meanDifference: 0, ratio: 1, mask: bitArray} :
170
+ const stats = bitArray.allFalse || bitArray.allTrue ? {count: rowCount, pValue: null, meanDifference: 0, ratio: 1, mask: bitArray} :
171
171
  getStats(activityColData, bitArray);
172
172
  const tableMap = getStatsTableMap(stats);
173
173
  const resultMap: {[key: string]: any} = {...tableMap, ...aggregatedColMap};