Created
February 6, 2018 02:30
-
-
Save agdiaz/aaeb18db8c9dfc7c4e6c0a2e5b862e2e to your computer and use it in GitHub Desktop.
Converts an ASCII text into a sequence of nucleotids
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 ./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