473,397 Members | 1,985 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Perl Exception Help

[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
2 2556
numberwhun
3,509 Expert Mod 2GB
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
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

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

Similar topics

13
by: Wayne Folta | last post by:
I've been a long-time Perl programmer, though I've not used a boatload of packages nor much of the tacky OO. A couple of years ago, I decided to look into Python and Ruby. Python looked OK, but...
0
by: arifvahora | last post by:
Active Server Pages error 'ASP 0240' Script Engine Exception work.asp A ScriptEngine threw exception 'C0000005' in 'IActiveScript::SetScriptState()' from...
1
by: Babu | last post by:
Hi, I am a Perl newbie and have a doubt on Perl exception handling. My understanding regarding exception handling is execute a piece of code, if any exception occurs, handle the exception and...
9
by: Dieter Vanderelst | last post by:
Dear all, I'm currently comparing Python versus Perl to use in a project that involved a lot of text processing. I'm trying to determine what the most efficient language would be for our...
1
by: JTrigger | last post by:
I need to call a .Net web service that takes an array or object as a parameter from a PERL client. I have been trying to use the PERL SOAP::Lite package to do this without success. I can call one...
6
by: surfivor | last post by:
I may be involved in a data migration project involving databases and creating XML feeds. Our site is PHP based, so I imagine the team might suggest PHP, but I had a look at the PHP documentation...
17
by: beginner | last post by:
Hi All, This is just a very simple question about a python trick. In perl, I can write __END__ in a file and the perl interpreter will ignore everything below that line. This is very handy...
7
numberwhun
by: numberwhun | last post by:
**NOTE: This article is written using the 5.8.8 Alpha2 release of Strawberry Perl. I am writing this article with much joy and glee. This is due to the fact that Active State no longer has a...
4
by: jonathan184 | last post by:
Hi I have a perl script, basically what it is suppose to do is check a folder with files. Now the files are checked using a timestamp with the command ls -l so the timestamp in this format is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.