use warnings; use strict; #use Frontier::Daemon; use lib '/opt/deepak/bioperl-1.5.1'; use Bio::Root::Exception; use Bio::SimpleAlign; use Bio::SearchIO; use Bio::AlignIO; #@NoCanDoException::ISA = qw( *Bio::Root::Exception* ); use Error qw(:try); use lib 'lib/perl5/site_perl/5.8.5/'; use Config::Simple; use Log::Log4perl; Log::Log4perl::init('log4perl.conf'); my $logger = Log::Log4perl->get_logger('rootLogger'); $logger->debug("Logger Initialised"); my $isException = 1; &blastParser; sub blastParser { #output file name to be send at the serverside my $outFileName = "OutPutFile"; open (outFILE,">$outFileName") or die "can't Open output file file"; try{ print "\nInside..."; $logger->debug("\nInside Method blastParser"); my $hitCount = 0; $hitCount = $ARGV[0]; my $hitAllignCnt = 0; my $seqCnt = 0; my $arrayCntr = 0; #This is the file that is transfered by to the xml-client to 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 "\nInside result.."; $logger->debug("\nAnalysing result..."); my @stats = $result->available_statistics; my @params = $result->available_parameters; while ( my $hit = $result->next_hit and $hitCount) { $hitCount--; $hitAllignCnt++; print "\n\nRecordcount ::\t$hitCount\n\n"; $logger->debug("\nAnalysing hit"); $logger->debug("\nRecordCount $hitCount"); 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'); $logger->debug("\nHit Name : ".$hit->name); $logger->debug("\nHit Accession".$hit->accession); $logger->debug("\nHit Row score :".$hit->raw_score); $logger->debug("\nHit Bits :".$hit->bits); $logger->debug("\nHit Gaps :".$hit->gaps); $seqCnt=0; while(my $hsp = $hit->next_hsp) { $logger->debug("Analysing 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; $logger->debug("Evalue".$hsp->evalue); $logger->debug("Percent Identity".$hsp->percent_identity); $logger->debug("\nHit Name : ".$hit->name); $logger->debug("\nHit Accession".$hit->accession); $logger->debug("\nHit Row score :".$hit->raw_score); $logger->debug("\nHit Bits :".$hit->bits); $logger->debug("\nHit Gaps :".$hit->gaps); #alnIO object is required to show the sequences in well format $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 "\nReturning and Closing the OutPutFile\n"; close outFILE; $isException = 0; } catch Bio::Root::Exception with { my $ex = shift; print "\nDeepak Exception...:$ex\n"; print outFILE "\nERROR=START\n"; print outFILE "$ex\n"; print outFILE "ERROR=END\n"; return; } otherwise{ my $exOtherwise = shift; $isException = 1; print "Deepak Otherwise...:$exOtherwise\n"; } }