in reply to Re: Problem with getting the right object
in thread Problem with getting the right object

Hello Chromatic!
I have revised it to make it simpler. I need to parse a blast report. I am using an if/else to print to 2 different
out files. $hd_out should have:
Name: 13426|HD
Percent Identity: 97.0856102003643
Alignment: Bio::SimpleAlign=HASH(0x4012f2c)

and $hu_out should have:
Name: 13426|HU
Percent Identity: 99.7737556561086
Alignment: Bio::SimpleAlign=HASH(0x401965c)

Where "Bio::SimpleAlign=HASH(object)" is should have the actual data, which is an alignment.
I am confused about dereferencing the hash object since it is a scalar($hu_aln, $hd_aln) in my code

my $in = new Bio::SearchIO(-format => 'blast', -file => $maid_dir."\\".$maid."_aln.out", -report_type => 'blastn'); open (my $hu_out,">".$maid_dir."\\".$maid."_hu_parsed.out"); open (my $hd_out,">".$maid_dir."\\".$maid."_hd_parsed.out"); while(my $result = $in->next_result){ # get info about the first hit my $hit = $result->next_hit; my $hu_name = $hit->name; my $hd_name = $hit->name; if($hu_name =~ /^>.*HU/){ # get info about the first hsp of the first hit my $hsp = $hit->next_hsp; my $best_hsp = $hit->hsp('best'); my $hu_Percent_id = $hsp->percent_identity; print $hu_out "Name: ", $hu_name, "\n"; + print $hu_out "Percent Identity: ", $hu_Percent_id, "\n"; my $hu_aln = $hsp->get_aln; my $alnIO = Bio::AlignIO->new(-format =>"clustalw", -file +=> ">$hu_out"); $alnIO->write_aln($hu_aln); print $hu_out "Alignment: ", $hu_aln, "\n"; } else { $hd_name =~ /^>.*HD/; # get info about the first hsp of the first hit my $hsp = $hit->next_hsp; my $best_hsp = $hit->hsp('best'); my $hd_Percent_id = $hsp->percent_identity; print $hd_out "Name: ", $hd_name, "\n"; + print $hd_out "Percent Identity: ", $hd_Percent_id, "\n"; my $hd_aln = $hsp->get_aln; my $alnIO = Bio::AlignIO->new(-format =>"clustalw", -file +=> ">$hd_out"); $alnIO->write_aln($hd_aln); print $hd_out "Alignment: ", $hd_aln, "\n"; } } close $hu_out; close $hd_out;

I am expecting to get two files. Each with the name, Percent ID, and the sequence alignment.
Your help is appreciated!
LomSpace

Replies are listed 'Best First'.
Re^3: Problem with getting the right object
by chromatic (Archbishop) on May 19, 2009 at 19:03 UTC

    $hu_aln and $hd_aln contain Bio::SimpleAlign objects. If you read the linked documentation, you may find that one of the methods of that class gives you access to the data you need. It doesn't support a default stringification, so you can't print the object directly and get what you expect. (I don't know what you expect, so I can't tell you which method is likely to help.)