-
Notifications
You must be signed in to change notification settings - Fork 0
Julenmendieta/milab 6505 user error #61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
8a05314
Add selected sequence to block label
julenmendieta 21a1487
Remove dead code
julenmendieta 0e8ca06
Upgrade to kind usage
julenmendieta 3ced003
Changeset
julenmendieta 2c18532
Load Settings types directly from kind into UI
julenmendieta b5bb01f
Merge branch 'main' into julenmendieta/MILAB-6505_userError
julenmendieta 763b604
built lockfile
julenmendieta File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| --- | ||
| "@platforma-open/milaboratories.immune-assay-data.workflow": minor | ||
| "@platforma-open/milaboratories.immune-assay-data": minor | ||
| "@platforma-open/milaboratories.immune-assay-data.model": minor | ||
| "@platforma-open/milaboratories.immune-assay-data.kind": minor | ||
| "@platforma-open/milaboratories.immune-assay-data.ui": minor | ||
| --- | ||
|
|
||
| Fix trace gap |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| { | ||
| "extends": ["node_modules/@milaboratories/ts-builder/configs/oxfmt.json"], | ||
| "ignorePatterns": ["dist", "coverage", "CHANGELOG.md"] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| { | ||
| "extends": ["node_modules/@milaboratories/ts-builder/dist/configs/oxlint-node.json"] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| { | ||
| "name": "@platforma-open/milaboratories.immune-assay-data.kind", | ||
| "version": "1.0.0", | ||
| "private": true, | ||
| "type": "module", | ||
| "main": "./dist/index.cjs", | ||
| "module": "./dist/index.js", | ||
| "types": "./dist/index.d.ts", | ||
| "exports": { | ||
| ".": { | ||
| "types": "./dist/index.d.ts", | ||
| "sources": "./src/index.ts", | ||
| "import": "./dist/index.js", | ||
| "require": "./dist/index.cjs", | ||
| "default": "./dist/index.js" | ||
| } | ||
| }, | ||
| "scripts": { | ||
| "fmt": "ts-builder format", | ||
| "watch": "ts-builder build --target block-kind --watch", | ||
| "build": "ts-builder build --target block-kind && block-tools build-kind-manifest", | ||
| "check": "ts-builder check --target block-kind" | ||
| }, | ||
| "dependencies": { | ||
| "@milaboratories/pl-model-common": "catalog:", | ||
| "@platforma-sdk/block-kind": "catalog:", | ||
| "es-toolkit": "catalog:" | ||
| }, | ||
| "devDependencies": { | ||
| "@milaboratories/ts-builder": "catalog:", | ||
| "@milaboratories/ts-configs": "catalog:", | ||
| "@platforma-sdk/block-tools": "catalog:" | ||
| }, | ||
| "peerDependencies": { | ||
| "@types/node": "*", | ||
| "typescript": "*" | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,146 @@ | ||
| import type { ImportFileHandle, PlRef, SUniversalPColumnId } from "@milaboratories/pl-model-common"; | ||
| import { isColumnUniversalId, isPlRef } from "@milaboratories/pl-model-common"; | ||
| import { assertParamsObject, defineBlockKind } from "@platforma-sdk/block-kind"; | ||
| import { isBoolean, isPlainObject, isString } from "es-toolkit"; | ||
| import { isArray, isNumber } from "es-toolkit/compat"; | ||
| import { name, version } from "../package.json" with { type: "json" }; | ||
|
|
||
| /** | ||
| * Matching method and thresholds. | ||
| */ | ||
| export type Settings = { | ||
| coverageThreshold: number; | ||
| identity: number; | ||
| /** | ||
| * `alignment-score` / `sequence-identity` run MMseqs2; `exact-match` reports only | ||
| * byte-identical sequences and ignores identity/coverage/fast-mode. | ||
| */ | ||
| similarityType: "sequence-identity" | "alignment-score" | "exact-match"; | ||
| }; | ||
|
|
||
| /** Which upstream the block is pointed at. Lives here for the same reason as {@link Settings}. */ | ||
| export type Modality = "antibody_tcr" | "peptide"; | ||
|
|
||
| /** | ||
| * This block's init-params contract — everything a creator or a project template chooses, | ||
| * and nothing derived. Excluded on purpose: state the block recomputes from the assay file's | ||
| * own bytes (`importColumns`, `detectedXsvType`, `fileImportError`) and pure view state | ||
| * (`tableState`, `alignmentModel`). | ||
| * | ||
| * `mem` / `cpu` are excluded deliberately and permanently: resource allocation belongs to | ||
| * the machine a block runs on, not to configuration a template carries between machines. | ||
| * | ||
| * `fileHandle` travels only when it is an `index://` handle — that is `{storageId, path}`, | ||
| * which resolves for anyone whose server registers that storage. An `upload://` handle | ||
| * carries a signature bound to the instance that made it and will not resolve elsewhere. | ||
| * The model's `templateParams` projection is what drops an `upload://` handle, so one never | ||
| * reaches a template by export. It is still accepted here rather than rejected: a parser | ||
| * stricter than the states the UI reaches would make the block refuse its own exports, and a | ||
| * hand-written entry naming a local file is the author's call to make. | ||
| * | ||
| * Every field is optional: a block may be created without a template, and a template need | ||
| * not set all of them. | ||
| */ | ||
| export type BlockParams = { | ||
| customBlockLabel?: string; | ||
| datasetRef?: PlRef; | ||
| targetRef?: SUniversalPColumnId; | ||
| targetColumnLabel?: string; | ||
| fileHandle?: ImportFileHandle; | ||
| fileExtension?: string; | ||
| sequenceColumnHeader?: string; | ||
| selectedColumns?: string[]; | ||
| settings?: Settings; | ||
| lessSensitive?: boolean; | ||
| maxSeqs?: number; | ||
| /** | ||
| * Carried on purpose, like the rest of the recipe. The UI reapplies modality threshold | ||
| * defaults whenever the resolved modality differs from this field, so a template that | ||
| * carried `settings` without it would land, see `undefined`, and have its thresholds | ||
| * overwritten. Carrying it also stays correct when a template lands on the other | ||
| * modality: the values then differ, the watcher fires, and the new defaults win. | ||
| */ | ||
| lastAppliedModality?: Modality; | ||
| }; | ||
|
|
||
| type Guard<T> = (v: unknown) => v is T; | ||
| type Check<T> = { is: Guard<T>; must: string }; | ||
|
|
||
| function check<T>(is: Guard<T>, must: string): Check<T> { | ||
| return { is, must }; | ||
| } | ||
|
|
||
| /** Both handle forms are `<scheme>://<scheme>/<urlencoded JSON>`; the scheme is the envelope. */ | ||
| const isImportFileHandle: Guard<ImportFileHandle> = (v): v is ImportFileHandle => | ||
| isString(v) && (v.startsWith("upload://") || v.startsWith("index://")); | ||
|
|
||
| const isStringArray: Guard<string[]> = (v): v is string[] => isArray(v) && v.every(isString); | ||
|
|
||
| const isModality: Guard<Modality> = (v): v is Modality => v === "antibody_tcr" || v === "peptide"; | ||
|
|
||
| /** | ||
| * A whole number of at least `min`. `Number.isInteger` rather than es-toolkit's `isInteger`, | ||
| * which returns a plain boolean and so leaves the value un-narrowed for the comparison after it. | ||
| */ | ||
| function isIntAtLeast(min: number): Guard<number> { | ||
| return (v): v is number => isNumber(v) && Number.isInteger(v) && v >= min; | ||
| } | ||
|
|
||
| const SIMILARITY_TYPES: readonly Settings["similarityType"][] = [ | ||
| "sequence-identity", | ||
| "alignment-score", | ||
| "exact-match", | ||
| ]; | ||
|
|
||
| const isSettings: Guard<Settings> = (v): v is Settings => | ||
| isPlainObject(v) && | ||
| isNumber(v.coverageThreshold) && | ||
| isNumber(v.identity) && | ||
| SIMILARITY_TYPES.includes(v.similarityType as Settings["similarityType"]); | ||
|
|
||
| /** | ||
| * The runtime half of the contract. The `satisfies` clause is what stops it drifting: every | ||
| * field `BlockParams` declares must appear here, and each guard must narrow to that field's | ||
| * own type — so adding a param without a check stops compiling. | ||
| */ | ||
| const CONTRACT = { | ||
| customBlockLabel: check(isString, "a string"), | ||
| datasetRef: check(isPlRef, "a reference to an input dataset"), | ||
| targetRef: check(isColumnUniversalId, "a sequence column identifier"), | ||
| targetColumnLabel: check(isString, "a string"), | ||
| fileHandle: check(isImportFileHandle, "an upload:// or index:// file handle"), | ||
| fileExtension: check(isString, "a string"), | ||
| sequenceColumnHeader: check(isString, "a string"), | ||
| selectedColumns: check(isStringArray, "an array of column names"), | ||
| settings: check(isSettings, "an object with coverageThreshold, identity and similarityType"), | ||
| lessSensitive: check(isBoolean, "a boolean"), | ||
| maxSeqs: check(isIntAtLeast(0), "a whole number of 0 or more, where 0 means no limit"), | ||
| lastAppliedModality: check(isModality, '"antibody_tcr" or "peptide"'), | ||
| } satisfies { [K in keyof Required<BlockParams>]: Check<NonNullable<BlockParams[K]>> }; | ||
|
|
||
| /** | ||
| * The contract at runtime, for params arriving from a template file rather than typed code. | ||
| * An absent field is always allowed — every param is optional and the block's own default | ||
| * takes over — so each guard runs only on what is present. Keys the contract does not name | ||
| * are dropped by never being read. | ||
| */ | ||
| function parseInitializationParams(value: unknown): BlockParams { | ||
| assertParamsObject(value); | ||
|
|
||
| const params: Record<string, unknown> = {}; | ||
| for (const [field, { is, must }] of Object.entries(CONTRACT)) { | ||
| const v = value[field]; | ||
| if (v === undefined) continue; | ||
| if (!is(v)) throw new Error(`'${field}' must be ${must}.`); | ||
| params[field] = v; | ||
| } | ||
| return params as BlockParams; | ||
| } | ||
|
|
||
| // Identity comes from this package's own package.json, so the on-wire `{name}@{version}` | ||
| // reference can never drift from what is published; the bundler inlines the JSON import. | ||
| export const kind = defineBlockKind<BlockParams>({ | ||
| name, | ||
| version, | ||
| parseInitializationParams, | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| { | ||
| "extends": "@milaboratories/ts-configs/block/facade", | ||
| "compilerOptions": { | ||
| "outDir": "./dist", | ||
| "rootDir": ".", | ||
| "resolveJsonModule": true | ||
| }, | ||
| "include": ["src/**/*", "package.json"], | ||
| "exclude": ["dist", "node_modules"] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When a hand-written or externally generated template supplies
identityorcoverageThresholdoutside 0.1–1.0,isSettingsaccepts it and the model forwards it unchanged to alignment processing, causing invalid matching behavior or a failed run.Knowledge Base Used: Assay domain model
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agree