Help:=proc():print(`Cook(t,L,n); Con1(L), Con(W),`): print(`NexLeaf(s,f,v), Count(s,f,D1) `): print(`GrabWindow(TextL,v,L)`): print(` BestMotif(Text1,L) , TestM(t,L,n), NextVertex(s,f,v,D1)`): print(`CountV(s,f,D1),BestMotifBad(Text1,L)`): end: #NextLeaf(s,f,v): The next leaf in the complete #regular tree of D1+1 generations where every #vertex has exactly f-s+1 children labelled s through f #vertices are represented as lists #For example Lara Pudwell's full name is #[Eve, Seth, ..., Noah, ....,Anne ,Priscilia ,Kristine, Lara] NextLeaf:=proc(s,f,v) local i: for i from nops(v) by -1 to 1 while v[i]=f do od: if i=0 then RETURN(FAIL): fi: [op(1..i-1,v),v[i]+1,s$(nops(v)-i)]: end: #Count(s,f,D1): Counts from [s$D1] to [f$D1] #and prints out the "numbers" Count:=proc(s,f,D1) local v: v:=[s$D1]: print(`Guess what!, I can count to`, (f-s+1)^D1-1 ): while v<>FAIL do print(v): v:=NextLeaf(s,f,v): od: print(`Aren't you proud of me`): end: Cook:=proc(t,L,n) local X,i,ra,X1,ra1,X2,ra2,place1,place2,typo1,typo2,X1t, NewLine,Place,ra3,j: if L>=n then print(` L has to be less than n`): RETURN(FAIL): fi: if L<3 then RETURN(FAIL): fi: ra:=rand(1..4): X1:=[seq(ra(),i=1..L)]: ra1:=rand(1..L-1): ra3:=rand(1..n-L): X2:=[]: X:=[]: for i from 1 to t do place1:=ra1(): place2:=rand(place1+1..L)(): typo1:=ra(); typo2:=ra(): X1t:=[op(1..place1-1,X1),typo1,op(place1+1..place2-1,X1), typo2,op(place2+1..L,X1)]: Place:=ra3(): NewLine:=[seq(ra(),j=1..Place), op(X1t),seq(ra(),j=Place+1.. n-L)]: X:=[op(X), NewLine]: od: X: end: #Con1(L): the winner at the list Col1 #followed by the score Con1:=proc(L) local i,T,champ,rec: T[1]:=0: T[2]:=0: T[3]:=0: T[4]:=0: for i from 1 to nops(L) do T[L[i]]:=T[L[i]]+1: od: champ:=1: rec:=T[1]: for i from 2 to 4 do if T[i]>rec then champ:=i: rec:=T[i]: fi: od: champ,rec: end: #Con(W): the would-be motif of the #the window Window1 (a t-List if L-list) #followed by the score Con:=proc(W) local j,M,Col1,s,L,champ,s1,eric,t: L:=nops(W[1]): t:=nops(W): M:=[]: s:=0: for j from 1 to L do Col1:=[seq(W[i][j],i=1..nops(W))]: eric:=Con1(Col1): champ:=eric[1]: s1:=eric[2]: M:=[op(M),champ]: s:=s+s1: od: M,evalf(s/L/t): end: #GrabWindow(TextL,v,L): Given a t-list of n-lists # and a vector v of length t indicationg the #locations (1 througk n-L+1) for the starting #window at line i (i=1..t), outputs the #corresponding window (a t-list of L-lists) GrabWindow:=proc(TextL,v,L) local i,j: [seq( [op(v[i]..v[i]+L-1, TextL[i])], i=1..nops(v))]: end: #BestMotif(Text1,L): Inputs t (say) lines of text #each of length n (say), and L a #positive integer >=3 #finds the best motif of L-mers, followed #by the locations realizing it ( a list of #starting points, followed by the score BestMotif:=proc(Text1,L) local v,n,t,champ,rec,W,robbie: t:=nops(Text1): n:=nops(Text1[1]): v:=[1$t]: rec:=.25: while v<>FAIL do W:=GrabWindow(Text1,v,L): robbie:=Con(W): if robbie[2]>=rec then champ:=[robbie[1],v]: rec:=robbie[2]: fi: v:=NextLeaf(1,n-L+1,v): od: champ,rec: end: #TestM(t,L,n): tests the stupid bruce force algorithm for #finding motifs TestM:=proc(t,L,n) local X,i,ra,X1,ra1,X2,ra2,place1,place2,typo1,typo2,X1t, NewLine,Place,ra3,j,Y1,t0: t0:=time(): if L>=n then print(` L has to be less than n`): RETURN(FAIL): fi: if L<3 then RETURN(FAIL): fi: ra:=rand(1..4): X1:=[seq(ra(),i=1..L)]: ra1:=rand(1..L-1): ra3:=rand(1..n-L): X2:=[]: X:=[]: for i from 1 to t do place1:=ra1(): place2:=rand(place1+1..L)(): typo1:=ra(); typo2:=ra(): X1t:=[op(1..place1-1,X1),typo1,op(place1+1..place2-1,X1), typo2,op(place2+1..L,X1)]: Place:=ra3(): NewLine:=[seq(ra(),j=1..Place), op(X1t),seq(ra(),j=Place+1.. n-L)]: X:=[op(X), NewLine]: od: [BestMotif(X,L)[1][1], X1],time()-t0: end: #NextVertex(s,f,v,D1): The next vertex in the complete #regular tree of D1+1 generations where every #vertex has exactly f-s+1 children labelled s through f #vertices are represented as lists #For example Lara Pudwell's full name is #[Eve, Seth, ..., Noah, ....,Anne ,Priscilia ,Kristine, Lara] NextVertex:=proc(s,f,v,D1) local i: if nops(v)FAIL do print(v): v:=NextVertex(s,f,v,D1): od: print(`Aren't you proud of me`): end: #BestMotifBad(Text1,L): Inputs t (say) lines of text #each of length n (say), and L a #positive integer >=3 #finds the best motif of L-mers, followed #by the locations realizing it ( a list of #starting points, followed by the score BestMotifBad:=proc(Text1,L) local v,n,t,champ,rec,W,robbie: t:=nops(Text1): n:=nops(Text1[1]): v:=[]: rec:=.25: while v<>FAIL do W:=GrabWindow(Text1,v,L): robbie:=ConBad(W): if robbie[2]>=rec then champ:=[robbie[1],v]: rec:=robbie[2]: fi: v:=NextVertex(1,n-L+1,v,t): od: champ,rec: end: #TestMbad(t,L,n): tests the stupid bruce force algorithm for #finding motifs TestMbad:=proc(t,L,n) local X,i,ra,X1,ra1,X2,ra2,place1,place2,typo1,typo2,X1t, NewLine,Place,ra3,j,Y1,t0: t0:=time(): if L>=n then print(` L has to be less than n`): RETURN(FAIL): fi: if L<3 then RETURN(FAIL): fi: ra:=rand(1..4): X1:=[seq(ra(),i=1..L)]: ra1:=rand(1..L-1): ra3:=rand(1..n-L): X2:=[]: X:=[]: for i from 1 to t do place1:=ra1(): place2:=rand(place1+1..L)(): typo1:=ra(); typo2:=ra(): X1t:=[op(1..place1-1,X1),typo1,op(place1+1..place2-1,X1), typo2,op(place2+1..L,X1)]: Place:=ra3(): NewLine:=[seq(ra(),j=1..Place), op(X1t),seq(ra(),j=Place+1.. n-L)]: X:=[op(X), NewLine]: od: [BestMotifBad(X,L)[1][1], X1],time()-t0: end: #ConBad(W): the would-be motif of the #the window Window1 (a t-List if L-list) #followed by the score ConBad:=proc(W) local j,M,Col1,s,L,champ,s1,eric,t: if W=[] then RETURN([],0): fi: L:=nops(W[1]): t:=nops(W): M:=[]: s:=0: for j from 1 to L do Col1:=[seq(W[i][j],i=1..nops(W))]: eric:=Con1(Col1): champ:=eric[1]: s1:=eric[2]: M:=[op(M),champ]: s:=s+s1: od: M,evalf(s/L/t): end: #Bypass(s,f,v): The next vertex in the complete #bypassing the children of v #For example Lara Pudwell's full name is #[Eve, Seth, ..., Noah, ....,Anne ,Priscilia ,Kristine, Lara] Bypass:=proc(s,f,v) local i: for i from nops(v) by -1 to 1 while v[i]=f do od: if i=0 then RETURN(FAIL): fi: [op(1..i-1,v),v[i]+1]: end: