Skip to content

Instantly share code, notes, and snippets.

@agdiaz
Created February 6, 2018 02:30
Show Gist options
  • Save agdiaz/aaeb18db8c9dfc7c4e6c0a2e5b862e2e to your computer and use it in GitHub Desktop.
Save agdiaz/aaeb18db8c9dfc7c4e6c0a2e5b862e2e to your computer and use it in GitHub Desktop.
Converts an ASCII text into a sequence of nucleotids
#!/usr/bin/env ruby
# Don't forget to do: chmod +x ./text_dna.rb
print 'INPUT text: '
text = gets.strip
binary = text.unpack('B*')
bits = binary[0].scan(/\w/)
sequence_bits = bits.each_slice(2).map do |a, b|
seq = a + b
case seq
when '00' then 'A'
when '01' then 'C'
when '10' then 'G'
else 'T'
end
end
puts "OUTPUT sequence: #{sequence_bits.join('')}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment