Class Polypeptide

A class representing a polypeptide. It has a sequence of amino acids and an mRNA sequence that contains the coding sequence. The constructor enforces validation, and all members are readonly. Therefore, all Polypeptide objects can only exist in a valid state.

Biologically accurate: Translation occurs from mature mRNA, not pre-mRNA or other RNA types.

Constructors

  • Parameters

    • mRNA: MRNA

      A mature mRNA sequence that codes for a sequence of amino acids

    Returns Polypeptide

    Throws

    InvalidSequenceError Thrown if the mRNA coding sequence length is not divisible by 3 (invalid codons)

    Throws

    InvalidCodonError Thrown if any codon is invalid (doesn't code for an amino acid and is not a stop codon)

    Example

    const mRNA = new MRNA('GAUGAAAGGGAAAUAG', 'AUGAAAGGGAAAUAG', 1, 16);
    const polypeptide = new Polypeptide(mRNA); // 4 codons: Met-Lys-Gly-Lys, stops at UAG
    console.log(polypeptide.aminoAcidSequence.length); // 4

Properties

aminoAcidSequence: AminoAcid[]
mRNA: MRNA

Methods

  • Checks if the polypeptide contains the specified amino acid subsequence

    Parameters

    • subsequence: string | Polypeptide

      The amino acid subsequence to search for (string or Polypeptide)

    Returns boolean

    True if the subsequence is found, false otherwise

    Example

    const polypeptide = new Polypeptide(mRNA); // sequence: 'MKGK'
    console.log(polypeptide.contains('KG')); // true
    console.log(polypeptide.contains('AA')); // false
  • Checks if the polypeptide ends with the specified amino acid suffix

    Parameters

    • suffix: string | Polypeptide

      The amino acid suffix to check for (string or Polypeptide)

    Returns boolean

    True if the sequence ends with the suffix, false otherwise

    Example

    const polypeptide = new Polypeptide(mRNA); // sequence: 'MKGK'
    console.log(polypeptide.endsWith('GK')); // true
    console.log(polypeptide.endsWith('MK')); // false
  • Returns the single-letter amino acid sequence as a string

    Returns string

    String representation of the amino acid sequence

    Example

    const polypeptide = new Polypeptide(mRNA);
    console.log(polypeptide.getSequence()); // 'MKGK' (single letter codes)
  • Returns a sub-polypeptide 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 Polypeptide

    A new Polypeptide instance containing the amino acid subsequence

    Example

    const polypeptide = new Polypeptide(mRNA); // sequence: 'MKGK'
    const sub = polypeptide.getSubsequence(1, 3); // Creates polypeptide with 'KG'
    console.log(sub.getSequence()); // 'KG'
  • Returns the index of the first occurrence of the specified amino acid subsequence

    Parameters

    • subsequence: string | Polypeptide

      The amino acid subsequence to search for (string or Polypeptide)

    • 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 polypeptide = new Polypeptide(mRNA); // sequence: 'MKGK'
    console.log(polypeptide.indexOf('K')); // 1 (first K)
    console.log(polypeptide.indexOf('K', 2)); // 3 (second K)
    console.log(polypeptide.indexOf('AA')); // -1 (not found)
  • Returns the length of the polypeptide in amino acids

    Returns number

    The number of amino acids in the sequence

    Example

    const mRNA = new MRNA('GAUGAAAGGGAAAUAG', 'AUGAAAGGGAAAUAG', 1, 16);
    const polypeptide = new Polypeptide(mRNA);
    console.log(polypeptide.length()); // 4 amino acids
  • Checks if the polypeptide starts with the specified amino acid prefix

    Parameters

    • prefix: string | Polypeptide

      The amino acid prefix to check for (string or Polypeptide)

    Returns boolean

    True if the sequence starts with the prefix, false otherwise

    Example

    const polypeptide = new Polypeptide(mRNA); // sequence: 'MKGK'
    console.log(polypeptide.startsWith('MK')); // true
    console.log(polypeptide.startsWith('GK')); // false