Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #280 from teharrison/develop

fixed divide by error for some edgae case metagenomes
  • Loading branch information...
commit 89c12dafdacbc48981fdc331dce8e0e8f1137796 2 parents c4c9e46 + e5f881b
@teharrison teharrison authored
View
16 src/MGRAST/lib/WebPage/MetagenomeOverview.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);
View
18 src/MGRAST/lib/resources2/metagenome_statistics.pm
@@ -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;
Please sign in to comment.
Something went wrong with that request. Please try again.