By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,035 Members | 1,064 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,035 IT Pros & Developers. It's quick & easy.

Perl Exception Help

P: 11
[The Problem]
I have been receiving a "Floating point exception" from Perl after my program has run several iterations. I have not been able to pin point the location of the error, and I am clueless. Especially as I can't seem to find exactly what this exception means.

[The Questions]
1) What is a floating point exception?
2) What causes it?
3) Is there any way to fix it?

I have included my code below, but as there is quite a bit any suggestion of how to handle this error would be greatly appreciated.

[Program Explanation]
Basically, I query BLAST with a sequence retrieved from NCBI. The two sub functions follow the main one. Once I have one sequence, I add the seed sequence to a hash and point it to a hash of the returned BLAST sequences. I then iterate through the sequences returned and perform the same process.

Thank you for the help!
Cheers,
Stephen

Expand|Select|Wrap|Line Numbers
  1. sub ash_hash() {
  2.     my $ash_hash = {};
  3.  
  4.     ##### Open files
  5.     open(ERR,">>$files{dir}$files{error}");            # open error file handle
  6.     open(WARN,">>$files{dir}$files{warning}");        # open warning file handle
  7.  
  8.     #### First Blast Query
  9.     print "Running seed query";
  10.     my $blast_temp = ash_sab(\$seed{seq},\$seed{acc}); 
  11.  
  12.     chmod(0777,$blast_temp);                                            # share the file
  13.     if(!-e $blast_temp) { die("No BLAST data returned.\n"); }            # kill program if no blast data
  14.  
  15.     #### Parse Blast Query
  16.     $ash_hash->{$seed{acc}} = ash_sabParse($blast_temp);                # parse BLAST data
  17.     unlink($blast_temp);                                                # destroy the file
  18.  
  19.     ##### Build the Hash
  20.     while($flags{count} < $flags{iterations}) {
  21.         foreach my $branch (keys(%{$ash_hash})) {                            # loop through seq w/ returned blast queries
  22.             foreach my $leaf (keys(%{$ash_hash->{$branch}})) {            # loop through seq returned in the blast queries
  23.                 if(!(defined $ash_hash->{$leaf})) {                    # skip if we already have this sequence
  24.                     if(exists($bad_sequences{$leaf})) {                # if we've already logged this seq, skip it entirely
  25.                         delete $ash_hash->{$branch}->{$leaf};
  26.                         next;
  27.                     }
  28.  
  29.                     my $seq = acc2seq($leaf);                            # retrieve the sequence REFERENCE!!!
  30.                     if($seq <= 0) {                                # no string data -- no seq
  31.                         if($seq == -1) {                                 # not a protein sequence
  32.                             print ERR "Nucleotide sequence: $leaf.\n"; }
  33.                         elsif($seq == 0) {                                # unable to get a sequence returned
  34.                             print ERR "Bad sequence: $leaf.\n"; }
  35.                         else {
  36.                             print ERR "Unknown value returned: $leaf.\n"; }
  37.                         $bad_sequences{$leaf} = 1;
  38.                         delete $ash_hash->{$branch}->{$leaf};
  39.                         next;
  40.                     }
  41.  
  42.                     ##### output iteration count ON THE SAME LINE
  43.                     #$| = 1;
  44.                     print "\rRunning iteration $flags{count}:\t$leaf          ";
  45.                     #$| = 0;
  46.                     my $blast_temp = ash_sab($seq,\$leaf);                # run BLAST
  47.                     chmod(0777,$blast_temp);                            # share the file
  48.                     if(!-e $blast_temp) {
  49.                         die("\n\nNo BLAST data returned.\n"); }            # kill program if no blast data
  50.                     if(!($ash_hash->{$leaf} = ash_sabParse($blast_temp))) {    # add results to hash
  51.                         print ERR "No BLAST sequences returned: $leaf.\n";
  52.                         delete $ash_hash->{$leaf};
  53.                         $bad_sequences{$leaf} = 1;
  54.                         next;
  55.                     }
  56.                     if($flags{save_everything}) {                        # move the file to the blast folder or
  57.                         move($blast_temp,$files{dir}."BLAST/".$leaf.".blast");
  58.                     } else { unlink($blast_temp); }                    # destroy the file
  59.                     $flags{count}++;
  60.                 }
  61.             }
  62.         }
  63.     }
  64. ...
  65. }
Expand|Select|Wrap|Line Numbers
  1. sub ash_sab( $ $ ) {
  2.     my $seq = shift or die("No sequence data.\n");                    # read in variables
  3.     my $acc = shift or die("No accession number.\n");
  4.     my $out = "$files{dir}$files{temp}";
  5.  
  6.     my @params = (                                                    # blast factory parameters
  7.         'program' => $blast{program},
  8.         'database' => $blast{db},
  9.         'outfile' => $out,
  10.         'expect' => $blast{evalue});
  11. #        'method' => $blast{method});                                # parameter variable for factory creation
  12.     my $factory = Bio::Tools::Run::StandAloneBlast->new(@params);    # create handler for SAB
  13.     my $seqobj = Bio::Seq->new(-id=> $$acc,-seq => $$seq);            # create a Seq object from seq string
  14.     my $blast_report = $factory->blastall($seqobj);                    # run BLAST on SEQ object
  15.     return $out;
  16. }
Expand|Select|Wrap|Line Numbers
  1. sub ash_sabParse($) {
  2.     my $in = shift;        # get filename
  3.     my $scores = ();        # hash ref to hold chosen scores
  4.     my $count = 0;            # number of results
  5.     my $acc = 0; my $bs = 0; my $ev = 0;    # values pulled from the blast file
  6.  
  7.     open(BF,$in);            # open the blast file
  8.     my @blast_file = <BF>;    # read in entire file
  9.     close(BF);                # close the file handle
  10.     undef $in;
  11.  
  12.     splice(@blast_file,0,20);                    # deletes the beginning file information
  13.  
  14.     ##### Open files
  15.     #open(ERR,">>$files{dir}$files{error}");            # open error file handle
  16.     #open(WARN,">>$files{dir}$files{warning}");        # open warning file handle
  17.  
  18.     foreach my $line (@blast_file) {    # iterate through file
  19.         # no more data
  20.         if($line =~ m/$>/ || $line =~ m/Matrix\:/) {
  21.             @blast_file = {};    # clear remaining data in blast file;
  22.         }
  23.  
  24.         # Getting the good data
  25.         if($line =~ m/^>/) { last; }
  26.         elsif($line =~ m/^(gb|dbj|emb|ref)\|([\w\d]*).*\s+([\d\.]+)\s+(\d+(e-|\.)\d*)/) {
  27.         # This section collects the normal data
  28.             $acc = $2;        # accession number
  29.             $bs = $3;        # raw score
  30.             $ev = $4;        # e-value
  31.         } elsif($line =~ m/^([\w\d]*) hypothetical protein.*\s+([\d\.]+)\s+(\d+(e-|\.)\d*)/ && $flags{hypotheticals}) {
  32.         # This section collects most of the hypothetical data
  33.             $acc = $1;        # accession number
  34.             $bs = $2;        # raw score
  35.             $ev = $3;        # e-value
  36.         } elsif($line =~ m/^(\w\d+).*\s+([\d\.]+)\s+(\d+(e-|\.)\d*)/) {
  37.         # This section collects a few others
  38.             $acc = $1;        # accession number
  39.             $bs = $2;        # raw score
  40.             $ev = $3;        # e-value
  41.         } else {
  42.             print WARN "NOT USED: $line"; 
  43.         }
  44.  
  45.         # saving the good data or printing to error file
  46.         if(!$acc && !$ev && !$bs) { next;                                                        # not enough data collected
  47.         } elsif($acc =~ m/XP_/i) { print WARN "NOT USED, experimental: $line";                    # skip experimental data
  48.         } elsif(exists($bad_sequences{$acc})) { print WARN "SKIPPED: noted bad seq: $acc\n";    # skip found bad sequence
  49.         } elsif($flags{score_type} eq 'bitscore' && $bs) {                                     # save raw score and accn no.
  50.             $scores->{$acc} = $bs; 
  51.             $count++; 
  52.         } elsif($flags{score_type} eq 'evalue' && $ev) {                                        # save e-value and accn no.
  53.             $scores->{$acc} = $ev; 
  54.             $count++; }
  55.         else {}
  56.     }
  57.  
  58.     ##### close files
  59.     #close(ERR);
  60.     #close(WARN);
  61.  
  62.     ##### release variables
  63.     undef $acc;
  64.     undef $bs;
  65.     undef $ev;
  66.  
  67.     $count > 0 ? return $scores : return 0;
  68. }
Feb 6 '08 #1
Share this Question
Share on Google+
2 Replies


numberwhun
Expert Mod 2.5K+
P: 3,503
Would it be possible for you to re-create the issue and post all the text of the error here for us to see?

Regards,


Jeff
Feb 6 '08 #2

P: 11
The error was nothing more than
Expand|Select|Wrap|Line Numbers
  1. Floating point exception.
After many hours of headache and a little help, I figured out the problem: NCBI does not like to be queried too often. My code was just fine (in fact, the problem arose because it worked faster than the previous version). I solved the problem by querying for a whole batch of sequences at once rather than a single sequence at a time.

This actually results in faster processing, with a little bit more overhead every time you need to query NCBI. With this code, I can usually query about 800 sequences before NCBI throws a fit and calls the exception.
Mar 4 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.