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

ts-dna

v3.0.0

Published

A comprehensive TypeScript library for molecular biology simulation, modeling the gene expression pathway from DNA transcription to polypeptide translation with biological accuracy.

Downloads

73

Readme

ts-dna

A comprehensive TypeScript library for molecular biology simulation, modeling DNA replication, gene expression, and polypeptide translation with biological accuracy.

npm version License: MIT TypeScript

Features

🧬 DNA Replication & Gene Expression Pipeline

  • DNA Replication: Biologically accurate enzyme simulation with leading/lagging strand synthesis
  • Gene Expression: Structure modeling with exons, introns, and promoters
  • Transcription: Realistic promoter recognition and RNA synthesis
  • RNA Processing: 5' capping, splicing, and polyadenylation
  • Alternative Splicing: Multiple variant support with functional impact analysis
  • Translation: Accurate amino acid sequence generation

🛡️ Type-Safe & Immutable

  • Full TypeScript support with strict typing
  • Immutable objects with validation enforced at construction
  • Functional error handling with ValidationResult pattern
  • Zero runtime dependencies

🔬 Biologically Accurate

  • DNA Replication: Enzyme coordination, Okazaki fragments, primer synthesis/removal
  • Organism Profiles: E. coli and Human replication parameters (speed, fragment size)
  • Splice Sites: Real consensus sequences (GT-AG, GC-AG) with validation
  • Promoters: TATA, Initiator, DPE, CAAT, GC boxes with TSS identification
  • Polyadenylation: AAUAAA signals, cleavage sites, USE/DSE elements
  • Genetic Code: Complete codon tables and amino acid properties

🚀 Performance Optimized

  • O(n log n) exon validation with interval trees
  • O(1) codon lookups with optimized maps
  • Efficient pattern matching with compiled regex
  • Memory-efficient processing for large genes

Installation

npm install ts-dna
yarn add ts-dna

Requirements

  • Node.js ≥18.0.0
  • TypeScript ≥5.0 (recommended)

API Documentation

Complete API documentation with detailed examples is available at GitHub pages.

Quick Start

Basic DNA/RNA Operations

import { DNA, RNA, convertToRNA, NucleicAcidType } from 'ts-dna';

// Create and manipulate nucleic acids
const dna = new DNA('ATGTGCGACGAATTC');
const rna = convertToRNA(dna);

console.log(dna.getComplement()); // 'TACGCGCTGTTAAG'
console.log(rna.getSequence());   // 'AUGUGCGACGAAUC'

DNA Replication

import { DNA, replicateDNA, replicateDNASimple, E_COLI, HUMAN } from 'ts-dna';

// Simple DNA replication
const originalDNA = new DNA('ATGTGCGACGAATTC');
const result = replicateDNASimple(originalDNA);

if (result.success) {
  const [strand1, strand2] = result.data;
  console.log('Original:', originalDNA.getSequence());
  console.log('Strand 1:', strand1.getSequence());
  console.log('Strand 2:', strand2.getSequence());
}

// Advanced replication with organism-specific parameters
const replicationResult = replicateDNA(originalDNA, {
  organism: E_COLI,  // 1000 bp/s, 1000-2000 nt Okazaki fragments
  includeStatistics: true,
  validateReplication: true
});

if (replicationResult.success) {
  const { replicatedStrands, statistics } = replicationResult.data;
  console.log(`Replication events: ${statistics.totalEvents}`);
  console.log(`Okazaki fragments: ${statistics.okazakiFragments.length}`);
  console.log(`Leading strand length: ${statistics.leadingStrandLength} bp`);
}

Gene Expression Pipeline

import {
  Gene,
  transcribe,
  processRNA,
  Polypeptide,
  isSuccess
} from 'ts-dna';

// Define a simple gene
const geneSequence =
  'GCGCTATAAAAGGCGC' +           // Promoter with TATA box
  'ATGAAAGCCTTTGAG' +            // Exon 1: start codon + coding
  'GTAAGTCCCCCCCAG' +            // Intron 1: GT...AG splice sites
  'TTCGATGCCATGGAG' +            // Exon 2: more coding
  'GTAAGTAAAAAAAAG' +            // Intron 2
  'CTGAAGGACCTGTAG';             // Exon 3: coding + stop codon

const exons = [
  { start: 16, end: 31 },         // Exon 1
  { start: 46, end: 61 },         // Exon 2
  { start: 76, end: 91 }          // Exon 3
];

// Complete gene expression pathway
const gene = new Gene(geneSequence, exons);
const preMRNA = transcribe(gene).unwrap();
const mRNA = processRNA(preMRNA).unwrap();
const polypeptide = new Polypeptide(mRNA);

console.log(`Gene length: ${gene.getSequence().length} bp`);
console.log(`mRNA length: ${mRNA.getCodingSequence().length} bp`);
console.log(`Polypeptide length: ${polypeptide.aminoAcidSequence.length} amino acids`);
console.log(`First amino acid: ${polypeptide.aminoAcidSequence[0].name}`);

Alternative Splicing

import {
  Gene,
  AlternativeSplicingProfile,
  transcribe,
  processAllSplicingVariants
} from 'ts-dna';

// Define splicing variants
const splicingProfile: AlternativeSplicingProfile = {
  geneId: 'EXAMPLE',
  defaultVariant: 'full-length',
  variants: [
    {
      name: 'full-length',
      includedExons: [0, 1, 2, 3],
      description: 'Complete polypeptide with all domains'
    },
    {
      name: 'short-isoform',
      includedExons: [0, 1, 3],
      description: 'Alternative splicing skips exon 2'
    }
  ]
};

const gene = new Gene(sequence, exons, 'EXAMPLE', splicingProfile);
const preMRNA = transcribe(gene).unwrap();
const outcomes = processAllSplicingVariants(preMRNA).unwrap();

for (const outcome of outcomes) {
  console.log(`${outcome.variant.name}: ${outcome.proteinLength} amino acids`);
}

Pattern Matching

import { NucleotidePattern, DNA } from 'ts-dna';

// IUPAC pattern matching
const tataBox = new NucleotidePattern('TATAAWAW');
const promoterDNA = new DNA('GCGCTATAAAAGGCGC');

console.log(tataBox.test(promoterDNA));           // true
console.log(tataBox.findFirst(promoterDNA));      // { start: 4, end: 12 }

// Find all TATA box occurrences
const matches = tataBox.findAll(promoterDNA);
console.log(`Found ${matches.length} TATA boxes`);

Amino Acid Analysis

import { AminoAcid, RNA, getAminoAcidByCodon } from 'ts-dna';

// Single amino acid properties
const phe = new AminoAcid(new RNA('UUU'));
console.log(phe.name);                    // 'Phenylalanine'
console.log(phe.singleLetterCode);        // 'F'
console.log(phe.molecularWeight);         // 165.19
console.log(phe.polarity);                // AminoAcidPolarity.NONPOLAR
console.log(phe.getAllAlternateCodons()); // ['UUU', 'UUC']

// Direct codon lookup
const codonData = getAminoAcidByCodon('UUU');
console.log(codonData.name);              // 'Phenylalanine'

Advanced Features

DNA Replication Simulation

import {
  Replisome,
  ReplicationFork,
  EnzymeFactory,
  E_COLI,
  HUMAN,
  isSuccess
} from 'ts-dna';

// Create replication machinery
const dna = new DNA('ATGTGCGACGAATTCGGCATGGCC');
const fork = new ReplicationFork(0, dna.length(), E_COLI);
const replisome = new Replisome(fork, E_COLI);

// Manual enzyme creation with validation
const helicaseResult = EnzymeFactory.createHelicase(100);
if (isSuccess(helicaseResult)) {
  const helicase = helicaseResult.data;
  console.log(`Helicase at position: ${helicase.position}`);
  console.log(`Enzyme type: ${helicase.type}`);
}

// Access replication statistics
const statistics = replisome.getStatistics();
console.log(`Fork position: ${statistics.forkPosition}`);
console.log(`Completion: ${statistics.completionPercentage}%`);
console.log(`Active Okazaki fragments: ${statistics.activeOkazakiFragments}`);

Promoter Recognition

import { findPromoters, TATA_BOX, GC_BOX } from 'ts-dna';

const dna = new DNA('GCGCTATAAAAGGCCAATCGGGGCGG');
const promoters = findPromoters(dna, {
  elements: [TATA_BOX, GC_BOX],
  maxDistance: 200,
  minStrength: 0.7
});

for (const promoter of promoters) {
  console.log(`Promoter at ${promoter.transcriptionStartSite}`);
  console.log(`Elements: ${promoter.elements.map(e => e.name).join(', ')}`);
}

RNA Processing Control

import {
  processRNA,
  findPolyadenylationSites,
  add5PrimeCap,
  add3PrimePolyATail
} from 'ts-dna';

// Custom RNA processing
const preMRNA = transcribe(gene).unwrap();

// Manual processing steps
const cappedRNA = add5PrimeCap(preMRNA);
const splicedRNA = spliceRNA(cappedRNA).unwrap();

// Find poly-A sites
const polyASites = findPolyadenylationSites(splicedRNA);
const strongestSite = polyASites[0];

const mRNA = add3PrimePolyATailAtSite(
  splicedRNA,
  strongestSite.position,
  200  // tail length
);

Error Handling

import { DNA, ValidationResult, isSuccess, isFailure } from 'ts-dna';

// Safe construction with validation
const result: ValidationResult<DNA> = DNA.create('INVALID_SEQUENCE');

if (isSuccess(result)) {
  console.log('Valid DNA:', result.data.getSequence());
} else {
  console.log('Validation error:', result.error);
}

// Functional error handling
const processedResult = transcribe(gene)
  .chain(preMRNA => processRNA(preMRNA))
  .map(mRNA => new Polypeptide(mRNA));

if (isSuccess(processedResult)) {
  console.log('Polypeptide created successfully');
} else {
  console.log('Pipeline failed:', processedResult.error);
}

Biological Constants

The library includes comprehensive biological constants for realistic simulations:

import {
  // Genetic code
  START_CODON,
  STOP_CODONS,
  CODON_LENGTH,

  // Splice sites
  DONOR_SPLICE_CONSENSUS,
  ACCEPTOR_SPLICE_CONSENSUS,

  // Promoter elements
  TATA_BOX_CONSENSUS,
  INITIATOR_CONSENSUS,
  GC_BOX_CONSENSUS,

  // Polyadenylation
  DEFAULT_POLYA_SIGNALS,
  CANONICAL_POLYA_SIGNAL_DNA,

  // Gene structure
  MIN_EXON_SIZE,
  MAX_EXON_SIZE,
  MIN_INTRON_SIZE,
  MAX_INTRON_SIZE,

  // DNA Replication
  E_COLI_POLYMERASE_SPEED,
  HUMAN_POLYMERASE_SPEED,
  MIN_RNA_PRIMER_LENGTH,
  MAX_RNA_PRIMER_LENGTH,
  PROKARYOTIC_FRAGMENT_SIZE_RANGE,
  EUKARYOTIC_FRAGMENT_SIZE_RANGE
} from 'ts-dna';

License

MIT License - see LICENSE.md for details.