Class NucleotidePattern

A class to represent patterns comprised of nucleotide IUPAC notation symbols. The constructor enforces validation, and all members are readonly. Therefor, all NucleotidePattern objects can only exist in a valid state.

Constructors

Properties

pattern: string
patternRegex: RegExp

Methods

  • Finds the first occurrence of the pattern within a nucleic acid sequence

    Parameters

    • nucleicAcid: NucleicAcid

      The NucleicAcid to search within

    Returns null | {
        end: number;
        match: string;
        start: number;
    }

    Match object with start position, end position, and matched sequence, or null if no match found

    Example

     const pattern = new NucleotidePattern('RY');
    const dna = new DNA('ATGAGCGATC');
    const match = pattern.findFirst(dna);
    // Returns: { start: 2, end: 4, match: 'GA' }
  • Finds all occurrences of the pattern within a nucleic acid sequence

    Parameters

    • nucleicAcid: NucleicAcid

      The NucleicAcid to search within

    Returns {
        end: number;
        match: string;
        start: number;
    }[]

    Array of match objects with start position, end position, and matched sequence

    Example

     const pattern = new NucleotidePattern('RY');
    const dna = new DNA('ATGAGCGATC');
    const matches = pattern.findMatches(dna);
    // Returns: [{ start: 2, end: 4, match: 'GA' }, { start: 5, end: 7, match: 'GC' }]
  • Finds all occurrences of the pattern within a string sequence

    Parameters

    • sequence: string

      The sequence string to search within

    Returns {
        end: number;
        match: string;
        start: number;
    }[]

    Array of match objects with start position, end position, and matched sequence

    Example

     const pattern = new NucleotidePattern('RY');
    const matches = pattern.findMatchesString('ATGAGCGATC');
    // Returns: [{ start: 2, end: 4, match: 'GA' }, { start: 5, end: 7, match: 'GC' }]
  • Creates a NucleotidePattern representing the reverse complement of this pattern.

    Returns NucleotidePattern

    A new NucleotidePattern representing the reverse complement

    Example

     const pattern = new NucleotidePattern('GAATTC');
    const reverseComplement = pattern.getReverseComplement();
    // Returns pattern equivalent to 'GAATTC' (EcoRI site is palindromic)

    const asymmetric = new NucleotidePattern('ATCG');
    const rcAsymmetric = asymmetric.getReverseComplement();
    // Returns pattern equivalent to 'CGAT'
  • Checks if a given NucleicAcid matches the nucleotide IUPAC notation pattern

    Parameters

    • nucleicAcid: NucleicAcid

      The NucleicAcid to check against the pattern

    Returns boolean

    True if the NucleicAcid matches the pattern, false otherwise

    Example

     //given the following pattern object
    const pattern = new NucleotidePattern('ANNT');

    //check a valid DNA match
    pattern.matches(new DNA('AAAT')); //returns true

    //check an invalid DNA match
    pattern.matches(new DNA('CCCC')); //returns false

    //check an invalid RNA match
    pattern.matches(new RNA('AGCU')); //returns false

    //check DNA that matches the pattern, but is longer than the pattern
    pattern.matches(new DNA('ACCTAAA')); //returns false
  • Checks if the pattern matches either the forward strand or reverse complement strand of the given nucleic acid sequence

    Parameters

    • nucleicAcid: NucleicAcid

      The NucleicAcid to check against both strands

    Returns boolean

    True if the pattern matches either the forward or reverse complement strand

    Example

     const pattern = new NucleotidePattern('GAATTC'); // EcoRI restriction site
    const dna = new DNA('CTTAAG'); // Reverse complement of GAATTC
    console.log(pattern.matches(dna)); // false
    console.log(pattern.matchesEitherStrand(dna)); // true
  • Replaces all occurrences of the pattern in a nucleic acid sequence.

    Parameters

    • nucleicAcid: NucleicAcid

      The nucleic acid containing the sequence to modify

    • replacement: string

      The replacement string

    Returns string

    The modified sequence string

  • Replaces all occurrences of the pattern in a string sequence.

    Parameters

    • sequence: string

      The sequence string to modify

    • replacement: string

      The replacement string

    Returns string

    The modified sequence string

  • Splits a string sequence by the pattern.

    Parameters

    • sequence: string

      The sequence string to split

    Returns string[]

    Array of sequence parts split by the pattern

  • Tests if a string sequence contains the pattern.

    Parameters

    • sequence: string

      The sequence string to test

    Returns boolean

    True if the pattern is found in the sequence

  • Internal method to convert IUPAC nucleotide patterns to regular expressions.

    Parameters

    • pattern: string

      The IUPAC nucleotide pattern string

    • getComplement: boolean = false

      Whether to get the complement pattern

    • getRegex: boolean = true

      Whether to return RegExp (true) or string (false)

    Returns string | RegExp

    Regular expression or string representation

    Throws

    InvalidNucleotidePatternError Thrown if the pattern input contains invalid alpha characters (must be a valid IUPAC nucleotide symbol) or is not a valid regex