Class Gene

A class representing a Gene with exons and introns. Extends DNA to provide gene-specific functionality including exon/intron structure. Supports alternative splicing through splice variant profiles.

Hierarchy (view full)

Constructors

  • Creates a Gene instance with the specified DNA sequence and exon definitions. Introns are automatically calculated from the gaps between exons.

    Parameters

    • sequence: string

      The complete gene DNA sequence

    • exons: GenomicRegion[]

      Array of GenomicRegion objects defining exon locations

    • Optional name: string

      Optional name for the gene

    • Optional splicingProfile: AlternativeSplicingProfile

      Optional alternative splicing profile for this gene

    Returns Gene

    Throws

    InvalidSequenceError Thrown if the sequence is invalid, exons are invalid, or exons extend beyond sequence

    Example

    const gene = new Gene('ATGCCCGGGAAATTT', [
    { start: 0, end: 3, name: 'exon1' },
    { start: 9, end: 15, name: 'exon2' }
    ], 'BRCA1');
    // Introns automatically calculated: [{ start: 3, end: 9 }]

Properties

exons: readonly GenomicRegion[]
introns: readonly GenomicRegion[]
name?: string
nucleicAcidType: NucleicAcidType
splicingProfile?: AlternativeSplicingProfile

Methods

  • Checks if the sequence contains the specified subsequence

    Parameters

    • subsequence: string | NucleicAcid

      The subsequence to search for (string or same nucleic acid type)

    Returns boolean

    True if the subsequence is found, false otherwise

    Example

    const dna = new DNA('ATCGATCG');
    console.log(dna.contains('TCG')); // true
    console.log(dna.contains('AAA')); // false
  • Checks if the sequence ends with the specified suffix

    Parameters

    • suffix: string | NucleicAcid

      The suffix to check for (string or same nucleic acid type)

    Returns boolean

    True if the sequence ends with the suffix, false otherwise

    Example

    const dna = new DNA('ATCGATCG');
    console.log(dna.endsWith('TCG')); // true
    console.log(dna.endsWith('ATC')); // false
  • Returns the complement as a new DNA instance This is the object-oriented API for getting DNA complements

    Returns DNA

    A new DNA instance containing the complement sequence

    Example

    const dnaResult = DNA.create('ATCG');
    if (dnaResult.success) {
    const complement = dnaResult.data.getComplement(); // Returns new DNA('TAGC')
    console.log(complement.getSequence()); // 'TAGC'
    }
  • Gets the sequence of a specific exon.

    Parameters

    • exonIndex: number

      0-based index of the exon

    Returns string

    DNA sequence string of the specified exon

    Throws

    Error if exonIndex is out of bounds

  • Gets the sequence of a specific intron.

    Parameters

    • intronIndex: number

      0-based index of the intron

    Returns string

    DNA sequence string of the specified intron

    Throws

    Error if intronIndex is out of bounds

  • Gets the mature mRNA sequence by concatenating all exons.

    Returns string

    DNA sequence string of concatenated exons

  • Gets the name of this gene, if provided.

    Returns undefined | string

    The gene name, or undefined if no name was provided

  • Returns the reverse complement as a new DNA instance This represents the opposite strand of double-stranded DNA

    Returns DNA

    A new DNA instance containing the reverse complement sequence

    Example

    const dnaResult = DNA.create('ATCG');
    if (dnaResult.success) {
    const dna = dnaResult.data;
    const reverseComplement = dna.getReverseComplement(); // Returns new DNA('CGAT')

    // Chainable operations
    const original = dna.getReverseComplement().getReverseComplement(); // Returns new DNA('ATCG')
    const doubleComplement = dna.getComplement().getComplement(); // Returns new DNA('ATCG')
    }
  • Returns the reverse complement of the sequence This represents the opposite strand of double-stranded nucleic acids

    Returns string

    String representing the reverse complement of the sequence

    Example

    const dna = new DNA('ATCG');
    console.log(dna.getReverseComplementSequence()); // 'CGAT'

    const rna = new RNA('AUCG');
    console.log(rna.getReverseComplementSequence()); // 'CGAU'
  • Returns a DNA subsequence from the specified start position to the end position

    Parameters

    • start: number

      The starting position (inclusive, 0-based)

    • Optional end: number

      The ending position (exclusive, 0-based). If not specified, goes to end of sequence

    Returns DNA

    A new DNA instance containing the subsequence

    Example

    const dnaResult = DNA.create('ATCGATCG');
    if (dnaResult.success) {
    const sub = dnaResult.data.getSubsequence(2, 5); // Creates new DNA with 'CGA'
    console.log(sub.getSequence()); // 'CGA'
    }
  • Gets the mature sequence for a specific splice variant.

    Parameters

    Returns string

    DNA sequence string of the variant's concatenated exons

    Throws

    Error if variant contains invalid exon indices

  • Returns the index of the first occurrence of the specified subsequence

    Parameters

    • subsequence: string | NucleicAcid

      The subsequence to search for (string or same nucleic acid type)

    • startPosition: number = 0

      The position to start searching from (default: 0)

    Returns number

    The index of the first occurrence, or -1 if not found

    Example

    const dna = new DNA('ATCGATCG');
    console.log(dna.indexOf('TCG')); // 1
    console.log(dna.indexOf('TCG', 2)); // 5
    console.log(dna.indexOf('AAA')); // -1
  • Returns the length of the nucleic acid sequence

    Returns number

    The length of the sequence in nucleotides/base pairs

    Example

    const dna = new DNA('ATCG');
    console.log(dna.length()); // 4
  • Checks if the sequence starts with the specified prefix

    Parameters

    • prefix: string | NucleicAcid

      The prefix to check for (string or same nucleic acid type)

    Returns boolean

    True if the sequence starts with the prefix, false otherwise

    Example

    const dna = new DNA('ATCGATCG');
    console.log(dna.startsWith('ATC')); // true
    console.log(dna.startsWith('GTC')); // false
  • Creates a Gene instance, returning a ValidationResult instead of throwing.

    Parameters

    • sequence: string

      The complete gene DNA sequence

    • exons: GenomicRegion[]

      Array of GenomicRegion objects defining exon locations

    • Optional name: string

      Optional name for the gene

    • Optional splicingProfile: AlternativeSplicingProfile

      Optional alternative splicing profile for this gene

    Returns ValidationResult<Gene>

    ValidationResult containing Gene instance or error message