From c3803bcf6bc7f1e5e39db4f669624d40bb0b97aa Mon Sep 17 00:00:00 2001 From: Daniel Rios <dr2@sanger.ac.uk> Date: Wed, 29 Oct 2008 11:10:20 +0000 Subject: [PATCH] modified to include new_fast method to allow fast creation of objects within the adaptors --- modules/Bio/EnsEMBL/Exon.pm | 58 +++++++++++++++--------------- modules/Bio/EnsEMBL/Feature.pm | 25 ++++++++++--- modules/Bio/EnsEMBL/Gene.pm | 25 +++++++------ modules/Bio/EnsEMBL/Transcript.pm | 22 ++++++------ modules/Bio/EnsEMBL/Translation.pm | 26 +++++++++++--- 5 files changed, 94 insertions(+), 62 deletions(-) diff --git a/modules/Bio/EnsEMBL/Exon.pm b/modules/Bio/EnsEMBL/Exon.pm index 607c711422..8034877cb9 100755 --- a/modules/Bio/EnsEMBL/Exon.pm +++ b/modules/Bio/EnsEMBL/Exon.pm @@ -103,11 +103,11 @@ sub new { my $self = $class->SUPER::new( @_ ); + my ( $phase, $end_phase, $stable_id, $version, $created_date, $modified_date, - $is_current ) = - rearrange( [ "PHASE", "END_PHASE", "STABLE_ID", "VERSION", + $is_current ) = + rearrange( [ "PHASE", "END_PHASE", "STABLE_ID", "VERSION", "CREATED_DATE", "MODIFIED_DATE", "IS_CURRENT" ], @_ ); - $self->phase($phase) if (defined $phase); # make sure phase is valid. $self->{'end_phase'} = $end_phase; $self->{'stable_id'} = $stable_id; @@ -123,40 +123,40 @@ sub new { } -=head2 new_fast +# =head2 new_fast - Arg [1] : Bio::EnsEMBL::Slice $slice - Arg [2] : int $start - Arg [3] : int $end - Arg [4] : int $strand (1 or -1) - Example : none - Description: create an Exon object - Returntype : Bio::EnsEMBL::Exon - Exceptions : throws if end < start - Caller : general, creation in Bio::EnsEMBL::Lite::GeneAdaptor - Status : Stable +# Arg [1] : Bio::EnsEMBL::Slice $slice +# Arg [2] : int $start +# Arg [3] : int $end +# Arg [4] : int $strand (1 or -1) +# Example : none +# Description: create an Exon object +# Returntype : Bio::EnsEMBL::Exon +# Exceptions : throws if end < start +# Caller : general, creation in Bio::EnsEMBL::Lite::GeneAdaptor +# Status : Stable -=cut +# =cut -sub new_fast { - my ($class, $slice, $start, $end, $strand) = @_; +# sub new_fast { +# my ($class, $slice, $start, $end, $strand) = @_; - my $self = bless {}, $class; +# my $self = bless {}, $class; - # Swap start and end if they're in the wrong order - # We assume that the strand is correct and keep the input value. +# # Swap start and end if they're in the wrong order +# # We assume that the strand is correct and keep the input value. - if ($start > $end) { - throw( "End smaller than start not allowed" ); - } +# if ($start > $end) { +# throw( "End smaller than start not allowed" ); +# } - $self->start ($start); - $self->end ($end); - $self->strand($strand); - $self->slice($slice); +# $self->start ($start); +# $self->end ($end); +# $self->strand($strand); +# $self->slice($slice); - return $self; -} +# return $self; +# } =head2 end_phase diff --git a/modules/Bio/EnsEMBL/Feature.pm b/modules/Bio/EnsEMBL/Feature.pm index a571499391..700ee05582 100644 --- a/modules/Bio/EnsEMBL/Feature.pm +++ b/modules/Bio/EnsEMBL/Feature.pm @@ -99,11 +99,9 @@ sub new { my $caller = shift; my $class = ref($caller) || $caller; - - my($start, $end, $strand, $slice, $analysis,$seqname, $dbID, $adaptor) = - rearrange(['START','END','STRAND','SLICE','ANALYSIS', 'SEQNAME', - 'DBID', 'ADAPTOR'], @_); - + my ( $start, $end, $strand, $slice, $analysis,$seqname, $dbID, $adaptor ) = + rearrange(['START','END','STRAND','SLICE','ANALYSIS', 'SEQNAME', + 'DBID', 'ADAPTOR'], @_); if($slice) { if(!ref($slice) || !$slice->isa('Bio::EnsEMBL::Slice')) { throw('-SLICE argument must be a Bio::EnsEMBL::Slice not '.$slice); @@ -140,6 +138,23 @@ sub new { } +=head2 new_fast + + Arg [1] : hashref to be blessed + Description: Construct a new Bio::EnsEMBL::Feature using the hashref. + Exceptions : none + Returntype : Bio::EnsEMBL::Feature + Caller : general, subclass constructors + Status : Stable + +=cut + + +sub new_fast { + my $class = shift; + my $hashref = shift; + return bless $hashref, $class; +} =head2 start diff --git a/modules/Bio/EnsEMBL/Gene.pm b/modules/Bio/EnsEMBL/Gene.pm index 23297ba7f8..3cada903db 100755 --- a/modules/Bio/EnsEMBL/Gene.pm +++ b/modules/Bio/EnsEMBL/Gene.pm @@ -106,19 +106,18 @@ sub new { my $class = ref($caller) || $caller; my $self = $class->SUPER::new(@_); - my ( $stable_id, $version, $external_name, $type, $external_db, - $external_status, $display_xref, $description, $transcripts, - $created_date, $modified_date, $confidence, $biotype, $source, - $status, $is_current, $canonical_transcript, $canonical_annotation ) = - rearrange( [ 'STABLE_ID', 'VERSION', 'EXTERNAL_NAME', 'TYPE', - 'EXTERNAL_DB', 'EXTERNAL_STATUS', 'DISPLAY_XREF', - 'DESCRIPTION', - 'TRANSCRIPTS', 'CREATED_DATE', 'MODIFIED_DATE', - 'CONFIDENCE', 'BIOTYPE', 'SOURCE', 'STATUS', 'IS_CURRENT', - 'CANONICAL_TRANSCRIPT', 'CANONICAL_ANNOTATION' - ], - @_ ); + $external_status, $display_xref, $description, $transcripts, + $created_date, $modified_date, $confidence, $biotype, $source, + $status, $is_current, $canonical_transcript, $canonical_annotation ) = + rearrange( [ 'STABLE_ID', 'VERSION', 'EXTERNAL_NAME', 'TYPE', + 'EXTERNAL_DB', 'EXTERNAL_STATUS', 'DISPLAY_XREF', + 'DESCRIPTION', + 'TRANSCRIPTS', 'CREATED_DATE', 'MODIFIED_DATE', + 'CONFIDENCE', 'BIOTYPE', 'SOURCE', 'STATUS', 'IS_CURRENT', + 'CANONICAL_TRANSCRIPT', 'CANONICAL_ANNOTATION' + ], + @_ ); if ($transcripts) { $self->{'_transcript_array'} = $transcripts; @@ -187,7 +186,7 @@ sub external_name { $self->{'external_name'} = shift if (@_); - if (exists $self->{'external_name'}) { + if (defined $self->{'external_name'}) { return $self->{'external_name'}; } diff --git a/modules/Bio/EnsEMBL/Transcript.pm b/modules/Bio/EnsEMBL/Transcript.pm index e65faf69e0..838da3fb17 100755 --- a/modules/Bio/EnsEMBL/Transcript.pm +++ b/modules/Bio/EnsEMBL/Transcript.pm @@ -119,19 +119,19 @@ sub new { deprecate("Transcript constructor should use named arguments.\n" . 'Use Bio::EnsEMBL::Transcript->new(-EXONS => \@exons);' . "\ninstead of Bio::EnsEMBL::Transcript->new(\@exons);"); - } +} else { - ( $exons, $stable_id, $version, $external_name, $external_db, - $external_status, $display_xref, $created_date, $modified_date, - $description, $biotype, $confidence, $external_db_name, $status, - $is_current ) = - rearrange( [ "EXONS", 'STABLE_ID', 'VERSION', 'EXTERNAL_NAME', - 'EXTERNAL_DB', 'EXTERNAL_STATUS', 'DISPLAY_XREF', - 'CREATED_DATE', 'MODIFIED_DATE', 'DESCRIPTION', - 'BIOTYPE', 'CONFIDENCE', 'EXTERNAL_DB_NAME', 'STATUS', - 'IS_CURRENT' ], @_ ); + ( $exons, $stable_id, $version, $external_name, $external_db, + $external_status, $display_xref, $created_date, $modified_date, + $description, $biotype, $confidence, $external_db_name, $status, + $is_current ) = + rearrange( [ "EXONS", 'STABLE_ID', 'VERSION', 'EXTERNAL_NAME', + 'EXTERNAL_DB', 'EXTERNAL_STATUS', 'DISPLAY_XREF', + 'CREATED_DATE', 'MODIFIED_DATE', 'DESCRIPTION', + 'BIOTYPE', 'CONFIDENCE', 'EXTERNAL_DB_NAME', 'STATUS', + 'IS_CURRENT' ], @_ ); } - + if( $exons ) { $self->{'_trans_exon_array'} = $exons; $self->recalculate_coordinates(); diff --git a/modules/Bio/EnsEMBL/Translation.pm b/modules/Bio/EnsEMBL/Translation.pm index 08a9ba375e..ee3a43cef1 100755 --- a/modules/Bio/EnsEMBL/Translation.pm +++ b/modules/Bio/EnsEMBL/Translation.pm @@ -91,10 +91,10 @@ sub new { my ( $start_exon, $end_exon, $seq_start, $seq_end, $stable_id, $version, $dbID, $adaptor, $seq, - $created_date, $modified_date ) = - rearrange( [ "START_EXON", "END_EXON", "SEQ_START", "SEQ_END", - "STABLE_ID", "VERSION", "DBID", "ADAPTOR", - "SEQ", "CREATED_DATE", "MODIFIED_DATE" ], @_ ); + $created_date, $modified_date ) = + rearrange( [ "START_EXON", "END_EXON", "SEQ_START", "SEQ_END", + "STABLE_ID", "VERSION", "DBID", "ADAPTOR", + "SEQ", "CREATED_DATE", "MODIFIED_DATE" ], @_ ); my $self = bless { 'start_exon' => $start_exon, @@ -113,6 +113,24 @@ sub new { return $self; } +=head2 new_fast + + Arg [1] : hashref to be blessed + Description: Construct a new Bio::EnsEMBL::Translation using the hashref. + Exceptions : none + Returntype : Bio::EnsEMBL::Translation + Caller : general, subclass constructors + Status : Stable + +=cut + + +sub new_fast { + my $class = shift; + my $hashref = shift; + return bless $hashref, $class; +} + =head2 start -- GitLab