@platforma-sdk/model 1.91.0 → 1.92.0
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/components/PlDatasetSelector/build_dataset_options.cjs +43 -33
- package/dist/components/PlDatasetSelector/build_dataset_options.cjs.map +1 -1
- package/dist/components/PlDatasetSelector/build_dataset_options.d.ts +6 -2
- package/dist/components/PlDatasetSelector/build_dataset_options.d.ts.map +1 -1
- package/dist/components/PlDatasetSelector/build_dataset_options.js +46 -36
- package/dist/components/PlDatasetSelector/build_dataset_options.js.map +1 -1
- package/dist/components/PlDatasetSelector/dataset_selection.cjs.map +1 -1
- package/dist/components/PlDatasetSelector/dataset_selection.d.ts +13 -4
- package/dist/components/PlDatasetSelector/dataset_selection.d.ts.map +1 -1
- package/dist/components/PlDatasetSelector/dataset_selection.js.map +1 -1
- package/dist/components/PlDatasetSelector/enrichment_discovery.cjs +20 -26
- package/dist/components/PlDatasetSelector/enrichment_discovery.cjs.map +1 -1
- package/dist/components/PlDatasetSelector/enrichment_discovery.js +22 -28
- package/dist/components/PlDatasetSelector/enrichment_discovery.js.map +1 -1
- package/dist/components/PlDatasetSelector/filter_discovery.cjs +6 -14
- package/dist/components/PlDatasetSelector/filter_discovery.cjs.map +1 -1
- package/dist/components/PlDatasetSelector/filter_discovery.d.ts +5 -10
- package/dist/components/PlDatasetSelector/filter_discovery.d.ts.map +1 -1
- package/dist/components/PlDatasetSelector/filter_discovery.js +8 -13
- package/dist/components/PlDatasetSelector/filter_discovery.js.map +1 -1
- package/dist/components/PlDatasetSelector/index.cjs +0 -1
- package/dist/components/PlDatasetSelector/index.d.ts +3 -3
- package/dist/components/PlDatasetSelector/index.js +2 -2
- package/dist/components/index.cjs +0 -1
- package/dist/components/index.d.ts +3 -3
- package/dist/components/index.js +2 -2
- package/dist/index.cjs +0 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +2 -2
- package/dist/package.cjs +1 -1
- package/dist/package.js +1 -1
- package/package.json +7 -7
- package/src/columns/__test_helpers__/collection_driver.ts +45 -5
- package/src/components/PlDatasetSelector/build_dataset_options.test.ts +195 -0
- package/src/components/PlDatasetSelector/build_dataset_options.ts +86 -63
- package/src/components/PlDatasetSelector/dataset_selection.ts +14 -4
- package/src/components/PlDatasetSelector/enrichment_discovery.ts +26 -35
- package/src/components/PlDatasetSelector/filter_discovery.test.ts +16 -53
- package/src/components/PlDatasetSelector/filter_discovery.ts +10 -20
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Annotation,
|
|
3
|
+
createColumnDiscoveredId,
|
|
4
|
+
createGlobalPObjectId,
|
|
5
|
+
createPlRef,
|
|
6
|
+
isPColumnSpec,
|
|
7
|
+
} from "@milaboratories/pl-model-common";
|
|
8
|
+
import type { AxisSpec, PColumnSpec, PObjectSpec } from "@milaboratories/pl-model-common";
|
|
9
|
+
import { afterEach, beforeEach, describe, expect, test } from "vitest";
|
|
10
|
+
import { BlockRenderCtx } from "../../render";
|
|
11
|
+
import { buildDatasetOptions } from "./build_dataset_options";
|
|
12
|
+
import {
|
|
13
|
+
createTestCollectionDriver,
|
|
14
|
+
type TestCollectionDriverHandle,
|
|
15
|
+
} from "../../columns/__test_helpers__/collection_driver";
|
|
16
|
+
|
|
17
|
+
let driverHandle: TestCollectionDriverHandle;
|
|
18
|
+
|
|
19
|
+
beforeEach(() => {
|
|
20
|
+
driverHandle = createTestCollectionDriver();
|
|
21
|
+
driverHandle.installAmbientCtx();
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
afterEach(async () => {
|
|
25
|
+
driverHandle.uninstallAmbientCtx();
|
|
26
|
+
await driverHandle.dispose();
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
const sampleAxis: AxisSpec = { name: "sample", type: "String" };
|
|
30
|
+
const geneAxis: AxisSpec = { name: "gene", type: "String" };
|
|
31
|
+
const pathwayAxis: AxisSpec = { name: "pathway", type: "String" };
|
|
32
|
+
|
|
33
|
+
function spec(
|
|
34
|
+
name: string,
|
|
35
|
+
axesSpec: AxisSpec[],
|
|
36
|
+
annotations: Record<string, string> = {},
|
|
37
|
+
): PColumnSpec {
|
|
38
|
+
return { kind: "PColumn", name, valueType: "Int", axesSpec, annotations };
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** Registers the columns as outputs of the block, named as their specs are. */
|
|
42
|
+
function registerOutputs(blockId: string, specs: PColumnSpec[]): void {
|
|
43
|
+
driverHandle.register(
|
|
44
|
+
specs.map((s) => ({ id: createGlobalPObjectId(blockId, s.name), spec: s })),
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const isDataset = (s: PObjectSpec): boolean => s.name === "abundance";
|
|
49
|
+
|
|
50
|
+
const abundance = spec("abundance", [sampleAxis, geneAxis], { [Annotation.Label]: "Abundance" });
|
|
51
|
+
const other = spec("other", [sampleAxis, geneAxis], { [Annotation.Label]: "Other" });
|
|
52
|
+
const subset = spec("subset", [geneAxis], { [Annotation.IsSubset]: "true" });
|
|
53
|
+
const sampleSubset = spec("sampleSubset", [sampleAxis], { [Annotation.IsSubset]: "true" });
|
|
54
|
+
const foreignSubset = spec("foreignSubset", [pathwayAxis], { [Annotation.IsSubset]: "true" });
|
|
55
|
+
|
|
56
|
+
describe("buildDatasetOptions", () => {
|
|
57
|
+
test("offers the result pool columns the predicate accepts", () => {
|
|
58
|
+
registerOutputs("b1", [abundance, other]);
|
|
59
|
+
|
|
60
|
+
const options = buildDatasetOptions(new BlockRenderCtx(), { primary: isDataset });
|
|
61
|
+
|
|
62
|
+
expect(options).toEqual([
|
|
63
|
+
{ primary: { ref: createPlRef("b1", "abundance", true), label: "Abundance" } },
|
|
64
|
+
]);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
test("offers every result pool column without a primary option", () => {
|
|
68
|
+
registerOutputs("b1", [abundance, other]);
|
|
69
|
+
|
|
70
|
+
const options = buildDatasetOptions(new BlockRenderCtx()) ?? [];
|
|
71
|
+
|
|
72
|
+
expect(options.map((o) => o.primary.label).sort()).toEqual(["Abundance", "Other"]);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
test("a selector offers the same datasets as the predicate that says the same", () => {
|
|
76
|
+
registerOutputs("b1", [abundance, other, subset]);
|
|
77
|
+
const ctx = new BlockRenderCtx();
|
|
78
|
+
|
|
79
|
+
const bySelector = buildDatasetOptions(ctx, {
|
|
80
|
+
primary: { name: [{ type: "exact", value: "abundance" }] },
|
|
81
|
+
});
|
|
82
|
+
const byAxis = buildDatasetOptions(ctx, {
|
|
83
|
+
primary: { axes: [{ name: [{ type: "exact", value: "sample" }] }] },
|
|
84
|
+
filter: () => false,
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
expect(bySelector).toEqual(buildDatasetOptions(ctx, { primary: isDataset }));
|
|
88
|
+
expect(byAxis).toEqual(
|
|
89
|
+
buildDatasetOptions(ctx, {
|
|
90
|
+
primary: (s) => isPColumnSpec(s) && s.axesSpec.some((a) => a.name === "sample"),
|
|
91
|
+
filter: () => false,
|
|
92
|
+
}),
|
|
93
|
+
);
|
|
94
|
+
expect(byAxis).toHaveLength(2);
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
test("returns no options when nothing qualifies", () => {
|
|
98
|
+
registerOutputs("b1", [other]);
|
|
99
|
+
|
|
100
|
+
expect(buildDatasetOptions(new BlockRenderCtx(), { primary: isDataset })).toEqual([]);
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
test("leaves requireEnrichments off the dataset refs when asked", () => {
|
|
104
|
+
registerOutputs("b1", [abundance]);
|
|
105
|
+
|
|
106
|
+
const options = buildDatasetOptions(new BlockRenderCtx(), {
|
|
107
|
+
primary: isDataset,
|
|
108
|
+
requireEnrichments: false,
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
expect(options?.map((o) => o.primary.ref)).toEqual([createPlRef("b1", "abundance")]);
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
test("gives same-named datasets of different blocks distinct labels", () => {
|
|
115
|
+
const traced = (label: string): PColumnSpec => ({
|
|
116
|
+
...abundance,
|
|
117
|
+
domain: { "pl7.app/blockId": label },
|
|
118
|
+
annotations: {
|
|
119
|
+
...abundance.annotations,
|
|
120
|
+
[Annotation.Trace]: JSON.stringify([{ type: "import", label, importance: 10 }]),
|
|
121
|
+
},
|
|
122
|
+
});
|
|
123
|
+
registerOutputs("b1", [traced("First")]);
|
|
124
|
+
registerOutputs("b2", [traced("Second")]);
|
|
125
|
+
|
|
126
|
+
const options = buildDatasetOptions(new BlockRenderCtx(), { primary: isDataset }) ?? [];
|
|
127
|
+
|
|
128
|
+
expect(options.map((o) => o.primary.ref)).toEqual([
|
|
129
|
+
createPlRef("b1", "abundance", true),
|
|
130
|
+
createPlRef("b2", "abundance", true),
|
|
131
|
+
]);
|
|
132
|
+
expect(new Set(options.map((o) => o.primary.label)).size).toBe(2);
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
test("attaches the subsets on the dataset's axes as filters", () => {
|
|
136
|
+
registerOutputs("b1", [abundance]);
|
|
137
|
+
registerOutputs("b2", [subset, sampleSubset, foreignSubset]);
|
|
138
|
+
|
|
139
|
+
const options = buildDatasetOptions(new BlockRenderCtx(), { primary: isDataset }) ?? [];
|
|
140
|
+
|
|
141
|
+
expect(options).toHaveLength(1);
|
|
142
|
+
expect(options[0].filters?.map((f) => f.ref)).toEqual(
|
|
143
|
+
expect.arrayContaining([createPlRef("b2", "subset"), createPlRef("b2", "sampleSubset")]),
|
|
144
|
+
);
|
|
145
|
+
expect(options[0].filters).toHaveLength(2);
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
test("the filter option restricts the attached subsets", () => {
|
|
149
|
+
registerOutputs("b1", [abundance]);
|
|
150
|
+
registerOutputs("b2", [subset, sampleSubset]);
|
|
151
|
+
const ctx = new BlockRenderCtx();
|
|
152
|
+
|
|
153
|
+
const byPredicate = buildDatasetOptions(ctx, {
|
|
154
|
+
primary: isDataset,
|
|
155
|
+
filter: (s) => s.name === "subset",
|
|
156
|
+
});
|
|
157
|
+
const bySelector = buildDatasetOptions(ctx, {
|
|
158
|
+
primary: isDataset,
|
|
159
|
+
filter: { name: [{ type: "exact", value: "subset" }] },
|
|
160
|
+
});
|
|
161
|
+
const none = buildDatasetOptions(ctx, { primary: isDataset, filter: () => false });
|
|
162
|
+
|
|
163
|
+
expect(byPredicate?.[0].filters?.map((f) => f.ref)).toEqual([createPlRef("b2", "subset")]);
|
|
164
|
+
expect(bySelector).toEqual(byPredicate);
|
|
165
|
+
expect(none).toEqual([
|
|
166
|
+
{ primary: { ref: createPlRef("b1", "abundance", true), label: "Abundance" } },
|
|
167
|
+
]);
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
test("attaches the columns reached through a linker as enrichments", () => {
|
|
171
|
+
const linker = spec("pathwayToGene", [pathwayAxis, geneAxis], {
|
|
172
|
+
[Annotation.IsLinkerColumn]: "true",
|
|
173
|
+
});
|
|
174
|
+
const pathwayScore = spec("pathwayScore", [pathwayAxis], { [Annotation.Label]: "Score" });
|
|
175
|
+
registerOutputs("b1", [abundance]);
|
|
176
|
+
registerOutputs("b2", [linker, pathwayScore]);
|
|
177
|
+
const ctx = new BlockRenderCtx();
|
|
178
|
+
|
|
179
|
+
const without = buildDatasetOptions(ctx, { primary: isDataset }) ?? [];
|
|
180
|
+
const withAll = buildDatasetOptions(ctx, { primary: isDataset, withEnrichments: () => true });
|
|
181
|
+
const withNone = buildDatasetOptions(ctx, { primary: isDataset, withEnrichments: () => false });
|
|
182
|
+
|
|
183
|
+
expect(without[0].enrichments).toBeUndefined();
|
|
184
|
+
expect(withNone).toEqual(without);
|
|
185
|
+
expect(withAll?.[0].enrichments).toEqual([
|
|
186
|
+
{
|
|
187
|
+
id: createColumnDiscoveredId({
|
|
188
|
+
column: createGlobalPObjectId("b2", "pathwayScore"),
|
|
189
|
+
path: [{ type: "linker", column: createGlobalPObjectId("b2", "pathwayToGene") }],
|
|
190
|
+
}),
|
|
191
|
+
label: expect.any(String),
|
|
192
|
+
},
|
|
193
|
+
]);
|
|
194
|
+
});
|
|
195
|
+
});
|
|
@@ -1,24 +1,26 @@
|
|
|
1
1
|
import type { MultiColumnSelector, Option, PObjectSpec } from "@milaboratories/pl-model-common";
|
|
2
|
-
import {
|
|
3
|
-
|
|
2
|
+
import {
|
|
3
|
+
columnProducer,
|
|
4
|
+
createPlRef,
|
|
5
|
+
multiColumnSelectorsToPredicate,
|
|
6
|
+
} from "@milaboratories/pl-model-common";
|
|
7
|
+
import type { ColumnRecipe } from "../../columns";
|
|
8
|
+
import { ColumnsCollection } from "../../columns";
|
|
9
|
+
import {
|
|
10
|
+
deriveDistinctLabels,
|
|
11
|
+
type DeriveLabelsOptions,
|
|
12
|
+
} from "../../labels/derive_distinct_labels";
|
|
4
13
|
import type { RenderCtxBase } from "../../render";
|
|
5
14
|
import type { DatasetOption } from "./dataset_selection";
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import { ColumnsProvider, getCtxProviders } from "../../columns";
|
|
9
|
-
|
|
10
|
-
type SpecPredicateOption =
|
|
11
|
-
| MultiColumnSelector
|
|
12
|
-
| MultiColumnSelector[]
|
|
13
|
-
| ((spec: PObjectSpec) => boolean);
|
|
14
|
-
|
|
15
|
-
function toPredicate(opt: SpecPredicateOption | undefined): (spec: PObjectSpec) => boolean {
|
|
16
|
-
if (opt === undefined) return () => true;
|
|
17
|
-
return typeof opt === "function" ? opt : multiColumnSelectorsToPredicate(opt);
|
|
18
|
-
}
|
|
15
|
+
import { filterMatchesToOptions, findFilterColumns } from "./filter_discovery";
|
|
16
|
+
import { findEnrichmentColumns, labelEnrichments } from "./enrichment_discovery";
|
|
19
17
|
|
|
20
18
|
export type BuildDatasetOptions = {
|
|
21
|
-
/**
|
|
19
|
+
/**
|
|
20
|
+
* Which result pool columns qualify as datasets. Defaults to all. A selector
|
|
21
|
+
* is matched by the host; a predicate reads the spec of every result pool
|
|
22
|
+
* column, so prefer a selector when it can say the same.
|
|
23
|
+
*/
|
|
22
24
|
primary?: SpecPredicateOption;
|
|
23
25
|
/**
|
|
24
26
|
* Restricts which result pool columns are considered as filters. Intersected
|
|
@@ -57,62 +59,83 @@ export function buildDatasetOptions(
|
|
|
57
59
|
ctx: RenderCtxBase,
|
|
58
60
|
opts?: BuildDatasetOptions,
|
|
59
61
|
): DatasetOption[] | undefined {
|
|
60
|
-
const
|
|
61
|
-
const filterPredicate = toPredicate(opts?.filter);
|
|
62
|
-
|
|
63
|
-
const options = ctx.resultPool.getOptions(
|
|
64
|
-
(spec) => isPColumnSpec(spec) && primaryPredicate(spec),
|
|
65
|
-
{
|
|
66
|
-
refsWithEnrichments: opts?.requireEnrichments ?? true,
|
|
67
|
-
},
|
|
68
|
-
);
|
|
69
|
-
if (options.length === 0) return [];
|
|
62
|
+
const pool = ColumnsCollection(["result_pool"], { ctx: ctx.ctx });
|
|
70
63
|
|
|
71
|
-
|
|
64
|
+
// A dataset is stored as a reference to a block output, so only a column
|
|
65
|
+
// that is one can be offered.
|
|
66
|
+
const datasets = findDatasets(pool, opts?.primary).flatMap((column) => {
|
|
67
|
+
const producer = columnProducer(column.id);
|
|
68
|
+
return producer === undefined ? [] : [{ column, producer }];
|
|
69
|
+
});
|
|
70
|
+
if (datasets.length === 0) return [];
|
|
72
71
|
|
|
73
|
-
const
|
|
74
|
-
const
|
|
75
|
-
|
|
76
|
-
// calling it per dataset option would be O(N × tree).
|
|
77
|
-
const enrichmentSources = withEnrichments ? getCtxProviders(ctx) : undefined;
|
|
72
|
+
const labels = deriveDistinctLabels(datasets.map(({ column }) => column.getSpec()));
|
|
73
|
+
const requireEnrichments = opts?.requireEnrichments ?? true;
|
|
74
|
+
const filterPredicate = toPredicate(opts?.filter);
|
|
78
75
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
76
|
+
const withEnrichments = opts?.withEnrichments;
|
|
77
|
+
const enrichmentSearch =
|
|
78
|
+
withEnrichments === undefined
|
|
79
|
+
? undefined
|
|
80
|
+
: {
|
|
81
|
+
// Enrichments are also looked for among this block's own columns.
|
|
82
|
+
// Built once: every dataset searches the same set.
|
|
83
|
+
sources: [ColumnsCollection(["current_block", pool], { ctx: ctx.ctx })],
|
|
84
|
+
maxHops: opts?.enrichmentMaxHops,
|
|
85
|
+
...(typeof withEnrichments === "function"
|
|
86
|
+
? { predicate: withEnrichments }
|
|
87
|
+
: { include: withEnrichments }),
|
|
88
|
+
};
|
|
82
89
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
90
|
+
return datasets.map(({ column, producer }, i): DatasetOption => {
|
|
91
|
+
const datasetSpec = column.getSpec();
|
|
92
|
+
const primary: Option = {
|
|
93
|
+
ref: createPlRef(producer.blockId, producer.name, requireEnrichments),
|
|
94
|
+
label: labels[i],
|
|
95
|
+
};
|
|
87
96
|
|
|
88
|
-
const filters =
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
labelOptions: opts?.labelOptions,
|
|
95
|
-
});
|
|
97
|
+
const filters = filterMatchesToOptions(
|
|
98
|
+
findFilterColumns({ sources: [pool], anchorSpec: datasetSpec }).filter((match) =>
|
|
99
|
+
filterPredicate(match.getSpec()),
|
|
100
|
+
),
|
|
101
|
+
{ datasetSpec, labelOptions: opts?.labelOptions },
|
|
102
|
+
);
|
|
96
103
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
? { predicate: withEnrichments }
|
|
105
|
-
: { include: withEnrichments }),
|
|
106
|
-
});
|
|
107
|
-
if (enrichmentVariants.length > 0) {
|
|
108
|
-
enrichments = enrichmentVariantsToRefs(enrichmentVariants, opts?.labelOptions);
|
|
109
|
-
}
|
|
110
|
-
}
|
|
104
|
+
const enrichments =
|
|
105
|
+
enrichmentSearch === undefined
|
|
106
|
+
? []
|
|
107
|
+
: labelEnrichments(
|
|
108
|
+
findEnrichmentColumns({ ...enrichmentSearch, anchorSpec: datasetSpec }),
|
|
109
|
+
opts?.labelOptions,
|
|
110
|
+
);
|
|
111
111
|
|
|
112
112
|
return {
|
|
113
113
|
primary,
|
|
114
|
-
...(filters
|
|
115
|
-
...(enrichments
|
|
114
|
+
...(filters.length > 0 ? { filters } : {}),
|
|
115
|
+
...(enrichments.length > 0 ? { enrichments } : {}),
|
|
116
116
|
};
|
|
117
117
|
});
|
|
118
118
|
}
|
|
119
|
+
|
|
120
|
+
// Internals
|
|
121
|
+
|
|
122
|
+
type SpecPredicateOption =
|
|
123
|
+
| MultiColumnSelector
|
|
124
|
+
| MultiColumnSelector[]
|
|
125
|
+
| ((spec: PObjectSpec) => boolean);
|
|
126
|
+
|
|
127
|
+
function toPredicate(opt: SpecPredicateOption | undefined): (spec: PObjectSpec) => boolean {
|
|
128
|
+
if (opt === undefined) return () => true;
|
|
129
|
+
return typeof opt === "function" ? opt : multiColumnSelectorsToPredicate(opt);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function findDatasets(
|
|
133
|
+
pool: ColumnsCollection,
|
|
134
|
+
primary: SpecPredicateOption | undefined,
|
|
135
|
+
): ColumnRecipe[] {
|
|
136
|
+
if (primary === undefined) return pool.getColumns();
|
|
137
|
+
if (typeof primary === "function") {
|
|
138
|
+
return pool.getColumns().filter((column) => primary(column.getSpec()));
|
|
139
|
+
}
|
|
140
|
+
return pool.filter({ include: primary }).getColumns();
|
|
141
|
+
}
|
|
@@ -1,10 +1,20 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ColumnUniversalId, Option, PrimaryRef } from "@milaboratories/pl-model-common";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A column joined to a dataset without being picked by the user, with the header
|
|
5
|
+
* it is exported under. The id names a block output reached from the dataset
|
|
6
|
+
* through linker columns, so a workflow can find the column by the id alone.
|
|
7
|
+
*/
|
|
8
|
+
export type DatasetEnrichment = {
|
|
9
|
+
readonly id: ColumnUniversalId;
|
|
10
|
+
readonly label: string;
|
|
11
|
+
};
|
|
2
12
|
|
|
3
13
|
/** Dataset picker entry: user picks {@link primary}, gets {@link enrichments} attached. */
|
|
4
14
|
export type DatasetOption = {
|
|
5
15
|
readonly primary: Option;
|
|
6
16
|
readonly filters?: readonly Option[];
|
|
7
|
-
readonly enrichments?:
|
|
17
|
+
readonly enrichments?: readonly DatasetEnrichment[];
|
|
8
18
|
};
|
|
9
19
|
|
|
10
20
|
/**
|
|
@@ -14,7 +24,7 @@ export type DatasetOption = {
|
|
|
14
24
|
export type DatasetSelection = {
|
|
15
25
|
readonly __isDatasetSelection: "v1";
|
|
16
26
|
readonly primary: PrimaryRef;
|
|
17
|
-
readonly enrichments?:
|
|
27
|
+
readonly enrichments?: readonly DatasetEnrichment[];
|
|
18
28
|
};
|
|
19
29
|
|
|
20
30
|
export function isDatasetSelection(value: unknown): value is DatasetSelection {
|
|
@@ -28,7 +38,7 @@ export function isDatasetSelection(value: unknown): value is DatasetSelection {
|
|
|
28
38
|
|
|
29
39
|
export function createDatasetSelection(
|
|
30
40
|
primary: PrimaryRef,
|
|
31
|
-
enrichments?:
|
|
41
|
+
enrichments?: readonly DatasetEnrichment[],
|
|
32
42
|
): DatasetSelection {
|
|
33
43
|
if (enrichments !== undefined && enrichments.length > 0) {
|
|
34
44
|
return { __isDatasetSelection: "v1", primary, enrichments };
|
|
@@ -1,23 +1,20 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Annotation,
|
|
3
|
-
|
|
4
|
-
extractPObjectId,
|
|
3
|
+
isColumnDiscoveredId,
|
|
5
4
|
isGlobalPObjectId,
|
|
5
|
+
parseColumnDiscoveredId,
|
|
6
6
|
} from "@milaboratories/pl-model-common";
|
|
7
7
|
import type {
|
|
8
8
|
ColumnsCollectionDriverModel,
|
|
9
|
-
|
|
10
|
-
LabeledEnrichmentRef,
|
|
11
|
-
LabeledEnrichmentRefs,
|
|
9
|
+
ColumnUniversalId,
|
|
12
10
|
MultiColumnSelector,
|
|
13
11
|
PColumnSpec,
|
|
14
12
|
PObjectSpec,
|
|
15
13
|
} from "@milaboratories/pl-model-common";
|
|
16
|
-
import type { ColumnRecipe, ColumnsSource } from "../../columns";
|
|
14
|
+
import type { ColumnRecipe, ColumnsSource, ColumnsSourceShorthand } from "../../columns";
|
|
17
15
|
import {
|
|
18
16
|
hasSingleDataColumn,
|
|
19
17
|
ColumnsCollection,
|
|
20
|
-
collectLinkerIds,
|
|
21
18
|
hitQualifications,
|
|
22
19
|
collectLinkerColumns,
|
|
23
20
|
queriesQualifications,
|
|
@@ -27,9 +24,10 @@ import {
|
|
|
27
24
|
type DeriveLabelsOptions,
|
|
28
25
|
type Entry,
|
|
29
26
|
} from "../../labels/derive_distinct_labels";
|
|
27
|
+
import type { DatasetEnrichment } from "./dataset_selection";
|
|
30
28
|
|
|
31
29
|
export interface FindEnrichmentColumnsOptions {
|
|
32
|
-
sources: ReadonlyArray<ColumnsSource>;
|
|
30
|
+
sources: ReadonlyArray<ColumnsCollection | ColumnsSource | ColumnsSourceShorthand>;
|
|
33
31
|
anchorSpec: PColumnSpec;
|
|
34
32
|
maxHops?: number;
|
|
35
33
|
include?: MultiColumnSelector | MultiColumnSelector[];
|
|
@@ -42,6 +40,9 @@ export interface FindEnrichmentColumnsOptions {
|
|
|
42
40
|
* Linker-reached hits attached to the anchor primary. Drops zero-hop variants
|
|
43
41
|
* (filters / the primary itself) and structural hits (subset, linker, label
|
|
44
42
|
* columns). Narrow further with `include` selectors or a `predicate`.
|
|
43
|
+
*
|
|
44
|
+
* A hit is kept only when a workflow can find it by its id: the hit and every
|
|
45
|
+
* linker leading to it are block outputs.
|
|
45
46
|
*/
|
|
46
47
|
export function findEnrichmentColumns(options: FindEnrichmentColumnsOptions): ColumnRecipe[] {
|
|
47
48
|
const include =
|
|
@@ -68,48 +69,38 @@ export function findEnrichmentColumns(options: FindEnrichmentColumnsOptions): Co
|
|
|
68
69
|
const predicate = options.predicate;
|
|
69
70
|
return columns.filter((v) => {
|
|
70
71
|
if (hasSingleDataColumn(v)) return false;
|
|
71
|
-
if (
|
|
72
|
-
|
|
73
|
-
if (collectLinkerIds(v).some((id) => !isGlobalPObjectId(id))) return false;
|
|
74
|
-
return true;
|
|
72
|
+
if (!reachesBlockOutputs(v.id)) return false;
|
|
73
|
+
return predicate === undefined || predicate(v.getSpec());
|
|
75
74
|
});
|
|
76
75
|
}
|
|
77
76
|
|
|
78
77
|
/**
|
|
79
|
-
*
|
|
80
|
-
*
|
|
81
|
-
* `qualifications.forHit`; `forQueries` is re-derived by the table builder.
|
|
78
|
+
* Pairs each column with a label that tells apart the same hit reached through
|
|
79
|
+
* different linkers, so export headers stay unique.
|
|
82
80
|
*/
|
|
83
|
-
export function
|
|
81
|
+
export function labelEnrichments(
|
|
84
82
|
variants: ColumnRecipe[],
|
|
85
83
|
labelOptions?: DeriveLabelsOptions,
|
|
86
|
-
):
|
|
84
|
+
): DatasetEnrichment[] {
|
|
87
85
|
if (variants.length === 0) return [];
|
|
88
86
|
|
|
89
|
-
const
|
|
90
|
-
const hitQualsByVariant = variants.map((v) => [...hitQualifications(v)]);
|
|
91
|
-
|
|
92
|
-
const entries: Entry[] = variants.map((variant, i) => ({
|
|
87
|
+
const entries: Entry[] = variants.map((variant) => ({
|
|
93
88
|
spec: variant.getSpec(),
|
|
94
89
|
linkerPath: collectLinkerColumns(variant).map((linker) => ({ spec: linker.getSpec() })),
|
|
95
90
|
qualifications: {
|
|
96
|
-
forHit:
|
|
91
|
+
forHit: [...hitQualifications(variant)],
|
|
97
92
|
forQueries: queriesQualifications(variant),
|
|
98
93
|
},
|
|
99
94
|
}));
|
|
100
95
|
const labels = deriveDistinctLabels(entries, labelOptions);
|
|
101
96
|
|
|
102
|
-
return variants.map((variant, i):
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
}),
|
|
112
|
-
label: labels[i],
|
|
113
|
-
};
|
|
114
|
-
});
|
|
97
|
+
return variants.map((variant, i): DatasetEnrichment => ({ id: variant.id, label: labels[i] }));
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// Internals
|
|
101
|
+
|
|
102
|
+
function reachesBlockOutputs(id: ColumnUniversalId): boolean {
|
|
103
|
+
if (!isColumnDiscoveredId(id)) return false;
|
|
104
|
+
const key = parseColumnDiscoveredId(id);
|
|
105
|
+
return [key.column, ...(key.path ?? []).map((step) => step.column)].every(isGlobalPObjectId);
|
|
115
106
|
}
|
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
PlRef,
|
|
7
|
-
PObjectId,
|
|
1
|
+
import {
|
|
2
|
+
Annotation,
|
|
3
|
+
createGlobalPObjectId,
|
|
4
|
+
createLocalPObjectId,
|
|
5
|
+
createPlRef,
|
|
8
6
|
} from "@milaboratories/pl-model-common";
|
|
7
|
+
import type { AxisSpec, PColumn, PColumnSpec, PObjectId } from "@milaboratories/pl-model-common";
|
|
9
8
|
import canonicalize from "canonicalize";
|
|
10
9
|
import { afterEach, beforeEach, describe, expect, test } from "vitest";
|
|
11
10
|
import type { PColumnDataUniversal } from "../../render/internal";
|
|
12
|
-
import {
|
|
11
|
+
import { filterMatchesToOptions, findFilterColumns } from "./filter_discovery";
|
|
13
12
|
import {
|
|
14
13
|
createTestCollectionDriver,
|
|
15
14
|
type TestCollectionDriverHandle,
|
|
@@ -108,33 +107,11 @@ describe("findFilterColumns", () => {
|
|
|
108
107
|
});
|
|
109
108
|
});
|
|
110
109
|
|
|
111
|
-
describe("buildRefMap", () => {
|
|
112
|
-
test("maps canonicalized PlRef to original ref", () => {
|
|
113
|
-
const ref1 = createPlRef("b1", "out1");
|
|
114
|
-
const ref2 = createPlRef("b2", "out2", true);
|
|
115
|
-
const map = buildRefMap([{ ref: ref1 }, { ref: ref2 }]);
|
|
116
|
-
expect(map.get(canonicalize(ref1)! as PObjectId)).toBe(ref1);
|
|
117
|
-
expect(map.get(canonicalize(ref2)! as PObjectId)).toBe(ref2);
|
|
118
|
-
expect(map.size).toBe(2);
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
test("returns empty map for empty entries", () => {
|
|
122
|
-
expect(buildRefMap([]).size).toBe(0);
|
|
123
|
-
});
|
|
124
|
-
});
|
|
125
|
-
|
|
126
110
|
describe("filterMatchesToOptions", () => {
|
|
127
111
|
test("converts filter matches to Option[] with derived labels", () => {
|
|
128
112
|
const filterRef1 = createPlRef("b1", "filter-top1000");
|
|
129
113
|
const filterRef2 = createPlRef("b1", "filter-highconf");
|
|
130
114
|
|
|
131
|
-
// Build ref map from entries (simulating result pool)
|
|
132
|
-
const refMap = buildRefMap([
|
|
133
|
-
{ ref: anchorSnap.id as unknown as PlRef },
|
|
134
|
-
{ ref: filterRef1 },
|
|
135
|
-
{ ref: filterRef2 },
|
|
136
|
-
]);
|
|
137
|
-
|
|
138
115
|
const filterSpec1 = spec("filter1", [axis("sample")], { [Annotation.IsSubset]: "true" });
|
|
139
116
|
const filterSpec2 = spec("filter2", [axis("sample")], { [Annotation.IsSubset]: "true" });
|
|
140
117
|
|
|
@@ -149,14 +126,10 @@ describe("filterMatchesToOptions", () => {
|
|
|
149
126
|
});
|
|
150
127
|
expect(matches.length).toBe(2);
|
|
151
128
|
|
|
152
|
-
const options = filterMatchesToOptions(matches, {
|
|
153
|
-
refsByObjectId: refMap,
|
|
154
|
-
datasetSpec: anchorSpec,
|
|
155
|
-
});
|
|
129
|
+
const options = filterMatchesToOptions(matches, { datasetSpec: anchorSpec });
|
|
156
130
|
expect(options).toHaveLength(2);
|
|
131
|
+
expect(options.map((o) => o.ref)).toEqual(expect.arrayContaining([filterRef1, filterRef2]));
|
|
157
132
|
for (const opt of options) {
|
|
158
|
-
expect(opt.ref).toBeDefined();
|
|
159
|
-
expect(opt.label).toBeDefined();
|
|
160
133
|
expect(typeof opt.label).toBe("string");
|
|
161
134
|
}
|
|
162
135
|
});
|
|
@@ -176,7 +149,6 @@ describe("filterMatchesToOptions", () => {
|
|
|
176
149
|
});
|
|
177
150
|
|
|
178
151
|
const filterRef = createPlRef("b1", "filter");
|
|
179
|
-
const refMap = buildRefMap([{ ref: filterRef }]);
|
|
180
152
|
const filterSpec = spec("filter", [axis("sample")], {
|
|
181
153
|
[Annotation.IsSubset]: "true",
|
|
182
154
|
[Annotation.Label]: "Selected Leads",
|
|
@@ -197,7 +169,7 @@ describe("filterMatchesToOptions", () => {
|
|
|
197
169
|
});
|
|
198
170
|
expect(matches).toHaveLength(1);
|
|
199
171
|
|
|
200
|
-
const options = filterMatchesToOptions(matches, {
|
|
172
|
+
const options = filterMatchesToOptions(matches, { datasetSpec });
|
|
201
173
|
expect(options).toHaveLength(1);
|
|
202
174
|
expect(options[0].label).toBe("Bulk / Top 10");
|
|
203
175
|
|
|
@@ -205,7 +177,6 @@ describe("filterMatchesToOptions", () => {
|
|
|
205
177
|
// suppression — otherwise the algorithm short-circuits on the
|
|
206
178
|
// inherited "Selected Leads" label.
|
|
207
179
|
const withCustomNative = filterMatchesToOptions(matches, {
|
|
208
|
-
refsByObjectId: refMap,
|
|
209
180
|
datasetSpec,
|
|
210
181
|
labelOptions: { formatters: { native: (l) => `<<${l}>>` } },
|
|
211
182
|
});
|
|
@@ -213,7 +184,6 @@ describe("filterMatchesToOptions", () => {
|
|
|
213
184
|
|
|
214
185
|
// Non-native label options (here `separator`) flow through.
|
|
215
186
|
const withSeparator = filterMatchesToOptions(matches, {
|
|
216
|
-
refsByObjectId: refMap,
|
|
217
187
|
datasetSpec,
|
|
218
188
|
labelOptions: { separator: " :: " },
|
|
219
189
|
});
|
|
@@ -231,7 +201,6 @@ describe("filterMatchesToOptions", () => {
|
|
|
231
201
|
|
|
232
202
|
const ref1 = createPlRef("b1", "f1");
|
|
233
203
|
const ref2 = createPlRef("b2", "f2");
|
|
234
|
-
const refMap = buildRefMap([{ ref: ref1 }, { ref: ref2 }]);
|
|
235
204
|
const filterSpec1 = spec("filter1", [axis("sample")], {
|
|
236
205
|
[Annotation.IsSubset]: "true",
|
|
237
206
|
[Annotation.Label]: "Selected Leads",
|
|
@@ -262,22 +231,20 @@ describe("filterMatchesToOptions", () => {
|
|
|
262
231
|
});
|
|
263
232
|
expect(matches).toHaveLength(2);
|
|
264
233
|
|
|
265
|
-
const options = filterMatchesToOptions(matches, {
|
|
234
|
+
const options = filterMatchesToOptions(matches, { datasetSpec });
|
|
266
235
|
expect(options.map((o) => o.label).sort()).toEqual(["Bulk / Top 10", "Bulk / Top 11"]);
|
|
267
236
|
});
|
|
268
237
|
|
|
269
238
|
test("returns empty array for empty matches", () => {
|
|
270
|
-
expect(
|
|
271
|
-
filterMatchesToOptions([], { refsByObjectId: new Map(), datasetSpec: anchorSpec }),
|
|
272
|
-
).toEqual([]);
|
|
239
|
+
expect(filterMatchesToOptions([], { datasetSpec: anchorSpec })).toEqual([]);
|
|
273
240
|
});
|
|
274
241
|
|
|
275
|
-
test("skips
|
|
242
|
+
test("skips a column that is not a block output", () => {
|
|
276
243
|
const knownRef = createPlRef("b1", "known");
|
|
277
244
|
const knownSpec = spec("known", [axis("sample")], { [Annotation.IsSubset]: "true" });
|
|
278
245
|
const orphanSpec = spec("orphan", [axis("sample")], { [Annotation.IsSubset]: "true" });
|
|
279
246
|
const knownSnap = col(canonicalize(knownRef)! as PObjectId, knownSpec);
|
|
280
|
-
const orphanSnap = col(
|
|
247
|
+
const orphanSnap = col(createLocalPObjectId(["main"], "orphan"), orphanSpec);
|
|
281
248
|
registerCols([knownSnap, orphanSnap, anchorSnap]);
|
|
282
249
|
|
|
283
250
|
const matches = findFilterColumns({
|
|
@@ -286,12 +253,8 @@ describe("filterMatchesToOptions", () => {
|
|
|
286
253
|
driver: driverHandle.driver,
|
|
287
254
|
});
|
|
288
255
|
expect(matches.length).toBe(2);
|
|
289
|
-
const
|
|
290
|
-
const options = filterMatchesToOptions(matches, {
|
|
291
|
-
refsByObjectId: refMap,
|
|
292
|
-
datasetSpec: anchorSpec,
|
|
293
|
-
});
|
|
256
|
+
const options = filterMatchesToOptions(matches, { datasetSpec: anchorSpec });
|
|
294
257
|
expect(options).toHaveLength(1);
|
|
295
|
-
expect(options[0].ref).
|
|
258
|
+
expect(options[0].ref).toEqual(knownRef);
|
|
296
259
|
});
|
|
297
260
|
});
|