translate method

Map<String, dynamic> translate({
  1. dynamic rev = false,
  2. dynamic startIdx = 0,
})

Returns the translated version of this sequence.

Return the reverse complementary strand by setting rev to true. Alter the starting indexing by setting startIdx.

Implementation

Map<String, dynamic> translate({rev = false, startIdx = 0}) {
  // If [rev] is `true`, return the reverse complementary sequence to this sequence.
  String seq = rev ? complementary(rev: true) : this.seq;

  String aaSeq = '';
  // Loop through the sequence in batches of three characters at a time.
  for (var i = startIdx; i < seq.length - 2; i += 3) {
    // Grab three characters from the sequence.
    String codon = seq.substring(i, i + 3);
    // Retrive the matching amino acid from the correct codon table based on this sequence type.
    aaSeq += this.type == kDNA ? dnaCodonToAA[codon]! : rnaCodonToAA[codon]!;
  }
  return {kAASeq: aaSeq, 'nucCount': seq.length - startIdx - 1, 'aaCount': aaSeq.length};
}