Skip to content

AlignmentViewer

Multiple sequence alignment with conservation scores, consensus sequence, and residue coloring.

Demo

Usage

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

<AlignmentViewer data={alignmentData} width={800} height={400} />

Data Type — AlignmentData

FieldTypeRequiredDescription
sequencesAlignmentSequence[]yesAligned sequences
alphabetAlphabetno'dna' | 'rna' | 'protein'
conservationConservationScore[]noPer-position scores
annotationsAlignmentAnnotation[]noRegion annotations
namestringnoAlignment name

Props

PropTypeDefaultDescription
dataAlignmentDataPrimary data prop
widthnumber800Container width
heightnumber500Container height
cellWidthnumber12Residue cell width
cellHeightnumber16Residue cell height
showConsensusbooleantrueShow consensus row
showConservationbooleantrueShow conservation bars
showNamesbooleantrueShow sequence names

Example — Constructing Data

ts
import type {
  AlignmentData, AlignmentSequence, ConservationScore,
} from '@molbiohive/hatchlings';

const sequences: AlignmentSequence[] = [
  { id: '1', name: 'Human_HBA',
    sequence: 'MVLSPADKTNVKAAWGKVGAHAGEYGAEALERMFLSFPTTKTYFPHFDLSH-----GSAQVKGHGKKVADALTNAVAHVDDMPNALSALSDLHAHKLRVDPVNFKLLSHCLLVTLAAHLPAEFTPAVHASLDKFLASVSTVLTSKYR' },
  { id: '2', name: 'Mouse_HBA',
    sequence: 'MVLSGEDKSNIKAAWGKIGGHGAEYGAEALERMFASFPTTKTYFPHFDVSH-----GSAQVKGHGKKVADALTNAVAHIDDMPQALSALSDLHAHKLRVDPVNFKLLSHCLLVTLANHLPAEFTPAVHASLDKFLASVSTVLTSKYR' },
  { id: '3', name: 'Chicken_HBA',
    sequence: 'MVLSAADKNNVKGIFTKIAGHAEEYGAETLERMFTTYPPTKTYFPHFDLSH-----GSAQIKGHGKKVVAALIEAANHIDDIAGTLSKLSDLHAHKLRVDPVNFKLLGQCFLVVVAIHHPSALTPEVHASLDKFLCAVGTVLTAKYR' },
  { id: '4', name: 'Zebrafish_HBA',
    sequence: 'MSLSDKDKAAVRALWSKIGKSADAIGNDALSRMLIVYPQTKTYFSHWPDLS-----PGSAPVKKHGGVIMGALAVKAHIDDIAGALSKLSDLHAQKLRVDPVNFKLLAHCILVVLARHYPGDFTPAHHASLEKFLSHVISALVSKYR' },
  { id: '5', name: 'Frog_HBA',
    sequence: 'MLTADDKKLIQQAWEKAASHADEIGHDALSRMIVVYPQTKTYFSHWQDLS-----PGSAPVKKHGITIMAAVGSQAHDDIKNFLSKLSDKHAQKLRVDPANFKILAHCILVVAAAHYPSDFTPAVHASLDKFLANVHTVLTSKYR--' },
];

// Conservation computed per column: for each position, the fraction of
// sequences sharing the most common (non-gap) residue.
const conservation: ConservationScore[] = sequences[0].sequence
  .split('')
  .map((_, i) => {
    // count residues at column i across all sequences
    // score = maxCount / totalSequences, consensus = most frequent residue
    return { position: i, score: /* 0.0–1.0 */, consensus: /* e.g. 'M' */ };
  });
// Example first 3 values:
// { position: 0, score: 1.0, consensus: 'M' }
// { position: 1, score: 0.4, consensus: 'V' }
// { position: 2, score: 0.8, consensus: 'L' }
// ... one entry per alignment column (generated programmatically)

const alignmentData: AlignmentData = {
  sequences,
  alphabet: 'protein',
  conservation,
  name: 'Hemoglobin alpha subunit',
};

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

Gaps are represented as - in the sequence strings. All sequences must be the same length (pre-aligned).