From f78c94f5bc545ecfbb7abab667ebcc400082c4a9 Mon Sep 17 00:00:00 2001 From: Mariia Zueva Date: Thu, 19 Nov 2026 15:57:04 +0100 Subject: [PATCH 1/2] MILAB-7356 Add a raw trace view on the Files tab --- .changeset/raw-trace-files-view.md | 10 ++ model/src/index.ts | 22 ++++ ui/src/FilesTable.vue | 72 ++++++++++++- ui/src/RawTraceViewer.vue | 164 +++++++++++++++++++++++++++++ workflow/src/main.tpl.tengo | 5 + 5 files changed, 271 insertions(+), 2 deletions(-) create mode 100644 .changeset/raw-trace-files-view.md create mode 100644 ui/src/RawTraceViewer.vue diff --git a/.changeset/raw-trace-files-view.md b/.changeset/raw-trace-files-view.md new file mode 100644 index 0000000..7645058 --- /dev/null +++ b/.changeset/raw-trace-files-view.md @@ -0,0 +1,10 @@ +--- +"@platforma-open/milaboratories.clone-annotation.block": patch +"@platforma-open/milaboratories.clone-annotation.model": patch +"@platforma-open/milaboratories.clone-annotation.ui": patch +"@platforma-open/milaboratories.clone-annotation.workflow": patch +--- + +Add a raw trace view on the Files tab. Open any uploaded Sanger file (.ab1/.scf) to +see its full-length chromatogram and read quality, with the Mott-trimmed ends marked — +the read as the instrument wrote it, before trimming and the consensus merge. diff --git a/model/src/index.ts b/model/src/index.ts index 2b37457..8b2797f 100644 --- a/model/src/index.ts +++ b/model/src/index.ts @@ -109,6 +109,9 @@ export type TraceRead = { /** Mean Phred over that stretch. Absent where the form carried no quality. */ meanQuality?: number; kept: boolean; + /** Bases Mott trimming cut from the start and the end. Absent for a form that + * carries no quality, which is not trimmed. */ + trimmed?: [number, number]; }; /** A trace that produced nothing usable, and why. */ @@ -260,6 +263,11 @@ export type TraceReport = { sequences: Sequence[]; }; +/** + * Every raw read behind each sequence and clone, for the raw-trace view. Paths are + * the ones the Files table shows; the UI maps each to its uploaded file. Keyed as + * the tables are, so a table selection resolves straight to its reads. + */ /** * How a sheet's columns are read. Stated by the scientist rather than guessed * from the headers, on the same terms as the name pattern. @@ -642,6 +650,20 @@ export const platforma = BlockModelV3.create({ dataModel, kind }) { isActive: true }, ) + // Each uploaded read as a downloadable blob handle, keyed by its import handle, so + // the UI can fetch the raw .ab1 bytes and draw the untrimmed chromatogram. These are + // the exported blobs (`traceBlobs`), not `fileImports`, which holds the import index. + // Reads upload in the main run, so a handle appears here only once the block has run. + .output("traceContent", (ctx) => + Object.fromEntries( + ctx.outputs + ?.resolve({ field: "traceBlobs", assertFieldType: "Input" }) + ?.mapFields((handle, acc) => [handle as ImportFileHandle, acc.getFileHandle()], { + skipUnresolved: true, + }) ?? [], + ), + ) + // Drives the sheet's upload and lets the UI read its bytes to offer the columns. // The field exists only once a sheet has been picked, so its absence is normal. .output( diff --git a/ui/src/FilesTable.vue b/ui/src/FilesTable.vue index 6a46bf2..7ce3f2c 100644 --- a/ui/src/FilesTable.vue +++ b/ui/src/FilesTable.vue @@ -5,6 +5,7 @@ import type { } from "@platforma-open/milaboratories.clone-annotation.model"; import { basename, + DEFAULT_QUALITY_THRESHOLD, getFilePathFromHandle, } from "@platforma-open/milaboratories.clone-annotation.model"; import type { PlAgHeaderComponentParams } from "@platforma-sdk/ui-vue"; @@ -14,12 +15,14 @@ import { PlAgCellFile, PlAgCellStatusTag, PlAgColumnHeader, + PlAgTextAndButtonCell, } from "@platforma-sdk/ui-vue"; import type { ColDef, GridApi, GridOptions, GridReadyEvent, IRowNode } from "ag-grid-enterprise"; import { AgGridVue } from "ag-grid-vue3"; -import { computed, shallowRef } from "vue"; +import { computed, ref, shallowRef } from "vue"; import { useApp } from "./app"; import { cloneKey } from "./properties"; +import RawTraceViewer, { type RawTraceRead } from "./RawTraceViewer.vue"; import type { SelectedFile } from "./trace_set"; import { ALL_EXTENSIONS, compilePattern } from "./trace_set"; @@ -162,7 +165,26 @@ const wellLabel = computed(() => (identityIsName.value ? "Sequence ID" : "Well") const columnDefs = computed[]>(() => [ makeRowNumberColDef(), - { headerName: "Path", field: "path", flex: 2, minWidth: 160 }, + { + headerName: "Path", + field: "path", + flex: 2, + minWidth: 160, + // On an uploaded trace file, a hover button opens its raw Sanger trace. Other + // rows keep the plain path cell. + cellRendererSelector: (cell) => + canViewRaw(cell.data) + ? { + component: PlAgTextAndButtonCell, + params: { + icon: "maximize", + btnLabel: "Trace", + invokeRowsOnDoubleClick: false, + onClick: (p: { data?: FileRow }) => p.data && openRawRow(p.data), + }, + } + : undefined, + }, ...(hasValue("plate") && !identityIsName.value ? [{ headerName: "Plate", field: "plate", flex: 1, minWidth: 100 } satisfies ColDef] : []), @@ -262,6 +284,51 @@ const columnDefs = computed[]>(() => [ }, ]); +// Downloadable handle per uploaded read, keyed by its import handle. Present only +// after the block has run (reads upload in the main run), so the raw-trace action +// is offered only for files that are already there. +const traceContent = computed(() => app.model.outputs.traceContent ?? {}); +const isTraceForm = computed(() => (app.model.data.form ?? "trace") === "trace"); +const qualityThreshold = computed( + () => app.model.data.qualityThreshold ?? DEFAULT_QUALITY_THRESHOLD, +); + +const rawOpen = ref(false); +const rawReads = ref([]); + +function rawLabel(row: FileRow): string { + return [row.plate, row.well, row.chain, row.direction].filter(Boolean).join(" / ") || row.path; +} + +function rawReadsOf(rows: FileRow[]): RawTraceRead[] { + return rows.flatMap((row) => { + const handle = traceContent.value[row.file]; + return handle + ? [ + { + key: row.key, + label: rawLabel(row), + chainLabel: "", + handle: handle.handle, + trimmed: row.read?.trimmed, + }, + ] + : []; + }); +} + +/** True once a file's read is uploaded, so its raw trace can be opened. */ +function canViewRaw(row: FileRow | undefined): boolean { + return isTraceForm.value && row !== undefined && traceContent.value[row.file] !== undefined; +} + +function openRawRow(row: FileRow) { + const reads = rawReadsOf([row]); + if (reads.length === 0) return; + rawReads.value = reads; + rawOpen.value = true; +} + const gridApi = shallowRef>(); function onGridReady(params: GridReadyEvent) { @@ -318,6 +385,7 @@ const gridOptions: GridOptions = { :gridOptions="gridOptions" @grid-ready="onGridReady" /> + diff --git a/workflow/src/main.tpl.tengo b/workflow/src/main.tpl.tengo index f940b76..33d80b3 100644 --- a/workflow/src/main.tpl.tengo +++ b/workflow/src/main.tpl.tengo @@ -43,6 +43,9 @@ wf.setPreRun(assets.importTemplate(":prerun")) wf.body(func(args) { fileImports := {} + // The imported read blobs, keyed by import handle, so the UI can download the raw + // .ab1 bytes. fileImports holds the import index (for progress), not a blob. + traceBlobs := {} traces := args.traces if is_undefined(traces) { @@ -91,6 +94,7 @@ wf.body(func(args) { nextFile = nextFile + 1 fileIds[t.handle] = fileId blobs[fileId] = imp.file + traceBlobs[t.handle] = file.exportFile(imp.file) plate := "Unplaced" if !is_undefined(t.fields) { @@ -109,6 +113,7 @@ wf.body(func(args) { blockId := wf.blockId().getDataAsJson() outputs := { fileImports: fileImports, + traceBlobs: traceBlobs, clones: joined.clones, unmatched: clones.unmatched(traces), wellsWithoutProperties: joined.clonesWithout, From 3a0884add03d1f6cd8795285dffc497bf0214ef6 Mon Sep 17 00:00:00 2001 From: Mariia Zueva Date: Thu, 19 Nov 2026 17:18:05 +0100 Subject: [PATCH 2/2] MILAB-7356 Add a raw trace view on the Files tab --- model/src/index.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/model/src/index.ts b/model/src/index.ts index 8b2797f..0d25f7d 100644 --- a/model/src/index.ts +++ b/model/src/index.ts @@ -654,10 +654,12 @@ export const platforma = BlockModelV3.create({ dataModel, kind }) // the UI can fetch the raw .ab1 bytes and draw the untrimmed chromatogram. These are // the exported blobs (`traceBlobs`), not `fileImports`, which holds the import index. // Reads upload in the main run, so a handle appears here only once the block has run. + // A project last run before this field existed has no `traceBlobs`, so its absence + // is normal, not an error. .output("traceContent", (ctx) => Object.fromEntries( ctx.outputs - ?.resolve({ field: "traceBlobs", assertFieldType: "Input" }) + ?.resolve({ field: "traceBlobs", assertFieldType: "Input", allowPermanentAbsence: true }) ?.mapFields((handle, acc) => [handle as ImportFileHandle, acc.getFileHandle()], { skipUnresolved: true, }) ?? [],