Skip to content

Commit 4c0ec87

Browse files
committed
Fixed bugs with geometric mean and percentages not showing up on the module reports
1 parent b29ef9b commit 4c0ec87

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

FUNC-E.pl

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1347,7 +1347,8 @@ sub calculate_cluster_stats {
13471347

13481348
my $gid;
13491349
my @groups;
1350-
my $product;
1350+
my $product_geo;
1351+
my $product_score;
13511352
my $sum;
13521353
my $num_terms;
13531354
my %gstats;
@@ -1450,22 +1451,23 @@ sub calculate_cluster_stats {
14501451
# calculate the geometric mean and score of the cluster. For extremely
14511452
# small numbers we may get a rounding error. We'll use the Math::BigFloat
14521453
# module to overcome this problem
1453-
$product = Math::BigFloat->new("1"); # set to 1
1454-
$product->accuracy(64);
1454+
$product_geo = Math::BigFloat->new("1"); # set to 1
1455+
$product_score = Math::BigFloat->new("1"); # set to 1
1456+
$product_geo->accuracy(64);
1457+
$product_score->accuracy(64);
14551458
$sum = 0;
14561459
for $term (@{$gstats{$module}{$gid}{terms}}){
14571460
$type = $term_types->{$term};
1458-
$product = $product * $enriched->{$module}{$type}{$term};
1461+
$product_geo = $product_geo * $enriched->{$module}{$type}{$term};
1462+
$product_score = $product_score * $enriched->{$module}{$type}{$term};
14591463
$sum = $sum + $enriched->{$module}{$type}{$term};
14601464
}
14611465

14621466
# set the score for the cluster
14631467
$num_terms = scalar(@{$gstats{$module}{$gid}{terms}});
1464-
# $gstats{$module}{$gid}{geo} = $product ** (1/$num_terms); # geometric mean
1465-
$gstats{$module}{$gid}{geo} = $product->bpow(1/$num_terms); # geometric mean
1468+
$gstats{$module}{$gid}{geo} = $product_geo->bpow(1/$num_terms); # geometric mean
14661469
if($gstats{$module}{$gid}{geo} > 0){
1467-
# $gstats{$module}{$gid}{score} = -log10($gstats{$module}{$gid}{geo}); # the enrichment score
1468-
$gstats{$module}{$gid}{score} = - $gstats{$module}{$gid}{geo}->blog(10);
1470+
$gstats{$module}{$gid}{score} = $product_score->bpow(1/$num_terms)->blog(10); # geometric mean
14691471
}
14701472
$gstats{$module}{$gid}{mean} = $sum/$num_terms; # mean (average)
14711473
}
@@ -1558,7 +1560,7 @@ sub stats_reports {
15581560
print MOD_REPORT "num genes: " . scalar(@{$gstats->{$module}{$gid}{nodes}}) . "\t";
15591561
print MOD_REPORT "score: " . sprintf("%.4f", $gstats->{$module}{$gid}{score}) . "\t";
15601562
print MOD_REPORT "mean: " . sprintf("%.4f", $gstats->{$module}{$gid}{mean}) . "\t";
1561-
print MOD_REPORT "geo: " . sprintf("%.4f", $gstats->{$module}{$gid}{geo}) . "\n";
1563+
print MOD_REPORT "geo: " . sprintf("%.4e", $gstats->{$module}{$gid}{geo}) . "\n";
15621564
print MOD_REPORT "genes: " . join (", ", @{$gstats->{$module}{$gid}{nodes}}) ."\n";
15631565
for(@{$gstats->{$module}{$gid}{features}}){
15641566
print CLUSTER_LOCI "$module\tCluster$cluster_num\t$_\t$gstats->{$module}{$gid}{score}";
@@ -1586,7 +1588,8 @@ sub stats_reports {
15861588
}
15871589
print MOD_REPORT "Category\tTerm\tMod Count\tBg Count\t".
15881590
"Percentage\tFold Enrichment\tpvalue\tBonferroni".
1589-
"\tBenjamini\tFDR\n";
1591+
#"\tBenjamini\tFDR\n";
1592+
"\tBenjamini\n";
15901593

15911594
for($i =0; $i < scalar(@terms); $i++){
15921595
$term = $terms[$i];
@@ -1601,12 +1604,14 @@ sub stats_reports {
16011604
#"\t$gstats->{$module}{$gid}{PDC}".
16021605
#"\t$gstats->{$module}{$gid}{direct_connects_weights}\n";
16031606
};
1607+
$bg_count = $counts->{'Background'}{$type}{terms}{$term}{count};
1608+
$module_count = $counts->{$module}{$type}{terms}{$term}{count};
16041609
print CLUSTER_TERMS "\n";
16051610
print MOD_REPORT "$type\t";
16061611
print MOD_REPORT "$terms[$i]|"; # term
16071612
print MOD_REPORT "$terms->{$term}{def}\t"; # description
1608-
print MOD_REPORT "$counts->{$module}{$type}{terms}{$term}{count}\t"; # count
1609-
print MOD_REPORT "$counts->{'Background'}{$type}{terms}{$term}{count}\t";
1613+
print MOD_REPORT "$module_count\t";
1614+
print MOD_REPORT "$bg_count\t";
16101615
if($bg_count){
16111616
print MOD_REPORT (($module_count/$bg_count) * 100). "\t"; # %
16121617
} else {

0 commit comments

Comments
 (0)