From 2151b2cc10c1b98d9a1effbdea8c3ecb549ed67d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20Kusalananda=20K=C3=A4h=C3=A4ri?= <ak4@sanger.ac.uk> Date: Mon, 24 Oct 2011 13:19:07 +0000 Subject: [PATCH] In equals(): Reorder so that the defined() test is first. Reformat. --- modules/Bio/EnsEMBL/Exon.pm | 13 ++++++------ modules/Bio/EnsEMBL/Feature.pm | 33 ++++++++++++------------------- modules/Bio/EnsEMBL/Gene.pm | 17 +++++++--------- modules/Bio/EnsEMBL/Transcript.pm | 17 ++++++++-------- 4 files changed, 36 insertions(+), 44 deletions(-) diff --git a/modules/Bio/EnsEMBL/Exon.pm b/modules/Bio/EnsEMBL/Exon.pm index 425a1d683e..b1a2e309df 100755 --- a/modules/Bio/EnsEMBL/Exon.pm +++ b/modules/Bio/EnsEMBL/Exon.pm @@ -848,8 +848,8 @@ sub slice { sub equals { my ( $self, $exon ) = @_; + if ( !defined($exon) ) { return 0 } if ( $self eq $exon ) { return 1 } - if ( ! defined $exon ) { return 0 } assert_ref( $exon, 'Bio::EnsEMBL::Exon' ); @@ -862,15 +862,16 @@ sub equals { { if ( $self->stable_id() eq $exon->stable_id() ) { return 1; - } else { + } + else { return 0; } } - if ( $self->start() == $exon->start() - && $self->end() == $exon->end() - && $self->strand() == $exon->strand() - && $self->phase() == $exon->phase() ) + if ( $self->start() == $exon->start() && + $self->end() == $exon->end() && + $self->strand() == $exon->strand() && + $self->phase() == $exon->phase() ) { return 1; } diff --git a/modules/Bio/EnsEMBL/Feature.pm b/modules/Bio/EnsEMBL/Feature.pm index d78ef19842..c5c30a477c 100644 --- a/modules/Bio/EnsEMBL/Feature.pm +++ b/modules/Bio/EnsEMBL/Feature.pm @@ -438,12 +438,8 @@ sub equals { my ( $self, $feature ) = @_; # If the features are the same object, they are equal. - if ( $self eq $feature ) { - return 1; - } - if ( ! defined $feature ) { - return 0; - } + if ( !defined($feature) ) { return 0 } + if ( $self eq $feature ) { return 1 } assert_ref( $feature, 'Bio::EnsEMBL::Feature' ); @@ -454,12 +450,10 @@ sub equals { # If the features has the same dbID, they are equal. if ( defined( $self->dbID() ) && defined( $feature->dbID() ) ) { - if ( $self->dbID() == $feature->dbID() ) { - return 1; - } else { - return 0; - } + if ( $self->dbID() == $feature->dbID() ) { return 1 } + else { return 0 } } + # We now know that one of the features do not have a dbID. # If the features have the same start, end, strand and seq_region_id, @@ -468,19 +462,18 @@ sub equals { ( defined( $self->analysis() ) && defined( $feature->analysis() ) ) && ( defined( $self->slice() ) && defined( $feature->slice() ) ) ) { - if ( ( $self->start() == $feature->start() ) - && ( $self->end() == $feature->end() ) - && ( $self->strand() == $feature->strand() ) - && ( $self->slice()->get_seq_region_id() == - $feature->slice()->get_seq_region_id() ) - && ( $self->analysis()->dbID() == $feature->analysis()->dbID() ) - ) + if ( ( $self->start() == $feature->start() ) && + ( $self->end() == $feature->end() ) && + ( $self->strand() == $feature->strand() ) && + ( $self->slice()->get_seq_region_id() == + $feature->slice()->get_seq_region_id() ) && + ( $self->analysis()->dbID() == $feature->analysis()->dbID() ) ) { return 1; - } else { - return 0; } + else { return 0 } } + # We now know that one of the features does not have either analysis # or slice. diff --git a/modules/Bio/EnsEMBL/Gene.pm b/modules/Bio/EnsEMBL/Gene.pm index 9a1f6c8dad..722699032c 100755 --- a/modules/Bio/EnsEMBL/Gene.pm +++ b/modules/Bio/EnsEMBL/Gene.pm @@ -389,8 +389,8 @@ sub description { sub equals { my ( $self, $gene ) = @_; + if ( !defined($gene) ) { return 0 } if ( $self eq $gene ) { return 1 } - if ( ! defined $gene ) { return 0 } assert_ref( $gene, 'Bio::EnsEMBL::Gene' ); @@ -405,20 +405,17 @@ sub equals { if ( defined( $self->stable_id() ) && defined( $gene->stable_id() ) ) { - if ( $self->stable_id() eq $gene->stable_id() ) { - return 1; - } else { - return 0; - } + if ( $self->stable_id() eq $gene->stable_id() ) { return 1 } + else { return 0 } } my @self_transcripts = sort { - $a->start() <=> $b->start() - || $a->length() <=> $b->length() + $a->start() <=> $b->start() || + $a->length() <=> $b->length() } @{ $self->get_all_Transcripts() }; my @gene_transcripts = sort { - $a->start() <=> $b->start() - || $a->length() <=> $b->length() + $a->start() <=> $b->start() || + $a->length() <=> $b->length() } @{ $gene->get_all_Transcripts() }; if ( scalar(@self_transcripts) != scalar(@gene_transcripts) ) { diff --git a/modules/Bio/EnsEMBL/Transcript.pm b/modules/Bio/EnsEMBL/Transcript.pm index 2f395532de..2613bc3f2d 100755 --- a/modules/Bio/EnsEMBL/Transcript.pm +++ b/modules/Bio/EnsEMBL/Transcript.pm @@ -2091,7 +2091,7 @@ sub swap_exons { sub equals { my ( $self, $transcript ) = @_; - if ( ! defined $transcript ) { return 0 } + if ( !defined($transcript) ) { return 0 } if ( $self eq $transcript ) { return 1 } assert_ref( $transcript, 'Bio::EnsEMBL::Transcript' ); @@ -2105,23 +2105,24 @@ sub equals { return 0; } - if ( defined( $self->stable_id() ) - && defined( $transcript->stable_id() ) ) + if ( defined( $self->stable_id() ) && + defined( $transcript->stable_id() ) ) { if ( $self->stable_id() eq $transcript->stable_id() ) { return 1; - } else { + } + else { return 0; } } my @self_exons = sort { - $a->start() <=> $b->start() - || $a->length() <=> $b->length() + $a->start() <=> $b->start() || + $a->length() <=> $b->length() } @{ $self->get_all_Exons() }; my @transcript_exons = sort { - $a->start() <=> $b->start() - || $a->length() <=> $b->length() + $a->start() <=> $b->start() || + $a->length() <=> $b->length() } @{ $transcript->get_all_Exons() }; if ( scalar(@self_exons) != scalar(@transcript_exons) ) { -- GitLab