npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@ncbijs/clinvar

v0.1.1

Published

Typed client for NCBI ClinVar clinical variant data

Downloads

85

Readme

@ncbijs/clinvar

Runtime: Browser + Node.js

Typed client for NCBI ClinVar clinical variant data. Search variants and fetch detailed reports with automatic rate limiting and retry logic.

Installation

npm install @ncbijs/clinvar

Usage

import { ClinVar } from '@ncbijs/clinvar';

const clinvar = new ClinVar({ apiKey: process.env.NCBI_API_KEY });

const searchResult = await clinvar.search('TP53 pathogenic');
console.log(searchResult.total); // 5
console.log(searchResult.ids); // ['846933', '123456']

const variants = await clinvar.fetch(searchResult.ids);
console.log(variants[0].title); // 'NM_000546.6(TP53):c.743G>A (p.Arg248Gln)'
console.log(variants[0].clinicalSignificance); // 'Pathogenic/Likely pathogenic'
console.log(variants[0].genes[0].symbol); // 'TP53'
console.log(variants[0].traits[0].name); // 'Li-Fraumeni syndrome'
console.log(variants[0].locations[0].chromosome); // '17'

API

new ClinVar(config?)

| Option | Default | Description | | ------------ | ------- | --------------------------------------------------- | | apiKey | -- | NCBI API key (raises rate limit from 3 to 10 req/s) | | tool | -- | Tool name for NCBI E-utilities identification | | email | -- | Contact email for NCBI E-utilities identification | | maxRetries | 3 | Number of retries on 429/5xx errors |

Search

search(term: string, options?): Promise<ClinVarSearchResult>

Search ClinVar by query term. Returns total count and matching UIDs.

| Option | Default | Description | | -------- | ------- | -------------------------------- | | retmax | -- | Maximum number of UIDs to return |

Fetch

fetch(ids: Array<string>): Promise<Array<VariantReport>>

Fetch variant details by UIDs. Entries with errors are automatically skipped.

Convenience

searchAndFetch(term: string, options?): Promise<Array<VariantReport>>

Search and fetch in one call. Combines search + fetch. Returns empty array if no results.

Variation Services

refsnp(rsid: number): Promise<RefSnpReport>

Get a RefSNP variant report by rsID. Returns variant type and placements with alleles in SPDI and HGVS notation.

const report = await clinvar.refsnp(328);
console.log(report.variantType); // 'snv'
console.log(report.placements[0].sequenceAccession); // 'NC_000011.10'
console.log(report.placements[0].alleles[0].hgvs); // 'NC_000011.10:g.5227002C>T'

spdi(spdiExpression: string): Promise<SpdiAllele>

Validate and resolve an SPDI expression. Returns the parsed sequence accession, position, deleted sequence, and inserted sequence.

const result = await clinvar.spdi('NC_000011.10:5227001:C:T');
console.log(result.sequenceAccession); // 'NC_000011.10'
console.log(result.position); // 5227001
console.log(result.deletedSequence); // 'C'
console.log(result.insertedSequence); // 'T'

spdiToHgvs(spdiExpression: string): Promise<string>

Convert an SPDI expression to HGVS notation.

const hgvs = await clinvar.spdiToHgvs('NC_000011.10:5227001:C:T');
console.log(hgvs); // 'NC_000011.10:g.5227002C>T'

hgvsToSpdi(hgvsExpression: string, assembly?: string): Promise<Array<SpdiAllele>>

Convert an HGVS expression to contextual SPDI alleles. Optionally filter by genome assembly.

| Option | Default | Description | | ---------- | ------- | -------------------------------------------------- | | assembly | -- | Genome assembly filter (e.g. 'GCF_000001405.40') |

const alleles = await clinvar.hgvsToSpdi('NC_000011.10:g.5227002C>T');
console.log(alleles[0].sequenceAccession); // 'NC_000011.10'
console.log(alleles[0].position); // 5227001

frequency(rsid: number): Promise<FrequencyReport>

Get allele frequency data (ALFA) for a variant by rsID. Returns population-level allele counts and frequencies.

const freq = await clinvar.frequency(328);
console.log(freq.populations[0].study); // 'ALFA'
console.log(freq.populations[0].population); // 'European'
console.log(freq.populations[0].frequency); // 0.234

Storage mode

Query locally stored ClinVar variants with the same API — no network, no rate limits.

import { ClinVar } from '@ncbijs/clinvar';
import { DuckDbFileStorage } from '@ncbijs/store';

const storage = await DuckDbFileStorage.open('./ncbijs.duckdb');
const clinvar = ClinVar.fromStorage(storage);

const variants = await clinvar.searchAndFetch('BRCA1');

Available methods in storage mode

| Method | Supported | | ------------------ | --------- | | searchAndFetch() | Yes | | fetch() | Yes | | search() | No | | refsnp() | No | | spdi() | No | | spdiToHgvs() | No | | hgvsToSpdi() | No | | frequency() | No |

Methods not available in storage mode throw a StorageModeError.

Bulk parsers

parseVariantSummaryTsv(tsv)

Parses a ClinVar variant_summary.txt TSV file into an array of VariantReport records.

import { parseVariantSummaryTsv } from '@ncbijs/clinvar';
import fs from 'node:fs';

const variants = parseVariantSummaryTsv(fs.readFileSync('variant_summary.txt', 'utf-8'));
console.log(variants[0].clinicalSignificance); // 'Pathogenic'

parseClinVarVcf(vcf)

Parses a ClinVar VCF file (clinvar.vcf.gz) into an array of ClinVarVcfVariant records.

import { parseClinVarVcf } from '@ncbijs/clinvar';
import fs from 'node:fs';

const variants = parseClinVarVcf(fs.readFileSync('clinvar.vcf', 'utf-8'));
console.log(variants[0].chrom); // '1'
console.log(variants[0].clinicalSignificance); // 'Pathogenic'
console.log(variants[0].geneInfo); // 'BRCA1:672'

Returns ReadonlyArray<ClinVarVcfVariant> with fields: chrom, pos, id, ref, alt, qual, filter, clinicalSignificance, diseaseNames, geneInfo, rsId, variantClass.

Error handling

import { ClinVar, ClinVarHttpError } from '@ncbijs/clinvar';

try {
  await clinvar.search('TP53 pathogenic');
} catch (err) {
  if (err instanceof ClinVarHttpError) {
    console.error(`HTTP ${err.status}: ${err.body}`);
  }
}

The client automatically retries on HTTP 429, 500, 502, 503 and network errors with exponential backoff + jitter.

Response types

ClinVarSearchResult

interface ClinVarSearchResult {
  total: number;
  ids: Array<string>;
}

VariantReport

interface VariantReport {
  uid: string;
  title: string;
  objectType: string;
  accession: string;
  accessionVersion: string;
  clinicalSignificance: string;
  genes: Array<ClinVarGene>;
  traits: Array<ClinVarTrait>;
  locations: Array<VariantLocation>;
  supportingSubmissions: Array<string>;
}

ClinVarGene

interface ClinVarGene {
  geneId: number;
  symbol: string;
}

ClinVarTrait

interface ClinVarTrait {
  name: string;
  xrefs: Array<TraitXref>;
}

VariantLocation

interface VariantLocation {
  assemblyName: string;
  chromosome: string;
  start: number;
  stop: number;
}

RefSnpReport

interface RefSnpReport {
  rsid: number;
  variantType: string;
  placements: Array<RefSnpPlacement>;
}

RefSnpPlacement

interface RefSnpPlacement {
  sequenceAccession: string;
  alleles: Array<RefSnpAllele>;
}

RefSnpAllele

interface RefSnpAllele {
  spdi: string;
  hgvs: string;
}

SpdiAllele

interface SpdiAllele {
  sequenceAccession: string;
  position: number;
  deletedSequence: string;
  insertedSequence: string;
}

FrequencyReport

interface FrequencyReport {
  rsid: number;
  populations: Array<PopulationFrequency>;
}

PopulationFrequency

interface PopulationFrequency {
  study: string;
  population: string;
  alleleCount: number;
  totalCount: number;
  frequency: number;
}

ClinVarVcfVariant

interface ClinVarVcfVariant {
  chrom: string;
  pos: number;
  id: string;
  ref: string;
  alt: string;
  qual: string;
  filter: string;
  clinicalSignificance: string;
  diseaseNames: string;
  geneInfo: string;
  rsId: string;
  variantClass: string;
}