PROT: Translating RNA into Protein | Ben Cunningham

PROT: Translating RNA into Protein

Problem by Rosalind · on July 1, 2012

The 20 commonly occurring amino acids are abbreviated by using 20 letters from the English alphabet (all letters except for B, J, O, U, X, and Z). Protein strings are constructed from these 20 symbols. Henceforth, the term genetic string will incorporate protein strings along with DNA strings and RNA strings.

The RNA codon table dictates the details regarding the encoding of specific codons into the amino acid alphabet.

Given: An RNA string corresponding to a strand of mRNA (of length at most 10 kbp).

Return: The protein string encoded by .

Sample Dataset

AUGGCCAUGGCGCCCAGAACUGAGAUCAAUAGUACCCGUAUUAACGGGUGA

Sample Output

MAMAPRTEINSTRING

R

library(readr)
library(dplyr)
library(stringr)

f <- "prot.txt"
cod_f <- "rna_codon_table.csv"

cod <- read_csv(cod_f)

rna <- data_frame(
  codon =
    readLines(f) %>%
    str_replace_all("(.{3})", "\\1 ") %>%
    str_split(" ") %>%
    unlist()
)

prot <-
  rna %>%
  left_join(cod, by = "codon") %>%
  filter(!is.na(acid), acid != "Stop")

cat(prot$acid, sep = "")
MAMAPRTEINSTRING