[Tutor] A genomic sequence generator?

Magnus Lycka magnus@thinkware.se
Sat, 05 Oct 2002 02:12:35 +0200


At 13:08 2002-10-04 -0700, Danny Yoo wrote:
>Hi everyone,
>
>I just ran into an puzzle that I thought might be interesting to folks
>here.  Here's the problem:
>
>
>    """Genomic Sequence Generator:
>
>       Given a pattern like AT<GC>A<TA>, produce the strings ATGAT, ATGAA,
>       ATCAT, ATCAA.
>    """
>
>I shamelessly copied this from M-J. Dominus's hilarious talk on Conference
>Presentation Judo:
>
>     http://perl.plover.com/yak/judo/presentation/slide019.html)
>
>
>This might be a nice puzzle for Useless Python.


# genomic.py

genom = "AT<GC>A<TA>"
result = []

def makeGenes(rest, soFar, result):
     if not rest:
         result.append("".join(soFar))
         return
     char = rest.pop(0)
     if char == '<':
         char = rest.pop(0)
         while char != '>':
             makeGenes(rest[rest.index('>')+1:], soFar+[char], result)
             char = rest.pop(0)
     else:
         makeGenes(rest[:], soFar+[char], result)

print makeGenes(list(genom), [], result)
for gene in result: print gene



-- 
Magnus Lycka, Thinkware AB
Alvans vag 99, SE-907 50 UMEA, SWEDEN
phone: int+46 70 582 80 65, fax: int+46 70 612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se