2014-05-09 31 views
0

我必须找到简单序列重复,并且必须存储每个唯一重复及其位置。我已经写了一个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";} 
} 
+0

你的Perl代码有太多的重复。另外,你能澄清你的意思吗?存储每个独特的重复以及他们的位置? (也许用**输入**和**预期输出**的测试用例) –

+0

我知道,我只是在尝试,我可以用子程序去,但是再次,我仍然没有明确的逻辑在我脑海里。 – Siddharth

+0

我不明白这个问题。 –

回答

2

喜欢的东西的正则表达式应该帮助您开始这适用于“二聚体”你说在你的问题中,可以扩展找到更长的序列。

String s = "AATTAAAATTTTAAAAAAAAGGGCCCTTTAAATATATATATATATAAGGGATTTAAGGAATTAAGATGATGATGATGATGATGGTAG"; 
Pattern pattern = Pattern.compile("([ATGC][ATGC])\\1+"); 
Matcher matcher = pattern.matcher(s); 

while (matcher.find()) { 
    System.out.print("Start index: " + matcher.start()); 
    System.out.print(" End index: " + matcher.end()); 
    System.out.println(" Found: " + matcher.group()); 
} 

这给出了一个输出:

Start index: 4 End index: 8 Found: AAAA 
Start index: 8 End index: 12 Found: TTTT 
Start index: 12 End index: 20 Found: AAAAAAAA 
Start index: 31 End index: 45 Found: ATATATATATATAT 

一个词法库实际上可能帮助你,你可以建立状态机这些正则表达式,帮助识别更为复杂的模式。看看JLex


编辑: 你说AA并不能算作一种模式,他们必须是不同的字符。 您可以尝试this regex代替:

Pattern pattern = Pattern.compile("(?:([ATGC])(?!\\1)([ATGC])\\1\\2)+"); 

这有预测先行断言,以确保它不匹配相同的字符。

+0

谢谢,但它有一个小问题。 AA不是一个序列重复序列,这里的二聚体意味着它可以是AT或TA或任何其他序列,不能重复其自身,就像它不能是AA或TT。虽然,我会尽力纠正这一点。再次感谢。 – Siddharth

+0

@Siddharth这可以通过负前瞻断言来解决。我会在一段时间内更新正则表达式。 –

+0

再次感谢,我在看JLex,它可能会帮助我在将来可能需要使用预编译数据库查找生物相关模式的项目。 – Siddharth

0

这看起来很像LZ。看一看,它可以帮助你:

编码算法的高级视图如下所示:

初始化字典包含一个长度所有字符串。
查找字典中与当前输入相匹配的最长字符串W.
发出W的字典索引以输出并从输入中移除W.
添加W后跟字典输入中的下一个符号。
转到步骤2。

http://en.wikipedia.org/wiki/Lempel%E2%80%93Ziv%E2%80%93Welch

你也可以使用修改后的特里,这里所说的指示也将存储重复的次数。

http://en.wikipedia.org/wiki/Trie

+0

我有点困惑,我应该用所有可能的组合填充字典吗?让我用我的观点重写算法。 1)将它与来自一组的所有可能的核苷酸/字符组合结合。2)找到与输入序列中的子字符串匹配的最长“字”。3)移除该子字符串并增加计数器。4)继续迭代直到没有任何东西从原始输入留下。这种方法如何比使用正则表达式更好? – Siddharth

+0

只是输入文件中使用的长度为1的输入字符串。在你的情况下,A,T,G,C –

+0

然后最长的字符串可以是(例如)AAAAAAA左右,而我需要找到连续的模式,但它们本身不同,像ATATATA – Siddharth

相关问题