use warnings; use strict; use lib '/opt/deepak/bioperl-1.5.1'; use lib 'lib/perl5/site_perl/5.8.5/'; use Bio::SimpleAlign; use Bio::SearchIO; use Bio::AlignIO; use Error qw(:try); use Config::Simple; &blastParser; sub blastParser { my $outFileName = "OutPutFile"; open (outFILE,">$outFileName") or die "can't Open output file file"; try{ print "\nTEST-Inside..."; my $hitCount = 0; $hitCount = $ARGV[0]; my $hitAllignCnt = 0; my $seqCnt = 0; my $arrayCntr = 0; #This is the file that is transfered by ftp to the current working #directory my $file = "tempBlastFile"; my $in = new Bio::SearchIO(-format => 'blast', # comment out the next line to read STDIN -file => $file ); while ( my $result = $in->next_result ) { print "\nTEST-Inside result.."; my @stats = $result->available_statistics; my @params = $result->available_parameters; while ( my $hit = $result->next_hit and $hitCount) { $hitCount--; $hitAllignCnt++; print "\n\nTEST-Recordcount ::\t$hitCount\n\n"; my $id = $hit->matches('id'); my $cons = $hit->matches('cons'); my @accs = $hit->each_accession_number; my @qidentical = $hit->seq_inds('query','identical'); my @qconserved = $hit->seq_inds('query','conserved'); my @hidentical = $hit->seq_inds('hit','identical'); my @hconserved = $hit->seq_inds('hit','conserved'); $seqCnt=0; while(my $hsp = $hit->next_hsp) { $seqCnt++; my ($qid,$qcons) = $hsp->matches('hit'); my ($id,$cons) = $hsp->matches('query'); @qidentical = $hsp->seq_inds('query','identical'); @qconserved = $hsp->seq_inds('query','conserved'); @hidentical = $hsp->seq_inds('hit','identical'); @hconserved = $hsp->seq_inds('hit','conserved'); my @hrange = $hsp->range('hit'); my @qrange = $hsp->range('query'); my $aln = $hsp->get_aln; my $alnIO = Bio::AlignIO->new(-format=>"clustalw",-file=>'>tempHitFile'); print outFILE "\nHIT-NUMBER=$hitAllignCnt.$seqCnt"; print outFILE "\nHIT-NAME=".$hit->name; print outFILE "\nHIT-ACCESSION=".$hit->accession; print outFILE "\nHIT-ROW-SCORE=".$hit->raw_score; print outFILE "\nHIT-BITS=".$hit->bits; print outFILE "\nHIT-GAPS=".$hit->gaps; print outFILE "\nHIT-EVALUE=".$hsp->evalue; print outFILE "\nHIT-PERCENT-IDENTITY=".$hsp->percent_identity; $alnIO->write_aln($aln); open hitFile, "tempHitFile" or die "Can't read file"; undef $/; my $allignMent = ; close hitFile; print outFILE "\nALLIGNMENT=START"; print outFILE "\n$allignMent"; print outFILE "\nEND"; undef $hsp; undef $allignMent; undef $alnIO; undef $aln; undef @qrange; undef @hrange; undef @hconserved; undef @hidentical; undef @qconserved; undef @qidentical; }#hsp while ends undef $hit; }#hit while ends undef $result; }#result while end undef $in; print "\nTEST=Returning and Closing the OutPutFile\n"; close outFILE; } catch Error with { my $ex = shift; #print "\nException...:$ex\n"; close outFILE; my $commandLine = "rm $outFileName"; system($commandLine); open (outFILE,">$outFileName") or die "can't Open output file file"; print outFILE "\nERROR=$ex\n"; close outFILE; return ; } }