Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
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
5 changes: 5 additions & 0 deletions .changeset/wes-run-requests.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@elixir-cloud/wes": minor
---

Build WES run requests from GA4GH IO Schemas: `ecc-client-ga4gh-wes-run-create` gains a schema mode (`ioSchema`, `trsToolVersion`, `engineProfile`, `allowedSchemes`) that shows the workflow's input form and submits the request built by the profile's engine bindings; the raw mode stays. `@elixir-cloud/wes/utils` exports the builder (`toWorkflowParams`, `buildRunRequest`), TRS helpers (`trsDescriptorUrl`, `findSchemaFile`, `findPrimaryDescriptorPath`, `unsupportedBy`) and `conquestEngineProfile`.
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import React, { useMemo, useState } from 'react';
import { ECCClientGa4ghWesRunCreate } from '@elixir-cloud/wes/react';
import type { RunRequest, WesProvider } from '@elixir-cloud/wes/providers';
import PreviewLayout from '@/components/common/PreviewLayout';
import { ioFormExamples } from '@/components/packages/wes/ioFormExamples';

const allowedSchemes = ['drs', 'https', 's3'];

/** A TRS tool version for each example (made up, nothing is fetched). */
const trsToolVersion = (example: string) => ({
trsUrl: 'https://trs.example.org/ga4gh/trs/v2',
toolId: example,
versionId: '1.0.0',
descriptorTypeVersions: ['DSL2', '8', 'v1.2', '1.1'],
});

/**
* A provider that runs nothing: it says that it runs every workflow type
* and shows the request that the component would submit.
*/
class DryRunProvider implements WesProvider {
private show: (request: RunRequest) => void;

constructor(show: (request: RunRequest) => void) {
this.show = show;
}

async getServiceInfo() {
const all = { workflow_type_version: [] as string[] };
return {
workflow_type_versions: { NFL: all, SMK: all, WDL: all, CWL: all },
supported_wes_versions: ['1.1.0'],
supported_filesystem_protocols: allowedSchemes,
workflow_engine_versions: {},
default_workflow_engine_parameters: [],
system_state_counts: {},
};
}

async runWorkflow(request: RunRequest) {
this.show(request);
return { run_id: 'dry-run' };
}

async listRuns() {
return { runs: [] };
}

async getRunLog(): Promise<never> {
throw new Error('A dry run has no runs.');
}

async getRunStatus(): Promise<never> {
throw new Error('A dry run has no runs.');
}

async cancelRun(): Promise<never> {
throw new Error('A dry run has no runs.');
}
}

export default function RunCreateSchemaPreview() {
const [example, setExample] = useState('greetings-nextflow');
const [request, setRequest] = useState<RunRequest | null>(null);
const provider = useMemo(() => new DryRunProvider(setRequest), []);

return (
<PreviewLayout>
<div className='flex w-full flex-col gap-4'>
<label className='flex items-center gap-2 text-sm'>
Example
<select
className='rounded-md border px-2 py-1'
value={example}
onChange={(e) => {
setRequest(null);
setExample(e.target.value);
}}
>
{Object.entries(ioFormExamples).map(([key, { label }]) => (
<option key={key} value={key}>
{label}
</option>
))}
</select>
</label>
<ECCClientGa4ghWesRunCreate
key={example}
provider={provider}
ioSchema={ioFormExamples[example].schema}
trsToolVersion={trsToolVersion(example)}
allowedSchemes={allowedSchemes}
/>
{request && (
<pre className='overflow-auto rounded-md bg-muted p-3 text-xs'>
{JSON.stringify(request, null, 2)}
</pre>
)}
</div>
</PreviewLayout>
);
}
64 changes: 60 additions & 4 deletions apps/documentation/pages/docs/wes/components/run-create.mdx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Tabs } from 'nextra/components'
import ComponentName from '@/components/common/ComponentName'
import RunCreatePreview from '@/components/packages/wes/RunCreatePreview'
import RunCreateSchemaPreview from '@/components/packages/wes/RunCreateSchemaPreview'

# EccClientGa4ghWesRunCreate Component

Expand All @@ -12,7 +13,10 @@ import RunCreatePreview from '@/components/packages/wes/RunCreatePreview'

## Overview

The `ecc-client-ga4gh-wes-run-create` component provides a form for submitting new workflow runs to a WES endpoint.
The `ecc-client-ga4gh-wes-run-create` component provides a form for submitting new workflow runs to a WES endpoint. It has two modes:

- **Raw mode** (default): the user enters the workflow URL, type, version and `workflow_params` as JSON.
- **Schema mode** (with `ioSchema` and `trsToolVersion`): the user fills in the input form of the workflow's [I/O Schema](/docs/wes/io-schema) instead, and the component builds the run request from the schema, the values and the TRS tool version (see [Run requests](/docs/wes/io-schema#run-requests)).

## Usage

Expand Down Expand Up @@ -71,11 +75,63 @@ This example shows the basic form for creating a new workflow run.
</Tabs.Tab>
</Tabs>

### Schema mode

With an IO schema and the TRS tool version to run, the form shows the workflow's inputs ([`ecc-client-ga4gh-wes-io-form`](./io-form)) instead of the raw fields, and the workflow that will run: its type and language version (from the schema's `x-ga4gh-workflow`, else the first version of the TRS tool version that the service runs, else the first version of the TRS tool version) and the workflow URL (the plain primary descriptor in TRS). It says when the WES service doesn't run the workflow's type or version (from its `service-info`), and submits only valid values.

On submit, the values are translated into `workflow_params` by the profile's engine binding for the descriptor type (`NFL`, `SMK`, `WDL`, `CWL`); values that the binding refuses (e.g. a file reference with a scheme that isn't allowed) are shown as `<JSON Pointer>: <message>`, and `ecc-run-create-failed` is fired with that text. The engine parameters, tags and attachments of the advanced section are added. An `engineProfile` then adapts the request to a particular WES server.

This preview uses a provider that submits nothing and shows the request instead:

<Tabs items={['Preview', 'React']}>
<Tabs.Tab>
<RunCreateSchemaPreview />
</Tabs.Tab>

<Tabs.Tab>
```tsx showLineNumbers copy filename="run-create-schema.tsx"
import React from 'react';
import { ECCClientGa4ghWesRunCreate } from '@elixir-cloud/wes/react';
import { RestWesProvider } from '@elixir-cloud/wes/providers';

export default function RunCreateSchema({ schema }: { schema: object }) {
const provider = new RestWesProvider(
'https://wes.example.com/ga4gh/wes/v1'
);

return (
<ECCClientGa4ghWesRunCreate
provider={provider}
ioSchema={schema}
trsToolVersion={{
trsUrl: 'https://trs.example.org/ga4gh/trs/v2',
toolId: 'greetings',
versionId: '1.0.0',
primaryDescriptorPath: 'main.nf',
descriptorTypeVersions: ['DSL2'],
}}
/>
);
}
```
</Tabs.Tab>
</Tabs>

#### Engine profiles

Some WES servers need more than the profile's binding gives. An engine profile (`EngineProfile` from `@elixir-cloud/wes/utils`) takes the built request and returns the request for one server; it is kept out of the generic builder. The package has one:

- `conquestEngineProfile`: [Conquest](https://github.com/elixir-cloud-aai/conquest) runs workflows from public GitHub repositories at a full commit SHA. The profile sets `workflow_url` to the repository and adds the engine parameters `revision` and the path of the main workflow file (`main_script` for Nextflow, `snakefile` for Snakemake, `main_workflow_path` for WDL), all taken from `trsToolVersion.primaryDescriptorUrl`: the `url` of the TRS descriptor, a `raw.githubusercontent.com` or `github.com/.../blob/...` URL at a commit. It refuses CWL, branches and tags.

## Properties

| Property | Type | Default | Description |
|------------|---------------------------|---------|--------------------------------------------------------------------------------|
| `provider` | `WesProvider` | `null` | Data provider for submitting the run (see [Providers](/docs/wes/providers)) |
| Property | Type | Default | Description |
|------------------|---------------------|--------------------|-------------|
| `provider` | `WesProvider` | `null` | Data provider for submitting the run (see [Providers](/docs/wes/providers)) |
| `ioSchema` | `object` | `undefined` | An IO schema (GA4GH IO Schema Profile 0.3.0); switches to schema mode |
| `trsToolVersion` | `TrsToolVersionRef` | `undefined` | The TRS tool version to run in schema mode: `trsUrl`, `toolId`, `versionId`, and optionally `primaryDescriptorPath` (as TRS lists it; else the schema's `primary_descriptor_path`), `descriptorTypeVersions` (of the tool version) and `primaryDescriptorUrl` (for engine profiles) |
| `engineProfile` | `EngineProfile` | `undefined` | Adapts the built request to a WES server, e.g. `conquestEngineProfile` |
| `allowedSchemes` | `string[]` | `['drs', 'https']` | URI schemes that file references may have in schema mode, in the I/O form and in the built request |

## Events

Expand Down
26 changes: 25 additions & 1 deletion apps/documentation/pages/docs/wes/io-schema.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ The WES components understand the [GA4GH IO Schema Profile](https://github.com/e

## Profile version

The package supports version **0.3.0** of the profile, pinned at commit [`2c3dc49`](https://github.com/elixir-cloud-aai/ga4gh-io-schema/tree/2c3dc49ad89f0a556272f160369a2a2d7a21dac3). Its meta-schema and vocabularies are bundled with the package; `scripts/sync-io-schema.mjs` in the package copies them, the conformance suite and the example schemas from a checkout of the profile's repository at the pinned commit.
The package supports version **0.3.0** of the profile, pinned at commit [`2c3dc49`](https://github.com/elixir-cloud-aai/ga4gh-io-schema/tree/2c3dc49ad89f0a556272f160369a2a2d7a21dac3). Its meta-schema and vocabularies are bundled with the package; `scripts/sync-io-schema.mjs` in the package copies them, the conformance suite, the test vectors and the example schemas from a checkout of the profile's repository at the pinned commit.

## Checks

Expand Down Expand Up @@ -51,6 +51,30 @@ JSON Schema can't check the values of file references (`x-ga4gh-file`), so the c

Outputs must be absolute URIs. The checks pass the profile's test vectors for file reference values (`tests/vectors/file-values`).

## Run requests

`@elixir-cloud/wes/utils` builds WES run requests from input values by the profile's [engine bindings](https://ga4gh-io-schema.readthedocs.io/en/latest/specification/engine-bindings/), which [`ecc-client-ga4gh-wes-run-create`](./components/run-create#schema-mode) uses in schema mode:

```typescript
import {
buildRunRequest,
findPrimaryDescriptorPath,
trsDescriptorUrl,
} from '@elixir-cloud/wes/utils';

const request = await buildRunRequest(schema, values, {
workflowUrl: trsDescriptorUrl(trsUrl, toolId, versionId, 'NFL', findPrimaryDescriptorPath(files)),
binding: { descriptorTypeVersion: 'DSL2' }, // only if the schema has none
});
```

- `toWorkflowParams()` checks the schema, validates the values against `inputs`, checks every file reference value, and translates the values for the descriptor type: unqualified names for `NFL` and `SMK`, names qualified with the entry point for `WDL`, `File` and `Directory` objects for CWL file values. Inputs are renamed by `x-ga4gh-parameter`; defaults of the schema are never inserted. Values that Nextflow or the CWL loader would change (`${`, keys with `-` for Nextflow; `File` objects, keys with `$` or `:` for CWL) are refused. Errors are `TranslationError`s with the JSON Pointer of the value.
- `buildRunRequest()` adds `workflow_type`, `workflow_type_version` and `workflow_url` (for CWL, with the entry point as its fragment). Tags and engine parameters are left to the caller and to [engine profiles](./components/run-create#engine-profiles).
- `trsDescriptorUrl()`, `findPrimaryDescriptorPath()` and `findSchemaFile()` give the workflow URL of a TRS tool version and find its IO schema among its files.
- `unsupportedBy()` says whether a WES service runs a binding's type and version, by its `service-info`.

The translation passes the profile's test vectors (`tests/vectors/wes-params`, `workflow-urls` and `trs-files`). It needs a validator that can check subschemas (`validateAt` of the check result), and refuses schemas that it can't follow: references that don't resolve within the document, references and branches inside embedded `$id` resources, and `$dynamicRef`. GALAXY workflows have no binding in profile 0.3.0.

## Descriptions

Titles, descriptions and `enum` values of IO schemas are always shown as text, never as markup.
Expand Down
86 changes: 84 additions & 2 deletions packages/ecc-client-ga4gh-wes/scripts/sync-io-schema.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
* - `src/io-schema/profile.ts`: the meta-schema and its vocabularies, with
* the commit and the version of the profile;
* - `src/io-schema/tests/fixtures/*.ts`: the conformance suite, the test
* vectors of file reference values and the example schemas, for the tests
* and the demos.
* vectors (file reference values, engine bindings, workflow URLs and TRS
* files) and the example schemas, for the tests and the demos.
*
* Usage, from the package directory:
*
Expand Down Expand Up @@ -125,6 +125,88 @@ export const FILE_VALUE_CASES: FileValueCase[] = ${json(
`
);

/**
* The cases of `tests/vectors/<kind>/<descriptor type>/<case>/`, each with
* its JSON files by name (without `.json`), sorted by type and name.
*/
const caseDirectories = (kind) => {
const directories = (...parts) =>
readdirSync(path.join(checkout, "tests", "vectors", kind, ...parts), {
withFileTypes: true,
})
.filter((entry) => entry.isDirectory())
.map((entry) => entry.name)
.sort();
return directories().flatMap((descriptorType) =>
directories(descriptorType).map((name) => {
const files = {};
const at = ["tests", "vectors", kind, descriptorType, name];
for (const file of readdirSync(path.join(checkout, ...at))
.filter((entry) => entry.endsWith(".json"))
.sort()) {
files[file.replace(/\.json$/, "")] = readJson(...at, file);
}
return { descriptorType, name, ...files };
})
);
};

write(
"src/io-schema/tests/fixtures/wes-params.ts",
`${header(
"Test vectors of the engine bindings (`tests/vectors/wes-params/`)."
)}
export interface WesParamsCase {
descriptorType: string;
name: string;
schema: Record<string, unknown>;
values: unknown;
/** The expected \`workflow_params\`, or else \`error\` */
workflow_params?: Record<string, unknown>;
error?: { pointer: string };
options?: { allowedSchemes?: string[]; allowAbsolutePaths?: boolean };
}

export const WES_PARAMS_CASES: WesParamsCase[] = ${json(
caseDirectories("wes-params")
)};
`
);

write(
"src/io-schema/tests/fixtures/trs.ts",
`${header(
"Test vectors of workflow URLs and TRS files (`tests/vectors/workflow-urls/`, `tests/vectors/trs-files/`)."
)}
export interface WorkflowUrlCase {
name: string;
trsUrl: string;
toolId: string;
versionId: string;
descriptorType: string;
primaryDescriptorPath?: string;
workflowUrl?: string;
error?: boolean;
imports?: { reference: string; url: string }[];
}

export interface TrsFilesCase {
name: string;
files: unknown;
schemaFile: { path: string; file_type: string } | null;
primaryDescriptorPath?: string | null;
}

export const WORKFLOW_URL_CASES: WorkflowUrlCase[] = ${json(
readJson("tests", "vectors", "workflow-urls", "cases.json")
)};

export const TRS_FILES_CASES: TrsFilesCase[] = ${json(
readJson("tests", "vectors", "trs-files", "cases.json")
)};
`
);

const examples = {
example_tool: readJson("tests", "data", "example_tool.schema.json"),
example_wdl: readJson("tests", "data", "example_wdl.schema.json"),
Expand Down
Loading
Loading