Hello all, I am trying to use a function that essentially counts matches of a string with a list of strings that have indices. (i.e. 1,"ATAT"\n 2,"GCGC" \n etc.). The code takes two inputs, one is a hash of sequence and index numbers that looks like so
indexfile' => { 'GCTCAGGA' => '4', 'AGCGTAGC' => '5', 'TTCTGCCT' => '3', 'CATGCCTA' => '6', 'TCGCCTTA' => '1', 'GTAGAGAG' => '7', 'GCGTAAGA' => '13', 'TAGATCGC' => '9', 'CTAGTACG' => '2', 'CTAAGCCT' => '16', 'CTCTCTAT' => '10', 'ACTGCATA' => '14', 'AGAGTAGA' => '12', 'TATCCTCT' => '11', 'AAGGAGTA' => '15', 'CCTCTCTG' => '8' },
and the other file is a query sequence string. I want to find the best match between them. The code fails at the line I will comment on, and I would really appreciate any insight into why.
sub match_query(){ my $indexfile = shift; my $queryseq = shift; my @match_count; for my $key (keys %$indexfile){ my $count; for(my $k=0; $k<length($key)-1; $k++){ my $k_nuc = substr $key,$k,2; for(my $i=0; $i<length($queryseq)-1; $i++){ my $i_nuc = substr $queryseq,$i,2; my $rel = $k-$i; if($k_nuc eq $i_nuc){ $count->{$rel} ||= 0; $count->{$rel} += 1; }else{ $count->{$rel} ||= 0; $count->{$rel} += 0; } } } my @array = sort{$b <=> $a} values %$count; my $max_count = shift @array; my $element; $element->{bar} = $key; $element->{max} = $max_count; push @match_count, $element; } my $result; @match_count = sort{$b ->{max} <=> $a->{max}} @match_count; #CODE +#FAILS HERE DOESNT LIKE ->{max} if($match_count[0]->{max} == $match_count[1]->{max}){ $result = 0; }elsif($match_count[0]->{max}>5){ my $called_bar = $match_count[0]->{bar}; $result = $indexfile->{$called_bar}; }else{ $result = 0; } return $result }
If anyone could explain to my why the code fails I would really appreciate it, the error message I recieve looks like this:
Use of uninitialized value in numeric comparison (<=>) at /Users/XXXXX +X/Desktop/test.pl line 602.
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |