1

我必须在基因组序列的FASTA 文件wTTTAYRTTTW中搜索模式,其中W= Aor T, Y= Cor T, R= Aor 。应该允许一些不匹配,即完全匹配字符串及其位置。我的做法是:R

#!user/bin/perl -w
use strict;
my @name = qw( NC_004314.2_10 );
for (my $i = 0 ; $i< scalar(@name);$i++)
{
my $fname = $name[$i];
print "$fname\n";
my $read_pat= "WTTTAYRTTTW";
#print"\nPlease enter how many mismatch is allowd : ";
my $m =<STDIN>;
chomp $m;
unless(open(fh1, "$fname")){
    print "Cannot open file \"$fname\"\n\n";
    exit;
                }
my @fh=<fh1>;
close fh1;
if ($fh[0] !~ /^>/)
    {
        print "not fasta file\n";
        exit;
    }
my $seq='';
foreach my $line(@fh)
    {
        if($line =~ /^>/)
        {
        next;
        }
        else
        {
        $seq=$seq.$line;
        }
    }
sub trans_pat
    {
     my $pat=shift;
     $pat=~s/R/\[CG\]/g;
        $pat=~s/W/\[AT\]/g;
        $pat=~s/Y/\[AG\]/g;
    return $pat;
    }
open(FH1,">$fname.csv");
sub find_pat
{
my ($pat,$seq) = (@_);
#print FH1 "Looking for pattern $pat\n";
}

find_pat (trans_pat($read_pat),$seq);

# Allowing for a single mismatch

my $pat=trans_pat($read_pat);
print FH1 "Looking for pattern $pat\n";
while ($seq=~m/(?=$pat)/g)
{
print FH1"match at\t$-[0]\t$&\n"
}
foreach my $i (1..(length $read_pat)-($m-1))
{
my $mis_pat = $read_pat;
substr($mis_pat,$i-1,$m)=".{$m}";
my $pat1=trans_pat($mis_pat);
print FH1 "Looking for pattern $pat1\n";
while ($seq=~m/(=?$pat1)/g)

{
print FH1 "match at\t$-[0]\t$&\n";
}
#print FH1"$& \n";
}
close FH1;

这段代码发现的结果对于FASTA文件中给定序列NC_004314.2的精确匹配是错误的,总匹配数应该是829。任何人都可以纠正这个代码吗?

4

1 回答 1

3

我对基因组搜索一无所知,也无法快速理解您的程序,但作为建议:

你真的应该扫描:

也许会有所帮助,您可以获得一些如何做事的想法。

Perl 是生物信息学语言。

于 2012-06-20T12:33:29.510 回答