@vitessce/zarr 3.5.7 → 3.5.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.
Files changed (35) hide show
  1. package/dist/index.js +743 -195
  2. package/dist/zstd-561fda0e.js +778 -0
  3. package/dist-tsc/AnnDataSource.d.ts +3 -4
  4. package/dist-tsc/AnnDataSource.d.ts.map +1 -1
  5. package/dist-tsc/AnnDataSource.js +1 -2
  6. package/dist-tsc/ZarrDataSource.d.ts +3 -4
  7. package/dist-tsc/ZarrDataSource.d.ts.map +1 -1
  8. package/dist-tsc/ZarrDataSource.js +1 -2
  9. package/dist-tsc/anndata-loaders/ComparisonMetadataAnndataLoader.d.ts +20 -0
  10. package/dist-tsc/anndata-loaders/ComparisonMetadataAnndataLoader.d.ts.map +1 -0
  11. package/dist-tsc/anndata-loaders/ComparisonMetadataAnndataLoader.js +29 -0
  12. package/dist-tsc/anndata-loaders/FeatureSetStatsAnndataLoader.d.ts +49 -0
  13. package/dist-tsc/anndata-loaders/FeatureSetStatsAnndataLoader.d.ts.map +1 -0
  14. package/dist-tsc/anndata-loaders/FeatureSetStatsAnndataLoader.js +143 -0
  15. package/dist-tsc/anndata-loaders/FeatureStatsAnndataLoader.d.ts +53 -0
  16. package/dist-tsc/anndata-loaders/FeatureStatsAnndataLoader.d.ts.map +1 -0
  17. package/dist-tsc/anndata-loaders/FeatureStatsAnndataLoader.js +157 -0
  18. package/dist-tsc/anndata-loaders/ObsSetStatsAnndataLoader.d.ts +66 -0
  19. package/dist-tsc/anndata-loaders/ObsSetStatsAnndataLoader.d.ts.map +1 -0
  20. package/dist-tsc/anndata-loaders/ObsSetStatsAnndataLoader.js +183 -0
  21. package/dist-tsc/anndata-loaders/comparative-utils.d.ts +19 -0
  22. package/dist-tsc/anndata-loaders/comparative-utils.d.ts.map +1 -0
  23. package/dist-tsc/anndata-loaders/comparative-utils.js +30 -0
  24. package/dist-tsc/anndata-loaders/index.d.ts +4 -0
  25. package/dist-tsc/anndata-loaders/index.js +4 -0
  26. package/package.json +11 -14
  27. package/src/AnnDataSource.js +1 -2
  28. package/src/ZarrDataSource.js +1 -2
  29. package/src/anndata-loaders/ComparisonMetadataAnndataLoader.js +34 -0
  30. package/src/anndata-loaders/FeatureSetStatsAnndataLoader.js +164 -0
  31. package/src/anndata-loaders/FeatureStatsAnndataLoader.js +177 -0
  32. package/src/anndata-loaders/ObsSetStatsAnndataLoader.js +211 -0
  33. package/src/anndata-loaders/comparative-utils.js +35 -0
  34. package/src/anndata-loaders/index.js +4 -0
  35. package/dist/zstd-ec5a40b8.js +0 -808
package/dist/index.js CHANGED
@@ -26,7 +26,7 @@ var __privateMethod = (obj, member, method) => {
26
26
  __accessCheck(obj, member, "access private method");
27
27
  return method;
28
28
  };
29
- var _bytes, _encoder, _data, _strides, _TypedArray, _BYTES_PER_ELEMENT, _shape, _endian, _encoder_config, _decoder_config, _shape2, _strides2, _metadata, _metadata2, _a, _b, _overrides, _use_suffix_request, _merge_init, merge_init_fn, _overrides2, _refs, _opts, _overrides3;
29
+ var _bytes, _encoder, _data, _stride, _TypedArray, _BYTES_PER_ELEMENT, _shape, _endian, _encoder_config, _decoder_config, _order, _inverseOrder, _shape2, _strides, _metadata, _metadata2, _a, _b, _overrides, _use_suffix_request, _merge_init, merge_init_fn, _overrides2, _refs, _opts, _overrides3;
30
30
  class NodeNotFoundError extends Error {
31
31
  constructor(context, options = {}) {
32
32
  super(`Node not found: ${context}`, options);
@@ -59,11 +59,9 @@ class BoolArray {
59
59
  get byteLength() {
60
60
  return __privateGet(this, _bytes).byteLength;
61
61
  }
62
- /** @type {ArrayBuffer} */
63
62
  get buffer() {
64
63
  return __privateGet(this, _bytes).buffer;
65
64
  }
66
- /** @type {number} */
67
65
  get length() {
68
66
  return __privateGet(this, _bytes).length;
69
67
  }
@@ -114,11 +112,9 @@ class ByteStringArray {
114
112
  get byteLength() {
115
113
  return this._data.byteLength;
116
114
  }
117
- /** @type {ArrayBuffer} */
118
115
  get buffer() {
119
116
  return this._data.buffer;
120
117
  }
121
- /** @type {number} */
122
118
  get length() {
123
119
  return this.byteLength / this.BYTES_PER_ELEMENT;
124
120
  }
@@ -175,11 +171,9 @@ const _UnicodeStringArray = class {
175
171
  get byteOffset() {
176
172
  return __privateGet(this, _data).byteOffset;
177
173
  }
178
- /** @type {ArrayBuffer} */
179
174
  get buffer() {
180
175
  return __privateGet(this, _data).buffer;
181
176
  }
182
- /** @type {number} */
183
177
  get length() {
184
178
  return __privateGet(this, _data).length / this.chars;
185
179
  }
@@ -230,53 +224,43 @@ function byteswap_inplace(view, bytes_per_element2) {
230
224
  }
231
225
  }
232
226
  }
233
- const CONSTRUCTORS = {
234
- int8: Int8Array,
235
- int16: Int16Array,
236
- int32: Int32Array,
237
- int64: globalThis.BigInt64Array,
238
- uint8: Uint8Array,
239
- uint16: Uint16Array,
240
- uint32: Uint32Array,
241
- uint64: globalThis.BigUint64Array,
242
- float32: Float32Array,
243
- float64: Float64Array,
244
- bool: BoolArray
245
- };
246
- const V2_STRING_REGEX = /v2:([US])(\d+)/;
247
227
  function get_ctr(data_type) {
248
228
  if (data_type === "v2:object") {
249
229
  return globalThis.Array;
250
230
  }
251
- let match = data_type.match(V2_STRING_REGEX);
231
+ let match = data_type.match(/v2:([US])(\d+)/);
252
232
  if (match) {
253
233
  let [, kind, chars] = match;
254
234
  return (kind === "U" ? UnicodeStringArray : ByteStringArray).bind(null, Number(chars));
255
235
  }
256
- let ctr = CONSTRUCTORS[data_type];
257
- if (!ctr) {
258
- throw new Error(`Unknown or unsupported data_type: ${data_type}`);
259
- }
236
+ let ctr = {
237
+ int8: Int8Array,
238
+ int16: Int16Array,
239
+ int32: Int32Array,
240
+ int64: globalThis.BigInt64Array,
241
+ uint8: Uint8Array,
242
+ uint16: Uint16Array,
243
+ uint32: Uint32Array,
244
+ uint64: globalThis.BigUint64Array,
245
+ float16: globalThis.Float16Array,
246
+ float32: Float32Array,
247
+ float64: Float64Array,
248
+ bool: BoolArray
249
+ }[data_type];
250
+ assert$1(ctr, `Unknown or unsupported data_type: ${data_type}`);
260
251
  return ctr;
261
252
  }
262
253
  function get_strides(shape, order) {
263
- return (order === "C" ? row_major_stride : col_major_stride)(shape);
264
- }
265
- function row_major_stride(shape) {
266
- const ndim = shape.length;
267
- const stride = globalThis.Array(ndim);
268
- for (let i = ndim - 1, step = 1; i >= 0; i--) {
269
- stride[i] = step;
270
- step *= shape[i];
254
+ const rank = shape.length;
255
+ if (typeof order === "string") {
256
+ order = order === "C" ? Array.from({ length: rank }, (_, i) => i) : Array.from({ length: rank }, (_, i) => rank - 1 - i);
271
257
  }
272
- return stride;
273
- }
274
- function col_major_stride(shape) {
275
- const ndim = shape.length;
276
- const stride = globalThis.Array(ndim);
277
- for (let i = 0, step = 1; i < ndim; i++) {
278
- stride[i] = step;
279
- step *= shape[i];
258
+ assert$1(rank === order.length, "Order length must match the number of dimensions.");
259
+ let step = 1;
260
+ let stride = new Array(rank);
261
+ for (let i = order.length - 1; i >= 0; i--) {
262
+ stride[order[i]] = step;
263
+ step *= shape[order[i]];
280
264
  }
281
265
  return stride;
282
266
  }
@@ -291,20 +275,12 @@ function create_chunk_key_encoder({ name, configuration }) {
291
275
  }
292
276
  throw new Error(`Unknown chunk key encoding: ${name}`);
293
277
  }
294
- function get_array_order(codecs) {
295
- var _a2;
296
- const maybe_transpose_codec = codecs.find((c) => c.name === "transpose");
297
- return ((_a2 = maybe_transpose_codec == null ? void 0 : maybe_transpose_codec.configuration) == null ? void 0 : _a2.order) === "F" ? "F" : "C";
298
- }
299
- const endian_regex = /^([<|>])(.*)$/;
300
278
  function coerce_dtype(dtype) {
301
279
  if (dtype === "|O") {
302
280
  return { data_type: "v2:object" };
303
281
  }
304
- let match = dtype.match(endian_regex);
305
- if (!match) {
306
- throw new Error(`Invalid dtype: ${dtype}`);
307
- }
282
+ let match = dtype.match(/^([<|>])(.*)$/);
283
+ assert$1(match, `Invalid dtype: ${dtype}`);
308
284
  let [, endian, rest] = match;
309
285
  let data_type = {
310
286
  b1: "bool",
@@ -316,12 +292,11 @@ function coerce_dtype(dtype) {
316
292
  u4: "uint32",
317
293
  i8: "int64",
318
294
  u8: "uint64",
295
+ f2: "float16",
319
296
  f4: "float32",
320
297
  f8: "float64"
321
298
  }[rest] ?? (rest.startsWith("S") || rest.startsWith("U") ? `v2:${rest}` : void 0);
322
- if (!data_type) {
323
- throw new Error(`Unsupported or unknown dtype: ${dtype}`);
324
- }
299
+ assert$1(data_type, `Unsupported or unknown dtype: ${dtype}`);
325
300
  if (endian === "|") {
326
301
  return { data_type };
327
302
  }
@@ -399,6 +374,40 @@ function ensure_correct_scalar(metadata) {
399
374
  }
400
375
  return metadata.fill_value;
401
376
  }
377
+ function rethrow_unless(error, ...errors) {
378
+ if (!errors.some((ErrorClass) => error instanceof ErrorClass)) {
379
+ throw error;
380
+ }
381
+ }
382
+ function assert$1(expression, msg = "") {
383
+ if (!expression) {
384
+ throw new Error(msg);
385
+ }
386
+ }
387
+ class BitroundCodec {
388
+ constructor(configuration, _meta) {
389
+ __publicField(this, "kind", "array_to_array");
390
+ assert$1(configuration.keepbits >= 0, "keepbits must be zero or positive");
391
+ }
392
+ static fromConfig(configuration, meta) {
393
+ return new BitroundCodec(configuration, meta);
394
+ }
395
+ /**
396
+ * Encode a chunk of data with bit-rounding.
397
+ * @param _arr - The chunk to encode
398
+ */
399
+ encode(_arr) {
400
+ throw new Error("`BitroundCodec.encode` is not implemented. Please open an issue at https://github.com/manzt/zarrita.js/issues.");
401
+ }
402
+ /**
403
+ * Decode a chunk of data (no-op).
404
+ * @param arr - The chunk to decode
405
+ * @returns The decoded chunk
406
+ */
407
+ decode(arr) {
408
+ return arr;
409
+ }
410
+ }
402
411
  const LITTLE_ENDIAN_OS = system_is_little_endian();
403
412
  function system_is_little_endian() {
404
413
  const a = new Uint32Array([305419896]);
@@ -414,7 +423,7 @@ function bytes_per_element(TypedArray) {
414
423
  const _BytesCodec = class {
415
424
  constructor(configuration, meta) {
416
425
  __publicField(this, "kind", "array_to_bytes");
417
- __privateAdd(this, _strides, void 0);
426
+ __privateAdd(this, _stride, void 0);
418
427
  __privateAdd(this, _TypedArray, void 0);
419
428
  __privateAdd(this, _BYTES_PER_ELEMENT, void 0);
420
429
  __privateAdd(this, _shape, void 0);
@@ -422,7 +431,7 @@ const _BytesCodec = class {
422
431
  __privateSet(this, _endian, configuration == null ? void 0 : configuration.endian);
423
432
  __privateSet(this, _TypedArray, get_ctr(meta.data_type));
424
433
  __privateSet(this, _shape, meta.shape);
425
- __privateSet(this, _strides, get_strides(meta.shape, get_array_order(meta.codecs)));
434
+ __privateSet(this, _stride, get_strides(meta.shape, "C"));
426
435
  const sample = new (__privateGet(this, _TypedArray))(0);
427
436
  __privateSet(this, _BYTES_PER_ELEMENT, sample.BYTES_PER_ELEMENT);
428
437
  }
@@ -443,12 +452,12 @@ const _BytesCodec = class {
443
452
  return {
444
453
  data: new (__privateGet(this, _TypedArray))(bytes.buffer, bytes.byteOffset, bytes.byteLength / __privateGet(this, _BYTES_PER_ELEMENT)),
445
454
  shape: __privateGet(this, _shape),
446
- stride: __privateGet(this, _strides)
455
+ stride: __privateGet(this, _stride)
447
456
  };
448
457
  }
449
458
  };
450
459
  let BytesCodec = _BytesCodec;
451
- _strides = new WeakMap();
460
+ _stride = new WeakMap();
452
461
  _TypedArray = new WeakMap();
453
462
  _BYTES_PER_ELEMENT = new WeakMap();
454
463
  _shape = new WeakMap();
@@ -468,15 +477,9 @@ class Crc32cCodec {
468
477
  }
469
478
  }
470
479
  function throw_on_nan_replacer(_key, value) {
471
- if (Number.isNaN(value)) {
472
- throw new Error("JsonCodec allow_nan is false but NaN was encountered during encoding.");
473
- }
474
- if (value === Number.POSITIVE_INFINITY) {
475
- throw new Error("JsonCodec allow_nan is false but Infinity was encountered during encoding.");
476
- }
477
- if (value === Number.NEGATIVE_INFINITY) {
478
- throw new Error("JsonCodec allow_nan is false but -Infinity was encountered during encoding.");
479
- }
480
+ assert$1(!Number.isNaN(value), "JsonCodec allow_nan is false but NaN was encountered during encoding.");
481
+ assert$1(value !== Number.POSITIVE_INFINITY, "JsonCodec allow_nan is false but Infinity was encountered during encoding.");
482
+ assert$1(value !== Number.NEGATIVE_INFINITY, "JsonCodec allow_nan is false but -Infinity was encountered during encoding.");
480
483
  return value;
481
484
  }
482
485
  function sort_keys_replacer(_key, value) {
@@ -518,13 +521,9 @@ const _JsonCodec = class {
518
521
  }
519
522
  encode(buf) {
520
523
  const { indent, encoding, ensure_ascii, check_circular, allow_nan, sort_keys } = __privateGet(this, _encoder_config);
521
- if (encoding !== "utf-8") {
522
- throw new Error("JsonCodec does not yet support non-utf-8 encoding.");
523
- }
524
+ assert$1(encoding === "utf-8", "JsonCodec does not yet support non-utf-8 encoding.");
524
525
  const replacer_functions = [];
525
- if (!check_circular) {
526
- throw new Error("JsonCodec does not yet support skipping the check for circular references during encoding.");
527
- }
526
+ assert$1(check_circular, "JsonCodec does not yet support skipping the check for circular references during encoding.");
528
527
  if (!allow_nan) {
529
528
  replacer_functions.push(throw_on_nan_replacer);
530
529
  }
@@ -556,15 +555,11 @@ const _JsonCodec = class {
556
555
  }
557
556
  decode(bytes) {
558
557
  const { strict } = __privateGet(this, _decoder_config);
559
- if (!strict) {
560
- throw new Error("JsonCodec does not yet support non-strict decoding.");
561
- }
558
+ assert$1(strict, "JsonCodec does not yet support non-strict decoding.");
562
559
  const items = json_decode_object(bytes);
563
560
  const shape = items.pop();
564
561
  items.pop();
565
- if (!shape) {
566
- throw new Error("0D not implemented for JsonCodec.");
567
- }
562
+ assert$1(shape, "0D not implemented for JsonCodec.");
568
563
  const stride = get_strides(shape, "C");
569
564
  const data = items;
570
565
  return { data, shape, stride };
@@ -631,39 +626,72 @@ function convert_array_order(src, target) {
631
626
  }
632
627
  return out;
633
628
  }
634
- function get_order(arr) {
635
- if (!arr.stride)
636
- return "C";
637
- let row_major_strides = get_strides(arr.shape, "C");
638
- return arr.stride.every((s, i) => s === row_major_strides[i]) ? "C" : "F";
629
+ function get_order(chunk) {
630
+ let rank = chunk.shape.length;
631
+ assert$1(rank === chunk.stride.length, "Shape and stride must have the same length.");
632
+ return chunk.stride.map((s, i) => ({ stride: s, index: i })).sort((a, b) => b.stride - a.stride).map((entry) => entry.index);
639
633
  }
640
- class TransposeCodec {
641
- constructor(configuration) {
642
- __publicField(this, "configuration");
634
+ function matches_order(chunk, target) {
635
+ let source = get_order(chunk);
636
+ assert$1(source.length === target.length, "Orders must match");
637
+ return source.every((dim, i) => dim === target[i]);
638
+ }
639
+ const _TransposeCodec = class {
640
+ constructor(configuration, meta) {
643
641
  __publicField(this, "kind", "array_to_array");
644
- this.configuration = configuration;
642
+ __privateAdd(this, _order, void 0);
643
+ __privateAdd(this, _inverseOrder, void 0);
644
+ let value = configuration.order ?? "C";
645
+ let rank = meta.shape.length;
646
+ let order = new Array(rank);
647
+ let inverseOrder = new Array(rank);
648
+ if (value === "C") {
649
+ for (let i = 0; i < rank; ++i) {
650
+ order[i] = i;
651
+ inverseOrder[i] = i;
652
+ }
653
+ } else if (value === "F") {
654
+ for (let i = 0; i < rank; ++i) {
655
+ order[i] = rank - i - 1;
656
+ inverseOrder[i] = rank - i - 1;
657
+ }
658
+ } else {
659
+ order = value;
660
+ order.forEach((x, i) => {
661
+ assert$1(inverseOrder[x] === void 0, `Invalid permutation: ${JSON.stringify(value)}`);
662
+ inverseOrder[x] = i;
663
+ });
664
+ }
665
+ __privateSet(this, _order, order);
666
+ __privateSet(this, _inverseOrder, inverseOrder);
645
667
  }
646
- static fromConfig(configuration) {
647
- return new TransposeCodec(configuration);
668
+ static fromConfig(configuration, meta) {
669
+ return new _TransposeCodec(configuration, meta);
648
670
  }
649
671
  encode(arr) {
650
- var _a2, _b2;
651
- if (get_order(arr) === ((_a2 = this.configuration) == null ? void 0 : _a2.order)) {
672
+ if (matches_order(arr, __privateGet(this, _inverseOrder))) {
652
673
  return arr;
653
674
  }
654
- return convert_array_order(arr, ((_b2 = this.configuration) == null ? void 0 : _b2.order) ?? "C");
675
+ return convert_array_order(arr, __privateGet(this, _inverseOrder));
655
676
  }
656
677
  decode(arr) {
657
- return arr;
678
+ return {
679
+ data: arr.data,
680
+ shape: arr.shape,
681
+ stride: get_strides(arr.shape, __privateGet(this, _order))
682
+ };
658
683
  }
659
- }
684
+ };
685
+ let TransposeCodec = _TransposeCodec;
686
+ _order = new WeakMap();
687
+ _inverseOrder = new WeakMap();
660
688
  const _VLenUTF8 = class {
661
689
  constructor(shape) {
662
690
  __publicField(this, "kind", "array_to_bytes");
663
691
  __privateAdd(this, _shape2, void 0);
664
- __privateAdd(this, _strides2, void 0);
692
+ __privateAdd(this, _strides, void 0);
665
693
  __privateSet(this, _shape2, shape);
666
- __privateSet(this, _strides2, get_strides(shape, "C"));
694
+ __privateSet(this, _strides, get_strides(shape, "C"));
667
695
  }
668
696
  static fromConfig(_, meta) {
669
697
  return new _VLenUTF8(meta.shape);
@@ -682,14 +710,14 @@ const _VLenUTF8 = class {
682
710
  data[i] = decoder.decode(bytes.buffer.slice(pos, pos + item_length));
683
711
  pos += item_length;
684
712
  }
685
- return { data, shape: __privateGet(this, _shape2), stride: __privateGet(this, _strides2) };
713
+ return { data, shape: __privateGet(this, _shape2), stride: __privateGet(this, _strides) };
686
714
  }
687
715
  };
688
716
  let VLenUTF8 = _VLenUTF8;
689
717
  _shape2 = new WeakMap();
690
- _strides2 = new WeakMap();
718
+ _strides = new WeakMap();
691
719
  function create_default_registry() {
692
- return (/* @__PURE__ */ new Map()).set("blosc", () => import("./blosc-537fd004.js").then((m) => m.default)).set("gzip", () => import("./gzip-6a24f0fe.js").then((m) => m.default)).set("lz4", () => import("./lz4-bbd18009.js").then((m) => m.default)).set("zlib", () => import("./zlib-175cd38d.js").then((m) => m.default)).set("zstd", () => import("./zstd-ec5a40b8.js").then((m) => m.default)).set("transpose", () => TransposeCodec).set("bytes", () => BytesCodec).set("crc32c", () => Crc32cCodec).set("vlen-utf8", () => VLenUTF8).set("json2", () => JsonCodec);
720
+ return (/* @__PURE__ */ new Map()).set("blosc", () => import("./blosc-537fd004.js").then((m) => m.default)).set("gzip", () => import("./gzip-6a24f0fe.js").then((m) => m.default)).set("lz4", () => import("./lz4-bbd18009.js").then((m) => m.default)).set("zlib", () => import("./zlib-175cd38d.js").then((m) => m.default)).set("zstd", () => import("./zstd-561fda0e.js").then((m) => m.default)).set("transpose", () => TransposeCodec).set("bytes", () => BytesCodec).set("crc32c", () => Crc32cCodec).set("vlen-utf8", () => VLenUTF8).set("json2", () => JsonCodec).set("bitround", () => BitroundCodec);
693
721
  }
694
722
  const registry = create_default_registry();
695
723
  function create_codec_pipeline(chunk_metadata) {
@@ -725,9 +753,7 @@ async function load_codecs(chunk_meta) {
725
753
  let promises = chunk_meta.codecs.map(async (meta) => {
726
754
  var _a2;
727
755
  let Codec = await ((_a2 = registry.get(meta.name)) == null ? void 0 : _a2());
728
- if (!Codec) {
729
- throw new Error(`Unknown codec: ${meta.name}`);
730
- }
756
+ assert$1(Codec, `Unknown codec: ${meta.name}`);
731
757
  return { Codec, meta };
732
758
  });
733
759
  let array_to_array = [];
@@ -747,9 +773,7 @@ async function load_codecs(chunk_meta) {
747
773
  }
748
774
  }
749
775
  if (!array_to_bytes) {
750
- if (!is_typed_array_like_meta(chunk_meta)) {
751
- throw new Error(`Cannot encode ${chunk_meta.data_type} to bytes without a codec`);
752
- }
776
+ assert$1(is_typed_array_like_meta(chunk_meta), `Cannot encode ${chunk_meta.data_type} to bytes without a codec`);
753
777
  array_to_bytes = BytesCodec.fromConfig({ endian: "little" }, chunk_meta);
754
778
  }
755
779
  return { array_to_array, array_to_bytes, bytes_to_bytes };
@@ -759,9 +783,7 @@ function is_typed_array_like_meta(meta) {
759
783
  }
760
784
  const MAX_BIG_UINT = 18446744073709551615n;
761
785
  function create_sharded_chunk_getter(location, shard_shape, encode_shard_key, sharding_config) {
762
- if (location.store.getRange === void 0) {
763
- throw new Error("Store does not support range requests");
764
- }
786
+ assert$1(location.store.getRange, "Store does not support range requests");
765
787
  let get_range = location.store.getRange.bind(location.store);
766
788
  let index_shape = shard_shape.map((d, i) => d / sharding_config.chunk_shape[i]);
767
789
  let index_codec = create_codec_pipeline({
@@ -827,6 +849,11 @@ class Group extends Location {
827
849
  }
828
850
  }
829
851
  _metadata = new WeakMap();
852
+ function get_array_order(codecs) {
853
+ var _a2;
854
+ const maybe_transpose_codec = codecs.find((c) => c.name === "transpose");
855
+ return ((_a2 = maybe_transpose_codec == null ? void 0 : maybe_transpose_codec.configuration) == null ? void 0 : _a2.order) ?? "C";
856
+ }
830
857
  const CONTEXT_MARKER = Symbol("zarrita.context");
831
858
  function get_context(obj) {
832
859
  return obj[CONTEXT_MARKER];
@@ -849,8 +876,8 @@ function create_context(location, metadata) {
849
876
  shape: configuration.chunk_shape,
850
877
  codecs: configuration.codecs
851
878
  }),
852
- get_strides(shape, order) {
853
- return get_strides(shape, order ?? native_order2);
879
+ get_strides(shape) {
880
+ return get_strides(shape, native_order2);
854
881
  },
855
882
  get_chunk_bytes: create_sharded_chunk_getter(location, metadata.chunk_grid.configuration.chunk_shape, shared_context.encode_chunk_key, configuration)
856
883
  };
@@ -865,8 +892,8 @@ function create_context(location, metadata) {
865
892
  shape: metadata.chunk_grid.configuration.chunk_shape,
866
893
  codecs: metadata.codecs
867
894
  }),
868
- get_strides(shape, order) {
869
- return get_strides(shape, order ?? native_order);
895
+ get_strides(shape) {
896
+ return get_strides(shape, native_order);
870
897
  },
871
898
  async get_chunk_bytes(chunk_coords, options) {
872
899
  let chunk_key = shared_context.encode_chunk_key(chunk_coords);
@@ -969,9 +996,8 @@ async function open_v2(location, options = {}) {
969
996
  if (options.kind === "group")
970
997
  return open_group_v2(loc, attrs);
971
998
  return open_array_v2(loc, attrs).catch((err) => {
972
- if (err instanceof NodeNotFoundError)
973
- return open_group_v2(loc, attrs);
974
- throw err;
999
+ rethrow_unless(err, NodeNotFoundError);
1000
+ return open_group_v2(loc, attrs);
975
1001
  });
976
1002
  }
977
1003
  async function open_array_v2(location, attrs) {
@@ -1029,10 +1055,8 @@ async function open(location, options = {}) {
1029
1055
  let open_primary = version_max === "v2" ? open.v2 : open.v3;
1030
1056
  let open_secondary = version_max === "v2" ? open.v3 : open.v2;
1031
1057
  return open_primary(location, options).catch((err) => {
1032
- if (err instanceof NodeNotFoundError) {
1033
- return open_secondary(location, options);
1034
- }
1035
- throw err;
1058
+ rethrow_unless(err, NodeNotFoundError);
1059
+ return open_secondary(location, options);
1036
1060
  });
1037
1061
  }
1038
1062
  open.v2 = open_v2;
@@ -1270,7 +1294,7 @@ async function get$2(arr, selection, opts2, setter2) {
1270
1294
  shape: arr.shape,
1271
1295
  chunk_shape: arr.chunks
1272
1296
  });
1273
- let out = setter2.prepare(new context.TypedArray(indexer.shape.reduce((a, b) => a * b, 1)), indexer.shape, context.get_strides(indexer.shape, opts2.order));
1297
+ let out = setter2.prepare(new context.TypedArray(indexer.shape.reduce((a, b) => a * b, 1)), indexer.shape, context.get_strides(indexer.shape));
1274
1298
  let queue = ((_a2 = opts2.create_queue) == null ? void 0 : _a2.call(opts2)) ?? create_queue();
1275
1299
  for (const { chunk_coords, mapping } of indexer) {
1276
1300
  queue.add(async () => {
@@ -1468,6 +1492,10 @@ function merge_init(storeOverrides, requestOverrides) {
1468
1492
  }
1469
1493
  };
1470
1494
  }
1495
+ function assert(expression, msg = "") {
1496
+ if (!expression)
1497
+ throw new Error(msg);
1498
+ }
1471
1499
  function resolve(root2, path) {
1472
1500
  const base = typeof root2 === "string" ? new URL(root2) : root2;
1473
1501
  if (!base.pathname.endsWith("/")) {
@@ -1478,7 +1506,7 @@ function resolve(root2, path) {
1478
1506
  return resolved;
1479
1507
  }
1480
1508
  async function handle_response(response) {
1481
- if (response.status === 404 || response.status === 403) {
1509
+ if (response.status === 404) {
1482
1510
  return void 0;
1483
1511
  }
1484
1512
  if (response.status === 200 || response.status === 206) {
@@ -2413,9 +2441,7 @@ class HTTPRangeReader {
2413
2441
  ...__privateGet(this, _overrides2),
2414
2442
  method: "HEAD"
2415
2443
  });
2416
- if (!req.ok) {
2417
- throw new Error(`failed http request ${this.url}, status: ${req.status}: ${req.statusText}`);
2418
- }
2444
+ assert(req.ok, `failed http request ${this.url}, status: ${req.status}: ${req.statusText}`);
2419
2445
  this.length = Number(req.headers.get("content-length"));
2420
2446
  if (Number.isNaN(this.length)) {
2421
2447
  throw Error("could not get length");
@@ -2428,9 +2454,7 @@ class HTTPRangeReader {
2428
2454
  return new Uint8Array(0);
2429
2455
  }
2430
2456
  const req = await fetch_range(this.url, offset, size, __privateGet(this, _overrides2));
2431
- if (!req.ok) {
2432
- throw new Error(`failed http request ${this.url}, status: ${req.status} offset: ${offset} size: ${size}: ${req.statusText}`);
2433
- }
2457
+ assert(req.ok, `failed http request ${this.url}, status: ${req.status} offset: ${offset} size: ${size}: ${req.statusText}`);
2434
2458
  return new Uint8Array(await req.arrayBuffer());
2435
2459
  }
2436
2460
  }
@@ -2720,71 +2744,6 @@ _refs = new WeakMap();
2720
2744
  _opts = new WeakMap();
2721
2745
  _overrides3 = new WeakMap();
2722
2746
  const ReferenceStore$1 = ReferenceStore;
2723
- function zarrOpenRoot(url, fileType, opts2) {
2724
- let store;
2725
- if (fileType && fileType.endsWith(".zip")) {
2726
- store = ZipFileStore$1.fromUrl(url, { overrides: opts2 == null ? void 0 : opts2.requestInit });
2727
- } else if (fileType && fileType.endsWith(".h5ad")) {
2728
- if (!(opts2 == null ? void 0 : opts2.refSpecUrl)) {
2729
- throw new Error("refSpecUrl is required for H5AD files");
2730
- }
2731
- const referenceSpecPromise = fetch(opts2.refSpecUrl).then((res) => res.json()).then((referenceSpec) => Object.fromEntries(
2732
- // We want ReferenceStore.fromSpec to use our `target` URL option regardless
2733
- // of what target URL(s) are specified in the reference spec JSON.
2734
- // Reference: https://github.com/manzt/zarrita.js/pull/155
2735
- Object.entries(referenceSpec).map(([key, entry]) => {
2736
- if (Array.isArray(entry) && entry.length >= 1) {
2737
- entry[0] = null;
2738
- }
2739
- return [key, entry];
2740
- })
2741
- ));
2742
- store = ReferenceStore$1.fromSpec(referenceSpecPromise, { target: url, overrides: opts2 == null ? void 0 : opts2.requestInit });
2743
- } else {
2744
- store = new FetchStore$1(url, { overrides: opts2 == null ? void 0 : opts2.requestInit });
2745
- }
2746
- return root$2(store);
2747
- }
2748
- class ZarrDataSource {
2749
- /**
2750
- * @param {DataSourceParams & { refSpecUrl?: string }} params The parameters object.
2751
- */
2752
- constructor({ url, requestInit: requestInit2, refSpecUrl, store, fileType }) {
2753
- if (store) {
2754
- this.storeRoot = root$2(store);
2755
- } else if (url) {
2756
- this.storeRoot = zarrOpenRoot(url, fileType, { requestInit: requestInit2, refSpecUrl });
2757
- } else {
2758
- throw new Error("Either a store or a URL must be provided to the ZarrDataSource constructor.");
2759
- }
2760
- }
2761
- /**
2762
- *
2763
- * @param {string} path
2764
- * @returns {ZarrLocation<Readable>}
2765
- */
2766
- getStoreRoot(path) {
2767
- return this.storeRoot.resolve(path);
2768
- }
2769
- /**
2770
- * Method for accessing JSON attributes, relative to the store root.
2771
- * @param {string} key A path to the item.
2772
- * @param {ZarrLocation<Readable>|null} storeRootParam An optional location,
2773
- * which if provided will override the default store root.
2774
- * @returns {Promise<any>} This async function returns a promise
2775
- * that resolves to the parsed JSON if successful.
2776
- * @throws This may throw an error.
2777
- */
2778
- async getJson(key, storeRootParam = null) {
2779
- const { storeRoot } = this;
2780
- const storeRootToUse = storeRootParam || storeRoot;
2781
- let dirKey = key;
2782
- if (key.endsWith(".zattrs") || key.endsWith(".zarray") || key.endsWith(".zgroup")) {
2783
- dirKey = key.substring(0, key.length - 8);
2784
- }
2785
- return (await open(storeRootToUse.resolve(dirKey))).attrs;
2786
- }
2787
- }
2788
2747
  var commonjsGlobal = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : {};
2789
2748
  function getDefaultExportFromCjs(x) {
2790
2749
  return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x;
@@ -3070,6 +3029,95 @@ var loglevel = { exports: {} };
3070
3029
  })(loglevel);
3071
3030
  var loglevelExports = loglevel.exports;
3072
3031
  const log = /* @__PURE__ */ getDefaultExportFromCjs(loglevelExports);
3032
+ const DEFAULT_DEBUG_MODE = false;
3033
+ let GLOBAL_DEBUG_MODE = DEFAULT_DEBUG_MODE;
3034
+ function getDebugMode() {
3035
+ return GLOBAL_DEBUG_MODE;
3036
+ }
3037
+ class RelaxedFetchStore extends FetchStore$1 {
3038
+ // This allows returning `undefined` for 403 responses,
3039
+ // as opposed to completely erroring.
3040
+ // Needed due to https://github.com/manzt/zarrita.js/pull/212
3041
+ // In the future, perhaps we could contribute a way to pass a
3042
+ // custom error handling function or additional options
3043
+ // to the zarrita FetchStore so that a subclass is not required.
3044
+ async get(key, options = {}) {
3045
+ var _a2;
3046
+ try {
3047
+ return await super.get(key, options);
3048
+ } catch (e) {
3049
+ if (((_a2 = e == null ? void 0 : e.message) == null ? void 0 : _a2.startsWith("Unexpected response status 403")) && !getDebugMode()) {
3050
+ return void 0;
3051
+ }
3052
+ throw e;
3053
+ }
3054
+ }
3055
+ }
3056
+ function zarrOpenRoot(url, fileType, opts2) {
3057
+ let store;
3058
+ if (fileType && fileType.endsWith(".zip")) {
3059
+ store = ZipFileStore$1.fromUrl(url, { overrides: opts2 == null ? void 0 : opts2.requestInit });
3060
+ } else if (fileType && fileType.endsWith(".h5ad")) {
3061
+ if (!(opts2 == null ? void 0 : opts2.refSpecUrl)) {
3062
+ throw new Error("refSpecUrl is required for H5AD files");
3063
+ }
3064
+ const referenceSpecPromise = fetch(opts2.refSpecUrl).then((res) => res.json()).then((referenceSpec) => Object.fromEntries(
3065
+ // We want ReferenceStore.fromSpec to use our `target` URL option regardless
3066
+ // of what target URL(s) are specified in the reference spec JSON.
3067
+ // Reference: https://github.com/manzt/zarrita.js/pull/155
3068
+ Object.entries(referenceSpec).map(([key, entry]) => {
3069
+ if (Array.isArray(entry) && entry.length >= 1) {
3070
+ entry[0] = null;
3071
+ }
3072
+ return [key, entry];
3073
+ })
3074
+ ));
3075
+ store = ReferenceStore$1.fromSpec(referenceSpecPromise, { target: url, overrides: opts2 == null ? void 0 : opts2.requestInit });
3076
+ } else {
3077
+ store = new RelaxedFetchStore(url, { overrides: opts2 == null ? void 0 : opts2.requestInit });
3078
+ }
3079
+ return root$2(store);
3080
+ }
3081
+ class ZarrDataSource {
3082
+ /**
3083
+ * @param {DataSourceParams & { refSpecUrl?: string }} params The parameters object.
3084
+ */
3085
+ constructor({ url, requestInit: requestInit2, refSpecUrl, store, fileType }) {
3086
+ if (store) {
3087
+ this.storeRoot = root$2(store);
3088
+ } else if (url) {
3089
+ this.storeRoot = zarrOpenRoot(url, fileType, { requestInit: requestInit2, refSpecUrl });
3090
+ } else {
3091
+ throw new Error("Either a store or a URL must be provided to the ZarrDataSource constructor.");
3092
+ }
3093
+ }
3094
+ /**
3095
+ *
3096
+ * @param {string} path
3097
+ * @returns {ZarrLocation<Readable>}
3098
+ */
3099
+ getStoreRoot(path) {
3100
+ return this.storeRoot.resolve(path);
3101
+ }
3102
+ /**
3103
+ * Method for accessing JSON attributes, relative to the store root.
3104
+ * @param {string} key A path to the item.
3105
+ * @param {ZarrLocation<Readable>|null} storeRootParam An optional location,
3106
+ * which if provided will override the default store root.
3107
+ * @returns {Promise<any>} This async function returns a promise
3108
+ * that resolves to the parsed JSON if successful.
3109
+ * @throws This may throw an error.
3110
+ */
3111
+ async getJson(key, storeRootParam = null) {
3112
+ const { storeRoot } = this;
3113
+ const storeRootToUse = storeRootParam || storeRoot;
3114
+ let dirKey = key;
3115
+ if (key.endsWith(".zattrs") || key.endsWith(".zarray") || key.endsWith(".zgroup")) {
3116
+ dirKey = key.substring(0, key.length - 8);
3117
+ }
3118
+ return (await open(storeRootToUse.resolve(dirKey))).attrs;
3119
+ }
3120
+ }
3073
3121
  function dirname(path) {
3074
3122
  const arr = path.split("/");
3075
3123
  arr.pop();
@@ -3992,8 +4040,13 @@ const ViewType$1 = {
3992
4040
  FEATURE_VALUE_HISTOGRAM: "featureValueHistogram",
3993
4041
  DOT_PLOT: "dotPlot",
3994
4042
  FEATURE_BAR_PLOT: "featureBarPlot",
4043
+ VOLCANO_PLOT: "volcanoPlot",
4044
+ OBS_SET_COMPOSITION_BAR_PLOT: "obsSetCompositionBarPlot",
4045
+ FEATURE_SET_ENRICHMENT_BAR_PLOT: "featureSetEnrichmentBarPlot",
3995
4046
  BIOMARKER_SELECT: "biomarkerSelect",
4047
+ COMPARATIVE_HEADING: "comparativeHeading",
3996
4048
  LINK_CONTROLLER: "linkController",
4049
+ NEUROGLANCER: "neuroglancer",
3997
4050
  DUAL_SCATTERPLOT: "dualScatterplot",
3998
4051
  TREEMAP: "treemap"
3999
4052
  };
@@ -4011,7 +4064,11 @@ const DataType$1 = {
4011
4064
  OBS_POINTS: "obsPoints",
4012
4065
  OBS_LOCATIONS: "obsLocations",
4013
4066
  SAMPLE_SETS: "sampleSets",
4014
- SAMPLE_EDGES: "sampleEdges"
4067
+ SAMPLE_EDGES: "sampleEdges",
4068
+ COMPARISON_METADATA: "comparisonMetadata",
4069
+ FEATURE_STATS: "featureStats",
4070
+ FEATURE_SET_STATS: "featureSetStats",
4071
+ OBS_SET_STATS: "obsSetStats"
4015
4072
  };
4016
4073
  const FileType$1 = {
4017
4074
  // Joint file types
@@ -4050,6 +4107,10 @@ const FileType$1 = {
4050
4107
  FEATURE_LABELS_ANNDATA_ZARR: "featureLabels.anndata.zarr",
4051
4108
  SAMPLE_EDGES_ANNDATA_ZARR: "sampleEdges.anndata.zarr",
4052
4109
  SAMPLE_SETS_ANNDATA_ZARR: "sampleSets.anndata.zarr",
4110
+ COMPARISON_METADATA_ANNDATA_ZARR: "comparisonMetadata.anndata.zarr",
4111
+ COMPARATIVE_FEATURE_STATS_ANNDATA_ZARR: "comparativeFeatureStats.anndata.zarr",
4112
+ COMPARATIVE_FEATURE_SET_STATS_ANNDATA_ZARR: "comparativeFeatureSetStats.anndata.zarr",
4113
+ COMPARATIVE_OBS_SET_STATS_ANNDATA_ZARR: "comparativeObsSetStats.anndata.zarr",
4053
4114
  // AnnData - zipped
4054
4115
  OBS_FEATURE_MATRIX_ANNDATA_ZARR_ZIP: "obsFeatureMatrix.anndata.zarr.zip",
4055
4116
  OBS_FEATURE_COLUMNS_ANNDATA_ZARR_ZIP: "obsFeatureColumns.anndata.zarr.zip",
@@ -4063,6 +4124,10 @@ const FileType$1 = {
4063
4124
  FEATURE_LABELS_ANNDATA_ZARR_ZIP: "featureLabels.anndata.zarr.zip",
4064
4125
  SAMPLE_EDGES_ANNDATA_ZARR_ZIP: "sampleEdges.anndata.zarr.zip",
4065
4126
  SAMPLE_SETS_ANNDATA_ZARR_ZIP: "sampleSets.anndata.zarr.zip",
4127
+ COMPARISON_METADATA_ANNDATA_ZARR_ZIP: "comparisonMetadata.anndata.zarr.zip",
4128
+ COMPARATIVE_FEATURE_STATS_ANNDATA_ZARR_ZIP: "comparativeFeatureStats.anndata.zarr.zip",
4129
+ COMPARATIVE_FEATURE_SET_STATS_ANNDATA_ZARR_ZIP: "comparativeFeatureSetStats.anndata.zarr.zip",
4130
+ COMPARATIVE_OBS_SET_STATS_ANNDATA_ZARR_ZIP: "comparativeObsSetStats.anndata.zarr.zip",
4066
4131
  // AnnData - h5ad via reference spec
4067
4132
  OBS_FEATURE_MATRIX_ANNDATA_H5AD: "obsFeatureMatrix.anndata.h5ad",
4068
4133
  OBS_FEATURE_COLUMNS_ANNDATA_H5AD: "obsFeatureColumns.anndata.h5ad",
@@ -4076,6 +4141,10 @@ const FileType$1 = {
4076
4141
  FEATURE_LABELS_ANNDATA_H5AD: "featureLabels.anndata.h5ad",
4077
4142
  SAMPLE_EDGES_ANNDATA_H5AD: "sampleEdges.anndata.h5ad",
4078
4143
  SAMPLE_SETS_ANNDATA_H5AD: "sampleSets.anndata.h5ad",
4144
+ COMPARISON_METADATA_ANNDATA_H5AD: "comparisonMetadata.anndata.h5ad",
4145
+ COMPARATIVE_FEATURE_STATS_ANNDATA_H5AD: "comparativeFeatureStats.anndata.h5ad",
4146
+ COMPARATIVE_FEATURE_SET_STATS_ANNDATA_H5AD: "comparativeFeatureSetStats.anndata.h5ad",
4147
+ COMPARATIVE_OBS_SET_STATS_ANNDATA_H5AD: "comparativeObsSetStats.anndata.h5ad",
4079
4148
  // SpatialData
4080
4149
  IMAGE_SPATIALDATA_ZARR: "image.spatialdata.zarr",
4081
4150
  LABELS_SPATIALDATA_ZARR: "labels.spatialdata.zarr",
@@ -4274,6 +4343,11 @@ const CoordinationType$1 = {
4274
4343
  EMBEDDING_CONTOUR_PERCENTILES: "embeddingContourPercentiles",
4275
4344
  CONTOUR_COLOR_ENCODING: "contourColorEncoding",
4276
4345
  CONTOUR_COLOR: "contourColor",
4346
+ // For volcano plot:
4347
+ FEATURE_POINT_SIGNIFICANCE_THRESHOLD: "featurePointSignificanceThreshold",
4348
+ FEATURE_LABEL_SIGNIFICANCE_THRESHOLD: "featureLabelSignificanceThreshold",
4349
+ FEATURE_POINT_FOLD_CHANGE_THRESHOLD: "featurePointFoldChangeThreshold",
4350
+ FEATURE_LABEL_FOLD_CHANGE_THRESHOLD: "featureLabelFoldChangeThreshold",
4277
4351
  // Treemap
4278
4352
  HIERARCHY_LEVELS: "hierarchyLevels"
4279
4353
  };
@@ -13637,6 +13711,42 @@ const annDataConvenienceObsEmbeddingItem = z.object({
13637
13711
  dims: z.array(z.number()).optional(),
13638
13712
  embeddingType: z.string()
13639
13713
  });
13714
+ z.object({
13715
+ path: z.string().describe("Path to the comparison metadata, such as /uns/comparison_metadata")
13716
+ });
13717
+ z.object({
13718
+ // TODO: implement a featureStats.anndata.zarr loader
13719
+ // which does not depend on comparisonMetadata
13720
+ // (instead, would point directly to the root of
13721
+ // the dataframe containing a set of diff exp results)
13722
+ // path: z.string().describe('Path to the dataframe containing the results.'),
13723
+ metadataPath: z.string().describe("Path to the comparison metadata."),
13724
+ indexColumn: z.string().optional().describe("Provide a column to use for the feature index, if different than the default dataframe index."),
13725
+ pValueColumn: z.string(),
13726
+ foldChangeColumn: z.string(),
13727
+ pValueTransformation: z.enum(["minuslog10"]).optional(),
13728
+ pValueAdjusted: z.boolean().optional(),
13729
+ foldChangeTransformation: z.enum(["log2"]).optional()
13730
+ });
13731
+ z.object({
13732
+ metadataPath: z.string().describe("Path to the comparison metadata."),
13733
+ indexColumn: z.string().optional().describe("Provide a column to use for the feature set index, if different than the default dataframe index."),
13734
+ termColumn: z.string().optional(),
13735
+ pValueColumn: z.string(),
13736
+ pValueAdjusted: z.boolean().optional(),
13737
+ analysisType: z.string().optional().describe("Optionally, provide an analysis_type name. By default, pertpy_hypergeometric.")
13738
+ });
13739
+ z.object({
13740
+ metadataPath: z.string().describe("Path to the comparison metadata."),
13741
+ indexColumn: z.string().optional().describe("Provide a column to use for the obs set index, if different than the default dataframe index."),
13742
+ interceptExpectedSampleColumn: z.string().describe("If we had a new sample (with no active covariates) with a total number of cells equal to the mean sampling depth of the dataset, then this distribution over the cell types would be most likely."),
13743
+ effectExpectedSampleColumn: z.string().describe("If we had a new sample (with no active covariates) with a total number of cells equal to the mean sampling depth of the dataset, then this distribution over the cell types would be most likely."),
13744
+ foldChangeColumn: z.string().describe("The log-fold change is then calculated between this expected sample and the expected sample with no active covariates from the intercept section."),
13745
+ foldChangeTransformation: z.enum(["log2"]).optional(),
13746
+ isCredibleEffectColumn: z.string().describe("Column which annotates effects as being credible or not (boolean)."),
13747
+ covariateColumn: z.string().describe("Column which defines the covariate used in the analysis."),
13748
+ analysisType: z.string().optional().describe("Optionally, provide an analysis_type name. By default, sccoda_df.")
13749
+ });
13640
13750
  const annDataObsLabels = annDataObs;
13641
13751
  const annDataFeatureLabels = annDataObs;
13642
13752
  const annDataSampleEdges = annDataObs;
@@ -20876,6 +20986,440 @@ class SampleSetsAnndataLoader extends AbstractTwoStepLoader {
20876
20986
  );
20877
20987
  }
20878
20988
  }
20989
+ function isEqualPathPair(pathPairA, pathPairB) {
20990
+ return isEqual(pathPairA[0], pathPairB[0]) && isEqual(pathPairA[1], pathPairB[1]) || isEqual(pathPairA[0], pathPairB[1]) && isEqual(pathPairA[1], pathPairB[0]);
20991
+ }
20992
+ async function loadComparisonMetadata(dataSource, metadataPath) {
20993
+ const metadata = JSON.parse(await dataSource._loadString(metadataPath));
20994
+ if (!(metadata.schema_version === "0.0.1" || metadata.schema_version === "0.0.2")) {
20995
+ throw new Error("Unsupported comparison_metadata schema version.");
20996
+ }
20997
+ return metadata;
20998
+ }
20999
+ class ComparisonMetadataAnndataLoader extends AbstractTwoStepLoader {
21000
+ /**
21001
+ *
21002
+ * @returns {Promise<LoaderResult<ComparisonMetadata>>}
21003
+ */
21004
+ async load() {
21005
+ const { path } = this.options;
21006
+ const superResult = await super.load().catch((reason) => Promise.resolve(reason));
21007
+ if (superResult instanceof AbstractLoaderError) {
21008
+ return Promise.reject(superResult);
21009
+ }
21010
+ const metadata = await loadComparisonMetadata(this.dataSource, path);
21011
+ return Promise.resolve(new LoaderResult(
21012
+ {
21013
+ // Should a more complex class be wrapping this
21014
+ // JSON object to help with downstream querying?
21015
+ comparisonMetadata: metadata
21016
+ },
21017
+ null
21018
+ ));
21019
+ }
21020
+ }
21021
+ let FeatureStatsAnndataLoader$1 = class FeatureStatsAnndataLoader extends AbstractTwoStepLoader {
21022
+ /**
21023
+ * Class method for loading feature string labels.
21024
+ * @returns {Promise<any>} A promise for the array.
21025
+ */
21026
+ async loadSignificances(dfPath) {
21027
+ const { pValueColumn, pValueTransformation } = this.options;
21028
+ const values = await this.dataSource.loadNumeric(`${dfPath}/${pValueColumn}`);
21029
+ if (pValueTransformation === "minuslog10") {
21030
+ values.data = values.data.map((val) => 10 ** -val);
21031
+ }
21032
+ return values.data;
21033
+ }
21034
+ /**
21035
+ * Class method for loading feature string labels.
21036
+ * @returns {Promise<any>} A promise for the array.
21037
+ */
21038
+ async loadFoldChanges(dfPath) {
21039
+ const { foldChangeColumn, foldChangeTransformation } = this.options;
21040
+ const values = await this.dataSource.loadNumeric(`${dfPath}/${foldChangeColumn}`);
21041
+ if (foldChangeTransformation === "log2") {
21042
+ values.data = values.data.map((val) => 2 ** val);
21043
+ }
21044
+ return values.data;
21045
+ }
21046
+ async loadFeatureNames(dfPath) {
21047
+ const { indexColumn } = this.options;
21048
+ if (indexColumn) {
21049
+ return this.dataSource._loadColumn(`${dfPath}/${indexColumn}`);
21050
+ }
21051
+ return this.dataSource.loadDataFrameIndex(dfPath);
21052
+ }
21053
+ async loadDataFrame(dfPath) {
21054
+ const [
21055
+ featureId,
21056
+ featureFoldChange,
21057
+ featureSignificance
21058
+ ] = await Promise.all([
21059
+ this.loadFeatureNames(dfPath),
21060
+ this.loadFoldChanges(dfPath),
21061
+ this.loadSignificances(dfPath)
21062
+ ]);
21063
+ return {
21064
+ featureId,
21065
+ featureFoldChange,
21066
+ featureSignificance
21067
+ };
21068
+ }
21069
+ /**
21070
+ *
21071
+ * @returns {Promise<StatsMeta[]>}
21072
+ */
21073
+ async loadMetadata() {
21074
+ const { metadataPath } = this.options;
21075
+ if (this.metadata) {
21076
+ return this.metadata;
21077
+ }
21078
+ if (!this.metadata) {
21079
+ this.metadata = await loadComparisonMetadata(this.dataSource, metadataPath);
21080
+ return this.metadata;
21081
+ }
21082
+ return this.metadata;
21083
+ }
21084
+ /**
21085
+ * Load data from multiple dataframes, merged.
21086
+ * @param {object} volcanoOptions
21087
+ * @param {string[]|null} [volcanoOptions.sampleFacet]
21088
+ * @param {string[]|null} [volcanoOptions.obsSetFacet]
21089
+ * @param {number|null} [volcanoOptions.topK]
21090
+ * @param {string[][]|null} [volcanoOptions.sampleSetSelection]
21091
+ * @returns {Promise<LoaderResult<FeatureStatsData>>}
21092
+ */
21093
+ async loadMulti(volcanoOptions) {
21094
+ const { analysisType: targetAnalysisType = "rank_genes_groups" } = this.options;
21095
+ const { sampleSetSelection, obsSetSelection } = volcanoOptions || {};
21096
+ const rawObsSetSelection = obsSetSelection;
21097
+ const rawSampleSetSelection = sampleSetSelection;
21098
+ if (sampleSetSelection) {
21099
+ if (sampleSetSelection.length !== 2) {
21100
+ return Promise.reject(new Error("Expected exactly two sample sets for volcano plot."));
21101
+ }
21102
+ }
21103
+ if (!obsSetSelection) {
21104
+ return Promise.reject(new Error("Expected obsSetSelection to be present."));
21105
+ }
21106
+ const metadata = await this.loadMetadata();
21107
+ const matchingComparisons = [];
21108
+ Object.values(metadata.comparisons).forEach((comparisonGroupObject) => {
21109
+ const { results } = comparisonGroupObject;
21110
+ results.forEach((resultObject) => {
21111
+ const {
21112
+ analysis_type,
21113
+ // analysis_params,
21114
+ coordination_values
21115
+ // path,
21116
+ } = resultObject;
21117
+ if (analysis_type === targetAnalysisType) {
21118
+ if (sampleSetSelection) {
21119
+ rawObsSetSelection.forEach((obsSetPath) => {
21120
+ if (isEqual([obsSetPath], coordination_values.obsSetFilter)) {
21121
+ if (isEqualPathPair(rawSampleSetSelection, coordination_values.sampleSetFilter)) {
21122
+ matchingComparisons.push(resultObject);
21123
+ }
21124
+ }
21125
+ });
21126
+ } else if (obsSetSelection) {
21127
+ rawObsSetSelection.forEach((obsSetPath) => {
21128
+ if (isEqual([obsSetPath], coordination_values.obsSetSelection)) {
21129
+ matchingComparisons.push(resultObject);
21130
+ }
21131
+ });
21132
+ }
21133
+ }
21134
+ });
21135
+ });
21136
+ const result = await Promise.all(matchingComparisons.map(async (comparisonObject) => {
21137
+ const df = await this.loadDataFrame(comparisonObject.path);
21138
+ return {
21139
+ df,
21140
+ metadata: comparisonObject
21141
+ };
21142
+ }));
21143
+ return new LoaderResult({ featureStats: result }, null);
21144
+ }
21145
+ // eslint-disable-next-line class-methods-use-this
21146
+ async load() {
21147
+ throw new Error("The load() method is not implemented for FeatureStatsAnndataLoader.");
21148
+ }
21149
+ };
21150
+ class FeatureStatsAnndataLoader2 extends AbstractTwoStepLoader {
21151
+ /**
21152
+ * Class method for loading feature string labels.
21153
+ * @returns {Promise<any>} A promise for the array.
21154
+ */
21155
+ async loadSignificances(dfPath) {
21156
+ const { pValueColumn } = this.options;
21157
+ const values = await this.dataSource.loadNumeric(`${dfPath}/${pValueColumn}`);
21158
+ return values.data;
21159
+ }
21160
+ async loadFeatureSetNames(dfPath) {
21161
+ const { indexColumn } = this.options;
21162
+ if (indexColumn) {
21163
+ return this.dataSource._loadColumn(`${dfPath}/${indexColumn}`);
21164
+ }
21165
+ return this.dataSource.loadDataFrameIndex(dfPath);
21166
+ }
21167
+ async loadFeatureSetTerms(dfPath) {
21168
+ const { termColumn } = this.options;
21169
+ return this.dataSource._loadColumn(`${dfPath}/${termColumn}`);
21170
+ }
21171
+ async loadDataFrame(dfPath) {
21172
+ const [
21173
+ featureSetName,
21174
+ featureSetTerm,
21175
+ featureSetSignificance
21176
+ ] = await Promise.all([
21177
+ this.loadFeatureSetNames(dfPath),
21178
+ this.loadFeatureSetTerms(dfPath),
21179
+ this.loadSignificances(dfPath)
21180
+ ]);
21181
+ return {
21182
+ featureSetName,
21183
+ featureSetTerm,
21184
+ featureSetSignificance
21185
+ };
21186
+ }
21187
+ /**
21188
+ *
21189
+ * @returns {Promise<StatsMeta[]>}
21190
+ */
21191
+ async loadMetadata() {
21192
+ const { metadataPath } = this.options;
21193
+ if (this.metadata) {
21194
+ return this.metadata;
21195
+ }
21196
+ if (!this.metadata) {
21197
+ this.metadata = await loadComparisonMetadata(this.dataSource, metadataPath);
21198
+ return this.metadata;
21199
+ }
21200
+ return this.metadata;
21201
+ }
21202
+ /**
21203
+ * Load data from multiple dataframes, merged.
21204
+ * @param {object} volcanoOptions
21205
+ * @param {string[]|null} [volcanoOptions.sampleFacet]
21206
+ * @param {string[]|null} [volcanoOptions.obsSetFacet]
21207
+ * @param {number|null} [volcanoOptions.topK]
21208
+ * @param {string[][]|null} [volcanoOptions.sampleSetSelection]
21209
+ * @returns {Promise<LoaderResult<FeatureStatsData>>}
21210
+ */
21211
+ async loadMulti(volcanoOptions) {
21212
+ const { analysisType: targetAnalysisType = "pertpy_hypergeometric" } = this.options;
21213
+ const { sampleSetSelection, obsSetSelection } = volcanoOptions || {};
21214
+ const rawObsSetSelection = obsSetSelection;
21215
+ const rawSampleSetSelection = sampleSetSelection;
21216
+ if (sampleSetSelection) {
21217
+ if (sampleSetSelection.length !== 2) {
21218
+ return Promise.reject(new Error("Expected exactly two sample sets for volcano plot."));
21219
+ }
21220
+ }
21221
+ if (!obsSetSelection) {
21222
+ return Promise.reject(new Error("Expected obsSetSelection to be present."));
21223
+ }
21224
+ const metadata = await this.loadMetadata();
21225
+ const matchingComparisons = [];
21226
+ Object.values(metadata.comparisons).forEach((comparisonGroupObject) => {
21227
+ const { results } = comparisonGroupObject;
21228
+ results.forEach((resultObject) => {
21229
+ const {
21230
+ analysis_type,
21231
+ // analysis_params,
21232
+ coordination_values
21233
+ // path,
21234
+ } = resultObject;
21235
+ if (analysis_type === targetAnalysisType) {
21236
+ if (sampleSetSelection) {
21237
+ rawObsSetSelection.forEach((obsSetPath) => {
21238
+ if (isEqual([obsSetPath], coordination_values.obsSetFilter)) {
21239
+ if (isEqualPathPair(rawSampleSetSelection, coordination_values.sampleSetFilter)) {
21240
+ matchingComparisons.push(resultObject);
21241
+ }
21242
+ }
21243
+ });
21244
+ } else if (obsSetSelection) {
21245
+ rawObsSetSelection.forEach((obsSetPath) => {
21246
+ if (isEqual([obsSetPath], coordination_values.obsSetSelection)) {
21247
+ matchingComparisons.push(resultObject);
21248
+ }
21249
+ });
21250
+ }
21251
+ }
21252
+ });
21253
+ });
21254
+ const result = await Promise.all(matchingComparisons.map(async (comparisonObject) => {
21255
+ const df = await this.loadDataFrame(comparisonObject.path);
21256
+ return {
21257
+ df,
21258
+ metadata: comparisonObject
21259
+ };
21260
+ }));
21261
+ return new LoaderResult({ featureSetStats: result }, null);
21262
+ }
21263
+ // eslint-disable-next-line class-methods-use-this
21264
+ async load() {
21265
+ throw new Error("The load() method is not implemented for FeatureSetStatsAnndataLoader.");
21266
+ }
21267
+ }
21268
+ class ObsSetStatsAnndataLoader extends AbstractTwoStepLoader {
21269
+ /**
21270
+ * Class method for loading feature string labels.
21271
+ * @returns {Promise<any>} A promise for the array.
21272
+ */
21273
+ async loadInterceptValues(dfPath) {
21274
+ const { interceptExpectedSampleColumn } = this.options;
21275
+ const values = await this.dataSource.loadNumeric(`${dfPath}/${interceptExpectedSampleColumn}`);
21276
+ return values.data;
21277
+ }
21278
+ /**
21279
+ * Class method for loading feature string labels.
21280
+ * @returns {Promise<any>} A promise for the array.
21281
+ */
21282
+ async loadEffectValues(dfPath) {
21283
+ const { effectExpectedSampleColumn } = this.options;
21284
+ const values = await this.dataSource.loadNumeric(`${dfPath}/${effectExpectedSampleColumn}`);
21285
+ return values.data;
21286
+ }
21287
+ /**
21288
+ * Class method for loading feature string labels.
21289
+ * @returns {Promise<any>} A promise for the array.
21290
+ */
21291
+ async loadIsCredible(dfPath) {
21292
+ const { isCredibleEffectColumn } = this.options;
21293
+ const values = await this.dataSource.loadNumeric(`${dfPath}/${isCredibleEffectColumn}`);
21294
+ return Array.from(values.data);
21295
+ }
21296
+ /**
21297
+ * Class method for loading feature string labels.
21298
+ * @returns {Promise<any>} A promise for the array.
21299
+ */
21300
+ async loadFoldChanges(dfPath) {
21301
+ const { foldChangeColumn, foldChangeTransformation } = this.options;
21302
+ const values = await this.dataSource.loadNumeric(`${dfPath}/${foldChangeColumn}`);
21303
+ if (foldChangeTransformation === "log2") {
21304
+ values.data = values.data.map((val) => 2 ** val);
21305
+ }
21306
+ return values.data;
21307
+ }
21308
+ async loadCovariate(dfPath) {
21309
+ const { covariateColumn } = this.options;
21310
+ return this.dataSource._loadColumn(`${dfPath}/${covariateColumn}`);
21311
+ }
21312
+ async loadObsSetNames(dfPath) {
21313
+ const { indexColumn } = this.options;
21314
+ if (indexColumn) {
21315
+ return this.dataSource._loadColumn(`${dfPath}/${indexColumn}`);
21316
+ }
21317
+ return this.dataSource.loadDataFrameIndex(dfPath);
21318
+ }
21319
+ async loadDataFrame(dfPath) {
21320
+ const [
21321
+ obsSetId,
21322
+ obsSetFoldChange,
21323
+ interceptExpectedSample,
21324
+ effectExpectedSample,
21325
+ isCredibleEffect,
21326
+ // TODO: rather than passing this down,
21327
+ // do the fold change direction swapping in the loader
21328
+ // (as opposed to in the view).
21329
+ // TODO: also, see https://github.com/keller-mark/compasce/issues/30
21330
+ // which would allow not loading this column altogether.
21331
+ covariate
21332
+ ] = await Promise.all([
21333
+ this.loadObsSetNames(dfPath),
21334
+ this.loadFoldChanges(dfPath),
21335
+ this.loadInterceptValues(dfPath),
21336
+ this.loadEffectValues(dfPath),
21337
+ this.loadIsCredible(dfPath),
21338
+ this.loadCovariate(dfPath)
21339
+ ]);
21340
+ return {
21341
+ obsSetId,
21342
+ obsSetFoldChange,
21343
+ interceptExpectedSample,
21344
+ effectExpectedSample,
21345
+ isCredibleEffect,
21346
+ covariate
21347
+ };
21348
+ }
21349
+ /**
21350
+ *
21351
+ * @returns {Promise<StatsMeta[]>}
21352
+ */
21353
+ async loadMetadata() {
21354
+ const { metadataPath } = this.options;
21355
+ if (this.metadata) {
21356
+ return this.metadata;
21357
+ }
21358
+ if (!this.metadata) {
21359
+ this.metadata = await loadComparisonMetadata(this.dataSource, metadataPath);
21360
+ return this.metadata;
21361
+ }
21362
+ return this.metadata;
21363
+ }
21364
+ /**
21365
+ * Load data from multiple dataframes, merged.
21366
+ * @param {object} volcanoOptions
21367
+ * @param {string[]|null} [volcanoOptions.sampleFacet]
21368
+ * @param {string[]|null} [volcanoOptions.obsSetFacet]
21369
+ * @param {number|null} [volcanoOptions.topK]
21370
+ * @param {string[][]|null} [volcanoOptions.sampleSetSelection]
21371
+ * @returns {Promise<LoaderResult<ObsSetStatsData>>}
21372
+ */
21373
+ async loadMulti(volcanoOptions) {
21374
+ const { analysisType: targetAnalysisType = "sccoda_df" } = this.options;
21375
+ const { sampleSetSelection, obsSetSelection } = volcanoOptions || {};
21376
+ const rawObsSetSelection = obsSetSelection;
21377
+ const rawSampleSetSelection = sampleSetSelection;
21378
+ if (!sampleSetSelection || (sampleSetSelection == null ? void 0 : sampleSetSelection.length) !== 2) {
21379
+ return Promise.reject(new Error("Expected exactly two sample sets for cell type composition analysis plot."));
21380
+ }
21381
+ if (!obsSetSelection) {
21382
+ return Promise.reject(new Error("Expected obsSetSelection to be present."));
21383
+ }
21384
+ const metadata = await this.loadMetadata();
21385
+ const rawObsSetGroups = Array.from(
21386
+ new Set(rawObsSetSelection.map((setPath) => setPath == null ? void 0 : setPath[0]))
21387
+ );
21388
+ const matchingComparisons = [];
21389
+ Object.values(metadata.comparisons).forEach((comparisonGroupObject) => {
21390
+ const { results } = comparisonGroupObject;
21391
+ results.forEach((resultObject) => {
21392
+ const {
21393
+ analysis_type,
21394
+ // analysis_params,
21395
+ coordination_values
21396
+ // path,
21397
+ } = resultObject;
21398
+ if (analysis_type === targetAnalysisType) {
21399
+ if (sampleSetSelection) {
21400
+ if (isEqual([rawObsSetGroups], coordination_values.obsSetSelection)) {
21401
+ if (isEqualPathPair(rawSampleSetSelection, coordination_values.sampleSetFilter)) {
21402
+ matchingComparisons.push(resultObject);
21403
+ }
21404
+ }
21405
+ }
21406
+ }
21407
+ });
21408
+ });
21409
+ const result = await Promise.all(matchingComparisons.map(async (comparisonObject) => {
21410
+ const df = await this.loadDataFrame(comparisonObject.path);
21411
+ return {
21412
+ df,
21413
+ metadata: comparisonObject
21414
+ };
21415
+ }));
21416
+ return new LoaderResult({ obsSetStats: result }, null);
21417
+ }
21418
+ // eslint-disable-next-line class-methods-use-this
21419
+ async load() {
21420
+ throw new Error("The load() method is not implemented for ObsSetStatsAnndataLoader.");
21421
+ }
21422
+ }
20879
21423
  class GenomicProfilesZarrLoader extends AbstractTwoStepLoader {
20880
21424
  loadAttrs() {
20881
21425
  if (this.attrs) {
@@ -20896,7 +21440,10 @@ class GenomicProfilesZarrLoader extends AbstractTwoStepLoader {
20896
21440
  }
20897
21441
  export {
20898
21442
  AnnDataSource,
21443
+ ComparisonMetadataAnndataLoader,
20899
21444
  FeatureLabelsAnndataLoader,
21445
+ FeatureStatsAnndataLoader2 as FeatureSetStatsAnndataLoader,
21446
+ FeatureStatsAnndataLoader$1 as FeatureStatsAnndataLoader,
20900
21447
  GenomicProfilesZarrLoader,
20901
21448
  MatrixZarrAsObsFeatureMatrixLoader,
20902
21449
  MuDataSource,
@@ -20907,6 +21454,7 @@ export {
20907
21454
  ObsLocationsAnndataLoader,
20908
21455
  ObsPointsAnndataLoader,
20909
21456
  ObsSegmentationsAnndataLoader,
21457
+ ObsSetStatsAnndataLoader,
20910
21458
  ObsSetsAnndataLoader,
20911
21459
  ObsSpotsAnndataLoader,
20912
21460
  SampleEdgesAnndataLoader,