-1
我在此程序中執行兩個文件時遇到問題。我正在嘗試訪問文件$Q
和$s
的內容。從模式中找到2個文件中的最長匹配
print "Input the K value \n";
$k = <>;
chomp $k;
print "Input T\n";
$t = <>;
chomp $t;
%Qkmer =();
$i = 1;
$query=' ';
while ($line=<IN>) {
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=<MYDATA>) { \
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)###
輸入文件只包含字母串。例如:
文件1:
ahhtsagnchjgstffhjyfcsghnvzfhg
文件2:
ggujvfbgfgkjfcijjjffcvvafcsghnvzfhgvugxckugcbhfcgh
ghnvzfhgvugxckHhfgjgcfujvftjbvdtkhvddgjcdgjxdjkfrh
ajdbvciyqdanvkjghnvzfhgvugxc
從匹配文件2長度$k
在文件1的單詞的,我從檢查在文件2中匹配詞的左側和右側以進一步匹配。最終輸出是基於$k
的文件1和文件2之間最長的匹配。現在我GE
有了這個代碼,我得到一個語法錯誤,爲什麼,因爲它看起來是正確的給我我不發售者:
syntax error at testk.pl line 56, near "$Skmerkey("
syntax error at testk.pl line 83, near "}"
謝謝。
已使用'$ k',但未定義。 '用警告;嚴格使用;' – Mike
哈希'%kmer' allways空!!! – Mike
是的,我只是把代碼從我的編輯器直接放在這裏,所以我不得不手動添加空格,以便將所有內容都整合到一個代碼塊中。在我的實際程序中,註釋掉的區域未被註釋掉。我用哈希來區分我特別遇到問題並可能需要以另一種方式實現的區域。 –