print "Input the K value \n"; $k = <>; chomp $k; print "Input T\n"; $t = <>; chomp $t; %Qkmer = (); $i = 1; $query=' '; while ($line=) { chomp($line); if ($line=~ m/^>/ ) { next; } $query=$query.$line; $line=~ s/(^|\n)[\n\s]*/$1/g; while (length($line) >= $k) { $line =~ m/(.{$k})/; if (! defined $Qkmer{$1}) {#every key not deined as the first match $Qkmer{$1} = $i; } $i++; $line = substr($line, 1, length($line) -1); } } open(MYDATA, '<', "data.txt"); while ($line=) { \ chomp($line); %Skmer = (); # This initializes the hash called Skmer. $j = 1; if ($line=~ m/^>/ ) { #if the line starts with > next; #start on next line #separated characters } $line=~ s/^\s+|\s+$//g ; #remove all spaces from file while (length($line) >= $k) { $line =~ m/(.{$k})/;#match any k characters and only k characters in dna $Skmer{$1} = $j; #set the key position to $j and increase for each new key $j++; $line = substr($line, 1, length($line) -1); #this removes the first character in the current string } ###(56)###for($Skmerkey(keys %Skmer)){ $i=$Skmer{$Skmerkey}; if(defined $Qkmer($Skmerkey)){ $j=$Qkmer($Skmerkey); } $S1=$line; $S2=$query; @arrayS1= split(//, $S1); @array2= split(//, $S2); $l=0; while($arrayS1[$i-$l] eq $arrayS2[$j-$l]){ $l++; } $start=$i-$l; $m=0; while ($arrayS1[$i+$k+$m] eq $arrayS2[$j+$k+$m]) { $m++; } $length=$l+$k+$m; $match= substr($S1, $start, $length); if($length>$t){ $longest=length($match); print "Longest: $match of length $longest \n"; } } }###(83)###