You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add a resource management workflow and integrate prepared resources into sftool run
Description
Introduce an extensible resource-management command group:
sftool resources setup
The command prepares the persistent datasets and generated resources required by SFtool before sample analysis. Once the workflow is fully integrated, sftool run must consume already installed resources instead of downloading or generating shared resources at runtime.
The initial implementation includes only setup. Future commands such as resources check or resources update remain outside the scope of this issue.
The runtime integration should follow the actual SFtool execution stages. Resource preparation belongs exclusively to sftool resources setup; sftool run should only validate, resolve, select, and consume installed resources.
Main requirements
sftool resources setup must:
load the resource versions bundled with the installed SFtool release;
download the required external datasets;
generate PR and RR catalog resources for GRCh37 and GRCh38;
prepare ClinVar resources for every supported evidence level;
download HPO and PharmCAT support resources;
optionally download and index reference genomes;
write an installed resource manifest;
avoid repeating downloads or processing when valid outputs already exist.
sftool run must:
load and validate the installed resource manifest during bootstrap;
resolve the resources required by the selected assembly, categories, evidence level, and execution modes;
select the correct catalog BED convention independently for each sample;
consume the prepared catalog, ClinVar, HPO, PharmCAT, RR-STR, and reference resources;
never download or generate persistent shared resources at runtime.
The implementation should remain simple and dictionary-based. A generic provider framework, Pydantic models, dataclasses, or a large resource-management hierarchy are not required.
Use stable installed paths and register the files and versions in the manifest.
The PharmCAT executable and its runtime dependencies remain configured separately. Only the PharmCAT support resource belongs to the installed resource bundle.
Explicit user-provided reference genome paths remain supported as runtime overrides.
Installed manifest
Write:
<output-dir>/resources.json
The manifest must contain:
schema version;
selected resource channel;
SFtool version;
resolved dataset versions;
installed relative paths;
SHA-256 checksums;
catalog resources by assembly;
ClinVar source files;
ClinVar assembly-level databases;
ClinVar resources by assembly, catalog, and evidence level;
HPO and PharmCAT paths;
RR-STR catalog path;
optional reference genome paths;
installation metadata.
The schema should remain simple and dictionary-based. Paths stored in the manifest must be relative to <output-dir> so that the complete resource directory can be moved without rewriting every entry.
A valid manifest must expose runtime-consumable resources unambiguously. The current implementation may use structures such as:
The reference_genomes entries may be omitted, represented as null, or contain null assembly entries when setup is executed without --download-reference-genomes.
Idempotency and validation
Setup must:
reuse existing valid files;
use temporary .part files for downloads;
atomically rename completed downloads;
validate required outputs;
reject incomplete or inconsistent installations;
avoid silently overwriting a manifest that refers to incompatible resources.
Runtime bootstrap must:
validate manifest JSON and schema compatibility;
resolve the installation root;
reject absolute paths or paths escaping the resource root;
verify that required files exist;
verify checksums;
fail early with actionable error messages;
validate only supported assemblies, catalogs, and evidence levels;
resolve a configured reference genome override before falling back to an installed reference.
Implementation phases and task checklist
The original task numbering and completion state up to Task 14 are retained. Tasks from 15 onwards are reorganized around the actual sftool run execution stages and runtime responsibilities.
Phase 1 — Resource CLI foundation and bundled specification
Task 1 — Add the sftool resources command group
Add the extensible Click command group.
Register the initial resources setup subcommand.
Task 2 — Add the bundled resource specification
Add and package sftool/data/resources/bundled_resources.json.
Define pinned versions, URLs, filenames, and checksums.
Load the file through importlib.resources.
Task 3 — Add basic resource utility functions
Add small shared helpers for downloads, checksums, manifest loading/writing, and installed-file validation.
Keep orchestration in the command implementation.
Phase 2 — Catalog preparation
Task 4 — Decouple catalog generation from patient VCFs
Remove the dependency on a sample VCF when retrieving catalog coordinates.
Generate reusable resources directly from the bundled catalog definitions.
Task 5 — Generate both BED chromosome conventions
Generate BED files with 1, 2, X, MT naming.
Generate equivalent .chr.bed files with chr1, chr2, chrX, chrM naming.
Retrieve coordinates only once per catalog and assembly.
Task 6 — Generate all catalog resources during setup
Generate PR and RR BED/JSON resources for GRCh37 and GRCh38.
Preserve existing GRCh37 aliases.
Retain RR-STR as its bundled CSV definition without generating BED or JSON files.
Phase 3 — External datasets and installed manifest
Task 7 — Download the bundled ClinVar snapshot
Download the pinned variant_summary and submission_summary files.
Preserve the downloaded source files under clinvar/source/.
Task 8a — Generate ClinVar databases for both assemblies
This is the original completed Task 8 and retains its historical status.
Generate the assembly-level ClinVar intermediate databases for GRCh37 and GRCh38.
Task 8b — Generate catalog- and evidence-specific ClinVar JSON resources
Generate resources for PR and RR.
Generate them for GRCh37 and GRCh38.
Generate cumulative evidence levels 1, 2, 3, and 4.
Produce and register all 16 resulting JSON resources.
Parse shared ClinVar inputs only once where possible.
Task 9 — Download HPO and PharmCAT resources
Download the pinned HPO gene-to-phenotype file.
Download the pinned PharmCAT positions VCF.
Store both at stable installed paths.
Task 10 — Add optional reference genome download
Download GRCh37 and GRCh38 only when requested.
Validate, normalize filenames, and generate FASTA indexes.
Task 11 — Write the installed resource manifest
Generate resources.json.
Register versions, paths, checksums, and installation metadata.
Include the Task 8b resources indexed by assembly, catalog, and evidence level.
Phase 4 — Bootstrap and runtime resource resolution
Task 12 — Add the manifest to runtime configuration
Allow runtime configuration to locate the installed resource bundle and manifest.
Keep executable and runtime-tool configuration separate from installed resource data.
Task 13 — Validate the resource bundle during bootstrap
Verify manifest compatibility and required installed files before analysis starts.
Verify checksums and fail early with actionable error messages.
Task 14 — Resolve shared execution resources
Resolve HPO, PharmCAT, RR-STR, ClinVar, catalogs, and reference genomes from the manifest.
Select resources for the requested assembly, requested categories, and ClinVar evidence level.
Expose resolved paths through a runtime resource object attached to the execution context.
Phase 5 — sftool run stage integration
Task 15 — Complete the runtime resource access API
Finalize the RuntimeResources public API.
Expose catalog JSON resources by category.
Expose both BED chromosome conventions by category.
Expose ClinVar filtered resources by category.
Expose the assembly-level ClinVar database where required by variant confirmation.
Expose HPO, PharmCAT, RR-STR, and reference genome resources.
Ensure accessors are implemented as class methods or properties, not detached module-level functions.
Keep the underlying manifest available for provenance and debugging.
Task 16 — Replace catalog generation with per-sample catalog selection
Replace the runtime catalog_generation step with a catalog-selection step.
Inspect chromosome naming independently for each sample VCF.
Select .bed or .chr.bed independently for each sample and category.
Select resources for the requested assembly and analysis category.
Register the selected BED and catalog JSON resources in the sample or execution context.
Do not use only the first sample VCF to select a shared BED.
Do not generate or modify persistent catalog files during sftool run.
Suggested runtime entry point:
run_catalog_selection(ctx)
Task 17 — Integrate prepared ClinVar resources
Remove run_clinvar_setup() from sftool run.
Remove runtime calls to clinvar_manager() and any ClinVar download or transformation logic.
Use the Task 8b ClinVar JSON corresponding to:
execution assembly;
PR or RR catalog;
requested evidence level.
Adapt ClinVar consumers to obtain resources through ctx.resources.
Remove dependencies on legacy outputs such as:
ctx.outputs["clinvar"]["clinvar_db"];
ctx.outputs["clinvar"]["clinvar_summary_db"].
Define and implement the ClinVar resource used by variant_confirmation.
For variant-confirmation-only executions, use the assembly-level installed ClinVar database if ClinVar lookup is required, rather than forcing a PR/RR catalog selection.
Preserve ClinVar version and resource provenance for downstream reports where required.
Task 18 — Adapt sample preprocessing
Use the reference genome resolved during bootstrap.
Normalize each sample VCF using ctx.resources.reference_genome.
Intersect normalized VCFs with the BED selected for that specific sample and category.
Stop reading catalog BED paths from legacy ctx.outputs["catalogs"]["bed_files"].
Use the installed PharmCAT positions VCF when required by the PharmCAT preprocessing workflow.
Preserve runtime executable configuration for bcftools, bgzip, Python, PharmCAT, and other tools.
Support different chromosome naming conventions across samples in the same execution.
Do not create or alter persistent shared resources.
Task 19 — Adapt variant confirmation
Review the resource dependencies of run_variant_confirmation.
Use the normalized sample VCF generated during sample preprocessing.
Use the resolved reference genome.
Use the assembly-level installed ClinVar database when ClinVar annotation or lookup is required.
Avoid relying on PR/RR catalog resources unless the confirmation workflow explicitly needs them.
Support executions where variant_confirmation is the only enabled mode.
Preserve compatibility with combined secondary-findings and variant-confirmation executions.
Task 20 — Adapt variant evidence preparation
Replace legacy catalog and ClinVar path access with ctx.resources.
Use the selected catalog JSON for each PR/RR category.
Use the selected catalog- and evidence-specific ClinVar JSON.
Continue supporting GeneBe-only and GeneBe-plus-ClinVar execution modes.
Avoid rebuilding ClinVar evidence collections from source databases at runtime.
Preserve the structures expected by downstream variant collection and selection.
Task 21 — Adapt variant collection and supporting resources
Adapt run_variant_collection to consume installed resources.
Use the installed RR-STR CSV for STR-based RR analysis.
Use the installed PharmCAT positions resource where needed.
Use the installed HPO file for phenotype-based processing.
Remove legacy configuration-path dependencies for these datasets.
Preserve support for SNV/indel, STR, SMN1-copy, and PharmCAT collections.
Task 22 — Adapt variant selection and report provenance
Review run_variant_selection and report-generation inputs for legacy resource paths.
Use resource versions and manifest metadata for provenance where appropriate.
Ensure selected variants retain the same expected data structures.
Do not expose installation-internal absolute paths unnecessarily in reports.
Preserve existing report contents unless resource provenance is intentionally added.
Task 23 — Simplify run.py orchestration
Remove run_catalog_generation(ctx).
Remove run_clinvar_setup(ctx).
Add the catalog-selection stage.
Keep persistent resource validation and resolution in bootstrap.
Keep sample-specific selection and processing in runtime steps.
Remove obsolete resource-management conditionals from run.py.
Ensure report generation runs in normal executions as well as debug context reloads.
Keep the resulting orchestration focused on analysis stages.
Remove obsolete runtime ClinVar download and transformation code paths.
Retain reusable transformation logic required by sftool resources setup.
Remove unused helpers, imports, context outputs, and configuration models.
Rename modules whose responsibility has changed, for example:
catalog_generation.py → catalog_selection.py;
remove clinvar_setup.py when it no longer has a runtime responsibility.
Task 26 — Update documentation and examples
Document sftool resources setup.
Document the installed directory and manifest.
Document the two ways to provide a reference genome:
installed resource;
explicit runtime override.
Update example configuration files.
Update execution instructions.
Clarify that sftool run performs no persistent resource preparation.
Document supported ClinVar evidence levels and their cumulative behavior.
Task 27 — Add unit and integration tests
Test manifest validation and checksum failures.
Test runtime resource resolution for both assemblies.
Test PR-only, RR-only, PR+RR, and no-catalog executions.
Test all supported ClinVar evidence levels.
Test configured reference overrides and installed references.
Test missing reference failures.
Test per-sample BED convention selection.
Test executions containing two samples with different chromosome conventions.
Test variant-confirmation-only execution.
Test combined secondary-findings and variant-confirmation execution.
Test GeneBe-only execution without unnecessary ClinVar consumption.
Task 28 — Add end-to-end workflow tests
Test sftool resources setup.
Test repeated setup and idempotent resource reuse.
Test manifest generation and validation.
Test sftool run consuming installed resources.
Cover GRCh37 and GRCh38.
Cover PR and RR.
Cover BED and chr-BED VCF conventions.
Cover ClinVar evidence levels 1–4.
Verify that sftool run performs no download or persistent resource generation.
Verify report generation and resource provenance.
Runtime design notes
Resource preparation versus resource selection
Persistent resources are prepared only by:
sftool resources setup
Runtime stages may:
validate;
resolve;
select;
read;
register selected paths in the execution context.
Runtime stages must not:
download external datasets;
query Ensembl to generate catalogs;
generate shared catalog files;
transform ClinVar source files;
overwrite installed resources;
rewrite the installed manifest.
Per-sample BED selection
BED selection must be sample-specific.
This is required because two VCFs in the same execution may use different chromosome conventions. The implementation must not infer the convention from only the first sample and then reuse that BED for all samples.
The exact context structure may differ, provided that:
the selected BED is unambiguous per sample and category;
downstream preprocessing does not need to repeat chromosome-prefix detection;
persistent installed descriptors remain available through ctx.resources.
ClinVar selection
For PR and RR analysis, bootstrap should select the prepared ClinVar JSON using:
assembly + category + evidence level
For variant confirmation, the workflow may require the assembly-level ClinVar database rather than a PR/RR-filtered resource. This distinction should be explicit in RuntimeResources.
Context responsibilities
Recommended separation:
ctx.resources.installed
all validated installed resources;
ctx.resources.execution
run-level resources selected from assembly, categories, evidence level, and configuration;
sample.resources
sample-specific selections such as chromosome-convention-dependent BED files;
ctx.outputs and sample.vcf_outputs
files produced by the current analysis execution.
Installed resource paths should not be treated as analysis outputs.
Acceptance criteria
sftool resources setup installs all mandatory resources.
PR and RR BED/JSON resources are generated for GRCh37 and GRCh38.
Both chromosome naming conventions are available for every PR/RR BED.
RR-STR remains a CSV catalog and does not produce BED or JSON resources.
ClinVar source files and assembly-level databases are generated and retained.
Sixteen ClinVar JSON resources are generated for PR/RR, GRCh37/GRCh38, and evidence levels 1–4.
HPO and PharmCAT support resources are installed at stable paths.
Reference genomes are downloaded only when requested.
Every installed resource is represented in resources.json.
Re-running setup reuses valid resources and produces a consistent manifest.
Bootstrap validates installed resources before processing samples.
Bootstrap resolves the selected assembly, categories, evidence level, reference genome, and shared datasets.
BED convention selection is performed independently for each sample.
Two samples with different chromosome naming conventions are supported in one execution.
sftool run no longer generates catalog resources.
sftool run no longer downloads or processes ClinVar source data.
sftool run consumes only validated installed shared resources and runtime-generated sample outputs.
Variant-confirmation-only execution has access to the required assembly-level resources.
Add a resource management workflow and integrate prepared resources into
sftool runDescription
Introduce an extensible resource-management command group:
The command prepares the persistent datasets and generated resources required by SFtool before sample analysis. Once the workflow is fully integrated,
sftool runmust consume already installed resources instead of downloading or generating shared resources at runtime.The initial implementation includes only
setup. Future commands such asresources checkorresources updateremain outside the scope of this issue.The runtime integration should follow the actual SFtool execution stages. Resource preparation belongs exclusively to
sftool resources setup;sftool runshould only validate, resolve, select, and consume installed resources.Main requirements
sftool resources setupmust:sftool runmust:The implementation should remain simple and dictionary-based. A generic provider framework, Pydantic models, dataclasses, or a large resource-management hierarchy are not required.
Proposed command
sftool resources setup \ --output-dir /path/to/sftool_resources \ --resource-version bundled \ [--download-reference-genomes]--output-dirRoot directory where installed resources are stored.
--resource-versionInitially support:
Default:
Bundled mode uses dataset versions pinned for the installed SFtool release.
--download-reference-genomesWhen enabled, download and index the GRCh37 and GRCh38 FASTA files defined in the bundled resource specification.
Bundled resource specification
Add and package:
This file defines the versions, URLs, filenames, and checksums associated with an SFtool release. It must include definitions for:
The file must be loaded using
importlib.resourcesand must not depend on the current working directory.Expected resource structure
Catalog resources
Generate PR and RR resources for both assemblies:
Coordinates must be obtained from the appropriate Ensembl endpoint and reused to write both chromosome naming conventions.
Preserve the existing GRCh37 aliases:
The RR-STR catalog remains a bundled CSV definition. No RR-STR BED or JSON resources are generated.
ClinVar resources
ClinVar preparation is divided into two tasks while retaining the original Task 8 for backward compatibility.
Task 8a — Generate assembly-level ClinVar databases
This corresponds to the original completed Task 8 — Generate ClinVar databases for both assemblies.
Download the pinned ClinVar
variant_summaryandsubmission_summaryfiles and generate the intermediate databases for:The downloaded source files and assembly-level intermediate databases must be retained.
Task 8b — Generate catalog- and evidence-specific ClinVar resources
Using the assembly-level databases and the generated PR/RR catalogs, generate cumulative ClinVar JSON resources for every combination of:
This produces 16 directly consumable resources:
Evidence levels are cumulative. For example, evidence level
2includes variants meeting level2or higher.The transformation must:
submission_summaryonly once;Suggested implementation entry point:
build_clinvar_catalog_resources(...)Task 8b prepares and installs the resources. Runtime selection is handled later during bootstrap and workflow integration.
HPO and PharmCAT resources
Download, without additional transformation:
Use stable installed paths and register the files and versions in the manifest.
The PharmCAT executable and its runtime dependencies remain configured separately. Only the PharmCAT support resource belongs to the installed resource bundle.
Reference genomes
When
--download-reference-genomesis enabled:genome.fa;genome.fa.fai;Expected structure:
Explicit user-provided reference genome paths remain supported as runtime overrides.
Installed manifest
Write:
The manifest must contain:
The schema should remain simple and dictionary-based. Paths stored in the manifest must be relative to
<output-dir>so that the complete resource directory can be moved without rewriting every entry.A valid manifest must expose runtime-consumable resources unambiguously. The current implementation may use structures such as:
The
reference_genomesentries may be omitted, represented asnull, or containnullassembly entries when setup is executed without--download-reference-genomes.Idempotency and validation
Setup must:
.partfiles for downloads;Runtime bootstrap must:
Implementation phases and task checklist
The original task numbering and completion state up to Task 14 are retained. Tasks from 15 onwards are reorganized around the actual
sftool runexecution stages and runtime responsibilities.Phase 1 — Resource CLI foundation and bundled specification
Task 1 — Add the
sftool resourcescommand groupresources setupsubcommand.Task 2 — Add the bundled resource specification
sftool/data/resources/bundled_resources.json.importlib.resources.Task 3 — Add basic resource utility functions
Phase 2 — Catalog preparation
Task 4 — Decouple catalog generation from patient VCFs
Task 5 — Generate both BED chromosome conventions
1,2,X,MTnaming..chr.bedfiles withchr1,chr2,chrX,chrMnaming.Task 6 — Generate all catalog resources during setup
Phase 3 — External datasets and installed manifest
Task 7 — Download the bundled ClinVar snapshot
variant_summaryandsubmission_summaryfiles.clinvar/source/.Task 8a — Generate ClinVar databases for both assemblies
Task 8b — Generate catalog- and evidence-specific ClinVar JSON resources
Task 9 — Download HPO and PharmCAT resources
Task 10 — Add optional reference genome download
Task 11 — Write the installed resource manifest
resources.json.Phase 4 — Bootstrap and runtime resource resolution
Task 12 — Add the manifest to runtime configuration
Task 13 — Validate the resource bundle during bootstrap
Task 14 — Resolve shared execution resources
Phase 5 —
sftool runstage integrationTask 15 — Complete the runtime resource access API
RuntimeResourcespublic API.Task 16 — Replace catalog generation with per-sample catalog selection
catalog_generationstep with a catalog-selection step..bedor.chr.bedindependently for each sample and category.sftool run.Suggested runtime entry point:
Task 17 — Integrate prepared ClinVar resources
run_clinvar_setup()fromsftool run.clinvar_manager()and any ClinVar download or transformation logic.ctx.resources.ctx.outputs["clinvar"]["clinvar_db"];ctx.outputs["clinvar"]["clinvar_summary_db"].variant_confirmation.Task 18 — Adapt sample preprocessing
ctx.resources.reference_genome.ctx.outputs["catalogs"]["bed_files"].bcftools,bgzip, Python, PharmCAT, and other tools.Task 19 — Adapt variant confirmation
run_variant_confirmation.variant_confirmationis the only enabled mode.Task 20 — Adapt variant evidence preparation
ctx.resources.Task 21 — Adapt variant collection and supporting resources
run_variant_collectionto consume installed resources.Task 22 — Adapt variant selection and report provenance
run_variant_selectionand report-generation inputs for legacy resource paths.Task 23 — Simplify
run.pyorchestrationrun_catalog_generation(ctx).run_clinvar_setup(ctx).run.py.Expected high-level flow:
Individual stages may internally skip work when the relevant mode or category is not enabled.
Phase 6 — Cleanup, documentation, and validation
Task 24 — Remove obsolete configuration fields
Task 25 — Remove dead resource-generation code
sftool resources setup.catalog_generation.py→catalog_selection.py;clinvar_setup.pywhen it no longer has a runtime responsibility.Task 26 — Update documentation and examples
sftool resources setup.sftool runperforms no persistent resource preparation.Task 27 — Add unit and integration tests
Task 28 — Add end-to-end workflow tests
sftool resources setup.sftool runconsuming installed resources.sftool runperforms no download or persistent resource generation.Runtime design notes
Resource preparation versus resource selection
Persistent resources are prepared only by:
Runtime stages may:
Runtime stages must not:
Per-sample BED selection
BED selection must be sample-specific.
This is required because two VCFs in the same execution may use different chromosome conventions. The implementation must not infer the convention from only the first sample and then reuse that BED for all samples.
A possible structure is:
The exact context structure may differ, provided that:
ctx.resources.ClinVar selection
For PR and RR analysis, bootstrap should select the prepared ClinVar JSON using:
For variant confirmation, the workflow may require the assembly-level ClinVar database rather than a PR/RR-filtered resource. This distinction should be explicit in
RuntimeResources.Context responsibilities
Recommended separation:
ctx.resources.installedctx.resources.executionsample.resourcesctx.outputsandsample.vcf_outputsInstalled resource paths should not be treated as analysis outputs.
Acceptance criteria
sftool resources setupinstalls all mandatory resources.resources.json.sftool runno longer generates catalog resources.sftool runno longer downloads or processes ClinVar source data.sftool runconsumes only validated installed shared resources and runtime-generated sample outputs.