[Bioperl-guts-l] [15017] bioperl-live/trunk: [bug 2630]
Christopher John Fields
cjfields at dev.open-bio.org
Tue Nov 25 10:40:08 EST 2008
Revision: 15017
Author: cjfields
Date: 2008-11-25 10:40:07 -0500 (Tue, 25 Nov 2008)
Log Message:
-----------
[bug 2630]
* more LocatableSeq tweaks.
* no_gaps() reverted (was not counting gaps accurately)
* notes (and TODO tests) about issues with using globals variables and LocatableSeq; will fix in 1.7
Modified Paths:
--------------
bioperl-live/trunk/Bio/LocatableSeq.pm
bioperl-live/trunk/t/LocatableSeq.t
Modified: bioperl-live/trunk/Bio/LocatableSeq.pm
===================================================================
--- bioperl-live/trunk/Bio/LocatableSeq.pm 2008-11-24 05:46:14 UTC (rev 15016)
+++ bioperl-live/trunk/Bio/LocatableSeq.pm 2008-11-25 15:40:07 UTC (rev 15017)
@@ -89,15 +89,18 @@
use Bio::Location::Simple;
use Bio::Location::Fuzzy;
-use vars qw($GAP_SYMBOLS $OTHER_SYMBOLS $FRAMESHIFT_SYMBOLS $MATCHPATTERN);
+use vars qw($GAP_SYMBOLS $OTHER_SYMBOLS $FRAMESHIFT_SYMBOLS $RESIDUE_SYMBOLS $MATCHPATTERN);
-# should we change these to non-globals? (I can see this
-# causing problems down the road...) - cjfields
+# The following global variables contain symbols used to represent gaps,
+# frameshifts, residues, and other valid symbols. These are set at compile-time;
+# expect scoping errors when using 'local' and resetting $MATCHPATTERN (see
+# LocatableSeq.t)
$GAP_SYMBOLS = '\-\.=~';
$FRAMESHIFT_SYMBOLS = '\\\/';
$OTHER_SYMBOLS = '\?';
-$MATCHPATTERN = '0-9A-Za-z\*'.$GAP_SYMBOLS.$FRAMESHIFT_SYMBOLS.$OTHER_SYMBOLS;
+$RESIDUE_SYMBOLS = '0-9A-Za-z\*';
+$MATCHPATTERN = $RESIDUE_SYMBOLS.$GAP_SYMBOLS.$FRAMESHIFT_SYMBOLS.$OTHER_SYMBOLS;
use base qw(Bio::PrimarySeq Bio::RangeI);
@@ -167,7 +170,7 @@
if ($self->seq && $st != 0 ) {
my $len = $self->_ungapped_len;
my $calend = $st + $len - 1;
- my $id = $self->id;
+ my $id = $self->id || 'unknown';
if ($calend != $value) {
$self->warn("In sequence $id residue count gives end value ".
"$calend. \nOverriding value [$value] with value $calend for ".
@@ -322,14 +325,16 @@
$char ||= $GAP_SYMBOLS;
$self->warn("I hope you know what you are doing setting gap to [$char]")
- unless $char =~ /[-.]/;
+ unless $char =~ /[$GAP_SYMBOLS]/;
$seq = $self->seq;
return 0 unless $seq; # empty sequence does not have gaps
$seq =~ s/^([$char]+)//;
$seq =~ s/([$char]+)$//;
- $count = scalar( $seq =~ /[$char]+/g );
+ while ( $seq =~ /[$char]+/g ) {
+ $count++;
+ }
return $count;
}
@@ -553,7 +558,6 @@
0 otherwise.
Args : The sequence string to be validated.
-
=cut
sub validate_seq {
Modified: bioperl-live/trunk/t/LocatableSeq.t
===================================================================
--- bioperl-live/trunk/t/LocatableSeq.t 2008-11-24 05:46:14 UTC (rev 15016)
+++ bioperl-live/trunk/t/LocatableSeq.t 2008-11-25 15:40:07 UTC (rev 15017)
@@ -7,7 +7,7 @@
use lib 't/lib';
use BioperlTest;
- test_begin(-tests => 100);
+ test_begin(-tests => 112);
use_ok('Bio::LocatableSeq');
use_ok('Bio::AlignIO');
@@ -226,4 +226,55 @@
$seq->verbose(2);
eval { $seq->end(554);};
ok $@;
-like $@, qr/Overriding value \[554\] with value 552/;
\ No newline at end of file
+like $@, qr/Overriding value \[554\] with value 552/;
+
+# setting symbols (class variables) - demonstrate scoping issues when using
+# globals with and w/o localization. To be fixed in a future BioPerl version
+
+my $temp;
+
+{
+ $temp = $Bio::LocatableSeq::GAP_SYMBOLS;
+ $Bio::LocatableSeq::GAP_SYMBOLS = '-\?';
+ $seq = Bio::LocatableSeq->new(
+ -seq => '??atg-?-gta-?',
+ -strand => 1,
+ -start => 10,
+ -end => 15,
+ -alphabet => 'dna',
+ );
+ is $Bio::LocatableSeq::GAP_SYMBOLS, '-\?';
+ is $seq->start, 10;
+ is $seq->end, 15;
+}
+
+is $Bio::LocatableSeq::GAP_SYMBOLS, '-\?';
+is $seq->end(15), 15;
+$Bio::LocatableSeq::GAP_SYMBOLS = $temp;
+is $Bio::LocatableSeq::GAP_SYMBOLS, '\-\.=~';
+
+{
+ local $Bio::LocatableSeq::GAP_SYMBOLS = '-\?';
+ $seq = Bio::LocatableSeq->new(
+ -seq => '??atg-?-gta-?',
+ -strand => 1,
+ -start => 10,
+ -end => 15,
+ -alphabet => 'dna',
+ );
+ is $Bio::LocatableSeq::GAP_SYMBOLS, '-\?';
+ is $seq->start, 10;
+ is $seq->end, 15;
+}
+
+is $seq->end, 15;
+
+# note, recalling the end() method uses old $GAP_SYMBOLS, which
+# no longer are set (this argues for locally set symbols)
+TODO: {
+ local $TODO = 'Bio::LocatableSeq global variables have scoping issues';
+ is $Bio::LocatableSeq::GAP_SYMBOLS, '-\?';
+ # thsi should be 15
+ isnt $seq->end(19), 19;
+}
+
More information about the Bioperl-guts-l
mailing list