Package 'RClinVarbitration'

Title: Build Tidy ClinVar Evidence and Arbitration Tables
Description: Joins official 'ClinVar' variant and submission reports directly into one tidy scalar 'DuckDB' table containing variations, alleles, GRCh37/GRCh38 locations, decisions, source assertions, and gene links. ClinVarbitration policy is implemented in SQL over those reports. An optional package-owned native extension streams VCV XML into the same table when richer observations, conditions, citations, attributes, and attributable evidence text are required, and streams PubMed baseline or update XML into scalar PMID-authoritative literature relations.
Authors: Sounkou Mahamane Toure [aut, cre], DuckDB Foundation [cph] (Bundled DuckDB C extension headers), Centre for Population Genomics [cph] (ClinVarbitration 2.2.11 decision-policy semantics)
Maintainer: Sounkou Mahamane Toure <[email protected]>
License: GPL (>= 2)
Version: 0.1.1.9000
Built: 2026-11-17 15:05:40 UTC
Source: https://github.com/RGenomicsETL/DuckClinVarbitration

Help Index


Compare fixed-policy disease decisions between two ClinVar releases

Description

Returns the disease-level policy relation for two imported releases under one configured ClinVarbitration profile. The profile and pinned policy version are held fixed; this function does not calculate case rankings or evaluation summaries. transition_status is "inserted", "withdrawn", "changed", or "unchanged". classification_changed is true only for a retained allele-and-disease key whose policy classification changed. A changed status also covers changed gold-star evidence level or retained evaluation date.

Usage

rclinvarbitration_disease_release_transitions(
  con,
  old_release_id,
  new_release_id,
  profile_id = "default"
)

Arguments

con

A DuckDB DBI connection initialized with rclinvarbitration_init().

old_release_id

Earlier imported ClinVar release label.

new_release_id

Later imported ClinVar release label.

profile_id

Configured policy profile identifier, normally "default".

Value

A data frame at the allele-and-disease decision grain, suitable for filtering temporal reclassification cases.


Download official ClinVar source files

Description

Downloads either the current ClinVar release or a named monthly archive from the NCBI HTTPS service. The flat reports are the compact default input to rclinvarbitration_import_flat(). VCV XML feeds the same scalar clinvar table when an analysis also needs observations, citations, conditions, attributes, or attributable text that the flat reports do not contain.

Usage

rclinvarbitration_download_clinvar(
  release = "latest",
  file = "vcv_xml",
  cache_dir = tools::R_user_dir("RClinVarbitration", "cache"),
  overwrite = FALSE,
  quiet = FALSE
)

Arguments

release

"latest" or a monthly archive in "YYYY-MM" form.

file

One or more of "vcv_xml", "submission_summary", and "variant_summary".

cache_dir

Directory in which downloaded files are cached.

overwrite

Download even when a valid cached file is present?

quiet

Passed to utils::download.file().

Details

Existing files form a local cache. Current files and archived VCV XML files are checked against NCBI's MD5 sidecar; a matching file is reused and a stale or corrupt file is replaced only after a temporary download is verified. NCBI does not publish MD5 sidecars beside archived flat files, so those files are reused by name unless overwrite = TRUE.

A complete VCV release is several gigabytes. The default cache location is returned by tools::R_user_dir("RClinVarbitration", "cache"). The function raises R's download timeout to at least the value of option RClinVarbitration.download_timeout (7200 seconds by default) for the call.

Value

A named character vector of local paths. The download attribute is a data frame containing source URLs, MD5 values when available, and cache hit status.

Examples

xml <- rclinvarbitration_download_clinvar(release = "latest")
xml_2026_03 <- rclinvarbitration_download_clinvar(release = "2026-03")

Enable native ClinVar and PubMed XML scanning on a DuckDB connection

Description

Loads the package-owned duckclinvarbitration extension. Its native clinvar_xml_entities(path) and rclinvarbitration_pubmed_xml_rows(path) table functions are concrete one-pass staging surfaces for rclinvarbitration_import_xml() and rclinvarbitration_import_pubmed(). rclinvar_json_field() remains the compact ClinVar field scalar. The connection must have been created with duckdb::duckdb(config = list(allow_unsigned_extensions = "true")), as for any locally built DuckDB extension.

Usage

rclinvarbitration_enable(con, extension_path = NULL)

Arguments

con

A DuckDB DBI connection.

extension_path

Optional explicit exact-version extension path.

Value

con, invisibly.


Export ClinVarbitration decisions to Parquet

Description

schema = "compatibility" writes the seven columns in Centre for Population Genomics ClinVarbitration's clinvar_decisions.tsv: contig, position, reference, alternate, clinical_significance, gold_stars, and allele_id.

Usage

rclinvarbitration_export_clinvarbitration_parquet(
  con,
  path,
  release_id,
  assembly = c("GRCh38", "GRCh37"),
  profile_id = "default",
  submitter_exclusions = character(),
  schema = c("compatibility", "tidy")
)

Arguments

con

A DuckDB DBI connection initialized with rclinvarbitration_init().

path

New output .parquet file path.

release_id

Imported ClinVar release label to export.

assembly

Genome assembly: "GRCh38" or "GRCh37".

profile_id

Policy profile identifier, normally "default".

submitter_exclusions

Additional submitter names to exclude from this export. Matching is case-insensitive and ignores surrounding whitespace. These exclusions are combined with any exclusions already stored for profile_id; imported source submissions are not deleted.

schema

Output schema: the upstream-compatible seven-column relation or the canonical scalar evidence relation.

Details

schema = "tidy" writes the canonical scalar clinvar relation. record_kind distinguishes variations, alleles, assembly locations, source assertions, conditions, genes, observations, citations, text, attributes, allele policy decisions, and disease-level disease_decision policy rows. Every row has its own stable record_key; repeated source elements are rows rather than lists or structs. release_id is a required Parquet column, so a reopened export retains its source identity.

The compatibility source is the allele-level policy view joined through clinvar_vcf. Both GRCh37 and GRCh38 are supported, including distinct X/Y locations for one AlleleID. Primary NC_ placements take precedence when present. An allele available only on alternate placements retains its exact sequence accession and is not mislabeled as a primary-chromosome VCF record.

The file is schema-compatible with the upstream TSV/Hail decision resource, but is not claimed to be byte-for-byte equivalent: this package derives submissions and locations from VCV XML, whereas upstream uses ClinVar's tab-delimited submission and variant summaries. PM5 is deliberately not exported; Rduckhts/DuckHTS own downstream consequence and PM5 processing.

Value

A named list describing the written Parquet file, invisibly.


Locate a version-matched RClinVarbitration DuckDB extension

Description

Releases up to the stable C API floor are built against DuckDB's exact-version C_STRUCT_UNSTABLE ABI, so the package bundles one artifact per supported engine release. The floor release itself (v1.5.6) uses the stable C_STRUCT ABI, which DuckDB negotiates for every newer engine. From DuckDB v2.0 the package also bundles a dedicated stable C API v2 host (v2.0.0, ABI type C_STRUCT); resolution prefers that host for the v2.0 line and otherwise falls back to the newest stable artifact that is no newer than the running engine.

Usage

rclinvarbitration_extension_path(duckdb_version = NULL, duckdb_platform = NULL)

Arguments

duckdb_version

Exact DuckDB version, with or without a v prefix. NULL selects the version reported by the installed duckdb package.

duckdb_platform

Exact platform reported by ⁠PRAGMA platform⁠. NULL queries a temporary connection to the installed duckdb package. DuckDB distinguishes windows_amd64 from R-devel's windows_amd64_mingw even though both artifacts contain the same MinGW-built machine code.

Value

An absolute extension path.


Import the official ClinVar flat reports as one tidy table

Description

Joins variant_summary and submission_summary directly in DuckDB. The resulting clinvar table has one scalar row per variation, allele, assembly location, decision, SCV submission, RCV accession, or allele-gene link, identified by record_kind. It is the same canonical table used by rclinvarbitration_import_xml(). Location rows retain source coordinates even when ClinVar does not provide a complete VCF tuple (for example some CNVs). clinvar_vcf contains only locations with a usable one-based position and non-missing REF/ALT.

Usage

rclinvarbitration_import_flat(
  con,
  submission_path,
  variant_path,
  release_id,
  parquet_path = NULL,
  assembly = c("GRCh38", "GRCh37"),
  profile_id = "default",
  submitter_exclusions = character()
)

Arguments

con

A DuckDB DBI connection.

submission_path

Official submission_summary*.txt.gz.

variant_path

Official variant_summary*.txt.gz.

release_id

Immutable source-release label stored with the imported rows and returned in the import receipt.

parquet_path

Optional new Parquet path for the same tidy table. The returned import receipt can be passed directly to rclinvarbitration_publish_ducklake().

assembly

One or both of "GRCh38" and "GRCh37". Both are imported by default; policy decisions are computed once, preferring GRCh38 as the coordinate source when both are present.

profile_id

Policy profile recorded on decision rows.

submitter_exclusions

Submitters excluded from the policy decision.

Details

This is the compact default substrate for ClinVarbitration and temporal analysis. XML import remains available for evidence absent from the flat reports, including richer attributable observations and XML-only text.

Value

Invisibly returns the table name, release identity, source paths and byte sizes, and row counts by record kind.


Import a PubMed baseline or update XML source

Description

Streams concrete PubMed baseline or update XML through the package-owned libxml2 DuckDB extension. PMID is the article authority; DOI and PMCID are retained as ordinary article identifiers when supplied. Each import appends immutable source-versioned rows. DeleteCitation appends an explicit deleted article event; it does not erase earlier article or child facts.

Usage

rclinvarbitration_import_pubmed(
  con,
  path,
  source_id,
  source_kind = c("baseline", "update")
)

Arguments

con

A DuckDB DBI connection with rclinvarbitration_enable() loaded.

path

Path to a PubMed baseline or update XML or XML.GZ file.

source_id

Immutable source snapshot or update label.

source_kind

Whether path is a "baseline" or "update" source.

Details

The caller's current DuckDB or DuckLake catalog owns the resulting ⁠pubmed_*⁠ relations. ⁠pubmed_current_*⁠ selects the latest non-deleted event per PMID, while ⁠pubmed_*_as_of(source_id)⁠ table macros select a historical cutoff. This importer does not fetch Europe PMC or perform semantic screening.

Value

Invisibly returns source identity, typed source ordinal, and scalar row counts.


Stream a ClinVar VCV XML release into one relational DuckDB table

Description

The native extension reads .xml and .xml.gz with a libxml2 forward reader. One compact row per selected ClinVar entity is written to temporary spill-backed staging in one XML pass, projected into the scalar clinvar table, and dropped. Repeated XML entities become additional rows; no XML DOM, durable JSON, nested value, generic parser-node graph, or R data-frame materialization is used. Compatibility relations are views over clinvar.

Usage

rclinvarbitration_import_xml(
  con,
  path,
  release_id,
  replace = FALSE,
  source_url = NULL,
  source_md5 = NULL
)

Arguments

con

A DuckDB DBI connection.

path

Path to an official ClinVar VCV XML or XML.GZ release.

release_id

User-supplied release label stored with every row.

replace

Replace rows already stored for release_id?

source_url

Optional source URL for the release catalogue. When path is returned directly by rclinvarbitration_download_clinvar(), its download metadata supplies this value automatically.

source_md5

Optional 32-character source MD5 digest. Download metadata is used automatically when available.

Value

A named numeric vector with imported entity counts.


Initialize the ClinVar relational schema

Description

Initialize the ClinVar relational schema

Usage

rclinvarbitration_init(con)

Arguments

con

A DuckDB DBI connection.

Value

con, invisibly.


ClinVarbitration policy SQL

Description

Returns DuckDB views implementing the supported policy over clinvar_disease_submissions. The policy bins submitted classifications, excludes unknown bins and applies the upstream policy's intended qualified Illumina benign exclusion, optionally applies profile-specific submitter exclusions, prefers evidence evaluated from 2016 onward while always retaining expert-panel and practice guideline evidence, and applies the 60/20 majority rule. The disease-level and allele-level views both reproduce the upstream strong-review rule: the first retained practice-guideline or expert-panel classification in source order is decisive.

Usage

rclinvarbitration_policy_sql(
  policy_version = rclinvarbitration_policy_version()
)

Arguments

policy_version

Exact supported policy version. See rclinvarbitration_policy_version().

Details

clinvar_policy_pathogenic_alleles is the disease-specific pathogenic or likely-pathogenic join surface for downstream Rduckhts/DuckHTS annotation. It does not perform VEP or PM5 computation.

Value

A named character vector of DuckDB ⁠CREATE OR REPLACE VIEW⁠ statements.


Current ClinVarbitration policy version

Description

The identifier pins the policy semantics adapted from Centre for Population Genomics ClinVarbitration 2.2.11 (upstream commit ⁠658b9f241eb2d43aa11214b153b19c1e18a16337⁠) and records that decisions are grouped per disease rather than only per variation. The identifier has no package-local suffix: the view names, rather than a speculative v1, state whether the output is disease-scoped or allele-scoped.

Usage

rclinvarbitration_policy_version()

Value

A character scalar.


Publish a tidy ClinVar evidence export to DuckLake

Description

Registers one tidy Parquet export in a persistent staging table, then replaces the current evidence set by key in one DuckLake transaction. New keys are inserted, absent keys are deleted, changed content is updated, and byte-identical records are left untouched. DuckLake's native data-change feed is the release-delta authority.

Usage

rclinvarbitration_publish_ducklake(
  con,
  export,
  table_name = "clinvar",
  staging_table = "clinvar_incoming",
  ducklake_name = NULL,
  author = "RClinVarbitration",
  commit_message = NULL
)

Arguments

con

A DuckDB DBI connection whose current database is the writable DuckLake catalog.

export

The returned value from rclinvarbitration_export_clinvarbitration_parquet() with schema = "tidy", or the returned value from rclinvarbitration_import_flat() when parquet_path was supplied.

table_name

Persistent current-decision table.

staging_table

Persistent empty staging table.

ducklake_name

Attached DuckLake catalog. NULL uses the current database.

author

Snapshot author.

commit_message

Snapshot message. NULL derives one from the export.

Details

The staging and target tables are initialized once from the Parquet schema. The staging table is retained because current DuckLake releases cannot create, register, and drop that table safely in the same transaction. It is empty before and after every successful publication.

Value

Invisibly returns the publication snapshot, source identity, input row count, and DuckLake change counts.


Reproduce ClinVarbitration decisions from archived ClinVar flat files

Description

Reproduces Centre for Population Genomics ClinVarbitration 2.2.11's allele-level decision algorithm directly from NCBI's versioned submission_summary and variant_summary files. The generated Parquet has the exact seven-column clinvar_decisions.tsv layout: contig, position, reference, alternate, clinical_significance, gold_stars, and allele_id.

Usage

rclinvarbitration_reproduce_clinvarbitration_parquet(
  con,
  submission_path,
  variant_path,
  path,
  assembly = c("GRCh38", "GRCh37"),
  submitter_exclusions = character()
)

Arguments

con

A DuckDB DBI connection.

submission_path

Archived NCBI submission_summary_YYYY-MM.txt.gz.

variant_path

Archived NCBI variant_summary_YYYY-MM.txt.gz.

path

New output .parquet path.

assembly

Genome assembly: "GRCh38" or "GRCh37".

submitter_exclusions

Submitter names to exclude for a blinded run.

Details

This is separate from rclinvarbitration_import_xml() and the disease-aware policy views. It exists to reproduce and differentially validate the upstream allele-level artifact on matching archived flat-file releases. It uses DuckDB's streaming CSV reader and SQL aggregation; it does not invoke Python, Hail, VEP, or PM5 logic.

Value

A named list describing the written Parquet file, invisibly.


ClinVar relational schema SQL

Description

Returns DuckDB DDL for one scalar ClinVar fact table plus compatibility views and append-only, source-versioned PubMed relations. Every ClinVar XML entity is one clinvar row identified by record_kind; repeated conditions, observations, citations, names, and text are additional rows rather than nested values or Cartesian products. PubMed current and as-of relations use typed source order without deleting historical facts; read-only ⁠pubmed_literature_*⁠ views project all source versions for direct semantic consumers. Literature sections normalize article titles to section = "title" and abstracts to section = "abstract", retaining structured labels in subsection and abstract locators in source_entity_ordinal (NULL for titles). The release catalogue and small policy configuration tables remain separate.

Usage

rclinvarbitration_schema_sql()

Value

A named character vector of SQL statements.