From 6d244bfff2c1537e0d0723217aae3bcaf6bfd3f7 Mon Sep 17 00:00:00 2001 From: Andrew Yates <ayates@ebi.ac.uk> Date: Fri, 23 Nov 2012 17:13:03 +0000 Subject: [PATCH] Bringing in summaries as hashes --- modules/Bio/EnsEMBL/MiscFeature.pm | 25 +++++++++++++++++++++++++ modules/Bio/EnsEMBL/SimpleFeature.pm | 22 ++++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/modules/Bio/EnsEMBL/MiscFeature.pm b/modules/Bio/EnsEMBL/MiscFeature.pm index 854f2d53f4..5b30f19b35 100644 --- a/modules/Bio/EnsEMBL/MiscFeature.pm +++ b/modules/Bio/EnsEMBL/MiscFeature.pm @@ -376,7 +376,32 @@ sub display_id { } } +=head2 summary_as_hash + Example : my $hash = $misc_feature->summary_as_hash(); + Description: Generates a HashRef compatible with GFFSerializer. Adds + all attribute key value pairs plus MiscSet codes and names + Returntype : Hash + Exceptions : none + Caller : general + Status : Stable + +=cut + +sub summary_as_hash { + my ($self) = @_; + my $hash = $self->SUPER::summary_as_hash(); + my $attributes = $self->get_all_Attributes(); + foreach my $attr (@{$attributes}) { + $hash->{$attr->name()} = $attr->value(); + } + my $misc_sets = $self->get_all_MiscSets(); + foreach my $set (@{$misc_sets}) { + push(@{$hash->{misc_set_code}},$set->code()); + push(@{$hash->{misc_set_name}},$set->name()); + } + return $hash; +} 1; diff --git a/modules/Bio/EnsEMBL/SimpleFeature.pm b/modules/Bio/EnsEMBL/SimpleFeature.pm index e0c0ce8b6a..f0beadebb8 100644 --- a/modules/Bio/EnsEMBL/SimpleFeature.pm +++ b/modules/Bio/EnsEMBL/SimpleFeature.pm @@ -162,5 +162,27 @@ sub score { return $self->{'score'}; } +=head2 summary_as_hash + + Example : my $hash = $simple_feature->summary_as_hash(); + Description: Generates a HashRef compatible with GFFSerializer. Adds + score, external_name and logic_name to the basic Feature + hash + Returntype : Hash + Exceptions : none + Caller : general + Status : Stable + +=cut + +sub summary_as_hash { + my ($self) = @_; + my $hash = $self->SUPER::summary_as_hash(); + $hash->{score} = $self->score() if $self->score(); + $hash->{'external_name'} = $self->display_label() if $self->display_label(); + $hash->{'logic_name'} = $self->analysis->logic_name(); + return $hash; +} + 1; -- GitLab