[Bioperl-l] re trieving blast multiple alignment in fasta form

Ericde ericdemuinck at gmail.com
Wed Nov 30 23:36:36 UTC 2011


:-/

I am a newbie and I am trying to retrieve a blast multiple alignment in
fasta form. The BLAST output (m -2) gives several alignments (which is good)
and the parsing of the xml file seems to list all of these alignments (which
is also good) 

The problem is that the fasta alignment file only includes one of the hits
and the alignment does not include all the sequences (including the query
sequence).

I would like to generate a fasta file that includes all the alignments
included in the m -2 output (plus query sequence if possible). I have
cobbled together a script (below) ...I will attach the sample blast xml file
and the (m -2) file as well....any insight is appreciated :/

#module load perl
 
#give the name of the blast xml file to parse in the line where it says
'file =>'
use Bio::SearchIO; 
#Use m -7 to generate xml file from blastall
my $in = new Bio::SearchIO(-format => 'blastxml', 
                           -file   => 'BLASToutxml');
while( my $result = $in->next_result ) {
  ## $result is a Bio::Search::Result::ResultI compliant object
  while( my $hit = $result->next_hit ) {
    ## $hit is a Bio::Search::Hit::HitI compliant object
    while( my $hsp = $hit->next_hsp ) {
      ## $hsp is a Bio::Search::HSP::HSPI compliant object
#ENTER desired sequence length
      if( $hsp->length('total') > 50 ) {
#ENTER desired percent identity
        if ( $hsp->percent_identity >= 75 ) {
          print "Query=",   $result->query_name,
            " Hit=",        $hit->name,
            " Length=",     $hsp->length('total'),
            " Percent_id=", $hsp->percent_identity, "\n";
#Print alignment to file
#$aln will be a Bio::SimpleAlign object
       use Bio::AlignIO;
           my $aln = $hsp->get_aln;

#changed msf to fasta and hsp.msf to hsp.fas, output is now a fasta file 
          my $alnIO = Bio::AlignIO->new(-format =>"fasta", -file =>
">hsp.fas"); 
      $alnIO->write_aln($aln);

        }
      }
    }  
  }
}
http://old.nabble.com/file/p32886592/BLASToutxml BLASToutxml 
http://old.nabble.com/file/p32886592/hsp.fas hsp.fas 
-- 
View this message in context: http://old.nabble.com/retrieving-blast-multiple-alignment-in-fasta-form-tp32886592p32886592.html
Sent from the Perl - Bioperl-L mailing list archive at Nabble.com.




More information about the Bioperl-l mailing list