From: "Jesús Gabriel y Galán" Date: 2009-01-16T22:32:20+09:00 Subject: Re: Describing degerate dna strings On Fri, Jan 16, 2009 at 7:54 AM, George George wrote: > I am working with strings of 4 letter alphabet a,c,t,g that describe > biological dna sequences. sometimes a sequence can be described as > ac[ta]cct meaning that at position 3 you are can have 't 'or an 'a' > without changing the biological function of the sequence. > > Given ac[ta]cct as input i would like to generate a set of strings such > that it gives me the various combination of the strings that can > represent the above degenerate sequence e.g > 1. actcct > 2. acacct > > both satisfy the above degeneracy. > > any ideas? Hi, this reminded me so much of a Ruby Quiz I solved that I wanted to mention it :-) http://rubyquiz.com/quiz143.html http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/274375 (my solution) This code generates all strings that match a regexp. So we are left with the task of converting your strings to regexps: irb(main):010:0> require 'quiz143' => true irb(main):011:0> def expand a irb(main):012:1> re = Regexp.new(a.gsub(/\[(.*?)\]/) {|m| "(#{$1.split(//).join("|")})"}) irb(main):013:1> re.generate irb(main):014:1> end => nil irb(main):015:0> expand "ac[ta]cct" => ["actcct", "acacct"] It's probably overkill for your needs. Jesus.