Created
July 13, 2009 19:12
-
-
Save patrickberkeley/146375 to your computer and use it in GitHub Desktop.
DNA search program
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
class Dna | |
# Prompt user for input. | |
def pick_one | |
puts "Enter DNA sequence. Must contain a, t, c, and g." | |
input = gets.chomp | |
process_input(input) | |
end | |
# Hash of dna sequences and values. | |
# If input exists in hash, return value. | |
# Else request input. | |
def process_input(input) | |
dna_pairs = {"atcg" => "Human", "gtca" => "Canine", "tgac" => "Feline", "ctga" => "Reptile"} | |
if dna_pairs.has_key?(input) | |
dna_pairs.each_pair do |key,value| | |
if key == input | |
puts value + " DNA sequence found." | |
end | |
end | |
else | |
pick_one | |
end | |
end | |
end | |
# Instantiate DNA object. | |
dna_choice = Dna.new | |
# Call input method on DNA object. | |
dna_choice.pick_one |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment