[Bioperl-l] trying to save blast hit sequences to fasta file

Jay Hannah jay at jays.net
Wed Aug 1 13:30:50 UTC 2007


On Wed, 1 Aug 2007, Alicia Amadoz wrote:
> Hi, I have tried what you suggested and I get also some errors.
> With this code,
>
> my $seq_out = Bio::SearchIO->new("-file" => ">$fasfilename", "-format"
> => "fasta");
> while(my $result = $blast_report->next_result()) {
>   while(my $hit = $result->next_hit()) {
>      while(my $hsp = $hit->next_hsp()) {
> 	my $hseq = $hsp->hit_string();
>        $hseq =~ s/-//g; #### remove the gap within the aligment
>        my $hseq_obj = Bio::Seq->new(-display_id => $id, -seq => $hseq);
>        $seq_out->write_seq($hseq_obj);
>      }
>   }
> }
>
> I have the following error:
>
> Can't locate object method "write_seq" via package "Bio::SearchIO::fasta"

You don't want to write_seq() to a SearchIO, you want to write_seq() to a 
SeqIO. Try this:

my $seq_out = Bio::SeqIO->new(-file => ">$fasfilename", -format => "fasta");
while(my $result = $blast_report->next_result()) {
    while(my $hit = $result->next_hit()) {
       while(my $hsp = $hit->next_hsp()) {
 	my $hseq = $hsp->hit_string();
         $hseq =~ s/-//g; #### remove the gap within the aligment
         my $hseq_obj = Bio::Seq->new(-display_id => $id, -seq => $hseq);
         $seq_out->write_seq($hseq_obj);
       }
    }
}

(Untested.)

HTH,

Jay Hannah
http://clab.ist.unomaha.edu/CLAB/index.php/User:Jhannah



More information about the Bioperl-l mailing list