Skip to content

Instantly share code, notes, and snippets.

@fogonthedowns
Created July 29, 2014 05:23
Show Gist options
  • Save fogonthedowns/833023f115e3edd37ea3 to your computer and use it in GitHub Desktop.
Save fogonthedowns/833023f115e3edd37ea3 to your computer and use it in GitHub Desktop.
Question 3
x = {"Alanine"=>7.4, "Arginine"=>4.2, "Asparagine"=>4.4, "Aspartic Acid"=>5.9, "Cystine"=>3.3,
"Glutamic Acid"=>5.8, "Glutamine"=>3.7, "Glycine"=>7.4, "Histidine"=>2.9, "Isoleucine"=>3.8,
"Leucine"=>7.5, "Lysine"=>7.2, "Methionine"=>1.8, "Phenylalanine"=>4.0, "Proline"=>5.0,
"Serine"=>8.0, "Threonine"=>6.2, "Tryptophan"=>1.3, "Tyrosine"=>3.3, "Valine"=>6.8,
"Stop Codons"=>0.1}
# creates a sorted list of codons
sorted = x.sort_by {|_key, value| value}
=> [["Stop Codons", 0.1], ["Tryptophan", 1.3], ["Methionine", 1.8], ["Histidine", 2.9], ["Tyrosine", 3.3],
["Cystine", 3.3], ["Glutamine", 3.7], ["Isoleucine", 3.8], ["Phenylalanine", 4.0], ["Arginine", 4.2], ["Asparagine", 4.4],
["Proline", 5.0], ["Glutamic Acid", 5.8], ["Aspartic Acid", 5.9], ["Threonine", 6.2], ["Valine", 6.8], ["Lysine", 7.2],
["Glycine", 7.4], ["Alanine", 7.4], ["Leucine", 7.5], ["Serine", 8.0]]
# 1 represents the circle
# 2 represents the triangle
# 3 represents the square
# 4 represents the pentagon
array =["1","2","3","4"];
answer=[];
array.each do |x|
array.each do |y|
array.each do |z|
puts (x+y+z).to_i
answer << (x+y+z).to_i
end
end
answer
end
# a list of all possible combinations
irb(main):217:0> answer
=> [111, 112, 113, 114, 121, 122, 123, 124, 131, 132, 133, 134, 141, 142, 143, 144, 211, 212, 213, 214, 221, 222, 223, 224, 231,
232, 233, 234, 241, 242, 243, 244, 311, 312, 313, 314, 321, 322, 323, 324, 331, 332, 333, 334, 341, 342, 343, 344, 411, 412, 413,
414, 421, 422, 423, 424, 431, 432, 433, 434, 441, 442, 443, 444]
irb(main):218:0> answer.count
# the number of combinations of codons
=> 64
#the largest percent value I have in my data set is 8%, the smallest value is 0.8% my goal is to have a proportional representation of
#this range to represent the approximate percent
irb(main):220:0> 8/64.to_f
=> 8.0
# highest possible number is represented by 444, so every other number is ~8x its value.
# 8x8 = 64
# 1 x 0.8 ~ 1
# multiply each value by 8, to get an index to plug into the answer array
sorted.each{|x,v|v*8}
=> [["Stop Codons", 0.1], ["Tryptophan", 1.3], ["Methionine", 1.8], ["Histidine", 2.9], ["Tyrosine", 3.3], ["Cystine", 3.3], ["Glutamine", 3.7], ["Isoleucine", 3.8], ["Phenylalanine", 4.0], ["Arginine", 4.2], ["Asparagine", 4.4], ["Proline", 5.0], ["Glutamic Acid", 5.8], ["Aspartic Acid", 5.9], ["Threonine", 6.2], ["Valine", 6.8], ["Lysine", 7.2], ["Glycine", 7.4], ["Alanine", 7.4], ["Leucine", 7.5], ["Serine", 8.0]]
irb(main):235:0> n.each{|x,v|puts v*8}
0.8
10.4
14.4
23.2
26.4
26.4
29.6
30.4
32.0
33.6
35.2
40.0
46.4
47.2
49.6
54.4
57.6
59.2
59.2
60.0
# The above values are an approximate index value, 0.8 is rounded up 1.
# array of codons
array = [111, 112, 113, 114, 121, 122, 123, 124, 131, 132, 133, 134, 141, 142, 143, 144, 211, 212, 213, 214, 221, 222, 223, 224, 231,
232, 233, 234, 241, 242, 243, 244, 311, 312, 313, 314, 321, 322, 323, 324, 331, 332, 333, 334, 341, 342, 343, 344, 411, 412, 413,
414, 421, 422, 423, 424, 431, 432, 433, 434, 441, 442, 443, 444]
# insert each index value, and the returned value is an approximate representation of the percent
array[index_value]
Final Answer: (remember 1 represents a circle, 2 a trianlge, 3 a square and 4 a pentagon)
=>[["Stop Codons", 112], ["Tryptophan", 133], ["Methionine", 143], ["Histidine", 224],
["Tyrosine", 232], ["Cystine", 233], ["Glutamine", 242], ["Isoleucine", 243], ["Phenylalanine", 311],
["Arginine", 312], ["Asparagine", 314], ["Proline", 331], ["Glutamic Acid", 343], ["Aspartic Acid", 344],
["Threonine", 412], ["Valine", 423], ["Lysine", 431], ["Glycine", 432], ["Alanine", 433], ["Leucine", 434],
["Serine", 441]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment