iangibson has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks.

[Please refer to Population of HoAoA based on file contents for full context on this. I'm making a new post here, as the previous node seems to have run its course.]

I've been trying (without success) to work out what's going on regarding some error messages I'm getting. I'm getting the following:

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

..when I run a basic script that passes a whole chromosome file to the Bio::PopGen::Statistics module. I successfully ran this script previously, and got some statistics back, so I can only assume that in re-running it now and getting errors, I must have changed the original program at some point.

When I run my new, larger script in which I used complex data structures to build 100kb windows (that you guys helped me with in the node I linked to above), I get a different error:

Can't call method "isa" without a package or object reference at /usr/local/share/perl/5.14.2/Bio/PopGen/Statistics.pm line 901.

I'd like to know whether these problems originate with my own code, or with the module that the errors are originating from. If it's on my end, what can I do to fix it?

Help as always will be greatly appreciated.

Replies are listed 'Best First'.
Re: Errors when using module
by tobyink (Canon) on Jun 04, 2012 at 19:48 UTC

    Something is being passed to a function defined around line 901 in Bio::PopGen::Statistics. Bio::PopGen::Statistics expects that thing to be a blessed object. But it is not; hence the error.

    perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'
Re: Errors when using module
by NetWallah (Canon) on Jun 05, 2012 at 01:56 UTC
    The other clue to the problem is the message snippet:
    <GEN0> line 182
    This says - look at line 182 of your input file. Something in that line caused your code to call to the undefined "isa" method.

                 I hope life isn't a big joke, because I don't get it.
                       -SNL

Re: Errors when using module
by snape (Pilgrim) on Jun 04, 2012 at 19:43 UTC

    Hi

    It seems that you have used a method "isa" which is not defined in this Statistics package. Could you please show your code.

Re: Errors when using module
by iangibson (Scribe) on Jun 05, 2012 at 15:32 UTC

    Here is what I've found out so far.

    Firstly, my original, smaller script had been modified (it was referring to a different input file than previously). So I switched it back as accurately as I can. However, I did realize that in the part of the error that refers to <GENO> the line number given is always the last line of the input file (I tried deleting lines to test this).

    Just focusing on my original (smaller) program for now, the code for this is as follows:

    #!/usr/bin/perl use warnings; use strict; use v5.14; use Bio::PopGen::IO; use Bio::PopGen::Statistics; open my $out_file, ">", "chr22_exome_snps_processed_AMR_TRUNCATED_STAT +S" or die "Can't open output file: $!\n"; my $io = new Bio::PopGen::IO( -format => 'csv', -file => "chr22_exome_snps_processed_AMR_TRUNCATED" ); my @markers; my @samples; while ( my $ind = $io->next_individual ) { if ( $ind =~ /^SAMPLE/ ) { push @markers, $ind; } else { push @samples, [$ind]; } } my $segsites = Bio::PopGen::Statistics->segregating_sites_count( \@s +amples ); my $singletons = Bio::PopGen::Statistics->singleton_count( \@samples ) +; my $pi = Bio::PopGen::Statistics->pi( \@samples ); my $theta = Bio::PopGen::Statistics->theta( \@samples ); my $tajima_D = Bio::PopGen::Statistics->tajima_D( \@samples ); my $D_star = Bio::PopGen::Statistics->fu_and_li_D_star( \@samples +); my $F_star = Bio::PopGen::Statistics->fu_and_li_F_star( \@samples +); say $out_file "Population: AMR\tChromosome: 22_TRUNCATED"; say $out_file "Seg sites\tSingletons\tPi\tTheta\tTajima's D\tFu & Li F*\tFu & Li D +*"; say $out_file "$segsites\t$singletons\t$pi\t$theta\t$tajima_D\t$F_star\t$D_star";

    And the output is now:

    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 3

    I am using a truncated input file here, to test the general approach. This input file has a header line and two lines with CSV genetic data from separate individiduals, i.e. a 3-line input file, with the error referencing

     <GENO> line 3.

      Hi iangibson

      The arrays @markers and @samples are empty that is why you are getting the error. If you run the following code where file1.csv is input file and testGENO as the output file the you won't get any error

      #!/usr/bin/perl use strict; use warnings; use Bio::PopGen::IO; use Bio::PopGen::Statistics; use Data::Dumper; open my $input, "file1.csv" or die $!; open my $out_file, ">", "testGENO" or die "Can't open output file: $!\ +n"; my $io = new Bio::PopGen::IO( -format => 'csv', -file => "file1.csv" ); my @markers; my @samples; while ( my $ind = $io->next_individual ) { print $ind,"\n"; # my %hash = %$ind; print Dumper($ind); if ( $ind =~ /^SAMPLE/ ) { push @markers, $ind; } else { push @samples, [$ind]; } }

      $ind is a reference variable to the hash and it is not a list of scalar variable therefore the if and else loop wont work and hence @markers and samples are empty set. I use Data Dumper to check the contents of the referenced hash variable $ind. And then when you use the methods in the module

      my $segsites = Bio::PopGen::Statistics->segregating_sites_count( \@sam +ples );

      you get an error and the reason is because @samples is empty and then you are referencing to an empty array. You first need to dereference the hash variable, extract the content you are interested in, then push it into the array and then use methods you are interested in.

      I hope it is of some help to you.