Skip to content

About

🧬 Scan your whole-genome sequencing VCF against a local mirror of SNPedia

Resources

Stars

3 stars

Watchers

0 watching

Forks

Latest commit

Β 

History

8 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

DNAscanner

Scan a single-sample GRCh38 VCF against a local mirror of SNPedia and generate an interactive HTML or Markdown report of SNP annotations. Includes an experimental continental ancestry estimate when enough markers are observed.

Your VCF is processed locally and is not uploaded. download contacts the public database mirror and SNPedia; scan and report work offline once dependencies and the database are installed. Reports contain genetic information and the VCF filename. Opening a SNPedia link in a report makes a normal browser request to that site.

How it works

The pipeline has three stages: download the reference database, scan into a separate results database, then render a report:

uv run download          uv run scan                  uv run report

 SNPedia API        your VCF + data/snpedia.db         results.db
     |                       |                             |
     v                       v                             v
 data/snpedia.db  ───>  results.db  ──────────────>  report.html
  1. uv run download fetches a pre-built SNPedia database, then checks for recent changes via the MediaWiki API and applies them. Stores a sync timestamp so subsequent runs only fetch what's new.

  2. uv run scan extracts diploid single-base calls into results.db, matches them against data/snpedia.db by chromosome:position and annotated rsID, and looks up ancestry-informative markers. Incremental: reuses extraction when the VCF is unchanged and reuses matches only when both inputs and the matching version are unchanged.

  3. uv run report reads results.db and generates a self-contained interactive HTML report with ancestry proportions, summary cards, and a sortable/filterable table of findings. Can be re-run anytime to regenerate the report without re-scanning.

Setup

Requires Python 3.10+ and uv.

git clone https://github.com/viberaven/dnascanner.git
cd dnascanner
uv sync --locked

Run the following commands from the repository directory. Paths such as data/snpedia.db, results.db, and report.html are relative to your current directory. Output directories are created as needed.

Usage

Step 1: Download SNPedia

# Download pre-built database + apply any recent changes from SNPedia API
uv run download

# Download pre-built database only, skip API refresh
uv run download --no-refresh

# Adjust delay if hitting too many 502s
uv run download --delay 3

On first run, downloads a pre-built database from data.viberaven.com. Then checks the MediaWiki recentchanges API for new or edited pages since the last sync. Later runs check for a newer snapshot and apply recent edits. --no-refresh still requires network access to check or download the snapshot.

If a refresh fails, successfully downloaded pages are retained, the sync checkpoint is not advanced, and the command exits with an error. Run it again to retry. Edits made during a refresh remain eligible for the next run. Recent-change refreshes do not reconcile deleted or moved pages, and are limited by the server's retained change history; they are not a complete historical synchronization.

Flag Default Description
--db data/snpedia.db SQLite database path
--delay 1.0 Finite, non-negative seconds between API requests
--batch 50 Pages per API batch, from 1 to 50
--no-refresh off Skip checking for recent changes, pre-built only

Step 2: Scan your VCF

uv run scan --vcf /path/to/your.vcf.gz
Flag Default Description
--vcf (required) Path to VCF file (.vcf or .vcf.gz)
--snpedia data/snpedia.db SNPedia SQLite database
--out results.db Output results database
--force off Re-extract and recompute matches and ancestry

On first run, extracts supported calls from the VCF, matches them against SNPedia, and attempts an experimental ancestry estimate. On subsequent runs:

  • VCF unchanged β€” skips extraction entirely, uses cached variants
  • VCF changed β€” replaces extraction and invalidates previous matches and ancestry
  • SNPedia updated β€” re-runs matching against updated data
  • Both unchanged β€” reuses results, unless the processing version has changed

Extraction and matching are transactional: failed stages roll back instead of leaving partial results marked as complete. A successful new extraction clears results from the previous VCF, so a later interrupted stage cannot reuse them. Report generation refuses an extraction whose matching stage has not finished; rerun scan to complete it.

VCF caching uses the resolved path, file size, and nanosecond modification/change times, rather than hashing the whole file. SNPedia caching uses row counts and maximum revision IDs. Use --force after manually editing the database or whenever you need to bypass the cache:

uv run scan --vcf /path/to/your.vcf.gz --force

Experimental ancestry estimation

The built-in, hand-maintained marker panel is intended to represent five 1000 Genomes super-populations: European, African, East Asian, South Asian, and Americas. A maximum-likelihood model fits proportions to the observed genotypes. The panel and model have not been independently validated, and the repository does not include a reproducible source-data import for the marker frequencies. Treat the output as exploratory.

Only explicit, compatible diploid calls with FILTER=PASS or FILTER=. are used. Missing positions are unknown, never assumed to be homozygous reference. At least 10 observed markers are required to display an estimate; this threshold is a minimum-data check, not an accuracy guarantee. Variant-only VCFs can omit reference calls and bias the result. The report displays the observed marker count and explains when an estimate is unavailable. gVCF reference blocks are not interpreted. See GATK's explanation of reference confidence in gVCFs.

Step 3: Generate report

uv run report

# Markdown output
uv run report --format md

# Both HTML and Markdown
uv run report --format all
Flag Default Description
--db results.db Scan results database
--out report Output path (extension added automatically)
--format html html, md, or all

Can be re-run anytime β€” useful after updating SNPedia data and re-scanning.

Typical workflow

# First time: full pipeline
uv run download                                      # fetches pre-built DB + recent changes
uv run scan --vcf /mnt/dna/my_genome.vcf.gz
uv run report

# Later: update and re-scan
uv run download                                      # only fetches recent changes (fast)
uv run scan --vcf /mnt/dna/my_genome.vcf.gz            # reuses unchanged stages
uv run report                                        # regenerate report

Supported VCF formats

  • GRCh38 (hg38) coordinates; chromosomes with or without a chr prefix (chrM becomes MT)
  • Plain (.vcf) or gzip/BGZF-compressed (.vcf.gz) text, including DeepVariant and GATK VCFs
  • Exactly one sample column and a #CHROM header; multi-sample files are rejected
  • Complete diploid GT values, phased (0|1) or unphased (0/1), with concrete A/C/G/T alleles
  • Multi-allelic SNP records and explicit single-base reference calls (ALT=., GT=0/0)
  • Optional rsIDs in the ID column (including semicolon-separated IDs), VEP CSQ, snpEff ANN, or other INFO annotations

Haploid/polyploid calls, missing or invalid genotypes, indels, structural variants, N, spanning deletions (*), and symbolic alleles are skipped. Malformed record columns or positions produce an error. BCF, raw genotyping-array files, and gVCF reference blocks are not supported.

Headers explicitly mentioning GRCh37/hg19 are rejected. If the assembly is absent or unrecognized, the scanner cannot verify it: you must supply GRCh38 data. It does not perform genome-build conversion. SNP matching retains all FILTER statuses and applies no QUAL/GQ/DP threshold; pre-filter calls before scanning if you need quality restrictions. The VCF specification describes these fields.

The report

The HTML report includes:

  • Experimental ancestry estimate with colour-coded proportion bars, or an explanation of insufficient marker coverage
  • Summary cards: total matches, genotype info, notable findings, good/bad repute counts
  • Interactive table: sortable by any column, with combined repute, magnitude, and search filters plus a visible-results count
  • Each rsID links directly to its SNPedia page
  • Findings are ranked by magnitude (see below)

Self-contained file β€” open in any browser, no external dependencies.

The HTML table initially shows magnitude β‰₯ 1. Choose All under Magnitude to see every match, including rows without a scored genotype. The displayed genotype always uses the VCF's forward strand; the genotype used to look up a SNPedia annotation may be complemented (see matching logic below).

Magnitude

Magnitude is SNPedia's community-curated importance score, not a probability, effect size, or clinical classification. The report sorts it in descending order and uses these display groups: β‰₯ 2 is "notable", 1–<2 is "mildly interesting", and <1 or unscored is "other". Repute is the source's good/bad label. These labels do not establish a diagnosis or a treatment recommendation.

Database schemas

data/snpedia.db β€” SNPedia mirror

Table Description
snps One row per SNP: rsid, gene, chromosome, position, orientation, gmaf, summary, raw wikitext, revision tracking
genotypes One row per SNP+allele combo: rsid, alleles, magnitude, repute, summary
genosets Combinations of multiple SNPs: magnitude, repute, summary, criteria
download_meta Sync checkpoint for incremental API updates

Genosets are mirrored but are not evaluated by the scanner.

results.db β€” Scan results

Table Description
vcf_variants Extracted SNP variants from VCF: chromosome, position, ref, alt, genotype, quality
matches Matched variants, source rsID/revision, match method, VCF genotype, SNPedia-oriented geno_alleles, magnitude, repute, summary
ancestry Continental ancestry proportions (EUR, AFR, EAS, SAS, AMR)
ancestry_markers Per-marker details: rsid, genotype, alt count, reference frequencies
scan_meta Input fingerprints, processing versions, timestamps, counts, ancestry status

Matching logic

  1. Normalize VCF chromosome (chr1 -> 1, chrM -> MT)
  2. Look up (chromosome, position) in the SNPedia SNP table. If several rsIDs share a position, require an annotation that identifies exactly one of them.
  3. If no position matches, use a unique known rsID from the VCF ID or INFO fields. Conflicting or ambiguous known IDs are skipped.
  4. Convert the VCF genotype (0/1 with REF=A, ALT=G) to (A;G).
  5. Use SNPedia's StabilizedOrientation to orient the genotype: for a minus-strand entry, complement A↔T and C↔G. Then look up either allele ordering. Missing or unrecognized orientation leaves genotype annotations empty rather than guessing. See SNPedia's orientation documentation.

A position/rsID match is not the same as a genotype annotation. Missing genotype information is not evidence that a variant is harmless. The mirror does not store a reference allele/build per SNP, so position matching relies on compatible GRCh38 inputs and the accuracy of the mirror.

Development

The regression suite uses synthetic VCFs, temporary SQLite databases, and mocked downloads. It never needs a personal genome or network access:

uv run --locked python -m unittest discover -s tests -v

Install Node.js to also run the test of the generated report's JavaScript filters; that test is skipped if Node.js is absent. Python tests cover incremental scans, interrupted transactions, VCF parsing, strand matching, missing ancestry markers, downloader retry checkpoints, and report escaping.

After upgrading from an older version, run scan and regenerate your reports. Processing-version changes invalidate the relevant caches automatically. Existing reports remain static until regenerated.

Disclaimer

This tool is for informational and educational purposes only. It is not medical advice. SNPedia data is community-curated and may contain errors. Genetic variants interact in complex ways β€” a single SNP rarely determines an outcome. Always consult a qualified healthcare professional or genetic counselor for medical decisions.

License

The source code of this project is licensed under the MIT License.

The data/snpedia.db database contains content from SNPedia, which is available under the Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License (CC BY-NC-SA 3.0 US). If you redistribute data/snpedia.db, it must be shared under the same CC BY-NC-SA 3.0 US license with attribution to SNPedia. The non-commercial clause means you cannot sell or use the database in commercial products without separate permission from SNPedia.

About

🧬 Scan your whole-genome sequencing VCF against a local mirror of SNPedia

Resources

Stars

3 stars

Watchers

0 watching

Forks

Contributors

Languages