-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
是的,我只是把代码从我的编辑器直接放在这里,所以我不得不手动添加空格,以便将所有内容都整合到一个代码块中。在我的实际程序中,注释掉的区域未被注释掉。我用哈希来区分我特别遇到问题并可能需要以另一种方式实现的区域。 –