[Bioperl-l] Bio::SeqIO modifies $_

Carnë Draug carandraug+dev at gmail.com
Tue Jan 28 18:00:25 UTC 2014


Hi

I was under the impression that we had changed to use the builtin bug
tracker of github but for some reason, I can't do it, so I'm reporting
it here.

Consider the following very simple example:

use Bio::SeqIO;
my @files = ("NP_001136062.gb", "NP_001137300.gb");
my @seqs = map {Bio::SeqIO->new(-file => $_)->next_seq;} @files;

or the more canonical

foreach (@files) {
  my $seq = Bio::SeqIO->new(-file => $_)->next_seq;
}

This very simple snippet modifies @files. Following this, each element
of @lines becomes the string "//\n"

Stepping through the code with the debugger (and a lot of help from
the people at #perl), one finds that this is because there's an
assignment to $_ in many places of BioPerl. The first one is in
Bio::SeqIO::_guess_format [1]. Fixing it in this place is very easy
but I soon found out that this happens in multiple places. From the
example above, the debugger finds that this happens multiple times in:

Bio::Root::IO::_readline
Bio::SeqIO::genbank::_read_GenBank_References
Bio::SeqIO::genbank::next_seq
Bio::SeqIO::genbank::_read_FTHelper_GenBank

Note that simply doing "my $_" will not work in all places [2] and is
not recommended [3].

Carnë

[1] https://github.com/bioperl/bioperl-live/blob/ee6a77761340db12c747ab8cde387e958e5f8a0f/Bio/SeqIO.pm#L680
[2] https://github.com/bioperl/bioperl-live/blob/ee6a77761340db12c747ab8cde387e958e5f8a0f/Bio/SeqIO/genbank.pm#L838
[3] http://search.cpan.org/dist/perl-5.18.0/pod/perldelta.pod#Lexical_$__is_now_experimental




More information about the Bioperl-l mailing list