in reply to Re: Errors when using module
in thread Errors when using module
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.
|
---|