Skip to content

Commit

Permalink
Merge branch 'hotfix/v3.3.1'
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
kathryn-beal committed May 20, 2019
2 parents 772d703 + d232726 commit 689962f
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 10 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ addons:
- time
- curl
- r-base-dev
- libgd-dev
- libdb-dev

install: true

Expand Down
6 changes: 6 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -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).
Expand Down
3 changes: 3 additions & 0 deletions perl/bin/battenberg.pl
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion perl/lib/Sanger/CGP/Battenberg.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
18 changes: 9 additions & 9 deletions perl/lib/Sanger/CGP/Battenberg/Implement.pm
Original file line number Diff line number Diff line change
Expand Up @@ -239,29 +239,29 @@ 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;
if ($total_loci_remaining == $loci_per_file->{$file}) {
#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) {
Expand All @@ -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);
}
Expand Down

0 comments on commit 689962f

Please sign in to comment.