Class NucleicAcidAbstract

An abstract class representing a general nucleic acid (a sequence of nucleotides)

Hierarchy (view full)

Constructors

Properties

nucleicAcidType: NucleicAcidType

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 nucleic acid instance of the same type This is the object-oriented API for getting complements

    Returns NucleicAcid

    A new nucleic acid instance containing the complement sequence

    Example

    const dna = new DNA('ATCG');
    const complement = dna.getComplement(); // Returns new DNA('TAGC')

    const rna = new RNA('AUCG');
    const complement = rna.getComplement(); // Returns new RNA('UAGC')
  • Returns the reverse complement as a new nucleic acid instance of the same type This represents the opposite strand of double-stranded nucleic acids

    Returns NucleicAcid

    A new nucleic acid instance containing the reverse complement sequence

    Example

    const dna = new DNA('ATCG');
    const reverseComplement = dna.getReverseComplement(); // Returns new DNA('CGAT')

    // Chainable operations
    const result = dna.getReverseComplement().getComplement(); // Returns new DNA('ATCG')

    const rna = new RNA('AUCG');
    const reverseComplement = rna.getReverseComplement(); // Returns new RNA('CGAU')
  • 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 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 NucleicAcid

    A new instance of the same nucleic acid type containing the subsequence

    Example

    const dna = new DNA('ATCGATCG');
    const sub = dna.getSubsequence(2, 5); // Creates new DNA with 'CGA'
    console.log(sub.getSequence()); // 'CGA'
  • 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