[Bioperl-l] Automatic typing in Annotation::Collection

Charles Tilford charles.tilford@bms.com
Tue, 28 May 2002 17:53:32 -0400


Any objections to modifying Bio::Annotation::Collection so that the 
"common" annotation types can be passed on their own, and the code 
figure out the key value from them? Aside from allowing the user to be a 
little lazier, I think it would also help guarantee standardization of 
the hash keys in Collection - that is, if Collection.pm knew that DBLink 
objects should be put under the "dblink" key, I would not have to worry 
about such entries accidentally going to "DBlink" or "db_link" keys.

The modification I was thinking of would look something like this:

sub add_Annotation{
   my ($self,$key,$object,$archytype) = @_;
  
   if( !defined $object ) {
       # Check to see if the user passed a single object of known type:
       if (my $ref = ref($key)) {
       $object = $key;
       if ($ref eq "Bio::Annotation::Comment") {
           $key = "comment";
       } elsif ($ref eq "Bio::Annotation::DBLink") {
           $key = "dblink";
       } elsif ($ref eq "Bio::Annotation::Reference") {
           $key = "reference";
       } else {
           $object = undef;
           $self->throw("Must have at least key and object in 
add_Annotation - I was unsure how to classify the '$ref' object you 
provided.")
       }
       }
       $self->throw("Must have at least key and object in add_Annotation")
       if( !defined $object );
   }

-Charles