@vitessce/sets-utils 3.4.6 → 3.4.8

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/dist/index.js CHANGED
@@ -14,7 +14,7 @@ for (let i = 0; i < 256; ++i) {
14
14
  byteToHex.push((i + 256).toString(16).slice(1));
15
15
  }
16
16
  function unsafeStringify(arr, offset = 0) {
17
- return (byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + "-" + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + "-" + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + "-" + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + "-" + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]]).toLowerCase();
17
+ return byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + "-" + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + "-" + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + "-" + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + "-" + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]];
18
18
  }
19
19
  const randomUUID = typeof crypto !== "undefined" && crypto.randomUUID && crypto.randomUUID.bind(crypto);
20
20
  const native = {
@@ -2475,6 +2475,20 @@ const PALETTE = [
2475
2475
  [136, 34, 85],
2476
2476
  [170, 68, 153]
2477
2477
  ];
2478
+ function getValueTransformFunction(featureValueTransform, coefficient) {
2479
+ let transformFunction;
2480
+ switch (featureValueTransform) {
2481
+ case "log1p":
2482
+ transformFunction = (v) => Math.log(1 + v * coefficient);
2483
+ break;
2484
+ case "arcsinh":
2485
+ transformFunction = (v) => Math.asinh(v * coefficient);
2486
+ break;
2487
+ default:
2488
+ transformFunction = (v) => v;
2489
+ }
2490
+ return transformFunction;
2491
+ }
2478
2492
  var util;
2479
2493
  (function(util2) {
2480
2494
  util2.assertEqual = (val) => val;
@@ -2900,7 +2914,7 @@ class ParseStatus {
2900
2914
  status.dirty();
2901
2915
  if (value.status === "dirty")
2902
2916
  status.dirty();
2903
- if (typeof value.value !== "undefined" || pair.alwaysSet) {
2917
+ if (key.value !== "__proto__" && (typeof value.value !== "undefined" || pair.alwaysSet)) {
2904
2918
  finalObject[key.value] = value.value;
2905
2919
  }
2906
2920
  }
@@ -3003,6 +3017,7 @@ class ZodType {
3003
3017
  this.catch = this.catch.bind(this);
3004
3018
  this.describe = this.describe.bind(this);
3005
3019
  this.pipe = this.pipe.bind(this);
3020
+ this.readonly = this.readonly.bind(this);
3006
3021
  this.isNullable = this.isNullable.bind(this);
3007
3022
  this.isOptional = this.isOptional.bind(this);
3008
3023
  }
@@ -3210,6 +3225,9 @@ class ZodType {
3210
3225
  pipe(target) {
3211
3226
  return ZodPipeline.create(this, target);
3212
3227
  }
3228
+ readonly() {
3229
+ return ZodReadonly.create(this);
3230
+ }
3213
3231
  isOptional() {
3214
3232
  return this.safeParse(void 0).success;
3215
3233
  }
@@ -3219,10 +3237,11 @@ class ZodType {
3219
3237
  }
3220
3238
  const cuidRegex = /^c[^\s-]{8,}$/i;
3221
3239
  const cuid2Regex = /^[a-z][a-z0-9]*$/;
3222
- const ulidRegex = /[0-9A-HJKMNP-TV-Z]{26}/;
3223
- const uuidRegex = /^([a-f0-9]{8}-[a-f0-9]{4}-[1-5][a-f0-9]{3}-[a-f0-9]{4}-[a-f0-9]{12}|00000000-0000-0000-0000-000000000000)$/i;
3224
- const emailRegex = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\])|(\[IPv6:(([a-f0-9]{1,4}:){7}|::([a-f0-9]{1,4}:){0,6}|([a-f0-9]{1,4}:){1}:([a-f0-9]{1,4}:){0,5}|([a-f0-9]{1,4}:){2}:([a-f0-9]{1,4}:){0,4}|([a-f0-9]{1,4}:){3}:([a-f0-9]{1,4}:){0,3}|([a-f0-9]{1,4}:){4}:([a-f0-9]{1,4}:){0,2}|([a-f0-9]{1,4}:){5}:([a-f0-9]{1,4}:){0,1})([a-f0-9]{1,4}|(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2})))\])|([A-Za-z0-9]([A-Za-z0-9-]*[A-Za-z0-9])*(\.[A-Za-z]{2,})+))$/;
3225
- const emojiRegex = /^(\p{Extended_Pictographic}|\p{Emoji_Component})+$/u;
3240
+ const ulidRegex = /^[0-9A-HJKMNP-TV-Z]{26}$/;
3241
+ const uuidRegex = /^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/i;
3242
+ const emailRegex = /^(?!\.)(?!.*\.\.)([A-Z0-9_+-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i;
3243
+ const _emojiRegex = `^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`;
3244
+ let emojiRegex;
3226
3245
  const ipv4Regex = /^(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))$/;
3227
3246
  const ipv6Regex = /^(([a-f0-9]{1,4}:){7}|::([a-f0-9]{1,4}:){0,6}|([a-f0-9]{1,4}:){1}:([a-f0-9]{1,4}:){0,5}|([a-f0-9]{1,4}:){2}:([a-f0-9]{1,4}:){0,4}|([a-f0-9]{1,4}:){3}:([a-f0-9]{1,4}:){0,3}|([a-f0-9]{1,4}:){4}:([a-f0-9]{1,4}:){0,2}|([a-f0-9]{1,4}:){5}:([a-f0-9]{1,4}:){0,1})([a-f0-9]{1,4}|(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2})))$/;
3228
3247
  const datetimeRegex = (args) => {
@@ -3256,27 +3275,6 @@ function isValidIP(ip, version) {
3256
3275
  return false;
3257
3276
  }
3258
3277
  class ZodString extends ZodType {
3259
- constructor() {
3260
- super(...arguments);
3261
- this._regex = (regex, validation, message) => this.refinement((data) => regex.test(data), {
3262
- validation,
3263
- code: ZodIssueCode.invalid_string,
3264
- ...errorUtil.errToObj(message)
3265
- });
3266
- this.nonempty = (message) => this.min(1, errorUtil.errToObj(message));
3267
- this.trim = () => new ZodString({
3268
- ...this._def,
3269
- checks: [...this._def.checks, { kind: "trim" }]
3270
- });
3271
- this.toLowerCase = () => new ZodString({
3272
- ...this._def,
3273
- checks: [...this._def.checks, { kind: "toLowerCase" }]
3274
- });
3275
- this.toUpperCase = () => new ZodString({
3276
- ...this._def,
3277
- checks: [...this._def.checks, { kind: "toUpperCase" }]
3278
- });
3279
- }
3280
3278
  _parse(input) {
3281
3279
  if (this._def.coerce) {
3282
3280
  input.data = String(input.data);
@@ -3361,6 +3359,9 @@ class ZodString extends ZodType {
3361
3359
  status.dirty();
3362
3360
  }
3363
3361
  } else if (check.kind === "emoji") {
3362
+ if (!emojiRegex) {
3363
+ emojiRegex = new RegExp(_emojiRegex, "u");
3364
+ }
3364
3365
  if (!emojiRegex.test(input.data)) {
3365
3366
  ctx = this._getOrReturnCtx(input, ctx);
3366
3367
  addIssueToContext(ctx, {
@@ -3497,6 +3498,13 @@ class ZodString extends ZodType {
3497
3498
  }
3498
3499
  return { status: status.value, value: input.data };
3499
3500
  }
3501
+ _regex(regex, validation, message) {
3502
+ return this.refinement((data) => regex.test(data), {
3503
+ validation,
3504
+ code: ZodIssueCode.invalid_string,
3505
+ ...errorUtil.errToObj(message)
3506
+ });
3507
+ }
3500
3508
  _addCheck(check) {
3501
3509
  return new ZodString({
3502
3510
  ...this._def,
@@ -3594,6 +3602,31 @@ class ZodString extends ZodType {
3594
3602
  ...errorUtil.errToObj(message)
3595
3603
  });
3596
3604
  }
3605
+ /**
3606
+ * @deprecated Use z.string().min(1) instead.
3607
+ * @see {@link ZodString.min}
3608
+ */
3609
+ nonempty(message) {
3610
+ return this.min(1, errorUtil.errToObj(message));
3611
+ }
3612
+ trim() {
3613
+ return new ZodString({
3614
+ ...this._def,
3615
+ checks: [...this._def.checks, { kind: "trim" }]
3616
+ });
3617
+ }
3618
+ toLowerCase() {
3619
+ return new ZodString({
3620
+ ...this._def,
3621
+ checks: [...this._def.checks, { kind: "toLowerCase" }]
3622
+ });
3623
+ }
3624
+ toUpperCase() {
3625
+ return new ZodString({
3626
+ ...this._def,
3627
+ checks: [...this._def.checks, { kind: "toUpperCase" }]
3628
+ });
3629
+ }
3597
3630
  get isDatetime() {
3598
3631
  return !!this._def.checks.find((ch) => ch.kind === "datetime");
3599
3632
  }
@@ -5185,6 +5218,12 @@ class ZodRecord extends ZodType {
5185
5218
  }
5186
5219
  }
5187
5220
  class ZodMap extends ZodType {
5221
+ get keySchema() {
5222
+ return this._def.keyType;
5223
+ }
5224
+ get valueSchema() {
5225
+ return this._def.valueType;
5226
+ }
5188
5227
  _parse(input) {
5189
5228
  const { status, ctx } = this._processInputParams(input);
5190
5229
  if (ctx.parsedType !== ZodParsedType.map) {
@@ -5379,27 +5418,29 @@ class ZodFunction extends ZodType {
5379
5418
  const params = { errorMap: ctx.common.contextualErrorMap };
5380
5419
  const fn = ctx.data;
5381
5420
  if (this._def.returns instanceof ZodPromise) {
5382
- return OK(async (...args) => {
5421
+ const me = this;
5422
+ return OK(async function(...args) {
5383
5423
  const error = new ZodError([]);
5384
- const parsedArgs = await this._def.args.parseAsync(args, params).catch((e) => {
5424
+ const parsedArgs = await me._def.args.parseAsync(args, params).catch((e) => {
5385
5425
  error.addIssue(makeArgsIssue(args, e));
5386
5426
  throw error;
5387
5427
  });
5388
- const result = await fn(...parsedArgs);
5389
- const parsedReturns = await this._def.returns._def.type.parseAsync(result, params).catch((e) => {
5428
+ const result = await Reflect.apply(fn, this, parsedArgs);
5429
+ const parsedReturns = await me._def.returns._def.type.parseAsync(result, params).catch((e) => {
5390
5430
  error.addIssue(makeReturnsIssue(result, e));
5391
5431
  throw error;
5392
5432
  });
5393
5433
  return parsedReturns;
5394
5434
  });
5395
5435
  } else {
5396
- return OK((...args) => {
5397
- const parsedArgs = this._def.args.safeParse(args, params);
5436
+ const me = this;
5437
+ return OK(function(...args) {
5438
+ const parsedArgs = me._def.args.safeParse(args, params);
5398
5439
  if (!parsedArgs.success) {
5399
5440
  throw new ZodError([makeArgsIssue(args, parsedArgs.error)]);
5400
5441
  }
5401
- const result = fn(...parsedArgs.data);
5402
- const parsedReturns = this._def.returns.safeParse(result, params);
5442
+ const result = Reflect.apply(fn, this, parsedArgs.data);
5443
+ const parsedReturns = me._def.returns.safeParse(result, params);
5403
5444
  if (!parsedReturns.success) {
5404
5445
  throw new ZodError([makeReturnsIssue(result, parsedReturns.error)]);
5405
5446
  }
@@ -5621,8 +5662,28 @@ class ZodEffects extends ZodType {
5621
5662
  _parse(input) {
5622
5663
  const { status, ctx } = this._processInputParams(input);
5623
5664
  const effect = this._def.effect || null;
5665
+ const checkCtx = {
5666
+ addIssue: (arg) => {
5667
+ addIssueToContext(ctx, arg);
5668
+ if (arg.fatal) {
5669
+ status.abort();
5670
+ } else {
5671
+ status.dirty();
5672
+ }
5673
+ },
5674
+ get path() {
5675
+ return ctx.path;
5676
+ }
5677
+ };
5678
+ checkCtx.addIssue = checkCtx.addIssue.bind(checkCtx);
5624
5679
  if (effect.type === "preprocess") {
5625
- const processed = effect.transform(ctx.data);
5680
+ const processed = effect.transform(ctx.data, checkCtx);
5681
+ if (ctx.common.issues.length) {
5682
+ return {
5683
+ status: "dirty",
5684
+ value: ctx.data
5685
+ };
5686
+ }
5626
5687
  if (ctx.common.async) {
5627
5688
  return Promise.resolve(processed).then((processed2) => {
5628
5689
  return this._def.schema._parseAsync({
@@ -5639,20 +5700,6 @@ class ZodEffects extends ZodType {
5639
5700
  });
5640
5701
  }
5641
5702
  }
5642
- const checkCtx = {
5643
- addIssue: (arg) => {
5644
- addIssueToContext(ctx, arg);
5645
- if (arg.fatal) {
5646
- status.abort();
5647
- } else {
5648
- status.dirty();
5649
- }
5650
- },
5651
- get path() {
5652
- return ctx.path;
5653
- }
5654
- };
5655
- checkCtx.addIssue = checkCtx.addIssue.bind(checkCtx);
5656
5703
  if (effect.type === "refinement") {
5657
5704
  const executeRefinement = (acc) => {
5658
5705
  const result = effect.refinement(acc, checkCtx);
@@ -5936,6 +5983,22 @@ class ZodPipeline extends ZodType {
5936
5983
  });
5937
5984
  }
5938
5985
  }
5986
+ class ZodReadonly extends ZodType {
5987
+ _parse(input) {
5988
+ const result = this._def.innerType._parse(input);
5989
+ if (isValid(result)) {
5990
+ result.value = Object.freeze(result.value);
5991
+ }
5992
+ return result;
5993
+ }
5994
+ }
5995
+ ZodReadonly.create = (type, params) => {
5996
+ return new ZodReadonly({
5997
+ innerType: type,
5998
+ typeName: ZodFirstPartyTypeKind.ZodReadonly,
5999
+ ...processCreateParams(params)
6000
+ });
6001
+ };
5939
6002
  const custom = (check, params = {}, fatal) => {
5940
6003
  if (check)
5941
6004
  return ZodAny.create().superRefine((data, ctx) => {
@@ -5989,6 +6052,7 @@ var ZodFirstPartyTypeKind;
5989
6052
  ZodFirstPartyTypeKind2["ZodPromise"] = "ZodPromise";
5990
6053
  ZodFirstPartyTypeKind2["ZodBranded"] = "ZodBranded";
5991
6054
  ZodFirstPartyTypeKind2["ZodPipeline"] = "ZodPipeline";
6055
+ ZodFirstPartyTypeKind2["ZodReadonly"] = "ZodReadonly";
5992
6056
  })(ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {}));
5993
6057
  const instanceOfType = (cls, params = {
5994
6058
  message: `Input not instance of ${cls.name}`
@@ -6103,6 +6167,7 @@ var z = /* @__PURE__ */ Object.freeze({
6103
6167
  BRAND,
6104
6168
  ZodBranded,
6105
6169
  ZodPipeline,
6170
+ ZodReadonly,
6106
6171
  custom,
6107
6172
  Schema: ZodType,
6108
6173
  ZodSchema: ZodType,
@@ -9013,6 +9078,7 @@ const ViewType$1 = {
9013
9078
  OBS_SET_SIZES: "obsSetSizes",
9014
9079
  OBS_SET_FEATURE_VALUE_DISTRIBUTION: "obsSetFeatureValueDistribution",
9015
9080
  FEATURE_VALUE_HISTOGRAM: "featureValueHistogram",
9081
+ DOT_PLOT: "dotPlot",
9016
9082
  FEATURE_BAR_PLOT: "featureBarPlot"
9017
9083
  };
9018
9084
  const DataType$1 = {
@@ -9202,6 +9268,7 @@ const CoordinationType$1 = {
9202
9268
  GATING_FEATURE_SELECTION_X: "gatingFeatureSelectionX",
9203
9269
  GATING_FEATURE_SELECTION_Y: "gatingFeatureSelectionY",
9204
9270
  FEATURE_VALUE_TRANSFORM_COEFFICIENT: "featureValueTransformCoefficient",
9271
+ FEATURE_VALUE_POSITIVITY_THRESHOLD: "featureValuePositivityThreshold",
9205
9272
  TOOLTIPS_VISIBLE: "tooltipsVisible",
9206
9273
  FILE_UID: "fileUid",
9207
9274
  IMAGE_LAYER: "imageLayer",
@@ -9249,7 +9316,14 @@ const CoordinationType$1 = {
9249
9316
  SPATIAL_CHANNEL_LABEL_SIZE: "spatialChannelLabelSize",
9250
9317
  // Multi-sample / comparative
9251
9318
  SAMPLE_TYPE: "sampleType",
9252
- SAMPLE_SET_SELECTION: "sampleSetSelection"
9319
+ SAMPLE_SET_SELECTION: "sampleSetSelection",
9320
+ SAMPLE_SET_COLOR: "sampleSetColor",
9321
+ EMBEDDING_POINTS_VISIBLE: "embeddingPointsVisible",
9322
+ EMBEDDING_CONTOURS_VISIBLE: "embeddingContoursVisible",
9323
+ EMBEDDING_CONTOURS_FILLED: "embeddingContoursFilled",
9324
+ EMBEDDING_CONTOUR_PERCENTILES: "embeddingContourPercentiles",
9325
+ CONTOUR_COLOR_ENCODING: "contourColorEncoding",
9326
+ CONTOUR_COLOR: "contourColor"
9253
9327
  };
9254
9328
  const ViewType = {
9255
9329
  GENES: [
@@ -9497,6 +9571,7 @@ const annDataConvenienceObsEmbeddingItem = z.object({
9497
9571
  });
9498
9572
  const annDataObsLabels = annDataObs;
9499
9573
  const annDataFeatureLabels = annDataObs;
9574
+ const annDataSampleEdges = annDataObs;
9500
9575
  const annDataObsFeatureMatrix = z.object({
9501
9576
  path: z.string(),
9502
9577
  featureFilterPath: z.string().optional().describe("If the feature index should be filtered, put a boolean column here (analogous to the previous geneFilter option). e.g., var/in_obsm_X_small_matrix"),
@@ -9653,7 +9728,8 @@ z.object({
9653
9728
  obsEmbedding: z.union([
9654
9729
  annDataObsEmbedding,
9655
9730
  z.array(annDataConvenienceObsEmbeddingItem)
9656
- ])
9731
+ ]),
9732
+ sampleEdges: annDataSampleEdges
9657
9733
  }).partial();
9658
9734
  z.object({
9659
9735
  // TODO: should `image` be a special schema
@@ -10992,6 +11068,27 @@ function treeToCellColorsBySetNames(currTree, selectedNamePaths, cellSetColor, t
10992
11068
  });
10993
11069
  return new Map(cellColorsArray);
10994
11070
  }
11071
+ function treeToSelectedSetMap(currTree, selectedNamePaths) {
11072
+ let result = [];
11073
+ selectedNamePaths.forEach((setNamePath) => {
11074
+ const node = treeFindNodeByNamePath(currTree, setNamePath);
11075
+ if (node) {
11076
+ const nodeSet = nodeToSet(node);
11077
+ result = [
11078
+ ...result,
11079
+ ...nodeSet.map(([cellId]) => [
11080
+ cellId,
11081
+ // TODO: should this be the full path
11082
+ // (rather than only the node name)?
11083
+ // Or the index of the selected set
11084
+ // with respect to the selectedNamePaths array?
11085
+ setNamePath
11086
+ ])
11087
+ ];
11088
+ }
11089
+ });
11090
+ return new Map(result);
11091
+ }
10995
11092
  function treeToCellSetColorIndicesBySetNames(currTree, selectedNamePaths, cellSetColor) {
10996
11093
  let cellColorsArray = [];
10997
11094
  selectedNamePaths == null ? void 0 : selectedNamePaths.forEach((setNamePath) => {
@@ -11091,6 +11188,44 @@ function treeToSetSizesBySetNames(currTree, allNamePaths, selectedNamePaths, set
11091
11188
  });
11092
11189
  return sizes;
11093
11190
  }
11191
+ function treeToObsIdsBySetNames(currTree, selectedNamePaths) {
11192
+ const indices = [];
11193
+ selectedNamePaths.forEach((setNamePath) => {
11194
+ const node = treeFindNodeByNamePath(currTree, setNamePath);
11195
+ if (node) {
11196
+ const nodeSet = nodeToSet(node);
11197
+ indices.push({
11198
+ key: generateKey(),
11199
+ name: node.name,
11200
+ path: setNamePath,
11201
+ size: nodeSet.length,
11202
+ // TODO: handle the case where the ID is in the set but missing
11203
+ // from the obsIndexMap
11204
+ ids: nodeSet.map(([obsId]) => obsId)
11205
+ });
11206
+ }
11207
+ });
11208
+ return indices;
11209
+ }
11210
+ function treeToObsIndicesBySetNames(currTree, selectedNamePaths, obsIndexMap) {
11211
+ const indices = [];
11212
+ selectedNamePaths.forEach((setNamePath) => {
11213
+ const node = treeFindNodeByNamePath(currTree, setNamePath);
11214
+ if (node) {
11215
+ const nodeSet = nodeToSet(node);
11216
+ indices.push({
11217
+ key: generateKey(),
11218
+ name: node.name,
11219
+ path: setNamePath,
11220
+ size: nodeSet.length,
11221
+ // TODO: handle the case where the ID is in the set but missing
11222
+ // from the obsIndexMap
11223
+ indices: nodeSet.map(([obsId]) => obsIndexMap[obsId])
11224
+ });
11225
+ }
11226
+ });
11227
+ return indices;
11228
+ }
11094
11229
  function filterNode(node, prevPath, filterPath) {
11095
11230
  if (isEqual([...prevPath, node.name], filterPath)) {
11096
11231
  return null;
@@ -17226,6 +17361,134 @@ function getCellColors(params) {
17226
17361
  }
17227
17362
  return /* @__PURE__ */ new Map();
17228
17363
  }
17364
+ function stratifyArrays(sampleEdges, sampleIdToObsIdsMap, sampleSets, sampleSetSelection, obsIndex, mergedCellSets, cellSetSelection, arraysToStratify) {
17365
+ const result = new InternMap([], JSON.stringify);
17366
+ const hasSampleSetSelection = Array.isArray(sampleSetSelection) && sampleSetSelection.length > 0;
17367
+ const hasCellSetSelection = Array.isArray(cellSetSelection) && cellSetSelection.length > 0;
17368
+ const sampleSetKeys = hasSampleSetSelection ? sampleSetSelection : [null];
17369
+ const cellSetKeys = hasCellSetSelection ? cellSetSelection : [null];
17370
+ const arrKeys = Object.keys(arraysToStratify);
17371
+ if (arrKeys.includes("obsIndex") || arrKeys.includes("i")) {
17372
+ throw new Error('The keys "obsIndex" and "i" are reserved for internal use.');
17373
+ }
17374
+ if (Object.values(arraysToStratify).some((arr) => arr.length !== obsIndex.length)) {
17375
+ throw new Error("All arrays must have the same length as the obsIndex.");
17376
+ }
17377
+ const sampleSetInfo = sampleSets && sampleSetSelection ? treeToObsIdsBySetNames(sampleSets, sampleSetSelection) : null;
17378
+ const cellSetInfo = mergedCellSets && cellSetSelection ? treeToObsIdsBySetNames(mergedCellSets, cellSetSelection) : null;
17379
+ cellSetKeys.forEach((cellSetKey) => {
17380
+ result.set(cellSetKey, new InternMap([], JSON.stringify));
17381
+ sampleSetKeys.forEach((sampleSetKey) => {
17382
+ var _a, _b;
17383
+ result.get(cellSetKey).set(sampleSetKey, new InternMap([], JSON.stringify));
17384
+ const sampleIdsInSampleSet = (_a = sampleSetInfo && sampleSetKey ? sampleSetInfo == null ? void 0 : sampleSetInfo.find((n) => isEqual(n.path, sampleSetKey)) : null) == null ? void 0 : _a.ids;
17385
+ const obsIdsInSampleSet = sampleIdsInSampleSet ? sampleIdsInSampleSet.flatMap((sampleId) => (sampleIdToObsIdsMap == null ? void 0 : sampleIdToObsIdsMap.get(sampleId)) || []) : null;
17386
+ const obsIdsInCellSet = (_b = cellSetInfo && cellSetKey ? cellSetInfo == null ? void 0 : cellSetInfo.find((n) => isEqual(n.path, cellSetKey)) : null) == null ? void 0 : _b.ids;
17387
+ let subObsIndex = obsIndex;
17388
+ if (obsIdsInSampleSet && obsIdsInCellSet) {
17389
+ subObsIndex = Array.from(
17390
+ new Set(obsIdsInSampleSet).intersection(new Set(obsIdsInCellSet))
17391
+ );
17392
+ } else if (obsIdsInSampleSet) {
17393
+ subObsIndex = obsIdsInSampleSet;
17394
+ } else if (obsIdsInCellSet) {
17395
+ subObsIndex = obsIdsInCellSet;
17396
+ }
17397
+ const arrLen = subObsIndex.length;
17398
+ arrKeys.forEach((arrKey) => {
17399
+ const newArr = new arraysToStratify[arrKey].constructor(arrLen);
17400
+ result.get(cellSetKey).get(sampleSetKey).set(arrKey, newArr);
17401
+ });
17402
+ result.get(cellSetKey).get(sampleSetKey).set("obsIndex", subObsIndex);
17403
+ result.get(cellSetKey).get(sampleSetKey).set("i", 0);
17404
+ });
17405
+ });
17406
+ const sampleIdToSetMap = sampleSets && sampleSetSelection ? treeToSelectedSetMap(sampleSets, sampleSetSelection) : null;
17407
+ const cellIdToSetMap = mergedCellSets && cellSetSelection ? treeToSelectedSetMap(mergedCellSets, cellSetSelection) : null;
17408
+ for (let i = 0; i < obsIndex.length; i += 1) {
17409
+ const obsId = obsIndex[i];
17410
+ const cellSet = (cellIdToSetMap == null ? void 0 : cellIdToSetMap.get(obsId)) || null;
17411
+ const sampleId = sampleEdges == null ? void 0 : sampleEdges.get(obsId);
17412
+ const sampleSet = sampleId ? (sampleIdToSetMap == null ? void 0 : sampleIdToSetMap.get(sampleId)) || null : null;
17413
+ if (hasSampleSetSelection && !sampleSet || hasCellSetSelection && !cellSet) {
17414
+ continue;
17415
+ }
17416
+ const insertionIndex = result.get(cellSet).get(sampleSet).get("i");
17417
+ arrKeys.forEach((arrKey) => {
17418
+ const value = arraysToStratify[arrKey][i];
17419
+ result.get(cellSet).get(sampleSet).get(arrKey)[insertionIndex] = value;
17420
+ });
17421
+ result.get(cellSet).get(sampleSet).set("i", insertionIndex + 1);
17422
+ }
17423
+ cellSetKeys.forEach((cellSetKey) => {
17424
+ sampleSetKeys.forEach((sampleSetKey) => {
17425
+ const finalInsertionIndex = result.get(cellSetKey).get(sampleSetKey).get("i");
17426
+ if (finalInsertionIndex !== result.get(cellSetKey).get(sampleSetKey).get("obsIndex").length) {
17427
+ console.warn("The final insertion index is lower than expected.");
17428
+ }
17429
+ result.get(cellSetKey).get(sampleSetKey).delete("i");
17430
+ });
17431
+ });
17432
+ return result;
17433
+ }
17434
+ function stratifyExpressionData(sampleEdges, sampleSets, sampleSetSelection, expressionData, obsIndex, mergedCellSets, geneSelection, cellSetSelection, cellSetColor, featureValueTransform, featureValueTransformCoefficient) {
17435
+ const result = new InternMap([], JSON.stringify);
17436
+ const hasSampleSetSelection = Array.isArray(sampleSetSelection) && sampleSetSelection.length > 0;
17437
+ const hasCellSetSelection = Array.isArray(cellSetSelection) && cellSetSelection.length > 0;
17438
+ const hasGeneSelection = Array.isArray(geneSelection) && geneSelection.length > 0;
17439
+ const sampleSetKeys = hasSampleSetSelection ? sampleSetSelection : [null];
17440
+ const cellSetKeys = hasCellSetSelection ? cellSetSelection : [null];
17441
+ const geneKeys = hasGeneSelection ? geneSelection : [null];
17442
+ cellSetKeys.forEach((cellSetKey) => {
17443
+ result.set(cellSetKey, new InternMap([], JSON.stringify));
17444
+ sampleSetKeys.forEach((sampleSetKey) => {
17445
+ result.get(cellSetKey).set(sampleSetKey, new InternMap([], JSON.stringify));
17446
+ geneKeys.forEach((geneKey) => {
17447
+ result.get(cellSetKey).get(sampleSetKey).set(geneKey, []);
17448
+ });
17449
+ });
17450
+ });
17451
+ if (mergedCellSets && cellSetSelection && geneSelection && geneSelection.length >= 1 && expressionData) {
17452
+ const sampleIdToSetMap = sampleSets && sampleSetSelection ? treeToSelectedSetMap(sampleSets, sampleSetSelection) : null;
17453
+ const cellIdToSetMap = treeToSelectedSetMap(mergedCellSets, cellSetSelection);
17454
+ let exprMax = -Infinity;
17455
+ for (let i = 0; i < obsIndex.length; i += 1) {
17456
+ const obsId = obsIndex[i];
17457
+ const cellSet = cellIdToSetMap == null ? void 0 : cellIdToSetMap.get(obsId);
17458
+ const sampleId = sampleEdges == null ? void 0 : sampleEdges.get(obsId);
17459
+ const sampleSet = sampleId ? sampleIdToSetMap == null ? void 0 : sampleIdToSetMap.get(sampleId) : null;
17460
+ if (hasSampleSetSelection && !sampleSet) {
17461
+ continue;
17462
+ }
17463
+ geneKeys.forEach((geneKey, geneI) => {
17464
+ var _a, _b, _c;
17465
+ const value = expressionData[geneI][i];
17466
+ const transformFunction = getValueTransformFunction(
17467
+ featureValueTransform,
17468
+ featureValueTransformCoefficient
17469
+ );
17470
+ const transformedValue = transformFunction(value);
17471
+ exprMax = Math.max(transformedValue, exprMax);
17472
+ (_c = (_b = (_a = result.get(cellSet)) == null ? void 0 : _a.get(sampleSet)) == null ? void 0 : _b.get(geneKey)) == null ? void 0 : _c.push(transformedValue);
17473
+ });
17474
+ }
17475
+ return [result, exprMax];
17476
+ }
17477
+ return [null, null];
17478
+ }
17479
+ function aggregateStratifiedExpressionData(stratifiedResult, geneSelection) {
17480
+ const result = new InternMap([], JSON.stringify);
17481
+ if (stratifiedResult) {
17482
+ Array.from(stratifiedResult.keys()).forEach((cellSetKey) => {
17483
+ result.set(cellSetKey, new InternMap([], JSON.stringify));
17484
+ Array.from(stratifiedResult.get(cellSetKey).keys()).forEach((sampleSetKey) => {
17485
+ const values = stratifiedResult.get(cellSetKey).get(sampleSetKey).get(geneSelection[0]);
17486
+ result.get(cellSetKey).set(sampleSetKey, values);
17487
+ });
17488
+ });
17489
+ }
17490
+ return result;
17491
+ }
17229
17492
  export {
17230
17493
  FILE_EXTENSION_JSON,
17231
17494
  FILE_EXTENSION_TABULAR,
@@ -17233,6 +17496,7 @@ export {
17233
17496
  MIME_TYPE_TABULAR,
17234
17497
  PATH_SEP,
17235
17498
  SETS_DATATYPE_OBS,
17499
+ aggregateStratifiedExpressionData,
17236
17500
  callbackOnKeyPress,
17237
17501
  colorArrayToString,
17238
17502
  dataToCellSetsTree,
@@ -17262,6 +17526,8 @@ export {
17262
17526
  nodeTransform,
17263
17527
  pathToKey,
17264
17528
  setObsSelection,
17529
+ stratifyArrays,
17530
+ stratifyExpressionData,
17265
17531
  treeExportLevelZeroNode,
17266
17532
  treeExportSet,
17267
17533
  treeFindNodeByNamePath,
@@ -17273,6 +17539,9 @@ export {
17273
17539
  treeToIntersection,
17274
17540
  treeToMembershipMap,
17275
17541
  treeToObjectsBySetNames,
17542
+ treeToObsIdsBySetNames,
17543
+ treeToObsIndicesBySetNames,
17544
+ treeToSelectedSetMap,
17276
17545
  treeToSetSizesBySetNames,
17277
17546
  treeToUnion,
17278
17547
  treesConflict,
@@ -158,6 +158,20 @@ export function nodeToRenderProps(node: object, path: any, cellSetColor: any): o
158
158
  * and cellColors is an object mapping cellIds to color [r,g,b] arrays.
159
159
  */
160
160
  export function treeToCellColorsBySetNames(currTree: object, selectedNamePaths: array, cellSetColor: object[], theme: string): array;
161
+ /**
162
+ * Given a tree with state, get the cellIds and cellColors,
163
+ * based on the nodes currently marked as "visible".
164
+ * @param {object} currTree A tree object.
165
+ * @param {array} selectedNamePaths Array of arrays of strings,
166
+ * representing set "paths".
167
+ * @param {object[]} cellSetColor Array of objects with the
168
+ * properties `path` and `color`.
169
+ * @param {string} theme "light" or "dark" for the vitessce theme
170
+ * @returns {array} Tuple of [cellIds, cellColors]
171
+ * where cellIds is an array of strings,
172
+ * and cellColors is an object mapping cellIds to color [r,g,b] arrays.
173
+ */
174
+ export function treeToSelectedSetMap(currTree: object, selectedNamePaths: array): array;
161
175
  /**
162
176
  * Given a tree with state, get a mapping from cell ID to cell set color index,
163
177
  * based on the nodes currently marked as "visible".
@@ -201,6 +215,29 @@ export function treeToCellPolygonsBySetNames(currTree: any, obsIndex: any, obsEm
201
215
  * and `color`.
202
216
  */
203
217
  export function treeToSetSizesBySetNames(currTree: object, allNamePaths: array, selectedNamePaths: array, setColor: object[], theme: string): object[];
218
+ /**
219
+ * Given a tree with state, get the indices of observations
220
+ * contained in each selected obs set.
221
+ * @param {object} currTree A tree object.
222
+ * @param {array} selectedNamePaths Array of arrays of strings,
223
+ * representing set "paths".
224
+ * @returns {object[]} Array of objects
225
+ * with the properties `name`, `size`, `key`,
226
+ * and `color`.
227
+ */
228
+ export function treeToObsIdsBySetNames(currTree: object, selectedNamePaths: array): object[];
229
+ /**
230
+ * Given a tree with state, get the indices of observations
231
+ * contained in each selected obs set.
232
+ * @param {object} currTree A tree object.
233
+ * @param {array} selectedNamePaths Array of arrays of strings,
234
+ * representing set "paths".
235
+ * @param {object[]} obsIndex The observation index.
236
+ * @returns {object[]} Array of objects
237
+ * with the properties `name`, `size`, `key`,
238
+ * and `color`.
239
+ */
240
+ export function treeToObsIndicesBySetNames(currTree: object, selectedNamePaths: array, obsIndexMap: any): object[];
204
241
  /**
205
242
  * Find and remove a node from the descendants of the current node.
206
243
  * @param {object} node A node to search on.
@@ -1 +1 @@
1
- {"version":3,"file":"cell-set-utils.d.ts","sourceRoot":"","sources":["../src/cell-set-utils.js"],"names":[],"mappings":"AAoBA;;;;;GAKG;AACH,oCAHW,MAAM,SAWhB;AAED;;;;;;GAMG;AACH,uCALW,MAAM,UACN,MAAM,GACJ,MAAM,CAUlB;AAED;;;;;GAKG;AACH,wCAHW,MAAM,GACJ,MAAM,CAUlB;AA2BD;;;;;GAKG;AACH,iDAJW,MAAM,kBACN,MAAM,EAAE,GACN,MAAM,GAAC,IAAI,CAUvB;AAED;;;;;;;;;;;GAWG;AACH,oCAVW,MAAM,qFAQJ,MAAM,CAwBlB;AAED;;;;;;;;;;;GAWG;AACH,uCAVW,MAAM,qFAQJ,MAAM,CAyBlB;AAED;;;;;GAKG;AACH,0CAJW,MAAM,YACN,MAAM,GACJ,MAAM,CAOlB;AAED;;;;;GAKG;AACH,2CAJW,MAAM,YACN,MAAM,GACJ,MAAM,CAOlB;AAED;;;;;;GAMG;AACH,0CALW,MAAM,oCAGJ,MAAM,CASlB;AAED;;;;GAIG;AACH,sCAHW,MAAM,4BAQhB;AAED;;;;GAIG;AACH,6CAHW,MAAM,4BAQhB;AAED;;;;;GAKG;AACH,2CAJW,MAAM,wCAOhB;AAED;;;;;;;;;GASG;AACH,qDAPW,MAAM,SACN,MAAM,6BAEN,OAAO,GACL,MAAM,EAAE,CAgBpB;AAED;;;;GAIG;AACH,qCAHW,MAAM,kBACJ,MAAM,CAQlB;AAED;;;;;;;;;;GAUG;AACH,kDARW,MAAM,YACN,MAAM,8CAGN,MAAM,GACJ,MAAM,CAqBlB;AAED;;;;;GAKG;AACH,wCAJW,MAAM,kBAEJ,MAAM,CAKlB;AAED;;;;GAIG;AACH,yCAHW,MAAM,GACJ,MAAM,CAQlB;AAED;;;;;;GAMG;AACH,wCAJW,MAAM,iCACJ,MAAM,CAelB;AAoBD;;;;;;;;;;;;GAYG;AACH,qDAVW,MAAM,0CAGN,MAAM,EAAE,SAER,MAAM,SAyBhB;AAED;;;;;;;;;;;GAWG;AACH,8DATW,MAAM,0CAGN,MAAM,EAAE,SAuBlB;AAED;;;;;;;;;;;;GAYG;AACH,kDATW,MAAM,sCAGN,MAAM,EAAE,SAER,MAAM,GACJ,MAAM,EAAE,CAsBpB;AAED,4JA2CC;AAED;;;;;;;;;;;;;GAaG;AACH,mDAXW,MAAM,2DAIN,MAAM,EAAE,SAER,MAAM,GACJ,MAAM,EAAE,CAuCpB;AAED;;;;;;GAMG;AACH,iCALW,MAAM,uCAGJ,MAAM,CAelB;AAED,mFAgBC;AAED,yEA2BC;AAED,gFA6BC;AAED,uDAeC;AAED,kEA0BC"}
1
+ {"version":3,"file":"cell-set-utils.d.ts","sourceRoot":"","sources":["../src/cell-set-utils.js"],"names":[],"mappings":"AAoBA;;;;;GAKG;AACH,oCAHW,MAAM,GACJ,KAAK,CAUjB;AAED;;;;;;GAMG;AACH,uCALW,MAAM,UACN,MAAM,GACJ,MAAM,CAUlB;AAED;;;;;GAKG;AACH,wCAHW,MAAM,GACJ,MAAM,CAUlB;AA2BD;;;;;GAKG;AACH,iDAJW,MAAM,kBACN,MAAM,EAAE,GACN,MAAM,GAAC,IAAI,CAUvB;AAED;;;;;;;;;;;GAWG;AACH,oCAVW,MAAM,8DAIN,KAAK,kBAIH,MAAM,CAwBlB;AAED;;;;;;;;;;;GAWG;AACH,uCAVW,MAAM,8DAIN,KAAK,kBAIH,MAAM,CAyBlB;AAED;;;;;GAKG;AACH,0CAJW,MAAM,YACN,MAAM,GACJ,MAAM,CAOlB;AAED;;;;;GAKG;AACH,2CAJW,MAAM,YACN,MAAM,GACJ,MAAM,CAOlB;AAED;;;;;;GAMG;AACH,0CALW,MAAM,YACN,GAAC,eACD,GAAC,GACC,MAAM,CASlB;AAED;;;;GAIG;AACH,sCAHW,MAAM,sBACJ,KAAK,CAOjB;AAED;;;;GAIG;AACH,6CAHW,MAAM,sBACJ,KAAK,CAOjB;AAED;;;;;GAKG;AACH,2CAJW,MAAM,kCACJ,KAAK,CAMjB;AAED;;;;;;;;;GASG;AACH,qDAPW,MAAM,SACN,MAAM,6BAEN,OAAO,GACL,MAAM,EAAE,CAgBpB;AAED;;;;GAIG;AACH,qCAHW,MAAM,kBACJ,MAAM,CAQlB;AAED;;;;;;;;;;GAUG;AACH,kDARW,MAAM,YACN,MAAM,8CAGN,MAAM,GACJ,MAAM,CAqBlB;AAED;;;;;GAKG;AACH,wCAJW,MAAM,kBAEJ,MAAM,CAKlB;AAED;;;;GAIG;AACH,yCAHW,MAAM,GACJ,MAAM,CAQlB;AAED;;;;;;GAMG;AACH,wCAJW,MAAM,iCACJ,MAAM,CAelB;AAoBD;;;;;;;;;;;;GAYG;AACH,qDAVW,MAAM,qBACL,KAAK,gBAEN,MAAM,EAAE,SAER,MAAM,GACJ,KAAK,CAwBjB;AAED;;;;;;;;;;;;GAYG;AACH,+CAVW,MAAM,qBACL,KAAK,GAKJ,KAAK,CAwBjB;AAED;;;;;;;;;;;GAWG;AACH,8DATW,MAAM,qBACL,KAAK,gBAEN,MAAM,EAAE,GAEN,KAAK,CAqBjB;AAED;;;;;;;;;;;;GAYG;AACH,kDATW,MAAM,qBACN,KAAK,YAEL,MAAM,EAAE,SAER,MAAM,GACJ,MAAM,EAAE,CAsBpB;AAED,4JA2CC;AAED;;;;;;;;;;;;;GAaG;AACH,mDAXW,MAAM,gBACN,KAAK,qBACL,KAAK,YAEL,MAAM,EAAE,SAER,MAAM,GACJ,MAAM,EAAE,CAuCpB;AAED;;;;;;;;;GASG;AACH,iDAPW,MAAM,qBACN,KAAK,GAEH,MAAM,EAAE,CAsBpB;AAED;;;;;;;;;;GAUG;AACH,qDARW,MAAM,qBACN,KAAK,qBAGH,MAAM,EAAE,CAsBpB;AAED;;;;;;GAMG;AACH,iCALW,MAAM,YACN,KAAK,cACL,KAAK,GACH,MAAM,CAelB;AAED,mFAgBC;AAED,yEA2BC;AAED,gFA6BC;AAED,uDAeC;AAED,kEA0BC"}