[Bioperl-l] How to trap warnings when one doesn't have access
to the object?
Jason Stajich
jason@cgt.mc.duke.edu
Mon, 11 Nov 2002 08:18:43 -0500 (EST)
On Mon, 11 Nov 2002 CALLEY_JOHN_N@Lilly.com wrote:
> 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:
>
eval {
$str_fh = new IO::String($obj->{alignment});
$str = Bio::AlignIO->new (-fh => $str_fh, -format => 'fasta');
my $aln = $str->next_aln();
};
if( $@ ) {
print "Got the error $@\n";
}
If you never want to see warnings pass in
-verbose => -1
to the AlignIO object when initializing.
> open SAVEERR, ">&STDERR";
> open STDERR, "/dev/null";
> my $aln = $str->next_aln();
> open STDERR, ">&SAVEERR";
>
> Any better ideas?
>
> John Calley
>
>
>
> _______________________________________________
> Bioperl-l mailing list
> Bioperl-l@bioperl.org
> http://bioperl.org/mailman/listinfo/bioperl-l
>
--
Jason Stajich
Duke University
jason at cgt.mc.duke.edu