Skip to content

2022-1: Counting DNA Nucleotides?

This problem was inspired by Counting DNA Nucleotides found on the excellent bioinformatics website rosalind.info.

Write a function that:

  • takes a right argument that is a character vector or scalar representing a DNA string (whose alphabet contains the symbols 'A', 'C', 'G', and 'T').
  • returns a 4-element numeric vector containing the counts of each symbol 'A', 'C', 'G', and 'T' respectively.

Hint: The key operator f⌸ or the outer product operator ∘.g could be helpful.

Examples:

      
      (your_function) 'AGCTTTTCATTCTGACTGCAACGGGCAATATGTCTCTGTGTGGATTAAAAAAAGAGTGTCTGATAGCAGC'
20 12 17 21

      (your_function) ''
0 0 0 0

      (your_function) 'G'
0 0 1 0

your_function ←

Solutions

Video Thumbnail YouTube

Chat transcript Code on GitHub