Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Errors when using module

by iangibson (Scribe)
on Jun 05, 2012 at 15:32 UTC ( [id://974485]=note: print w/replies, xml ) Need Help??


in reply to Errors when using module

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.

Replies are listed 'Best First'.
Re^2: Errors when using module
by snape (Pilgrim) on Jun 05, 2012 at 21:09 UTC

    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.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (3)
As of 2024-04-19 22:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found