Skip to content

Instantly share code, notes, and snippets.

@agdiaz
Created February 6, 2018 02:31
Show Gist options
  • Save agdiaz/eaab479795bf3e8f8c81ff8bb9676bc3 to your computer and use it in GitHub Desktop.
Save agdiaz/eaab479795bf3e8f8c81ff8bb9676bc3 to your computer and use it in GitHub Desktop.
Converts a sequence of nucleotides (in char format) in an ASCII text
#!/usr/bin/env ruby
# Don't forget to do: chmod +x ./dna_text.rb
print 'INPUT sequence: '
sequence = gets.strip.scan(/\w/)
binary = sequence.map do |n|
case n
when 'A' then '00'
when 'C' then '01'
when 'G' then '10'
else '11'
end
end.join('')
text = Array(binary).pack('B*')
puts "OUTPUT text: #{text}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment