我必须找到简单序列重复,并且必须存储每个唯一重复及其位置。我已经写了一个perl代码来做到这一点(这对于查找重复直到pentamers确实有很多if和for)。我的问题是,是否有一些简单的方法来做到这一点在java中,就像一些正则表达式或者一些搜索字符串并返回连续重复和位置的计数,而不涉及许多控制语句和迭代。在Java中寻找简单序列重复的有效方法
更新:简单序列重复(SSR)只是一个不间断重复的字符串,从二聚体开始(即两个不同的字符重复在一起)。这就像一句话连续不断地重复一句话。在DNA的情况下,它看起来像
AATTAAAATTTTAAAAAAAAGGGCCCTTTAA[ATATATATATATAT]AAGGGATTTAAGGAATTAAGA[TGATGATGATGATGA]TGGTAG
在这里和TGA是简单的重复序列,AT是二聚体,和TGA是三聚体。 我必须找到的是序列重复序列的起始位置,它重复的次数(即长度)以及它是哪个序列(即AT例如从位置6开始,重复10次,TGA开始第25位等)
我的Perl代码:(它是一种越野车的)
my $i=0;
my $j=0;
my $dna;
my $m2=0;
my $m4=0;
my $m3=0;
my $m5=0;
my $temp1;
my $temp2;
my $min;
print "Please enter DNA sequence : ";
$dna=<>;
my $firstdi;
my $seconddi;
my $thirddi;
my $fourthdi;
my $fifthtet;
my $firsttet;
my $secondtet;
my $thirdtet;
my $fourthtet;
my $fifthtet;
my $firsttri;
my $secondtri;
my $thirdtri;
my $fourttri;
my $fifthtri;
my $firstpent;
my $secondpent;
my $thirdpent;
my $fourtpent;
my $fifthpent;
print "\n";
print "Please enter the length to search for : ";
$motif=<>;
print "\n";
print "Please enter the minimum number of motif repeats : " ;
$min=<>;
chomp($dna);
chomp($motif);
chomp($min);
my @output;
my @codearr = split //, $dna;
print "\n";print @codearr;print "\n";
my [email protected];
print "\nSize : ";
print "\n";print $arrsize; print "\n";
print "Output : ";
my $total=0;
if($motif==2)
{
for($i=0;$i<($arrsize-2);$i=$i+$motif)
{
if($codearr[$i] ne $codearr[$i+1])
{
$temp1 = join("",$codearr[$i],$codearr[$i+1]);
$temp2 = join("",$codearr[$i+2],$codearr[$i+3]);
if($temp1 eq $temp2)
{
if($m2==0)
{
$ms1=$i;
}
$total++;
$m2++;
}
}
}
}
if($motif==3)
{
for($i=0;$i<($arrsize-2);$i=$i+$motif)
{if($codearr[$i] ne $codearr[$i+1])
{
$temp1 = join("",$codearr[$i],$codearr[$i+1]);
$temp2 = join("",$codearr[$i+2],$codearr[$i+3]);
if($temp1 eq $temp2)
{
if($m2==0)
{
$ms1=$i;
}
$m2++;
$total++;
}
}
}
for($i=0;$i<($arrsize-3);$i=$i+$motif)
{if($codearr[$i] ne $codearr[$i+1])
{
$temp1 = join("",$codearr[$i],$codearr[$i+1],$codearr[$i+2]);
$temp2 = join("",$codearr[$i+3],$codearr[$i+4],$codearr[$i+5]);
if($temp1 eq $temp2)
{
if($m3==0)
{
$ms3=$i;
}
$m3++;
$total++;
}
}
}
}
if($motif==4)
{
for($i=0;$i<($arrsize-2);$i=$i+$motif)
{
if($codearr[$i] ne $codearr[$i+1])
{
$temp1 = join("",$codearr[$i],$codearr[$i+1]);
$temp2 = join("",$codearr[$i+2],$codearr[$i+3]);
if($temp1 eq $temp2)
{
if($m2==0)
{
$ms1=$i;
}
$m2++;
$total++;
}
}
}
for($i=0;$i<($arrsize-3);$i=$i+$motif)
{
if($codearr[$i] ne $codearr[$i+1])
{
$temp1 = join("",$codearr[$i],$codearr[$i+1],$codearr[$i+2]);
$temp2 = join("",$codearr[$i+3],$codearr[$i+4],$codearr[$i+5]);
if($temp1 eq $temp2)
{
if($m3==0)
{
$ms3=$i;
}
$m3++;
$total++;
}
}
}
for($i=0;$i<($arrsize-4);$i=$i+$motif)
{
if($codearr[$i] ne $codearr[$i+1])
{
$temp1 = join("",$codearr[$i],$codearr[$i+1],$codearr[$i+2],$codearr[$i+3]);
$temp2 = join("",$codearr[$i+4],$codearr[$i+5],$codearr[$i+6],$codearr[$i+7]);
if($temp1 eq $temp2)
{
if($m4==0)
{
$ms4=$i;
}
$m4++;
$total++;
}
}
}
}
if($motif==5)
{
for($i=0;$i<($arrsize-2);$i=$i+$motif)
{if($codearr[$i] ne $codearr[$i+1])
{
$temp1 = join("",$codearr[$i],$codearr[$i+1]);
$temp2 = join("",$codearr[$i+2],$codearr[$i+3]);
if($temp1 eq $temp2)
{
if($m2==0)
{
$ms1=$i;
}
$total++;
$m2++;
}
} }
for($i=0;$i<($arrsize-3);$i=$i+$motif)
{
if($codearr[$i] ne $codearr[$i+1])
{
$temp1 = join("",$codearr[$i],$codearr[$i+1],$codearr[$i+2]);
$temp2 = join("",$codearr[$i+3],$codearr[$i+4],$codearr[$i+5]);
if($temp1 eq $temp2)
{
if($m3==0)
{
$ms3=$i;
}
$total++;
$m3++;
}
}
}
for($i=0;$i<($arrsize-4);$i=$i+$motif)
{
if($codearr[$i] ne $codearr[$i+1])
{
$temp1 = join("",$codearr[$i],$codearr[$i+1],$codearr[$i+2],$codearr[$i+3]);
$temp2 = join("",$codearr[$i+4],$codearr[$i+5],$codearr[$i+6],$codearr[$i+7]);
if($temp1 eq $temp2)
{
if($m4==0)
{
$ms4=$i;
}
$total++;
$m4++;
}
}
}
for($i=0;$i<($arrsize-5);$i=$i+$motif)
{if($codearr[$i] ne $codearr[$i+1])
{
$temp1 = join("",$codearr[$i],$codearr[$i+1],$codearr[$i+2],$codearr[$i+3],$codearr[$i+4]);
$temp2 = join("",$codearr[$i+5],$codearr[$i+6],$codearr[$i+7],$codearr[$i+8],$codearr[$i+9]);
if($temp1 eq $temp2)
{
if($m5==0)
{
$ms5=$i;
}
$total++;
$m5++;
}
}
}
}
if($motif==2)
{
if($min<$total)
{
print"Number of Dimer repeats : ";
print $m2;
print"\n";
print"First position : ";
print $ms1;
print "\n";
print "Sequence Lenght : ";
print $arrsize;
print "\n";
}
else
{
print "No or less than minimum SSRs found";}
}
if($motif==3)
{
if($min<$total)
{
print"Number of Dimer repeats : ";
print $m2;
print"\n";
print"First position : ";
print $ms1;
print "\n";
print "Sequence Lenght : ";
print $arrsize;
print "\n";
print"Number of Trimer repeats : ";
print $m3;
print"\n";
print"First position : ";
print $ms3;
print "\n";
print "Sequence Lenght : ";
print $arrsize;
print "\n";
}
else
{
print "No or less than minimum SSRs found";}
}
if($motif==4)
{
if($min<$total)
{
print"Number of Dimer repeats : ";
print $m2;
print"\n";
print"First position : ";
print $ms1;
print "\n";
print "Sequence Lenght : ";
print $arrsize;
print "\n";
print"Number of Trimer repeats : ";
print $m3;
print"\n";
print"First position : ";
print $ms3;
print "\n";
print "Sequence Lenght : ";
print $arrsize;
print "\n";
print"Number of Tetramer repeats : ";
print $m4;
print"\n";
print"First position : ";
print $ms4;
print "\n";
print "Sequence Lenght : ";
print $arrsize;
print "\n";
}
else
{
print "No or less than minimum SSRs found";}
}
if($motif==5)
{
if($min<$total)
{
print"Number of Dimer repeats : ";
print $m2;
print"\n";
print"First position : ";
print $ms1;
print "\n";
print "Sequence Lenght : ";
print $arrsize;
print "\n";
print"Number of Trimer repeats : ";
print $m3;
print"\n";
print"First position : ";
print $ms3;
print "\n";
print "Sequence Lenght : ";
print $arrsize;
print "\n";
print"Number of Tetramer repeats : ";
print $m4;
print"\n";
print"First position : ";
print $ms4;
print "\n";
print "Sequence Lenght : ";
print $arrsize;
print "\n";
print"Number of Pentamer repeats : ";
print $m5;
print"\n";
print"First position : ";
print $ms5;
print "\n";
print "Sequence Lenght : ";
print $arrsize;
print "\n";
}
else
{
print "No or less than minimum SSRs found";}
}
你的Perl代码有太多的重复。另外,你能澄清你的意思吗?存储每个独特的重复以及他们的位置? (也许用**输入**和**预期输出**的测试用例) –
我知道,我只是在尝试,我可以用子程序去,但是再次,我仍然没有明确的逻辑在我脑海里。 – Siddharth
我不明白这个问题。 –