[Bioperl-l] Using a hash reference in the SeqFeature tag system

Lincoln Stein lstein at cshl.edu
Wed Jul 14 14:27:42 EDT 2004


get_tag_values returns a list!  Your example will work if you do this:

	my ($cage) = $seqextra->get_tag_values('Cage');  # keep first element
	print keys %$cage;

Lincoln

On Wednesday 14 July 2004 01:52 pm, Leo, Paul (NIH/NHGRI) wrote:
> Hi,
> I want to add additional information of a $seq object using the tag
> system. The tag value I want to add is a reference to a hash of
> hashes (though I don't think it worked for just a hash either).
> I thought that so long as the tag value was a scalar (i.e. a
> reference) then all would be ok?
> Perhaps I have done something silly ....and this is a simple perl
> programming mistake... But have been staring at this for too long!
> Can someone tell me why the example below fails? If so, any ideas
> on how to add this hash structure to a $seq object ??
>
>
>
> use Bio::DB::GenPept;
> use Bio::SeqFeature::Generic;
> use Bio::Seq;
> use Bio::SeqIO;
>
>
> ######## make a hash of hashes ###########
> $Data{cage1}{mouse1}{legs}=1;
> $Data{cage1}{mouse1}{tails}=10;
>
> $Data{cage1}{mouse2}{legs}=2;
> $Data{cage1}{mouse2}{tails}=20;
>
> $Data{cage2}{mouse1}{legs}=3;
> $Data{cage2}{mouse1}{tails}=30;
>
> $Data{cage2}{mouse2}{legs}=4;
> $Data{cage2}{mouse2}{tails}=40;
>
> print $Data{cage1}{mouse2}{legs}, "\n"; #just a check :gives "2"
> print map "$_ ",keys(%{$Data{cage2}{mouse2}});  #just a check gives
> "legs tails"
> print "\n";
> ########################################
>
> #### make a hash reference and put in into tag ###
> $href=\%{$Data{cage1}{mouse1}}; #make ref here to a hash since used
> in tests below
> $seqextra=new Bio::SeqFeature::Generic ( -tag => {
>                   experiment_id => 1,
>                   Cage =>  $href     });
>
> ###############Sanity Checks...
> print "Ref ok : \n";
> print map "$_ ",keys(%{$href}); #prints "legs tails" as expected
> print "\n";
>
> print "Ref in a simple hash ok : \n";
> $hashtest{zero}=$href;
> print map "$_ ",keys(%{$hashtest{zero}}); #prints "legs tails" as
> expected ############ This fails....
> print "\n";
> print "Tag in not ? \n";
> print map "$_ ",keys(%{$seqextra->get_tag_values('Cage')});
> #NOTHING!
>
> Any suggestions?
> Thanks in advance
> Paul

-- 
Lincoln D. Stein
Cold Spring Harbor Laboratory
1 Bungtown Road
Cold Spring Harbor, NY 11724


More information about the Bioperl-l mailing list