Skip to content

Browser and package integration ​

Variant-Linker provides a CLI, a CommonJS npm package, and a browser UMD bundle. The same analyzeVariant pipeline supports annotation, scoring, filtering, inheritance and custom features when supplied with the corresponding data.

This guide describes the 4.0.0 API. Use npm install variant-linker@4.0.0 after that release is published, or build this checkout while validating the release. Earlier npm releases do not include all the in-memory helpers below.

Capability matrix ​

CapabilityCLINode packageBrowser
rsID, HGVS, coordinate and CNV annotation--variant, --variants, files/stdinanalyzeVariantanalyzeVariant
Variant Recoder onlyIntegrated during identifier analysisvariantRecoder, variantRecoderPostSame helpers
VEP onlyCoordinate/VCF input bypasses RecodervepRegionsAnnotation, or parsed VCF analysisSame helpers
GRCh37/GRCh38 and validated liftover--assemblyassembly optionSame option
VCF parsing and source preservation--vcf-inputreadVariantsFromVcf or parseVcfTextFile.text() then parseVcfText
Bounded VCF file streaming--stream --chunk-sizeiterateVcfRecordsText parser materializes input; no filesystem iterator
PED/trio inheritance--ped, --calculate-inheritance, --sample-mapParsed VCF plus pedigreeData/sampleMapSame in-memory inputs
BED, gene-list, JSON gene enrichment--bed-file, --gene-list, --json-genesloadFeatures or pure parsers + buildFeaturesPure parsers + buildFeatures
Configurable scoring--scoring_config_pathscoringConfig or Node directoryParsed scoringConfig objects
Filtering and picked transcripts--filter, --pick-outputfilter, pickOutputSame options
JSON, SCHEMA, CSV, TSV, VCF--outputoutput object/string resultSame result; render or download a Blob
Spreadsheet-safe cells--spreadsheet-safespreadsheetSafeSame option
Request budgets/concurrencyCLI flags and JSON configrequestOptionsSame options
CancellationProcess terminationrequestOptions.signalAbortController, e.g. Cancel button
Memory request cache--cachecache: truecache: true
Persistent cacheNode configurationNode filesystem backendUnavailable; no IndexedDB adapter
HTTP proxyFlags or environmentproxyConfig or environmentDeployment/CORS routing, not Node proxy settings
Filesystem output--output-file, --saveNode output helpersApplication-controlled Blob download

The CLI reference lists every command option; the API reference describes return values and transport options. The documentation website explains these integrations; it is not itself an annotation submission application.

Importing the package ​

javascript
// Node CommonJS
const VariantLinker = require('variant-linker');
javascript
// Node ESM or a bundler configured for CommonJS dependencies
import VariantLinker from 'variant-linker';

const result = await VariantLinker.analyzeVariant({
  variant: 'rs6025',
  output: 'JSON',
});

The npm entry is CommonJS, not a native browser ESM module. A browser bundler must handle CommonJS and exclude Node-only modules. The repository's webpack setup uses fs, crypto, os and readline fallbacks set to false, and path-browserify for path. Reuse that configuration when building from source, or use the ready-made UMD bundle to avoid application bundler differences.

Copy node_modules/variant-linker/dist/variant-linker.bundle.js to your site's static assets, then load it before your application:

html
<script src="/vendor/variant-linker.bundle.js"></script>
<script type="module">
  const { analyzeVariant } = globalThis.VariantLinker;
  // Call analyzeVariant from an explicit application action.
</script>

A source checkout produces the same artifact with npm ci and npm run build. Pin your npm dependency and serve the built asset with your application. Network annotation still requires a reachable endpoint and browser CORS permission. An application backend can provide an explicitly configured compatible endpoint; do not embed server credentials in browser JavaScript.

VCF, pedigree, features and scoring ​

The following function works in Node or a browser. Its arguments are text and parsed JSON supplied by the application. In a browser, obtain selected file text with await file.text(); this reads the whole selected file into memory. In Node, use filesystem readers or the iterator for large VCFs.

javascript
async function annotateFamily(VariantLinker, input, signal) {
  const parsed = VariantLinker.parseVcfText(input.vcfText);
  const pedigreeData = VariantLinker.parsePedigreeText(input.pedText);
  const features = VariantLinker.buildFeatures({
    beds: [{ source: 'regions.bed', regions: VariantLinker.parseBedText(input.bedText) }],
    geneLists: [
      {
        source: 'panel.txt',
        genes: VariantLinker.parseGeneListText(input.geneListText, 'panel.txt'),
      },
    ],
    jsonGenes: [
      {
        source: 'genes.json',
        genes: VariantLinker.parseJsonGenesData(
          input.geneJson,
          { identifier: 'gene_symbol', dataFields: ['panel_name'] },
          'genes.json'
        ),
      },
    ],
  });
  const scoringConfig = VariantLinker.scoring.parseScoringConfig(
    { variables: { 'transcript_consequences.*.cadd_phred': 'max:cadd|default:0' } },
    { formulas: { annotationLevel: [{ priority: 'cadd' }] } }
  );
  return VariantLinker.analyzeVariant({
    variants: parsed.variantsToProcess,
    vcfInput: true,
    vcfRecordMap: parsed.vcfRecordMap,
    vcfHeaderLines: parsed.headerLines,
    samples: parsed.samples,
    pedigreeData,
    calculateInheritance: true,
    features,
    scoringConfig,
    assembly: 'hg38', // Match the assembly of the supplied VCF and feature data.
    vepOptions: { CADD: '1', hgvs: '1', mane: '1' },
    requestOptions: { signal, timeoutMs: 60000, deadlineMs: 120000 },
    output: 'JSON',
  });
}

For a browser's selected files, call it from a submit handler:

javascript
const controller = new AbortController();
const result = await annotateFamily(
  globalThis.VariantLinker,
  {
    vcfText: await vcfFile.text(),
    pedText: await pedFile.text(),
    bedText: await bedFile.text(),
    geneListText: await geneListFile.text(),
    geneJson: JSON.parse(await geneJsonFile.text()),
  },
  controller.signal
);
// Connect a Cancel button to controller.abort().

parseVcfText returns { variantsToProcess, vcfRecordMap, headerText, headerLines, samples }. parsePedigreeText returns a Map. BED input uses zero-based half-open coordinates; buildFeatures converts regions into one-based closed intervals for annotation matching. Gene parsers preserve source metadata. Parsing itself makes no annotation requests. The application chooses when to submit analysis.

All feature collections are optional; omit unused inputs. Inheritance needs VCF genotypes and matching pedigree/sample IDs, and compound heterozygosity requires the whole cohort. Scoring runs before inheritance and feature enrichment, so its expressions should use acquired annotation fields rather than later additions. The illustrative priority above copies CADD with a zero fallback; it is not a validated clinical classification model.

Results, filtering and downloads ​

JSON and SCHEMA return objects; CSV, TSV, and VCF return strings. Select the desired format in the analysis call. VCF output preserves source fields when parsed VCF context is supplied. Filters use field/operator objects:

javascript
const filter = JSON.stringify({
  'transcript_consequences.*.impact': { eq: 'HIGH' },
});

Supported operators are eq, ne, gt, gte, lt, lte, in and nin. Use pickOutput: true with vepOptions: { flag_pick: '1' } for picked transcripts. For CSV/TSV spreadsheet downloads, pass spreadsheetSafe: true.

A browser can serialize JSON into a Blob without calling Node output helpers:

javascript
const blob = new Blob([JSON.stringify(result, null, 2)], { type: 'application/json' });
const url = URL.createObjectURL(blob);
const link = document.createElement('a');
link.href = url;
link.download = 'annotations.json';
link.click();
setTimeout(() => URL.revokeObjectURL(url), 0);

Handle rejected promises and inspect annotationData for per-input error records. Liftover failures appear in meta.liftoverMeta. Display partial results as partial; do not infer completion from the presence of output. Request deadlines apply per fetch, so cancellation is useful for an application-wide time limit. See reliable processing for exact preservation, failure, streaming and cache semantics.

Configuration and environment boundaries ​

Configuration fileTunable defaults
config/cliDefaults.jsonCLI output/assembly/chunk size and default Recoder/VEP options.
config/apiConfig.jsonEndpoints, POST sizes, request budgets, concurrency/pacing, retry policy, cache tiers and proxy defaults.
config/benchmarkConfig.jsonBenchmark scenarios, process limits and reproducible public dataset acquisition defaults.
config/scoringLimits.jsonExpression source/AST/evaluation/collection budgets and bounded expression/warning caches.

Use CLI flags/--config and package requestOptions or scoringConfig for exposed runtime overrides. Not every repository default is a per-call option. JSON configuration imported by modules is loaded when Node starts and embedded when the browser bundle is built; restart Node or rebuild the bundle after changing these files. Validate deployment settings before shipping them.

Positive finite budgets, allowed input syntax, safe expression methods, prototype protection and ownership checks are security/protocol invariants. They remain enforced even when operational limits are configured. Browser filesystem readers, directory-based scoring, disk caches and environment proxy settings are unavailable; supply in-memory data and deployment routing instead.

Released under the MIT License.