2
$\begingroup$

Please consider the following toy code:

In[1]:= toylist = {hyb["chip1"], hyb["chip2"], hyb["chip3"]};

toyindices = {{{3, 1}, {3, 2}}, {{2, 3}, {2, 3}}, {{1, 3}, {1, 2}}};

toydata = {{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}, {{10, 11, 12}, {13, 14, 
     15}, {16, 17, 18}}, {{19, 20, 21}, {22, 23, 24}, {25, 26, 27}}};

Table[Evaluate[toylist[[i]]] = 
  Extract[toydata[[i]], toyindices[[j]]], {i, 1, Length[toylist]}, {j,
   1, Length[toyindices]}] (* Version B *)

During evaluation of In[1]:= Set::setraw: Cannot assign to raw object 7. >>

During evaluation of In[1]:= Set::setraw: Cannot assign to raw object 8. >>

During evaluation of In[1]:= Set::setraw: Cannot assign to raw object 7. >>

During evaluation of In[1]:= General::stop: Further output of Set::setraw will be suppressed during this calculation. >>

Out[4]= {{{7, 8}, {6, 6}, {3, 2}}, {{16, 17}, {15, 15}, {12, 
   11}}, {{25, 26}, {24, 24}, {21, 20}}}

In[5]:= hyb["chip2"]

Out[5]= {16, 17}

Even though the toy code above is producing the results I want, Mathematica throws the Set::setraw error.

Question1: Is the error happening because I am using strings as indexes?

Question2: Would it be safe to ignore or even turn this error off?

The toy code above was designed to help troubleshoot a real-world problem I have. In the real-world case, I get two errors Set::setraw and Set::shape, from the following statement:

Table[Evaluate[mmsignalnames[[i]]] = 
   Extract[celvarnames[[i]], mmammindices[[j]]], {i, 1, 
   Length[celvarnames]}, {j, 1, Length[mmammindices]}];

Would you have any advice about the Set::shape error? I can't tell if it is related to the Set::setraw error.


More detail about the real-world problem....

  1. I have 24 different biology datasets that have unique names. I have created a list called mmsignalnames which is composed of indexed symbols such as mmsignal["GSM356796"], mmsignal["GSM356797"] .... up to all 24 datasets. This is what I was trying to replicate in the toycode variable above.

  2. My desire is to programmatically load each of these mmsignal["GSM356796"] etc symbols with specific data from each experiment. Each of the mmsignal[ .... ] symbols needs to receive a subset of data from a master list containing all 24 experiments worth of data, where each experiment is a sublist within the master list. This is what I was trying to replicate in the toydata variable above, where in the toydata varaiable I have 3 experiments worth of data entered as sublists.

  3. The coordinates used to extract information from the masterlist (or toydata above) are contained within a list of indices that will be the same for each experiment. In other words, the same indices are used to extract data from the same position in 24 different experiments. So, in my toy code above, the output provided by my toy code, is actually what I want, and perhaps sloppily, does programmatically load specific information into the hyp["chip"] symbols.

  4. Unfortunately, my real-world problem also has the Set::shape error which I can't seem to replicate in my toycode.

$\endgroup$
0

1 Answer 1

6
$\begingroup$

This problem occurs because you are trying to make assignments to the same object multiple times. As far as I can tell this is simply broken code. You get the Set::setraw because you give hyb["chip1"] the value {7, 8}, then you try to set it to {6, 6}. Because you are forcing an Evaluate here you get {7, 8} = {6, 6} which is not an acceptable assignment. In effect:

x = 1;
Evaluate[x] = 2;

I am going out on a limb and suggesting this is what you want:

Evaluate[toylist] = 
  Table[Extract[toydata[[i]], toyindices[[j]]], {i, 1, 
    Length[toylist]}, {j, 1, Length[toyindices]}];

hyb["chip2"]
{{16, 17}, {15, 15}, {12, 11}}

This however is not as clean as it could be. I await an explanation of what you are actually trying to accomplish so that I can be more helpful.

As an example of cleaner coding, consider:

Outer[Extract, toydata, toyindices, 1]
{{{7, 8}, {6, 6}, {3, 2}},
 {{16, 17}, {15, 15}, {12, 11}},
 {{25, 26}, {24, 24}, {21, 20}}}

Addressing your edit, first an explanation of Set::shape. Set automatically threads over lists, such that {a, b} = {1, 2} is equivalent to a = 1; b = 2. This will work at deeper levels of the lists as well. If the lists on either side are not the same shape this fails.

{a, b, c} = {1, 2} (* failure *)

{{a}, b} = {{3}, 4} (* success *)

{a, b} = {{3}, 4} (* success *)

{{a}, b} = {3, 4} (* failure *)

You state:

I have created a list called mmsignalnames which is composed of indexed symbols such as mmsignal["GSM356796"], mmsignal["GSM356797"] .... up to all 24 datasets.

You're doing it wrong. :-) You should store the list of keys: {"GSM356796", "GSM356797", ..."}. This way you can handle the key names and the symbol mmsignal easily and without anything prematurely evaluating. Example:

keys = {"red", "green", "blue"};

Do[signal[ keys[[i]] ] = i^2, {i, 3}]

signal["green"]
4
signal /@ keys
{1, 4, 9}
$\endgroup$
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.