MathGroup Archive 2004

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: While or not to While that is the question :)

  • To: mathgroup at smc.vnet.net
  • Subject: [mg46845] Re: While or not to While that is the question :)
  • From: drbob at bigfoot.com (Bobby R. Treat)
  • Date: Wed, 10 Mar 2004 04:57:42 -0500 (EST)
  • References: <c2lpt2$9eb$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

You didn't show us your While statement, so of course we can't tell
you what you've done wrong. You also didn't make it clear what you're
doing. For instance, when you replace {g,c} with {g,c} followed by c,
does the next step operate on the new element c? That's what I assumed
(among other things) in the following code:

Clear@f
single = {a -> {a, t}, t -> {t, a}, c -> {c, g}, g -> {g, c}};
f[x : (a | t | c | g)] := x /. single
f[{x_, y_}] := Sequence[{x, y}, y]
adder@_List := 1; adder@_ := 0;
dna = {a, {g, c}, {t, a}, c, g, a, {g, c}, {a, t}, c, g, {a, c}, t, t}
i = 4;
j = 9;
limit = 30;
While[j ? Min[limit, Length@dna],
  add = adder@dna[[i]]; dna = MapAt[f, dna, i];
  i += 1; j += add; dna = MapAt[f, dna, j]; j += 1; Print@dna
  ]

Bobby

János <janos.lobb at yale.edu> wrote in message news:<c2lpt2$9eb$1 at smc.vnet.net>...
> Hi,
> 
> Inside a While loop I slide on a nested list like 
> {a,{g,c},{t,a},c,g,a,{g,c},{a,t},c,,g,a,t,t}.  Let's say I start after 
> {t,a} and {a,t} parallel - positions 4 and 9, that is element c and c.  
> If I find a single element then I pair it with its corresponding DNA 
> complement, a->t, t->a, c->g, g->c and replace the element with a 
> sublist of the element and its complement.  So, after the first step my 
> list will look like 
> {a,{g,c},{t,a},{c,g},g,a,{g,c},{a,t},{c,g},g,a,t,t}.  If I find a 
> double, like the {g,c} on position 7, then first I create a triplet 
> from it {g,c,c} - the original c in the double is now on the third 
> position inside the triplet -, and then after some housekeeping I take 
> the third element of the triplet off and put it into another bucket, so 
> the triplet becomes a double again and in the While I slide happily 
> further right on the nested list.   In the above example I would hit 
> {g,c} after 4 steps.  If I run the While, let say for 5 or more steps, 
> it errors out complaining that I want to select some parts of the empty 
> {} list.  If I ran it for 4 steps and then I manually execute ALL the 
> statements inside the While for step 5, I do not see any complains and 
> I can go up to as many steps manually, by increasing the loop variable, 
> as my heart desires.
> 
> As being a newbie I have not learned yet to use Modules or Blocks , - I 
> am still just at page 320 in the book - so all my variables are 
> globals.
> 
> So my first question is why I am getting different results if I execute 
> the while programatically, for 5 steps, compared to executing it for 4 
> steps and do the 5th step manually?  I am using 5.0.1 on OS X.
> 
> The first error message I get is this:
> \!\(\*
>    RowBox[{\(ReplacePart::"partw"\), \(\(:\)\(\ \)\), "\<\"Part 
> \\!\\({1, 2}\\)
>       of \\!\\({}\\) does not
>        exist. \\!\\(\\*ButtonBox[\\\"More?\\\", \
> ButtonStyle->\\\"RefGuideLinkText\\\", ButtonFrame->None, \
> ButtonData:>\\\"General::partw\\\"]\\)\"\>"}]\)
> 
> So, my second question is how to use Trace to determine where in the 
> code do I get the first  "partw" ?  I use ReplacePart in 4 places 
> inside the While, but at manual execution none of them complain.
> 
> I am sure my code is far from perfect, but still it should give the 
> same result on both cases.
> 
> János
> 
> 
> 
> 
> -------------------------------------------------
> clear perl code is better than unclear awk code; but NOTHING comes 
> close to unclear perl code
> http://www.faqs.org/faqs/computer-lang/awk/faq/


  • Prev by Date: Re: bessel function with complex order
  • Next by Date: Re: How to give back to an image using "Net/Link" and "asp.net"?
  • Previous by thread: Re: While or not to While that is the question :)
  • Next by thread: bessel function with complex order