codonFreq method

int codonFreq({
  1. required String codon,
})

Returns the frequency of a specified codon.

Scans in batches of three monomers per step. The exact codon must be present in the batch in order to be detected.

Implementation

int codonFreq({required String codon}) {
  if (codon.length != 3) {
    Errors.invalidCodonLen();
  }

  int codonFreq = 0;
  // Loop through the sequence in batches of three characters at a time.
  for (var i = 0; i < this._len - 2; i += 3) {
    // Grab three characters from the sequence and check if they match [codon].
    String fetchedCodon = this._seq.substring(i, i + 3);
    if (codon == fetchedCodon) {
      codonFreq++;
    }
  }
  return codonFreq;
}