Created
February 6, 2018 02:31
-
-
Save agdiaz/eaab479795bf3e8f8c81ff8bb9676bc3 to your computer and use it in GitHub Desktop.
Converts a sequence of nucleotides (in char format) in an ASCII text
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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