[Bioperl-l] How to trap warnings when one doesn't have access to the object?

CALLEY_JOHN_N@Lilly.com CALLEY_JOHN_N@Lilly.com
Mon, 11 Nov 2002 07:53:44 -0500


Hi,
   I'm using the following code from a CGI (bioperl 1.0.2)

   $str_fh = new IO::String($obj->{alignment});
   $str = Bio::AlignIO->new (-fh => $str_fh, -format => 'fasta');
   my $aln = $str->next_aln();

Unfortunately, this sometimes results in a warning that messes up the CGI. 
The warning is generated by a 
call to $self->warn from Bio::SimpleAlign->add_seq() that is called from 
within Bio::AlignIO::fasta->next_aln().
I need to trap this warning. I could do this by setting the verbosity of 
the SimpleAlign object to -1, except that this
object is created within the AlignIO object's next_aln method, so I have 
no access to it until the damage has been
done. I am reduced, I think, to having to do something really nasty like:

   $str_fh = new IO::String($obj->{alignment});
   $str = Bio::AlignIO->new (-fh => $str_fh, -format => 'fasta');
   open SAVEERR, ">&STDERR";
   open STDERR, "/dev/null";
   my $aln = $str->next_aln();
   open STDERR, ">&SAVEERR";

Any better ideas?

John Calley