[Bioperl-l] Detecting type of an object.

Peter van Heusden pvh@egenetics.com
Thu, 12 Oct 2000 11:23:28 +0200 (SAST)

On Thu, 12 Oct 2000, gert thijs wrote:

> I am wondering if it is possible to detect the type of an object. 
> For instance, I have written a module that parses a blast report to select a
> sequence. The module returns the sequence as a Bio::Seq object if the parsing
> was succesful and some error message when there was no good hit found.
> Now when I use this module in a script I would like to test whether or not
> there is a sequence found before doing something with the sequence. Is there a
> proper way to tackle such a problem?

You mean something like:

sub getmyseq {
  if ($got_hits) {
    return $seq;
  else {
    return "OOPS! error!";

$ret = getmyseq();

then to test if $ret is a sequence:

if (ref($ret) and $ret->isa(Bio::SeqI)) {
   # do something with sequence
} else {
   print STDERR "Error!: $ret\n";

Peter van Heusden				pvh@egenetics.com
Electric Genetics