Skip to content

Instantly share code, notes, and snippets.

@ybur-yug
Last active December 21, 2015 23:18
Show Gist options
  • Save ybur-yug/6380855 to your computer and use it in GitHub Desktop.
Save ybur-yug/6380855 to your computer and use it in GitHub Desktop.
Nucleotide counter. Takes input of ATGC sequence form dna and returns number of each type in the string using basic regex and a hash. Epicodus exercise.
def nucleo_counter(sequence)
g = sequence.gsub(/[ATC]/, "").length
c = sequence.gsub(/[ATG]/, "").length
a = sequence.gsub(/[GCT]/, "").length
t = sequence.gsub(/[AGC]/, "").length
nucleotides = {
"A's" => a,
"T's" => t,
"G's" => g,
"C's" => c
}
puts nucleotides
end
nucleo_counter("ATCGATGCCCCAT")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment