MathGroup Archive 2005

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

Search the Archive

Re: REpost: Nonatomic error associated with Intersection

  • To: mathgroup at smc.vnet.net
  • Subject: [mg53642] Re: [mg53618] REpost: Nonatomic error associated with Intersection
  • From: DrBob <drbob at bigfoot.com>
  • Date: Fri, 21 Jan 2005 06:35:54 -0500 (EST)
  • References: <200501200848.DAA04165@smc.vnet.net>
  • Reply-to: drbob at bigfoot.com
  • Sender: owner-wri-mathgroup at wolfram.com

First of all, I'm not sure you realize what this statement does:

acontology = Append[acontology[[outerindex]], temp[[innerindex]]];

It modifies a sublist of acontology, and then that submatrix replaces acontology itself. All the other submatrices are gone, and everything is at one less depth. When the outer loop starts and innerindex gets set to 1, the first element is no longer a List, as it was before.

Possibly things work better if you replace that statement with:

AppendTo[acontology[[outerindex]], temp[[innerindex]]];

This modifies one sublist without wiping out the others.

temp = {{"
     CEST-01-A-01", "CEST-17-A-06"}, {"CEST-01-A-02", "CEST-01-A-06", "CEST-02-
       C-06", "CEST-03-B-03", "CEST-03-G-07", "CEST-05-C-11", "CEST-06-
         A-09", "CEST-08-B-07", "CEST-09-A-02", "CEST-12-A-06", "CEST-12-
         G-11", "CEST-16-C-02", "CEST-16-H-04", "CEST-17-A-04", "CEST-18-
         D-05", "CEST-19-C-01", "CEST-19-D-04", "CEST-19-G-01", "CEST-20-
         C-09", "CEST-20-G-08", "CEST-22-D-07", "CEST-22-D-11", "CEST-23-
         C-09", "CEST-26-G-08", "CEST-27-E-04", "CEST-27-E-12", "CEST-30-
         C-08", "CEST-30-E-03", "CEST-34-C-06", "CEST-34-F-04", "CEST-35-
         G-09", "CEST-36-A-01", "CEST-36-B-01", "CEST-37-F-03", "CEST-37-
         F-06", "CEST-45-A-10", "CEST-45-H-05", "CEST-46-D-03", "CEST-46-
         D-11", "CEST-48-D-01", "CEST-48-E-01", "CEST-50-E-09", "CEST-51-
         A-01", "CEST-51-C-09", "CEST-53-G-01", "CEST-54-C-12", "CEST-54-
         H-11", "CEST-55-E-01", "CEST-55-G-06", "CEST-57-C-12", "CEST-57-
         E-12", "CEST-59-F-05"}, {"CEST-01-A-04"}};

acontology = {{"AEST-01-A-01", "blank", "None", "None"}, {"
       AEST-01-A-02", "CEST-01-A-01", "enzyme /
   ion transporter", "cell growth and/or maintenance / transport / ion
transport"}, {"AEST-01-A-03", "CEST-01-A-02", "translation regulator / \
translation factor", "cell growth and/or maintenance / metabolism /
biosynthesis"}};
outerindex = 1; innerindex = 1; While[outerindex <= Length[acontology], \
While[innerindex <= Length[temp],
     If[Length[Intersection[acontology[[outerindex]], temp[[innerindex]]]] == \
1, AppendTo[acontology[[outerindex]], temp[[innerindex]]];
       innerindex = Length[temp] + 1, innerindex++]];
   outerindex++;
   innerindex = 1];
save=acontology

{{"AEST-01-A-01", "blank",
    "None", "None"},
   {"AEST-01-A-02",
    "CEST-01-A-01",
    "enzyme / ion transporter", "\
cell growth and/or maintenance / \
transport / ion transport",
    {"CEST-01-A-01",
     "CEST-17-A-06"}},
   {"AEST-01-A-03",
    "CEST-01-A-02", "translation \
regulator / translation factor",
    "cell growth and/or \
maintenance / metabolism / \
biosynthesis", {"CEST-01-A-02",
     "CEST-01-A-06",
     "CEST-02-C-06",
     "CEST-03-B-03",
     "CEST-03-G-07",
     "CEST-05-C-11",
     "CEST-06-A-09",
     "CEST-08-B-07",
     "CEST-09-A-02",
     "CEST-12-A-06",
     "CEST-12-G-11",
     "CEST-16-C-02",
     "CEST-16-H-04",
     "CEST-17-A-04",
     "CEST-18-D-05",
     "CEST-19-C-01",
     "CEST-19-D-04",
     "CEST-19-G-01",
     "CEST-20-C-09",
     "CEST-20-G-08",
     "CEST-22-D-07",
     "CEST-22-D-11",
     "CEST-23-C-09",
     "CEST-26-G-08",
     "CEST-27-E-04",
     "CEST-27-E-12",
     "CEST-30-C-08",
     "CEST-30-E-03",
     "CEST-34-C-06",
     "CEST-34-F-04",
     "CEST-35-G-09",
     "CEST-36-A-01",
     "CEST-36-B-01",
     "CEST-37-F-03",
     "CEST-37-F-06",
     "CEST-45-A-10",
     "CEST-45-H-05",
     "CEST-46-D-03",
     "CEST-46-D-11",
     "CEST-48-D-01",
     "CEST-48-E-01",
     "CEST-50-E-09",
     "CEST-51-A-01",
     "CEST-51-C-09",
     "CEST-53-G-01",
     "CEST-54-C-12",
     "CEST-54-H-11",
     "CEST-55-E-01",
     "CEST-55-G-06",
     "CEST-57-C-12",
     "CEST-57-E-12",
     "CEST-59-F-05"}}}

Here's a much simpler equivalent code:

Do[
     Do[
       If[Length@Intersection[acontology[[outer]], temp[[inner]]] == 1,
         AppendTo[acontology[[outer]], temp[[inner]]]; Break[]
         ],
       {inner, Length@temp}],
     {outer, Length@acontology}];
save == acontology

True

Bobby

On Thu, 20 Jan 2005 03:48:11 -0500 (EST), Todd Allen <genesplicer28 at yahoo.com> wrote:

> (Re-post of previous message due to garbled
> characters...sorry for that (and thanks to Dr. Bob for
> the heads up on proper copy-paste methods).
>
> Hi everyone,
>
>     I was hoping the usergroup might have some
> thoughts on a peculiar error message I have been
> receiving from Mathematica V 5.1(win XP).
>
>     I have a set of nested loops where I try to
> compare the elements of two matrices using
> Intersection, and if there is indeed an intersection,
> make a change to one of the matrices.  The code
> generates an error message: Intersection::normal:
> "Nonatomic expression expected at position 1.......
>
> I believe the Head of the two lists I am comparing are
> in fact lists, however perhaps I am missing something
> as to how mathemamatica parses the input.
>
> Below is the basic code:
>
> temp={{"CEST-01-A-01", "CEST-17-A-06"},
> {"CEST-01-A-02", "CEST-01-A-06",
>    "CEST-02-C-06", "CEST-03-B-03", "CEST-03-G-07",
> "CEST-05-C-11",
>    "CEST-06-A-09", "CEST-08-B-07", "CEST-09-A-02",
> "CEST-12-A-06",
>    "CEST-12-G-11", "CEST-16-C-02", "CEST-16-H-04",
> "CEST-17-A-04",
>    "CEST-18-D-05", "CEST-19-C-01", "CEST-19-D-04",
> "CEST-19-G-01",
>    "CEST-20-C-09", "CEST-20-G-08", "CEST-22-D-07",
> "CEST-22-D-11",
>    "CEST-23-C-09", "CEST-26-G-08", "CEST-27-E-04",
> "CEST-27-E-12",
>    "CEST-30-C-08", "CEST-30-E-03", "CEST-34-C-06",
> "CEST-34-F-04",
>    "CEST-35-G-09", "CEST-36-A-01", "CEST-36-B-01",
> "CEST-37-F-03",
>    "CEST-37-F-06", "CEST-45-A-10", "CEST-45-H-05",
> "CEST-46-D-03",
>    "CEST-46-D-11", "CEST-48-D-01", "CEST-48-E-01",
> "CEST-50-E-09",
>    "CEST-51-A-01", "CEST-51-C-09", "CEST-53-G-01",
> "CEST-54-C-12",
>    "CEST-54-H-11", "CEST-55-E-01", "CEST-55-G-06",
> "CEST-57-C-12",
>    "CEST-57-E-12", "CEST-59-F-05"}, {"CEST-01-A-04"}};
>
> acontology={{"AEST-01-A-01", "blank", "None", "None"},
> {"AEST-01-A-02", "CEST-01-A-01",
>    "enzyme / ion transporter",
>    "cell growth and/or maintenance / transport / ion
> transport"},
>   {"AEST-01-A-03", "CEST-01-A-02",
>    "translation regulator / translation factor",
>    "cell growth and/or maintenance / metabolism /
> biosynthesis"}};
>
> outerindex = 1; innerindex = 1; While[outerindex <=
> Length[acontology],
>    While[innerindex <= Length[temp],
>      If[Length[Intersection[acontology[[outerindex]],
> temp[[innerindex]]]] ==
>        1, acontology =
> Append[acontology[[outerindex]], temp[[innerindex]]];
>        innerindex = Length[temp] + 1, innerindex++]];
> outerindex++;
>     innerindex = 1];
>
>
> The output I am hoping for is to progressively match
> components of each list to output as follows:
>
> Given input:
> Append[acontology[[2]], temp[[1]]]
>
> Desired output:
> {"AEST-01-A-02", "CEST-01-A-01", "enzyme / ion
> transporter",
>   "cell growth and/or maintenance / transport / ion
> transport",
>   {"CEST-01-A-01", "CEST-17-A-06"}}
>
>
> When I have used various statements contained within
> the above nested loops on their own, they seem to work
> fine....however things fall apart onces put inside a
> loop structure.  Any thoughts on why a loop or
> Intersection might generate the Nonatomic expression
> error?
>
> Thanks again for any thoughts!!
>
> Best regards,
> Todd
>
>
> __________________________________________________
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com
>
>
>
>



-- 
DrBob at bigfoot.com
www.eclecticdreams.net


  • Prev by Date: Re: Algebraic problem solved by simulation
  • Next by Date: Re: Saving the kernel state.
  • Previous by thread: REpost: Nonatomic error associated with Intersection
  • Next by thread: Re: Parameter Estimation for 3-parameter Weibull Distribution