Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I submitted this problem a few days ago and din't get much of a response (probably because I didn't explain it properly).... my program below is getting two errors messages and i really can't find anything wrong with it. the lines containing errors are:
if( ($counter > $pos_end) && ($orf_counter < @orf_array_pos) ) and
the error message for above is "uninitailised value in numeric gt (>) <FASTA> and
if( ($counter >= $pos_start) && ($counter <= $pos_end) )
in which the error message is "uninitalised vlaue in numeric le (<=) <FASTA> Maybe the problem is something to do with $pos_end. All the variables in these two lines are declared so i can't see the problem.

If it helps the program reads in strings of DNA and prints to an output file the bits that don't overlap. $counter reads along one string, and $orf_counter counts the position in the second file. $pos_start and $pos_end just refer to the start and stop positions of matches. The first command line input file contains three columns of data which are orf no, then start and stop positions of each orf. the second command line input file is a genome sequence. The program reads through the orf file trying to match the orfs to the genome sequence. Please help me monks, i need you!!!!!!

#! /usr/local/bin/perl -w use strict; my($num_of_params,$line,$key,$name); my @keys; my %orf_hash_pos; $num_of_params = @ARGV; if($num_of_params < 3) { die ("\n Not enough params have been entered!!!!\n"); } open (ORF_POS, $ARGV[0]) or die "unable to open file"; open (FASTA, $ARGV[1]) or die "unable to open file"; open (OUTFILE, ">$ARGV[2]"); foreach $line (<ORF_POS>) { if(! ($line =~ /(\d+)\s+(\d+)\s+(\d+)/)) { print "CHECK YOR FILE .... continue \n"; next; } if($2 <= $3) { $orf_hash_pos{$2} = $3; } else { $orf_hash_pos{$3} = $2; } } @keys = sort { $a <=> $b } ( keys %orf_hash_pos ); #--------------- step 2 --------------------------- my $counter=0; my $orf_counter=0; my $new_pos; my $pos_start=0; my $pos_end=0; my $found_new=0; my @lines; my @dna; my @orf_array_pos; my $base; my $dna; my $orf_names; @lines = <FASTA>; chomp @lines; $dna = join( '', @lines); @dna = split( '', $dna); foreach $key (@keys) { push @orf_array_pos , $key; push @orf_array_pos , $orf_hash_pos{$key}; } $pos_start = $orf_array_pos[$orf_counter]; $pos_end = $orf_array_pos[$orf_counter+1]; $found_new=0; foreach $base (@dna) { if( ($counter > $pos_end) && ($orf_counter < @orf_array_pos) ) { $orf_counter += 2; $new_pos = $orf_array_pos[$orf_counter]; if($new_pos < $pos_end) { $pos_start = $pos_end; } else { $pos_start = $new_pos; } $pos_end = $orf_array_pos[$orf_counter+1]; } if( ($counter >= $pos_start) && ($counter <= $pos_end) ) { $found_new=0; } else { if($found_new==0) { $orf_names = $orf_counter + 1; $found_new=1; print "\n\n> dORF$orf_names \n"; print OUTFILE "\n\n> dORF$orf_names \n"; } print $base; print OUTFILE $base; } $counter++; } print "\n";

Edit by tye

Replies are listed 'Best First'.
Re: uninitalised value in numeric
by jmcnamara (Monsignor) on May 22, 2002 at 12:22 UTC

    This warning means that either $counter or $pos_end are uninitialised.

    Since, you initialise both of these to 0 at the beginning of your program and since $counter is only incremented and not assigned to, it would suggest that $pos_end picks up an undef value along the way.

    In the absence of any test data I would guess that one of these assignments is reading off the end of the array:     $new_pos = $orf_array_pos[$orf_counter+1];

    Print out the value of $pos_end at the beginning of the for loop and see if it becomes uninitialised.

    --
    John.

Re: uninitalised value in numeric
by derby (Abbot) on May 22, 2002 at 12:15 UTC
    Hmmm ... well $pos_end is intitialized but you could definetly set it to an undefined value with these lines:

    $pos_end = $orf_array_pos[$orf_counter+1]

    If your @orf_array_pos is not divisible by two. What happens when you come to the edge cases? (Like the tail of your @orf_array_pos? Try placing this line near the second setting of $pos_end.

    if( ! defined( $orf_array_pos[$orf_counter+1] ) ) { print STDERR "Uhh ohh, going to undef $pos_end\n"; }

    -derby

Re: uninitalised value in numeric
by Android 18 (Novice) on May 22, 2002 at 12:05 UTC
    That isn't an error per say.. It's a warning. What it's complaining about the > test because at the time $counter has not yet been initialized. Note that being declared and being initialized are two different things. Perl will automatically assume, if it hasn't yet been initialized, that its value is 0 or an empty string depending on where you're using it for the first time.

    In short, if the automatically-set-to-zero behavior is acceptable, you don't need to give the warning any thought. But if at the time that warning is produced, you're expecting $counter to have a value, you should look at your code and see where you aren't assigning something to it where you should.

    Once bread becomes toast, it can never be bread again.

      It's complaining about the > test because at the time $counter has not yet been initialized.

      It is initialised:     my $counter=0;

      You're expecting $counter to have a value, you should look at your code and see where you aren't assigning something to it where you should.

      The $counter will always have a value, it is initialised and incremented, there is no subsequent assignment.

      --
      John.