2013-02-23 48 views
0

我在這裏得到了很好的輸入,對一串核苷酸進行3個核苷酸重複模式的搜索,要求通過爲它構建正則表達式連續7次重複發生。以條件形式輸入多個正則表達式?

my $regex1 = qr/(([ACGT]{3}) \2{6,})/x; 

我知道如何將它擴大到在7

連續搜索2個nucs在10行以及4個,但我想擴大代碼,以便用戶可以指向他們的輸入文件,它會檢查上面的正則表達式以及另外兩個正則表達式,我需要爲其他兩個搜索創建這兩個正則表達式。

編輯:如何使我的輸入文件受到像上面那樣的多個正則表達式?我的代碼(由哈希符號淘汰)

這裏是我當前的代碼

print "Please specify the file location (DO NOT DRAG/DROP files!) then press ENTER:\n"; 
$seq = <STDIN>; 

#Remove the newline from the filename 
chomp $seq; 

#open the file or exit 
open (SEQFILE, $seq) or die "Can't open '$seq': $!"; 

#read the dna sequence from the file and store it into the array variable @seq1 
@seq1 = <SEQFILE>; 

#Close the file 
close SEQFILE; 

#Put the sequence into a single string as it is easier to search for the motif 
$seq1 = join('', @seq1); 

#Remove whitespace 
$seq1 =~s/\s//g; 

#Count of number of nucleotides 
#Initialize the variable 
$number = 0; 
$number = length $seq1; 

#Use regex to say "Find 3 nucelotides and match at least 6 times 
# qr(quotes and compiles)/(([nucs]{number of nucs in pattern}) \2{number of repeats,}/x(permit within pattern) 
my $regex1 = qr/(([ACGT]{3}) \2{6,})/x; 
#my $regex = qr/(([ACGT]){2}) \2{9,})/x; 
#my $regex2 = qr/(([ACGT]{4}) \2{6,})/x; 

#Tell program to use $regex on variable that holds the file 
$seq1 =~ $regex1; 

#Now print the results to screen 
#This will need to change to printing to a file (WHAT KIND OF FILE?)in the following manner :site, nucelotide match, # of times, length of full sequence 
printf "MATCHED %s exactly %d times\n", $2, length($1)/3; 
print "Length of sequence: $number\n"; 
exit; 
+0

你的問題是什麼? – Borodin 2013-02-23 03:12:38

+0

對不起 - 我不清楚。我想讓我的輸入文件受到多個正則表達式的影響。 – Citizin 2013-02-23 03:32:54

回答

1

只需使用一個for迴路形成另兩個正則表達式。類似於

for my $regex ($regex1, $regex2, $regex3) { 
    next unless $seq1 =~ $regex; 
    printf "MATCHED %s exactly %d times\n", $2, length($1)/length($2); 
} 

但是,您可能需要更改輸出以更好地描述結果。

+0

我需要改變'長度($ 1)/ n;',但我怎麼去匹配用於它應該使用的printf的正則表達式呢? – Citizin 2013-02-23 03:44:49

+1

如果不知道你想要什麼輸出,很難提出任何建議。但是您可以將表達式更改爲'length($ 1)/ length($ 2)'。回答相應改變。 – Borodin 2013-02-23 03:47:41

+0

由於輸入seq只會滿足三個正則表達式的要求之一,所以我需要解決找不到任何東西的正則表達式,它會將'length($ 2)'返回爲'0',從而殺死程序。我怎樣才能告訴程序只提供它使用的正則表達式的結果? – Citizin 2013-02-23 04:49:35