Original rules by Сергей Слюсарев.
Last active
December 18, 2015 13:09
-
-
Save artm/5787932 to your computer and use it in GitHub Desktop.
GenePoker
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
module GenePoker | |
RnaAlphabet = %w(G A U C) | |
IupacComprehensions = { | |
' ' => '|', | |
'N' => '.', | |
'R' => '[AG]', | |
'Y' => '[UC]', | |
'H' => '[^G]', | |
} | |
AminoCodes = { | |
"Ala" => "GCN", | |
"Leu" => "UUR CUN", | |
"Arg" => "CGN AGR", | |
"Lys" => "AAR", | |
"Asn" => "AAY", | |
"Met" => "AUG", | |
"Asp" => "GAY", | |
"Phe" => "UUY", | |
"Cys" => "UGY", | |
"Pro" => "CCN", | |
"Gln" => "CAR", | |
"Ser" => "UCN AGY", | |
"Glu" => "GAR", | |
"Thr" => "ACN", | |
"Gly" => "GGN", | |
"Trp" => "UGG", | |
"His" => "CAY", | |
"Tyr" => "UAY", | |
"Ile" => "AUH", | |
"Val" => "GUN" | |
} | |
IupacCodesRegex = Regexp.union IupacComprehensions.keys | |
def self.iupac_to_regex iupac | |
Regexp.new iupac.gsub(IupacCodesRegex, IupacComprehensions) | |
end | |
AminoCodes.each do |acid,codes| | |
AminoCodes[acid] = iupac_to_regex(codes) | |
end | |
def self.hands | |
RnaAlphabet.repeated_combination(4) | |
end | |
def self.aminoacid code | |
acid, _ = AminoCodes.find{|acid,regex| regex === code} | |
acid | |
end | |
def self.produce_aminoacids hand | |
hand.permutation(3).map{|code|aminoacid(code.join)}.compact.uniq | |
end | |
end | |
GenePoker.hands.map do |hand| | |
aminoacids = GenePoker.produce_aminoacids(hand) | |
{ | |
hand: hand.join, | |
value: aminoacids.count, | |
aminoacids: aminoacids.join(' ') | |
} | |
end.sort_by do |row| | |
-row[:value] | |
end.each do |row| | |
puts row.values.join "\t" | |
end |
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
GAUC 13 Asp Val Ala Ser Met Ile Thr Cys Tyr Arg Gln His Leu | |
GAAU 9 Glu Asp Val Arg Ser Lys Asn Met Ile | |
GAAC 9 Glu Asp Ala Arg Ser Lys Asn Thr Gln | |
GACC 8 Asp Ala Ser Thr Arg Gln His Pro | |
GAUU 8 Asp Val Ser Met Ile Cys Tyr Leu | |
GGAU 8 Gly Glu Asp Val Arg Ser Met Trp | |
GGAC 8 Gly Glu Asp Ala Arg Ser Thr Gln | |
AAUC 8 Asn Ile Thr Tyr Ser Gln His Leu | |
GGUC 8 Gly Val Ala Trp Cys Ser Arg Leu | |
GUUC 7 Val Ala Cys Leu Phe Ser Arg | |
AUUC 7 Ile Thr Tyr Leu Phe Ser His | |
AUCC 7 Ile Thr Tyr Ser His Leu Pro | |
GUCC 7 Val Ala Cys Ser Arg Leu Pro | |
AACC 5 Asn Thr Gln His Pro | |
GGUU 5 Gly Val Trp Cys Leu | |
GUUU 4 Val Cys Leu Phe | |
GGCC 4 Gly Ala Arg Pro | |
AUUU 4 Ile Tyr Leu Phe | |
GGAA 4 Gly Glu Arg Lys | |
UUCC 4 Phe Ser Leu Pro | |
AAUU 4 Asn Ile Tyr Leu | |
AAAC 4 Lys Asn Thr Gln | |
GAAA 3 Glu Arg Lys | |
AAAU 3 Lys Asn Ile | |
GGGA 3 Gly Glu Arg | |
GCCC 3 Ala Arg Pro | |
UCCC 3 Ser Leu Pro | |
GGGU 3 Gly Val Trp | |
GGGC 3 Gly Ala Arg | |
ACCC 3 Thr His Pro | |
UUUC 3 Phe Ser Leu | |
GGGG 1 Gly | |
AAAA 1 Lys | |
UUUU 1 Phe | |
CCCC 1 Pro |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment