2014-05-09 4 views
0

단순 시퀀스 반복을 찾아야하며 각 고유 반복을 해당 위치와 함께 저장해야합니다. 나는 이미 그것을하기위한 펄 코드를 작성했다. (pentamers 때까지 반복을 찾는 if와 for를 가지고있다.) 내 질문은 일부 정규식 또는 문자열을 검색하고 연속 반복 및 위치, 많은 제어 문 및 반복이 포함되지 않은 뭔가를 계산 반환 뭔가 같은 Java에서이 작업을 수행하는 몇 가지 간단한 방법입니다.Java에서 단순 시퀀스 반복을 찾는 효율적인 방법

업데이트 : 간단한 시퀀스 반복 (SSR)은 2 중 문자 (즉, 서로 다른 두 문자가 함께 반복)에서 시작하는 중단되지 않은 반복 된 문자열입니다. 그것은 끊임없이 문장없이 반복적으로 반복되는 단어와 같습니다. AT 및 TGA 간단한 시퀀스는 AT 다이머이고, TGA는 삼량 체이고, 여기에 반복

AATTAAAATTTTAAAAAAAAGGGCCCTTTAA[ATATATATATATAT]AAGGGATTTAAGGAATTAAGA[TGATGATGATGATGA]TGGTAG 

같은 DNA의 경우, 보일 것이다. 내가 찾던 것은 시퀀스 반복의 시작 위치, 반복되는 반복 횟수 (즉, 길이) 및 시퀀스 (즉, 예를 들어 AT는 위치 6에서 시작하고 10 회 반복되고 TGA 그래서 위치 25)에서 시작

내 펄 코드 (그리고 그것은 버그의 종류) 당신이 "이량 체는는"당신이 진술에 적용을 시작하는 데 도움이해야 정규 표현식에 같은

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 부정적인 look-ahead 단언으로 해결 될 수 있습니다. 나는 한동안 정규 표현식을 업데이트 할 것이다. –

+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