Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Protein Translation #13

Open
wants to merge 1 commit into
base: Diamond
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions protein_translation.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
class Translation
def self.of_rna(codon)
Translation.of_codon(codon)
end
def self.of_codon(codon)
@@result = []
if codon.class == String
@codon_array = codon.split("")
@codon_string=""
char = 0
@codon_array.each do |i|
if char != 3
@codon_string += i
char += 1
end
if char == 3
return_proteins = self.new.proteins(@codon_string)
raise InvalidCodonError if return_proteins == "invalid"
if @@result == []
@@result << return_proteins
elsif return_proteins == "STOP"
break
else
@@result << return_proteins
end
@codon_string = ""
char = 0
end
end
else
codon.each do |i|
return_proteins = self.new.proteins(i)
raise InvalidCodonError if return_proteins == "invalid"
if @@result == []
@@result << return_proteins
elsif return_proteins == "STOP"
break
else
@@result << return_proteins
end
@codon_string = ""
char = 0
end
end
if @@result.uniq.length == 1
return @@result[0]
else
return @@result
end
end
def proteins(codon)
case codon
when "AUG" then return "Methionine"
when "UUU", "UUC" then return "Phenylalanine"
when "UUA", "UUG" then return "Leucine"
when "UCU", "UCC", "UCA", "UCG" then return "Serine"
when "UAU", "UAC" then return "Tyrosine"
when "UGU", "UGC" then return "Cysteine"
when "UGG" then return "Tryptophan"
when "UAA", "UAG", "UGA" then return "STOP"
else
return "invalid"
end
end
end
InvalidCodonError = Class.new(StandardError)