[Bioperl-l] Comment Objects vs. Comment Strings

Charles Tilford charles.tilford at bms.com
Mon Jun 14 17:07:55 EDT 2004


Hi Hafiz,

Your problems appear to be happening because of ambiguity in the content 
of DBLink comments. Technically (according to the DBLink module 
documentation), the comment() method for Annotation::DBLink should take 
a Bio::Annotation::Comment *object* as the argument. However, the 
comment() method does not verify that the passed value is in fact an 
object - you could pass it anything, including a simple string, and it 
would be happy. This is what SeqIO::swiss does when reading in a 
sequence in next_seq:

# edit comment to get rid of leading space and trailing dot
if( $comment =~ /^\s*(\S+)\./ ) {
   $dblinkobj->comment($1);
} else {
   $dblinkobj->comment($comment);
}

... that is, the SeqIO module that reads Swiss-Prot files stores DBLink 
comments as strings, rather than Bio::Annotation::Comment objects. I 
assumed in bsml.pm that the returned value would be a Comment object, 
and attempt to call a text() method on the returned value, which is 
croaking when it gets an unblessed string.

I'm curious what the community's thoughts on this problem are... I can 
see several ways to fix this:

1) Modules such as bsml.pm tread warily, and rather than *assuming* that 
a method call returns an object, it tests (coarsely in the example 
below) to see if it is:

my $com = $dblinkobject->comment;
$com = $com->text if (ref($com));

The downside is additional overhead on modules that make calls to 
methods like comment().

2) Modules such as DBLink.pm insist that they be given blessed objects 
with isa().

Downside is the moving of object verification overhead into *these* 
modules, which are often called quite a bit.

3) Alter "offending" modules such as swiss.pm so that they are using the 
objects, rather than passing strings (which would be needed with 2 as well)

The downside here (as with option 2) is that many folks have been using 
methods like comment() with the assumption that they are just simple 
strings, and suddenly imposing object insistence will start causing 
(potentially transparent) problems, such as "Verified by sequencing" 
suddenly becomming "Bio::Annotation::Comment=HASH(0xbb1a6a8)".

The Comment object always seemed a little excessive to me, kind of like 
having a Strand object. It only has one "real" method, which just spits 
back a string (or whatever was stuffed into text() ), and it struck me 
as overkill to use an object to hold that data. I think the object is 
designed primarily to allow recursive construction of a hash_tree, but 
it's unclear to me if that functionality is being utilized by anyone. 
Anyway, I can sympathize with people who presume that strings should be 
passed to comment() calls...

I'm happy to modify bsml.pm to be cautious if that's what folks would 
like. Hafiz, if you want to proceed while this discussion is in 
progress, you can modify the code on your machine from:

        if (my $com = $thing->comment) {
            push @{$descRef}, ["link" , $com->text ];
        }

to:

        if (my $com = $thing->comment) {
            $com = $com->text if (ref($com));
            push @{$descRef}, ["link" , $com ];
        }

You need to make similar changes in method _parse_annotation_old() at:

        if (my $com = $link->comment) {
           push @{$descRef}, ["link" , $com->text ];
        }

-CAT



hafiz hafiz wrote:

>Thank you to Brian Osborne. , I have install my
>bioperl against , therefore my output have change .
>after i do it this >perl -e 'use XML::DOM' nothing
>happen and i have got same output, so i have reinstall
>my bioperl and install against, please help me . why? 
>
>this is my code ;
>
>#! usr\bin\perl
>
>use Bio::Root::IO; 
>use Bio::SeqIO;
>use Bio::Seq;
>use Bio::Seq::RichSeq;
>use Location;
>
>
>$format = swiss;
>
>#Load  module Location.pm into an array
>@filelocation = Location::filelocation ("sprot42.dat",
>$database);
>
>
>#Access directory path that resides in second element
>of array @filelocation
> my $location = $filelocation[1];
>   
>
>chdir $location;
># chdir $location1;
>        print " location directory database
>swissprot:$location\n";
>
>#Open the directory that are returned by Location.pm
>modul
> opendir (DIR, $location)|| die "\nCouldn't open
>directory or directory not found\n";
>
>#Read the drectory and store its content in an array
>  @file = readdir (DIR);
>
>foreach $file(@file) {
>
>
>  if ($file eq "sprot42.dat") {  
>   
>
>print"\n CHANCE FORMAT FUNCTION\n";
>
>print "\nEnter filename for output file:";
>chomp ($outFile = <STDIN>);
>
>print "\nEnter format for output file:";
>chomp ($format1 = <STDIN>);
>
>print"\n........Chance funtion.......\n";
>
>#chance format function
>
>my $seq_in = Bio::SeqIO->new(-file=>$file,'-format'=>
>"$format");
>
>my $seq_out =
>Bio::SeqIO->new(-file=>">$outFile",'-format'=>
>"$format1");
>  
>  my $inseq;
>          while ( $inseq = $seq_in->next_seq) {
>             $seq_out->write_seq($inseq);
>          }
>
>        #Method from Bioperl module-Bio::SeqIO
>        #Create a sequence object and store it in
>scalar variable
>        $in = Bio::SeqIO->new(-file
>=>$file,'-format'=>"$format");
>
>
>    }#End first if loop
>
>}#End foreach loop
>
>my output;
>CHANCE FORMAT FUNCTION
>
>Enter filename for output
>file:/home/database/Bioperl/sprot42.bsml
>
>Enter format for output file:bsml
>
>........Chance funtion.......
>Can't call method "text" without a package or object
>reference at
>/usr/lib/perl5/site_perl/5.8.0/Bio/SeqIO/bsml.pm line
>1133, <GEN0> line 53.
>
>
>
>
>
>
>
>
>This is bsml.pm some of souce code ; 
>/usr/lib/perl5/site_perl/5.8.0/Bio/SeqIO/bsml.pm> line
>1158 
>
>foreach my $key ($ann->get_all_annotation_keys()) {
>        foreach my $thing
>($ann->get_Annotations($key)) {
>            if ($key eq 'description') {
>                push @{$descRef}, ["description" ,
>$thing->value];
>            } elsif ($key eq 'comment') {  
>                push @{$descRef}, ["comment" ,
>$thing->text];
>            } elsif ($key eq 'dblink') {
>                # DBLinks get dumped to attributes,
>too  
>                push @{$descRef}, ["db_xref" , 
>$thing->database . ":"
>                                   .
>$thing->primary_id ];
>                if (my $com = $thing->comment) {
>                    push @{$descRef}, ["link" ,
>$com->text ]; #line 1158 error
>                }
>      
>            } elsif ($key eq 'reference') {
>                $self->_parse_reference( @_, -refobj
>=> $thing );
>            } elsif (ref($thing) =~ /SimpleValue/) {
>                push @{$descRef}, [$key ,
>$thing->value];
>            } else {
>                # What is this??   
>                push @{$descRef}, ["error", "bsml.pm
>did not understand ".
>                                   "'$key' = '$thing'"
>];
>            }
>
>
>
>________________________________________________________________________
>Yahoo! Messenger - Communicate instantly..."Ping" 
>your friends today! Download Messenger Now 
>http://uk.messenger.yahoo.com/download/index.html
>_______________________________________________
>Bioperl-l mailing list
>Bioperl-l at portal.open-bio.org
>http://portal.open-bio.org/mailman/listinfo/bioperl-l
>  
>

-- 
Charles Tilford, Bioinformatics-Applied Genomics
Bristol-Myers Squibb PRI, Hopewell 3A039
P.O. Box 5400, Princeton, NJ 08543-5400, (609) 818-3213
charles.tilford at bms.com 



More information about the Bioperl-l mailing list