diff --git a/.travis.yml b/.travis.yml index ab012b0..c6a933f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -20,6 +20,8 @@ addons: - time - curl - r-base-dev + - libgd-dev + - libdb-dev install: true diff --git a/CHANGES.md b/CHANGES.md index 78d13cf..b84d3f6 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,11 @@ # Changes +## 3.3.1 + +* Fixed bug when creating split loci files which would occasionally count wrongly due to rounding errors. Fixed the cause of the rounding error and added a sort to the hash. +* Added check that the number of split loci files is at least the number of required contigs + + ## 3.3.0 * Upgrade to Battenberg [v2.2.8](https://github.com/Wedge-Oxford/battenberg/releases/tag/v2.2.8). diff --git a/perl/bin/battenberg.pl b/perl/bin/battenberg.pl index 5fe1f31..f3a3df5 100755 --- a/perl/bin/battenberg.pl +++ b/perl/bin/battenberg.pl @@ -292,6 +292,9 @@ sub setup { $opts{'num_loci_files'} = $no_of_jobs; $loci_files_defined = 0; } + if ($opts{'num_loci_files'} < $no_of_jobs) { + die "ERROR: Please define at least as many loci files (" . $opts{'num_loci_files'} . ") as required contigs ($no_of_jobs)"; + } if(exists $opts{'process'}) { PCAP::Cli::valid_process('process', $opts{'process'}, \@VALID_PROCESS); diff --git a/perl/lib/Sanger/CGP/Battenberg.pm b/perl/lib/Sanger/CGP/Battenberg.pm index 8bd8139..81d0a16 100644 --- a/perl/lib/Sanger/CGP/Battenberg.pm +++ b/perl/lib/Sanger/CGP/Battenberg.pm @@ -25,7 +25,7 @@ use strict; use Const::Fast qw(const); use base 'Exporter'; -our $VERSION = '3.3.0'; +our $VERSION = '3.3.1'; our @EXPORT = qw($VERSION); 1; diff --git a/perl/lib/Sanger/CGP/Battenberg/Implement.pm b/perl/lib/Sanger/CGP/Battenberg/Implement.pm index f7573bb..59b50e7 100644 --- a/perl/lib/Sanger/CGP/Battenberg/Implement.pm +++ b/perl/lib/Sanger/CGP/Battenberg/Implement.pm @@ -239,8 +239,7 @@ sub battenberg_splitlocifiles { my $num_loci_per_split = $total_loci_remaining / $num_loci_files; my $total_number_of_split_files_created = 0; - - foreach my $file (keys %$loci_per_file) { + foreach my $file (sort keys %$loci_per_file) { #Check if we are at the last file my $number_of_split_files_for_chr; @@ -248,20 +247,21 @@ sub battenberg_splitlocifiles { #Set last file to be what is left $number_of_split_files_for_chr = $requested_num_loci_files - $total_number_of_split_files_created; } else { - $number_of_split_files_for_chr = int($loci_per_file->{$file} / $num_loci_per_split); + $number_of_split_files_for_chr = $loci_per_file->{$file} / $num_loci_per_split; } #Must have each file at least once - if ($number_of_split_files_for_chr == 0) { - $number_of_split_files_for_chr = 1; - } #print "file=$file " . $loci_per_file->{$file} . " $number_of_split_files_for_chr $total_number_of_split_files_created\n"; + my $int_number_of_split_files_for_chr = int($number_of_split_files_for_chr); + if ($int_number_of_split_files_for_chr < 1) { + $int_number_of_split_files_for_chr = 1; + } #Write split loci files to the tmpdir - _create_split_files($file, $loci_per_file->{$file}, $number_of_split_files_for_chr, $tmp, $total_number_of_split_files_created); + _create_split_files($file, $loci_per_file->{$file}, $int_number_of_split_files_for_chr, $tmp, $total_number_of_split_files_created); #Keep track of the total number of files created - $total_number_of_split_files_created += $number_of_split_files_for_chr; + $total_number_of_split_files_created += $int_number_of_split_files_for_chr; #Need to keep refining the answer to avoid problems with rounding if ($num_loci_files > $number_of_split_files_for_chr) { @@ -270,7 +270,7 @@ sub battenberg_splitlocifiles { } if ($total_number_of_split_files_created != $requested_num_loci_files) { - die("The number of loci files created $total_number_of_split_files_created is not the same as the number requested $num_loci_files\n"); + die("The number of loci files created $total_number_of_split_files_created is not the same as the number requested $requested_num_loci_files\n"); } return PCAP::Threaded::touch_success(File::Spec->catdir($tmp, 'progress'), 0); }