Hello, I’ve been updating several of my solutions to meet updated tests. Most of these involved IllegalArgumentException with (newly) prescribed messages. Usually I’ve suoccesfully used something like
(throw (IllegalArgumentException. msg))
However, with protein translation I’ve not succeeded in getting the tests to pass. It seems that the :message
field of the Exception info is nil. However, “Invalid codon” does show up in the :cause
. Why?
Here’s my code:
(ns protein-translation)
(def codon-map
{
"AUG" "Methionine"
"UUU" "Phenylalanine"
"UUC" "Phenylalanine"
"UUA" "Leucine"
"UUG" "Leucine"
"UCU" "Serine"
"UCC" "Serine"
"UCA" "Serine"
"UCG" "Serine"
"UAU" "Tyrosine"
"UAC" "Tyrosine"
"UGU" "Cysteine"
"UGC" "Cysteine"
"UGG" "Tryptophan"
"UAA" "STOP"
"UAG" "STOP"
"UGA" "STOP"
} )
(defn translate-codon [codon]
(if (or (not (= (count codon) 3))
(not (contains? codon-map codon)))
(throw (IllegalArgumentException. "Invalid codon"))
(get codon-map codon)))
(defn translate-rna [rna-sequence]
(take-while #(not (= "STOP" %))
(map translate-codon
(map #(apply str %)(partition 3 rna-sequence)
))))