Permalink
Browse files

fixed divide by error for some edgae case metagenomes

  • Loading branch information...
1 parent 412a285 commit 6bbcd2c8167a6c673fb92634777c6c7a3184ef44 Travis Harrison committed Apr 8, 2013
Showing with 25 additions and 9 deletions.
  1. +12 −4 src/MGRAST/lib/WebPage/MetagenomeOverview.pm
  2. +13 −5 src/MGRAST/lib/resources2/metagenome_statistics.pm
@@ -1345,8 +1345,12 @@ sub get_drisee_chart {
my $x = shift @$row;
next if (($x eq '#') || (int($x) < 51));
my $sum = sum @$row;
- my @per = map { sprintf("%.2f", 100 * (($_ * 1.0) / $sum)) } @$row;
- push @$data, [ $x, @per[6..11], sum(@per[6..11]) ];
+ if ($sum == 0) {
+ push @$data, [ $x, 0, 0, 0, 0, 0, 0, 0 ];
+ } else {
+ my @per = map { sprintf("%.2f", 100 * (($_ * 1.0) / $sum)) } @$row;
+ push @$data, [ $x, @per[6..11], sprintf("%.2f", sum(@per[6..11])) * 1.0 ];
+ }
}
my @down_data = @$data;
unshift @down_data, ['Position','A','T','C','G','N','InDel','Total'];
@@ -1454,8 +1458,12 @@ sub get_consensus_chart {
next if (($row->[0] eq '#') || (! $row->[6]));
next if (($row->[0] > 100) && ($row->[6] < 1000));
my $sum = $row->[6];
- my @per = map { floor(100 * 100 * (($_ * 1.0) / $sum)) / 100 } @$row;
- push @$data, [ $row->[0] + 1, $per[5], $per[3], $per[2], $per[4], $per[1] ];
+ if ($sum == 0) {
+ push @$data, [ $row->[0] + 1, 0, 0, 0, 0, 0 ];
+ } else {
+ my @per = map { floor(100 * 100 * (($_ * 1.0) / $sum)) / 100 } @$row;
+ push @$data, [ $row->[0] + 1, $per[5], $per[3], $per[2], $per[4], $per[1] ];
+ }
}
my $consensus_link = $self->chart_export_link($data, 'consensus_plot');
my $consensus_rows = join(",\n", map { "[".join(',', @$_)."]" } @$data);
@@ -206,9 +206,13 @@ sub get_drisee {
if ($row->[0] > 50) {
my $x = shift @$row;
my $sum = sum @$row;
- my @tmp = map { sprintf("%.2f", 100 * (($_ * 1.0) / $sum)) * 1.0 } @$row;
- push @$per, [ $x, @tmp[6..11], sprintf("%.2f", sum(@tmp[6..11])) * 1.0 ];
- }
+ if ($sum == 0) {
+ push @$per, [ $x, 0, 0, 0, 0, 0, 0, 0 ];
+ } else {
+ my @tmp = map { sprintf("%.2f", 100 * (($_ * 1.0) / $sum)) * 1.0 } @$row;
+ push @$per, [ $x, @tmp[6..11], sprintf("%.2f", sum(@tmp[6..11])) * 1.0 ];
+ }
+ }
}
$data->{counts}{data} = $raw;
$data->{percents}{data} = $per;
@@ -234,8 +238,12 @@ sub get_nucleo {
push @$raw, [ $row->[0] + 1, $row->[1], $row->[4], $row->[2], $row->[3], $row->[5], $row->[6] ];
unless (($row->[0] > 100) && ($row->[6] < 1000)) {
my $sum = $row->[6];
- my @tmp = map { floor(100 * 100 * (($_ * 1.0) / $sum)) / 100 } @$row;
- push @$per, [ $row->[0] + 1, $tmp[1], $tmp[4], $tmp[2], $tmp[3], $tmp[5] ];
+ if ($sum == 0) {
+ push @$per, [ $row->[0] + 1, 0, 0, 0, 0, 0 ];
+ } else {
+ my @tmp = map { floor(100 * 100 * (($_ * 1.0) / $sum)) / 100 } @$row;
+ push @$per, [ $row->[0] + 1, $tmp[1], $tmp[4], $tmp[2], $tmp[3], $tmp[5] ];
+ }
}
}
$data->{counts}{data} = $raw;

0 comments on commit 6bbcd2c

Please sign in to comment.