From 2dc28bec455a5f65c64c57cd5325477ce4a89e61 Mon Sep 17 00:00:00 2001 From: Monika Komorowska <mk8@sanger.ac.uk> Date: Wed, 6 Jun 2012 10:47:40 +0000 Subject: [PATCH] added percentgc density type to fetch_stats --- .../Bio/EnsEMBL/DBSQL/AssemblyInfoAdaptor.pm | 23 ++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/modules/Bio/EnsEMBL/DBSQL/AssemblyInfoAdaptor.pm b/modules/Bio/EnsEMBL/DBSQL/AssemblyInfoAdaptor.pm index c58d797b84..0837a2a403 100644 --- a/modules/Bio/EnsEMBL/DBSQL/AssemblyInfoAdaptor.pm +++ b/modules/Bio/EnsEMBL/DBSQL/AssemblyInfoAdaptor.pm @@ -141,7 +141,7 @@ sub fetch_info { =head2 fetch_stats Arg [1] : string $seq_region_name (optional) - The name of a toplevel seq_region for which statistics should be fetched + The name of the toplevel seq_region for which statistics should be fetched Description: Returns a hash Returntype : hash with assembly statistics name and value pairs @@ -174,7 +174,7 @@ sub fetch_stats { @slices = @{$sa->fetch_all('toplevel')}; } - my @density_types = qw(genedensity knowngenedensity snpdensity); + my @density_types = qw(genedensity knowngenedensity snpdensity percentgc); my @attrib_types = qw(GeneNo% SNPCount); @@ -182,6 +182,10 @@ sub fetch_stats { my $dfa = $self->db()->get_adaptor('DensityFeature'); + #used to calculate the average density value for density types represented as ratios + + my %density_ft_count = (); + foreach my $slice (@slices) { $assembly_stats{'Length (bps)'} += $slice->length(); @@ -189,9 +193,13 @@ sub fetch_stats { foreach my $density_type (@density_types) { my $density_features = $dfa->fetch_all_by_Slice($slice,$density_type); - + foreach my $density_feature (@$density_features) { + if ($density_feature->density_type()->value_type() eq 'ratio') { + $density_ft_count{$density_feature->density_type()->analysis()->display_label()} += 1; + } + $assembly_stats{$density_feature->density_type()->analysis()->display_label()} += $density_feature->density_value(); } } @@ -206,6 +214,15 @@ sub fetch_stats { } } + foreach my $density_analysis (keys %density_ft_count) { + + if ($density_ft_count{$density_analysis} > 1) { + $assembly_stats{$density_analysis} /= $density_ft_count{$density_analysis}; + $assembly_stats{$density_analysis} = sprintf "%.2f", $assembly_stats{$density_analysis}; + $assembly_stats{$density_analysis} .= '%'; + } + } + return \%assembly_stats; } -- GitLab