in reply to Bioperl + perl modules

What type of object is in $gb?

Nothing seems to be working past here.

Do you mean that the code below that line does or does not work? If it doesn't work, (a) does it give any warnings and/or errors? If it doesn't give any warnings, what does it do that you think is wrong? If it does work, what part of the code doesn't, and goto (a)

update: annotation() is not in Bio::SeqFeatureI...

Replies are listed 'Best First'.
Re^2: Bioperl + perl modules
by Anonymous Monk on Jun 27, 2005 at 09:59 UTC
    Hi

    I have progressed slightly since my post. Here is my newer code below, it doesn't print any warnings or errors, I am having a problem in the loop starting  foreach $key ( $ac->get_all_annotation_keys() ) {

    . How can I tell whether $ac variable has a value? If I print it out, it looks like a hash.

    + my $seqio = $gb->get_Stream_by_id(['13474692']); #print $gb->get_Stream_by_id(['13474692']); + + while( my $seq = $seqio->next_seq ) { print "seq is ", $seq->display_id, "\n"; my @f=$seq->get_SeqFeatures; #This gives you the annotation of t +he retrieved sequence object + foreach my $feat (@f) { + print "Feature ",$feat->primary_tag," starts ",$feat->start," e +nds ", $feat->end," strand ",$feat->strand,"\n"; + # features retain link to underlying sequence object #print "Feature sequence is ",$feat->seq->seq(),"\n"; + my $ac=$feat->annotation(); + # HOW CAN I TELL IF $ac HAS A VALUE print "GETS TO HERE\n"; + foreach $key ( $ac->get_all_annotation_keys() ) { print "DOESN'T GET TO HERE\n"; @values = $ac->get_Annotations($key); foreach $value ( @values ) { # value is an Bio::AnnotationI, and defines a "as_text +" method print "Annotation ",$key," stringified value ",$value- +>as_text,"\n"; + # also defined hash_tree method, which allows data ori +entated # access into this object $hash = $value->hash_tree(); } } + + next unless ($ac->get_Annotations('coded_by')); my @coded=$ac->get_Annotations('coded_by'); foreach my $location (@coded) { print $location->value, " is the location that codes this pro +tein\n"; } } }
      foreach $key ( $ac->get_all_annotation_keys() ) {
      if $ac is not a valid object of the right type, that code would throw an error: note that you are not indexing a hash here, you're calling an object method. see perltoot for more information on the perl OO system.

      If you want to know what data is stored in a perl variable or object, an easy way to see that is to use the standard Data::Dumper module:

      use Data::Dumper; # ... print '$ac: ',Dumper($ac); foreach $key ( $ac->get_all_annotation_keys() ) print '$key: ',Dumper($key); }

      That should probably give you some indication of what these objects contain. Note that object can store data in such a way that Data::Dumper doesn't know how to get at it, but it's a start anyway.