Skip to content

DiffViewer

Side-by-side sequence comparison highlighting substitutions, insertions, and deletions.

Demo

Usage

svelte
<script>
  import { DiffViewer } from '@molbiohive/hatchlings';
</script>

<DiffViewer data={diffData} width={700} />

Data Type — DiffData

FieldTypeRequiredDescription
seqAstringyesFirst sequence
seqBstringyesSecond sequence
nameAstringnoLabel for first sequence
nameBstringnoLabel for second sequence
featuresAPart[]noFeatures on sequence A
featuresBPart[]noFeatures on sequence B
alphabetAlphabetnoSequence alphabet

Props

PropTypeDefaultDescription
dataDiffDataPrimary data prop
widthnumberSVG width

Example — Comparing Sequences

ts
import type { DiffData } from '@molbiohive/hatchlings';

const diffData: DiffData = {
  seqA: 'ATGCGATCGATCGATCGATCGATCGATCGATCGATCG',
  seqB: 'ATGCGATTGATCAATCGATC---GATCGATCAATCGATCGATCG',
  nameA: 'Wild type',
  nameB: 'Mutant',
  featuresA: [
    { name: 'CDS', type: 'CDS', start: 0, end: 36, strand: 1, color: '#4dc3ff' },
  ],
  featuresB: [
    { name: 'CDS', type: 'CDS', start: 0, end: 18, strand: 1, color: '#4dc3ff' },
    { name: 'Insert', type: 'misc_feature', start: 18, end: 25, strand: 1, color: '#58b56a' },
    { name: 'CDS-2', type: 'CDS', start: 25, end: 44, strand: 1, color: '#4dc3ff' },
  ],
};

This is the data used in the demo above. See docs/data/plasmid.ts for the full source.

Substitutions, insertions, and deletions are highlighted automatically. Gaps are represented as - in the sequence strings.