This is a test version of Biostars. For the public version, visit https://www.biostars.org.
perl warning message

Dear friends,

I need a help from you. I have written a perl program for KMP algorithm. program runs perfectly but it gives some warnings like, for a example as follows..

Replacement list is longer than search list at C:/Perl/site/lib/Bio/Range.pm line 251.
Use of uninitialized value in string ne at C:/Users/dell/workspace/subroutine/sub.pl line 99, <GEN0> line 2.
Use of uninitialized value in string ne at C:/Users/dell/workspace/subroutine/sub.pl line 99, <GEN0> line 2

Can somebody help me to get rid of this error...

Thanks

Here is the program

#!/usr/bin/perl -w

#use strict;
use Bio::SeqIO;
use Bio::Seq;

#my $seq_obj;
my $text;
my $pattern ="TATAAAT";
my $seq_obj;

open ("OUT_PUT",">C:\\Users\\dell\\Desktop\\GGGCGG.txt");

# defining the subroutine for prefix table for my pattern
sub PreprocessTable{

        # initializing first two valaue of the prefixtable array as -1 and 0
        my ($i,$j) = (0,-1);

        # converstion of pattern string into an array
        my @PtrnArray = split //,$pattern;

        # get the length/size of pattern array length
        my $PtrnArrayLength = scalar @PtrnArray;

        # initialize the Table array with known size(here the size of the array is 8) 
        # which is one index adding to the pattern array
        my @TableArray;$TableArray[$PtrnArrayLength]=undef;

        # assigning the  value of $j which is -1 as first index value of TableArray
        $TableArray[$i]= $j;

            # start to generate the TableArray which give out put as -1,0,0,1,2,0,0,1
            while ($i < $PtrnArrayLength){ 
                # check whether the adjecent characters of pattern
                # matching or not, if firsr condition and the adjecent 
                # two characters arenot match inner while loop is running
                while ($j >=0 && $PtrnArray[$i] ne $PtrnArray[$j]){

                    # if inner loop running, assigne first index value of
                    # Tabale Array as -1
                    $j= $TableArray[$j];
                    }
                        # increment both $i,$j
                        $i++;
                        $j++;
                        # output gives as -1,0,0,1,2,0,0,1
                        $TableArray[$i]=$j;
                }

        # return the TabaleArray for the further manupulation with KMPalgoSearch subroutine
        return (@TableArray)
} 
# pass the argument, in my case I am passing $pattern in order to
# generate the TableArray i.e. prefixtable
PreprocessTable($pattern);


# defining the pattern matching subroutine 

sub KMPalgoSearch{
    # open thw sequence files which is in fasta format
    my $seqio_obj = Bio::SeqIO->new(-file => "C:\\Users\\dell\\Desktop\\first.fasta", -format => "fasta",-alphabet => "dna");

    # read one sequence at a time                                                                       
    while ($seq_obj = $seqio_obj->next_seq){   
        # print the sequence  ID,sequence description,sequence
        # this helps to upload all the sequences to Exel ot Access database 
           my $count=0; 
         my $text = $seq_obj->seq;
        my $len =length($text);    

        # initialize the two scalar variable $i, $j with 0
         my ($i, $j) =(0,0);

     # call the PreprocessTable subroutine and pass $pattern as its argument
     # and this is assign to the TableArray as return from PreprocessTable subroutine
     my (@TableArray)= PreprocessTable($pattern);

     # both pattern and text coming to this subroutine as string
     # now convert both pattern and text into array for the further manipulation
     # within this subroutine
     my @pattern=split //,$pattern;
     my @text = split // ,$text;

     # obtain and assigne the length/size of both pattern and text arrays
     my $ptrnLen = scalar @pattern;
     my $textLen = scalar @text;
     # this regular expression used to print the sequences that do not having pattern

     if( $text !~ m/TATAAAT/g && $count==0){
                         OUT_PUT -> print  ($seq_obj->display_id);
                }

     # start to match the pattern charactoers with text characters
     while ( $i < $textLen){
         while ( $j >= 0 && $text[$i] ne $pattern[$j]){             
             # if first condition and the pattern and text characters are not match
             # have to refer the prefix table which is generated by first subroutine
             # since it has called within KMPalgoSearch subroutine now refering fisrt 
             # value of TableArray which is -1 and continue untill mach encount

             $j= $TableArray[$j];
         }
             $i++;
             $j++;

                     # return the match position of text once the pattern length and $j equals to each other 
                     # $count helpls to get the perticular sequence only
                     if ($j==$ptrnLen && $count==0){

                     # here return the match position.I added +1 to get the actual position
                     # since ($i-$ptrnLen) return the index
                         OUT_PUT -> print  ( $seq_obj->display_id,";",$seq_obj->desc,";",($i-$ptrnLen+1));

                         $count = $count+1;
                     } 
                     # if #count >0 print only location ,here I omit the douplicate printing of seq ID
                     elsif( $j==$ptrnLen && $count>0){
                         OUT_PUT -> print  (";",($i-$ptrnLen+1));
                }
             }
             # print a new line after the whlie loop before take second text string
             OUT_PUT -> print ("\n");
     }
     print "done","\n"    ;
}
# pass the arguments, here pass both $text and $pattern
KMPalgoSearch($pattern);

Thank you

sequence gene

Do you just not understand what the error messages are telling you?

This is probably more appropriate for stackoverflow or a perl forum.

According to the warning message, it indicates that I have some uninitialized string at, while ( $j >= 0 && $text[$i] ne $pattern[$j]) line...but ..I have no such uninitialized variables....this is the way I understood...I may wrong...can you suggest why this happen....?

For what it's worth, I don't receive any error when I run that code, though I just used a very short input fasta file.

thank you friend, but I don't understand why I still having such a warning. I run the perl program in eclipse..did you run the program in linux?

Yeah, I use Linux, so perhaps that's the reason (I really haven't a clue). I would strongly recommend you to post this on a Perl forum. Someone there is likely to be more helpful.

Thank you Devon

HI Devon,

I found something..the first warning ,Replacement list is longer than search list at C:/Perl/site/lib/Bio/Range.pm line 251. is due to the version variation. I did run the program in Linux with perl 5.14 instead perl 5.16 in my windows it did not give a warning

Similarly for the second warning,

Use of uninitialized value in string ne at C:/Users/dell/workspace/subroutine/sub.pl line 99, <GEN0> line 2.

simply overcome using ,

no warnings 'uninitialized';

now my program is running without warnings.

Anyway thank you very much for your support

shouldn't you be storing the results of PreprocessTable() in some variable?

0 answers

No answers yet.

Log in to answer this question.