Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .changeset/column-value-refs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
"@platforma-open/milaboratories.samples-and-data": minor
"@platforma-open/milaboratories.samples-and-data.model": minor
"@platforma-open/milaboratories.samples-and-data.ui": minor
"@platforma-open/milaboratories.samples-and-data.workflow": patch
---

Warns, on the metadata page and on every dataset page, when blocks that use data of this block no longer find it — an output it does not export or values it no longer has — and suggests adding the data or reconfiguring those blocks. The warning shows in desktop versions that compute links between blocks.
Built with SDK 1.88.0 (workflow-tengo 6.20.0, block-tools 2.17.5, tengo-builder 4.1.17).
95 changes: 95 additions & 0 deletions model/src/args_issues.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import { expect, test } from "vitest";
import type {
BarcodeRule,
BlockData,
DSAny,
DSMultiplexedFastq,
ImportFileHandle,
PlId,
} from "./args";
import { blockArgsIssues } from "./args_issues";

const sample = "SAMPLE0000000000000000000" as PlId;
const group = "GROUP00000000000000000000" as PlId;
const file = "index://storage/path" as ImportFileHandle;

function blockData(datasets: DSAny[]): BlockData {
return {
datasets,
metadata: [],
sampleIds: [sample],
sampleLabelColumnLabel: "Sample",
sampleLabels: { [sample]: "S1" },
h5adFilesToPreprocess: [],
seuratFilesToPreprocess: [],
metadataUploadHandle: undefined,
suggestedImport: false,
};
}

function multiplexed(label: string, rules: BarcodeRule[]): DSMultiplexedFastq {
return {
id: `${label}-id` as PlId,
label,
content: {
type: "MultiplexedFastq",
gzipped: true,
readIndices: ["R1"],
data: { [group]: { R1: file } },
sampleGroups: { [group]: { [sample]: "s1" } },
groupLabels: { [group]: "g1" },
barcodeTags: ["CELL"],
barcodeRules: rules,
},
};
}

function rule(barcode: string): BarcodeRule {
return { ruleId: "r1", sampleGroupId: group, sampleId: sample, barcodes: { CELL: barcode } };
}

test("a block with no datasets runs", () => {
expect(blockArgsIssues(blockData([]))).toEqual([]);
});

test("configured multiplexing rules let the block run", () => {
expect(blockArgsIssues(blockData([multiplexed("Mux", [rule("ACGT")])]))).toEqual([]);
});

test("dataset problems are reported without checking the rules", () => {
const ds = multiplexed("Mux", [rule("")]);
ds.content.data = {};
expect(blockArgsIssues(blockData([ds]))).toEqual([
{ severity: "error", message: 'No data in dataset: "Mux"' },
]);
});

test("rule issues are joined into one error, warnings included", () => {
const ds = multiplexed("Mux", [rule(""), { ...rule("x"), sampleGroupId: "OTHER" as PlId }]);
expect(blockArgsIssues(blockData([ds]))).toEqual([
{
severity: "error",
message:
"Mux: 1 empty barcode value in the rules table. | Mux: 1 rule reference unknown file groups.",
},
]);
});

test("a rule warning alone still blocks Run", () => {
const ds = multiplexed("Mux", []);
expect(blockArgsIssues(blockData([ds]))).toEqual([
{ severity: "error", message: "Mux: 1 file group without rules: g1." },
]);
});

test("the same barcodes for two samples of one group block Run", () => {
const other = "SAMPLE0000000000000000001" as PlId;
const ds = multiplexed("Mux", [rule("ACGT"), { ...rule("ACGT"), ruleId: "r2", sampleId: other }]);
const data = { ...blockData([ds]), sampleLabels: { [sample]: "S1", [other]: "S2" } };
expect(blockArgsIssues(data)).toEqual([
{
severity: "error",
message: "Mux: Same barcodes assigned to different samples in the same group — g1: S1, S2.",
},
]);
});
23 changes: 23 additions & 0 deletions model/src/args_issues.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import type { ArgsIssue } from "@platforma-sdk/model";
import type { BlockData } from "./args";
import { validateMultiplexingRules } from "./multiplexing-rules-validation";
import { validateDatasets } from "./validate_datasets";

/**
* Lists what keeps the block from running. Dataset problems are checked first;
* the multiplexing rules are checked only once the datasets themselves are
* runnable, and every rule issue blocks Run, warnings included.
*/
export function blockArgsIssues(data: BlockData): ArgsIssue[] {
const datasetIssues = validateDatasets(data.datasets);
if (datasetIssues.length > 0) return datasetIssues;

const ruleIssues = validateMultiplexingRules(data.datasets, data.sampleLabels);
if (ruleIssues.length === 0) return [];
return [
{
severity: "error",
message: ruleIssues.map((i) => `${i.datasetLabel}: ${i.message}`).join(" | "),
},
];
}
10 changes: 3 additions & 7 deletions model/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import type { ImportFileHandle, InferHrefType, InferOutputsType, PlId } from "@p
import { BlockModelV3 } from "@platforma-sdk/model";
import { blockDataModel } from "./data_model";
import type { BlockArgs, BlockPrerunArgs } from "./args";
import { validateMultiplexingRules } from "./multiplexing-rules-validation";
import { validateDatasets } from "./validate_datasets";
import { blockArgsIssues } from "./args_issues";
import { deriveTemplateParams } from "./template_params";

function sortedById<T extends { id: string }>(items: T[]) {
Expand All @@ -18,11 +17,6 @@ function sortedStr<S extends string>(items: S[]): S[] {
export const platforma = BlockModelV3.create({ dataModel: blockDataModel, kind })

.args<BlockArgs>((data) => {
validateDatasets(data.datasets);
const ruleIssues = validateMultiplexingRules(data.datasets, data.sampleLabels);
if (ruleIssues.length > 0) {
throw new Error(ruleIssues.map((i) => `${i.datasetLabel}: ${i.message}`).join(" | "));
}
return {
datasets: sortedById(data.datasets),
metadata: sortedById(data.metadata),
Expand All @@ -31,6 +25,8 @@ export const platforma = BlockModelV3.create({ dataModel: blockDataModel, kind }
};
})

.argsIssues(({ data }) => blockArgsIssues(data))

.prerunArgs((data): BlockPrerunArgs => {
return {
datasets: sortedById(data.datasets),
Expand Down
26 changes: 14 additions & 12 deletions model/src/validate_datasets.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,29 +34,31 @@ function bulkCountMatrix(label: string, withData: boolean): DSBulkCountMatrix {
};
}

function error(message: string) {
return [{ severity: "error", message }];
}

test("a block with no datasets runs", () => {
expect(() => validateDatasets([])).not.toThrow();
expect(validateDatasets([])).toEqual([]);
});

test("datasets with data pass", () => {
expect(() =>
validateDatasets([fastq("Reads", true), bulkCountMatrix("Counts", true)]),
).not.toThrow();
expect(validateDatasets([fastq("Reads", true), bulkCountMatrix("Counts", true)])).toEqual([]);
});

test("a single empty dataset is rejected by label", () => {
expect(() => validateDatasets([fastq("Reads", false)])).toThrow('No data in dataset: "Reads"');
expect(validateDatasets([fastq("Reads", false)])).toEqual(error('No data in dataset: "Reads"'));
});

test("an empty grouped dataset is rejected as empty, not as misconfigured", () => {
expect(() => validateDatasets([bulkCountMatrix("Counts", false)])).toThrow(
'No data in dataset: "Counts"',
expect(validateDatasets([bulkCountMatrix("Counts", false)])).toEqual(
error('No data in dataset: "Counts"'),
);
});

test("multiple empty datasets are all named", () => {
expect(() => validateDatasets([fastq("Reads", false), bulkCountMatrix("Counts", false)])).toThrow(
'No data in datasets: "Reads", "Counts"',
expect(validateDatasets([fastq("Reads", false), bulkCountMatrix("Counts", false)])).toEqual(
error('No data in datasets: "Reads", "Counts"'),
);
});

Expand All @@ -66,13 +68,13 @@ test("mixed datasets name only the empty ones", () => {
fastq("More reads", false),
bulkCountMatrix("Counts", true),
];
expect(() => validateDatasets(datasets)).toThrow('No data in dataset: "More reads"');
expect(validateDatasets(datasets)).toEqual(error('No data in dataset: "More reads"'));
});

test("a grouped dataset with data but no groups is still rejected", () => {
const ds = bulkCountMatrix("Counts", true);
ds.content.sampleGroups = undefined;
expect(() => validateDatasets([ds])).toThrow(
"Not all grouped datasets have sample groups configured",
expect(validateDatasets([ds])).toEqual(
error("Not all grouped datasets have sample groups configured"),
);
});
24 changes: 17 additions & 7 deletions model/src/validate_datasets.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
import type { ArgsIssue } from "@platforma-sdk/model";
import { isGroupedDataset } from "./args";
import type { DSAny } from "./args";

/**
* Rejects dataset states the block must not run with. Called from the model's
* `args` derivation, so a throw here keeps Run disabled.
* Lists the dataset states the block must not run with, each as an error that
* keeps Run disabled.
*
* A dataset with no data is a legal editor state (it is what a project
* template seeds), but running it would export empty columns, so it blocks
* Run until files are added. A block with no datasets at all still runs.
*/
export function validateDatasets(datasets: DSAny[]) {
export function validateDatasets(datasets: DSAny[]): ArgsIssue[] {
const empty = datasets.filter((ds) => Object.keys(ds.content.data).length === 0);
if (empty.length > 0) {
throw new Error(
`No data in dataset${empty.length > 1 ? "s" : ""}: ${empty.map((ds) => `"${ds.label}"`).join(", ")}`,
);
return [
{
severity: "error",
message: `No data in dataset${empty.length > 1 ? "s" : ""}: ${empty.map((ds) => `"${ds.label}"`).join(", ")}`,
},
];
}

const valid = datasets.every((ds) => {
Expand All @@ -23,5 +27,11 @@ export function validateDatasets(datasets: DSAny[]) {
Object.keys(ds.content.sampleGroups ?? {}).length === Object.keys(ds.content.data).length
);
});
if (!valid) throw new Error("Not all grouped datasets have sample groups configured");
if (!valid) {
return [
{ severity: "error", message: "Not all grouped datasets have sample groups configured" },
];
}

return [];
}
Loading
Loading