Wobble Hypothesis - Combination or Permutation of Array of strings in ruby

来源:互联网 发布:mac配置java环境 编辑:程序博客网 时间:2024/06/05 09:52

I have a ruby array with 4 strings

nucleotides = ['A', 'G', 'C', 'T']

I need 4^3 combinations of strings.

new_array = ['AGC', 'AGT' .. 'TTT']

This is the wobble hypothesis in genetics. Could someone explain how I could go about achieving this using ruby.

use Array#repeated_permutation:

nucleotides = %w(A G C T)nucleotides.repeated_permutation(3).map(&:join)#=> ["AAA", "AAG", "AAC", "AAT", "AGA", "AGG", "AGC", "AGT", "ACA", "ACG", "ACC", "ACT", "ATA", "ATG", "ATC", "ATT", "GAA", "GAG", "GAC", "GAT", "GGA", "GGG", "GGC", "GGT", "GCA", "GCG", "GCC", "GCT", "GTA", "GTG", "GTC", "GTT", "CAA", "CAG", "CAC", "CAT", "CGA", "CGG", "CGC", "CGT", "CCA", "CCG", "CCC", "CCT", "CTA", "CTG", "CTC", "CTT", "TAA", "TAG", "TAC", "TAT", "TGA", "TGG", "TGC", "TGT", "TCA", "TCG", "TCC", "TCT", "TTA", "TTG", "TTC", "TTT"]
0 0
原创粉丝点击