Commit ba568ca2 authored by Magali Ruffier's avatar Magali Ruffier
Browse files

using array reference rather than an array

parent b64d1356
......@@ -9,25 +9,27 @@ use base qw/Bio::EnsEMBL::Pipeline::Production::StatsGenerator/;
sub get_attrib_codes {
my ($self) = @_;
my @attrib_codes = ('coding_cnt', 'pseudogene_cnt', 'noncoding_cnt');
return @attrib_codes;
my %biotypes;
foreach my $code (@attrib_codes) {
my ($group) = $code =~ /(\w+)\_cnt/;
my $biotypes = $self->get_biotype_group($group);
$biotypes{$code} = $biotypes;
}
return %biotypes;
}
sub get_total {
my ($self) = @_;
my $species = $self->param('species');
my $total = scalar(@{ Bio::EnsEMBL::Registry->get_adaptor($species, 'core', 'gene')->fetch_all });
return $total;
}
sub get_feature_count {
my ($self, $slice, $key) = @_;
my $prod_dba = $self->get_production_DBAdaptor();
my $prod_helper = $prod_dba->dbc()->sql_helper();
my ($group) = $key =~ /(\w+)\_cnt/;
my $sql = q{
SELECT name
FROM biotype
WHERE biotype_group = ?
AND object_type = 'gene'
AND is_current = 1
AND db_type like '%core%' };
my @biotypes = @{ $prod_helper->execute_simple(-SQL => $sql, -PARAMS => [$group]) };
my ($self, $slice, $key, $biotypes) = @_;
my $count = 0;
foreach my $biotype (@biotypes) {
foreach my $biotype (@$biotypes) {
$count += scalar(@{ $slice->get_all_Genes_by_type($biotype) });
}
return $count;
......
......@@ -13,23 +13,27 @@ sub run {
my $species = $self->param('species');
my $dba = Bio::EnsEMBL::Registry->get_DBAdaptor($species, 'core');
my @attrib_codes = $self->get_attrib_codes();
$self->delete_old_attrib($dba, @attrib_codes);
my %attrib_codes = $self->get_attrib_codes();
$self->delete_old_attrib($dba, %attrib_codes);
my $total = $self->get_total();
my $sum = 0;
my $slices = Bio::EnsEMBL::Registry->get_adaptor($species, 'core', 'slice')->fetch_all('toplevel');
while (my $slice = shift @$slices) {
foreach my $code (@attrib_codes) {
my $count = $self->get_feature_count($slice, $code);
if ($count > 0) {
$self->store_attrib($slice, $count, $code);
}
foreach my $code (keys %attrib_codes) {
my $count = $self->get_feature_count($slice, $code, $attrib_codes{$code});
$self->store_attrib($slice, $count, $code);
$sum += $count;
}
if ($sum >= $total) {
last;
}
}
}
sub delete_old_attrib {
my ($self, $dba, @attrib_codes) = @_;
my ($self, $dba, %attrib_codes) = @_;
my $helper = $dba->dbc()->sql_helper();
my $sql = q{
DELETE sa
......@@ -39,7 +43,7 @@ sub delete_old_attrib {
AND at.attrib_type_id = sa.attrib_type_id
AND cs.species_id = ?
AND at.code = ? };
foreach my $code (@attrib_codes) {
foreach my $code (keys %attrib_codes) {
$helper->execute_update(-SQL => $sql, -PARAMS => [$dba->species_id(), $code]);
}
}
......@@ -77,6 +81,22 @@ sub store_attrib {
$aa->store_on_Slice($slice, \@attribs);
}
sub get_biotype_group {
my ($self, $biotype) = @_;
my $prod_dba = $self->get_production_DBAdaptor();
my $helper = $prod_dba->dbc()->sql_helper();
my $sql = q{
SELECT name
FROM biotype
WHERE object_type = 'gene'
AND is_current = 1
AND biotype_group = ?
AND db_type like '%core%' };
my @biotypes = @{ $helper->execute_simple(-SQL => $sql, -PARAMS => [$biotype]) };
return \@biotypes;
}
1;
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment