AGENT SKILL

qc-vcf-callset

Judge whether a germline VCF callset is trustworthy before interpreting any variant - Ti/Tv, Het/Hom, SNP, indel and multiallelic counts, sample count and genotype call rate from bcftools stats (falling back to cyvcf2, then to a plain-Python Ti/Tv scan) - and flag values outside the expected human WGS or WES ranges. Writes tables/vcf_qc_summary.csv and data/vcf_qc.json with a qc_flags list. Use when a VCF (one sample or a cohort) arrives for annotation or prioritization, when a Ti/Tv or Het/Hom value needs interpreting, or when deciding whether downstream variant tables must carry a low-confidence caveat.

License 许可
MIT
最近更新
2026-11-14
Stars
★ 0
Forks
2

01 前言 Front Matter

name
qc-vcf-callset
license
MIT
metadata
{ "tags": "vcf, qc, callset-qc, ti-tv, het-hom, call-rate, bcftools, cyvcf2, wgs, wes", "author": "Yijun Sun", "status": "community", "aliases": "vcf_qc_stats", "compute": "1 CPU, under 100 MB RAM, about 1 s for a 5-record, 2-sample VCF", "version": "1.0.0", "category": "variants", "scheduler": "none", "tested-with": "bcftools 1.24, htslib 1.23.1, cyvcf2 0.34.0, numpy 2.5.4, Python 3.12.15 (plain-Python path also on 3.13.9)", "requires-gpu": "false", "requires-network": "install", "requires-secrets": "none" }
description
Judge whether a germline VCF callset is trustworthy before interpreting any variant - Ti/Tv, Het/Hom, SNP, indel and multiallelic counts, sample count and genotype call rate from bcftools stats (falling back to cyvcf2, then to a plain-Python Ti/Tv scan) - and flag values outside the expected human WGS or WES ranges. Writes tables/vcf_qc_summary.csv and data/vcf_qc.json with a qc_flags list. Use when a VCF (one sample or a cohort) arrives for annotation or prioritization, when a Ti/Tv or Het/Hom value needs interpreting, or when deciding whether downstream variant tables must carry a low-confidence caveat.
compatibility
Python 3.11+. bcftools (bioconda) for the full metrics; cyvcf2 as a fallback; with neither, only Ti/Tv and counts. No GPU, no scheduler.

02 资源文件 2

03 SKILL.md 正文

QC a VCF callset

scripts/reference.py computes callset-level QC metrics and flags anything outside the expected range. It tries bcftools stats first (all metrics), then cyvcf2 (no multiallelic count), then a plain-Python scan that gives only Ti/Tv and the SNP and indel counts. It writes tables/vcf_qc_summary.csv and data/vcf_qc.json, which records the method used and a qc_flags list.

Run it before interpreting individual variants. A low Ti/Tv or an off-range Het/Hom means the downstream consequence and pathogenicity tables describe a noisy callset: excess false positives, contamination, or a sample swap. An off-range Ti/Tv is the strongest single quick signal of a callset heavy with false positives. The most likely mistake is the wrong SEQ_TYPE: an exome callset judged against the WGS band (or the reverse) is flagged, or passed, for the wrong reason.

Adapted from the variant-calling-vcf-statistics protocol of operon (MIT licence, Copyright (c) 2026 Swarup Lab), which also gives the expected ranges below.

Tested on synthetic data only (tests/: a 2-sample VCF of 4 SNPs and 1 deletion with known genotypes, run through each of the three methods, plus a 3-SNP VCF judged as WGS and as WES) with bcftools 1.24, htslib 1.23.1, cyvcf2 0.34.0 and Python 3.12.15 on macOS arm64; the plain-Python path also with Python 3.13.9. It has been an AiScientist skill since July 2026.

1. Environment setup

mamba create -y -n vcfqc -c conda-forge -c bioconda bcftools=1.24 cyvcf2=0.34.0 python=3.12
source "$(conda info --base)/etc/profile.d/conda.sh"
conda activate vcfqc
bcftools --version | head -1   # bcftools 1.24

Without bcftools the script falls back to cyvcf2; with neither, it still runs on the standard library but gives no genotype metrics.

2. Prepare inputs

  • The VCF (.vcf or .vcf.gz). The script reads $AISCIENTIST_DATASET, else $AISCIENTIST_WORK/normalized.vcf.gz (the output of a normalization step).

  • Every record is counted, whatever its FILTER. To judge the calls you will actually use, QC a PASS-only copy:

    bcftools view -f .,PASS -Oz -o /path/to/calls.pass.vcf.gz /path/to/calls.vcf.gz
    

3. Configure

Variable Meaning Default
AISCIENTIST_DATASET the VCF to QC (INPUT_VCF in the script) $AISCIENTIST_WORK/normalized.vcf.gz
AISCIENTIST_SEQ_TYPE WGS or WES (SEQ_TYPE); sets the Ti/Tv band; any other value uses the WGS band WGS
AISCIENTIST_ARTIFACTS where tables/ and data/ are written .

The expected ranges, for human germline calls (operon), and when the script flags:

Metric WGS WES Flagged when
Ti/Tv about 2.0-2.1 about 2.8-3.3 WGS below 1.8 or above 2.5; WES below 2.5 or above 3.5
Het/Hom 1.5-2.0 1.5-2.0 outside 1.5-2.0
Call rate above 95% above 95% below 90%

The bands live in TITV_BAND, HETHOM_BAND and CALLRATE_MIN at the top of the script. They do not apply to somatic or non-human calls; change them only with a reason, and report it.

4. Run

export AISCIENTIST_DATASET=/path/to/calls.vcf.gz AISCIENTIST_SEQ_TYPE=WES
export AISCIENTIST_ARTIFACTS=/path/to/results
python scripts/reference.py

In AiScientist: read the script with read_skill_reference, set INPUT_VCF and SEQ_TYPE, and run it with run_code. annotate_variants reports the PASS/non-PASS split but nothing about callset quality, so run this first; route a flagged callset's caveat to Diagnostics, not to the manuscript's conclusions.

5. Validate before using the output

  1. method in vcf_qc.json: only bcftools stats and cyvcf2 give Het/Hom and call rate. The plain-Python scan leaves them null; say so rather than reporting them as passed.
  2. n_records, n_samples: match what you expect of the file.
  3. ti_tv, then het_hom and call_rate, against the bands above.

How the metrics are defined, which matters when comparing runs:

  • Call rate is called genotypes (hom-ref, het and hom-alt) over all genotypes, records times samples. Missing calls (./.) are the only thing that lowers it.
  • Het/Hom is heterozygous over homozygous-alternate genotypes, pooled over all samples. With bcftools it counts SNPs only; with cyvcf2 it counts every record, indels included, so the two can differ. Pooling can hide one outlier sample in a cohort: the per-sample PSC lines of bcftools stats -s - /path/to/calls.vcf.gz show each sample. Het/Hom also depends on ancestry, so read the band as a guide to outliers, not a pass mark.
  • Ti/Tv: bcftools counts every ALT allele of a multiallelic site; cyvcf2 and the plain-Python scan count only the first. The plain-Python scan counts every record whose REF and ALT are not both a single base as an indel, MNPs included.

Report

Ti/Tv with the sequencing type and the method used, Het/Hom and call rate when available, the record, SNP, indel and sample counts, and every entry of qc_flags. If anything was flagged, frame the downstream variant tables as describing a lower-confidence callset.

04 同仓库更多 Skills

lijinbio
lijinbio/aiscientist-skills

verb-object-with-tool

One or two sentences on what the skill does and when to use it. Name the tool, the input it takes and the output it produces, then list the situations that should trigger it (for example "Use when setting up X, writing a Y config, or diagnosing a failed Z run").

★ 0
lijinbio
lijinbio/aiscientist-skills

write-variant-tables

Write the five standard variant-annotation result tables - consequence, impact and ClinVar-significance distributions, a ClinVar pathogenic and likely-pathogenic list, and a shortlist of rare, damaging variants not in ClinVar - plus a JSON summary, from an annotated per-variant TSV (VEP consequence and impact, SIFT, PolyPhen, max population AF, rsID, ClinVar significance), in pure Python without re-parsing the VCF or re-running VEP. Use when a study needs these tables with a different rarity cutoff, impact set or damaging-predictor rule, or when rebuilding them from an existing annotation table. In AiScientist, annotate_variants already writes the default tables, so use this only for a custom cut.

★ 0
lijinbio
lijinbio/aiscientist-skills

rank-phenotype-differentials-with-mcp

Map clinical phenotype text to grounded HPO terms and rank a research differential through an already configured phenotype-diagnosis MCP service with LIRICAL and optional literature adjudication. Use for explicit service-based analysis while preserving negation, uncertainty and original probabilities; retain the established workflow when the service is unavailable.

★ 0
lijinbio
lijinbio/aiscientist-skills

prioritize-clinical-variants

Rank annotated variants into research-triage tiers (ClinVar pathogenic, likely pathogenic, VUS favouring pathogenic, VUS, likely benign, benign) from ClinVar significance used verbatim, gnomAD allele frequency against a dominant or recessive disease-model cutoff and the ACMG BA1 5 percent rule, and in-silico predictors (SIFT, PolyPhen, REVEL, CADD, AlphaMissense) as supporting evidence only. Pure Python; reads a per-variant annotation TSV and writes a tier-sorted CSV with the evidence for each tier plus a JSON of tier counts. Use when a rare-variant list from VEP, ClinVar and gnomAD annotation must be ordered for review (which variants to look at first) or when choosing the disease model and cutoffs for that ordering. Research triage only, NOT a clinical ACMG/AMP classification.

★ 0
lijinbio
lijinbio/aiscientist-skills

normalize-vcf-with-bcftools

Normalize a VCF with bcftools norm before annotation or ClinVar/gnomAD matching - split multiallelic sites into biallelic records, atomize MNPs into SNPs, then left-align and trim indels against the reference FASTA of the same build - writing an indexed normalized.vcf.gz and a JSON of record counts before and after. Use when a VCF not known to be normalized (especially an indel-heavy one) will be matched against ClinVar, gnomAD or dbSNP, compared between callers or loaded into PLINK, or when a known pathogenic indel comes back as not in ClinVar. In AiScientist, the offline annotate_variants path already normalizes, so do not plan it as a separate step there.

★ 0
lijinbio
lijinbio/aiscientist-skills

build-variant-db-with-tiledbvcf

Build and query a TileDB-VCF variant database for a cohort with tiledbvcf-py - ingest many indexed single-sample VCFs into one compressed sparse-array dataset (a re-run adds only new samples, with no re-merging), query genomic regions across all or selected samples, and export the matching records (sample, contig, position, alleles, genotype) to a TSV with per-sample counts. Use when a study has many single-sample VCFs and needs population-scale storage, incremental sample addition or fast region and sample queries instead of repeated bcftools merges. Skip it for a single VCF.

★ 0