1
votes

(=( (defn sdsu-dna-count[dna-string]

(let [a (group-by identity dna-string)] 

   (zipmap (keys a) (map #(count (second %)) a)))
)

"ATGCTTC")

{\C 2,\G 1,\T 3,\A 1})

I am trying to learn Clojure. I am supposed to write a function that takes one argument, a DNA string, and returns a map that indicates the number of times each of the four characters appears in the DNA string. I want the output to be like this: {A 1 :T 3 :G 1 :C 2} instead of {\C 2,\G 1,\T 3,\A 1}. I know I should be able to do that using format, but I am still not able to get it right. Can anyone help me with this?

1
\A is the clojure notation for the character "A", if you want another type of data for the keys in the map, you need to convert the type. - noisesmith

1 Answers

3
votes

It looks like you want to convert characters to keywords. Try:

(frequencies (map (comp keyword str) dna-string))