Hey, if you’re casually reading my blog you can probably ignore this post. I want to talk about a rare pitfall in BioPERL, and I want to make it very accessible to Google search. So here goes:
If you’re using the Bio::TreeIO package to parse Newick-formatted phylogenetic trees, you might encounter an error which looks like this:
Modification of non-creatable array value attempted, subscript -2 at /Library/Perl/5.8.6/Bio/TreeIO/TreeEventBuilder.pm line 256, <GEN0> chunk 2.For me, this error appeared when I executed the following code block:
while( my $tree = $treeio->next_tree ) {
# Do something with the $tree object here }
Unfortunately, three hours of Google searching yielded no clues about a solution. Instead, I dived into the BioPERL source code, and here is what I learned. . .
The error message indicates that PERL is trying to write to an array index which has not been initialized. But here’s the trick: the cause of the problem isn’t your PERL code. The problem actually comes from your Newick tree file.
As you probably know, Newick tree files consist of long parenthetical strings. A short example looks like this:
((A:3, B:1):4, C:5):0;
If your parenthetical tree is missing a parenthesis, then you’ll recieve the error message I mentioned above. For example, a “broken” tree looks like this:
(A:3, B:1):4, C:5):0; # notice the missing first parenthesis.
You might wonder: Why are my trees missing a parenthesis?
Answer: When you re-root or un-root a parenthetical tree, it is possible to lose a parenthesis but still have a tree which can recognized by software like FigTree and TreeGraph. Unfortunately, BioPerl is not so forgiving.
So, long story short:
If you’re using Bio::TreeIO and you get an error like this. . .
Modification of non-creatable array value attempted, subscript -2 at /Library/Perl/5.8.6/Bio/TreeIO/TreeEventBuilder.pm line 256, <GEN0> chunk 2.
. . . check your parentheses!
January 4, 2008 at 10:04 am |
I wish I was disciplined enough to write up little things like this I find. The world will thank you.