Beefy Boxes and Bandwidth Generously Provided by pair Networks vroom
Think about Loose Coupling
 
PerlMonks  

Re^2: Population of HoAoA based on file contents

by state-o-dis-array (Hermit)
on May 22, 2012 at 22:24 UTC ( #971903=note: print w/ replies, xml ) Need Help??


in reply to Re: Population of HoAoA based on file contents
in thread Population of HoAoA based on file contents

I'm going to deal with just this section, I think once you understand/update what is happening here, everything else you have will work.

my $id; # ?? foreach my $window ( @{ $data{$id} } ) { # only pass windows with > min number of stats (i.e. >1 for now), an +d # of course we also ignore any 'undef' windows. next unless scalar @{ $data{$id} }[$window] >= 2; foreach my $individual ( keys(%data) ) {
First, I think that you understand that having an undefined $id as a hash key won't work. And to fix this, you want to just rearrange your for loops.
foreach my $id ( keys %data ){ foreach my $window ( @{$data{$id}} ){

Just this will get you much further. There is still a problem with the second loop though, at least in how you use $window in the subsequent code. You are attempting to use $window as an index, but it's not an index. Since you have experience using Data::Printer, I suggest going ahead and checking out what $window is.

Now, the way to fix things with the fewest number of overall edits is to change the second for loop.

foreach my $id ( keys %data ){ foreach my $window ( 0 .. $#{$data{$id}} ){ next unless scalar @{ $data{$id}[$window] } >= 2;
Then in your method calls, just change those to align with the scalar test above:
\@{ $data{$id}[$window] }
I hope that helps.


Comment on Re^2: Population of HoAoA based on file contents
Select or Download Code
Re^3: Population of HoAoA based on file contents
by iangibson (Scribe) on May 24, 2012 at 19:53 UTC

    Thanks for your further help on this. I feel like I'm almost there, but not quite.. I made the changes you suggested, but I'm still getting errors starting at the line

    next unless scalar @{ $data{$id}[$window] } >= 2;

    The error is:

    Can't use an undefined value as an ARRAY reference

    Is this referring to $window? Regarding the way I was using it above, was $window the outer array that holds all the smaller arrays? Even if this is true, I don't see why I'm getting the error messages I'm getting.

      Hmm, based on your expectation for your data, I'm guessing what you probably need is to add:
      next unless ref( $data{$id}[$window] ) eq "ARRAY";
      just before the line getting the error.

        That appears to have fixed that problem. However, now I'm getting errors from the module:

        Can't call method "isa" on unblessed reference at /usr/local/share/per +l/5.14.2/Bio/PopGen/Statistics.pm line 901, <GEN0> line 182.

        I went back and re-ran my simpler code from earlier (i.e. where I just passed a file without building windows), and I'm now getting a similar error on this too, whereas before it successfully gave me output.

        This is very strange, so I'll have to investigate further to see how to proceed.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://971903]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (9)
As of 2014-04-18 09:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (465 votes), past polls