1

从给定的两个序列中,我需要检查每三个密码子,如果更改与以下列表中的相同,那么我必须检查更改的位置和更改的密码子并计算它们的出现次数。

例如:

sequence 1 - TTCAUUUCCCAU
sequence 2 - TTTAUAUCGCAC

我需要得到的输出是

TTC->TTT considered/location-1/count-1
AUU->AUA considered/location-2/count-1
UCC->UCG considered/location-3/count-1

注意:CAU->CAC不考虑,因为它不在以下列表中。LIST:-> 还应考虑变化的方向。

first sequence->second sequence
TTC->TTT
CTG->UUA
AUU->AUA
GUG->GUA
UCC->UCG
CCC->CCG
ACC->ACG
GCC->GCG
UAC->UAU
UGA->UAG
CAC->CAU
CAG->CAA
AAC->AAU
AAG->AAA
GAC->GAU
GAG->GAA
UGC->UGU
CGG->CGU
AGC->AGU
AGG->CGU
AGA->CGU
UAA->UAG
GGC->GGU

我写到现在的代码是:

print "Enter the sequence:";
$a = <>;

print "Enter the mutated sequence:";
$b = <>;

chomp($a);
chomp($b);

my @codon = split(/(\w{3})/, $a);
my @codon1 = split(/(\w{3})/, $b);

open(OUT, ">output.txt") or die;
$count = 0;
@new = ();
@new1 = ();
for ($i = 0; $i <= $#codon; $i++) {
    for ($j = 0; $j <= $#codon1; $j++) {
        if ($codon[$i] = {TTC}) || ($codon1[$j] = {TTT}) {
            $count++;
        }
    }
}
print OUT " @new";
close OUT;
4

3 回答 3

2
#!/usr/bin/env perl
use strict;

my %seq_map = (
    "TTC"=>"TTT",
    "CTG"=>"UUA",
    "AUU"=>"AUA",
    "GUG"=>"GUA",
    "UCC"=>"UCG",
    "CCC"=>"CCG",
    "ACC"=>"ACG",
    "GCC"=>"GCG",
    "UAC"=>"UAU",
    "UGA"=>"UAG",
    "CAC"=>"CAU",
    "CAG"=>"CAA",
    "AAC"=>"AAU",
    "AAG"=>"AAA",
    "GAC"=>"GAU",
    "GAG"=>"GAA",
    "UGC"=>"UGU",
    "CGG"=>"CGU",
    "AGC"=>"AGU",
    "AGG"=>"CGU",
    "AGA"=>"CGU",
    "UAA"=>"UAG",
    "GGC"=>"GGU"
);

my %seq_count = ();

my $seq1 = "TTCAUUUCCCAU";
my $seq2 = "TTTAUAUCGCAC";

my $max = int(length($seq1) / 3);
for(my $i=0;$i<$max;$i++) {
    my $c1 = substr($seq1, $i*3, 3);
    my $c2 = substr($seq2, $i*3, 3);
    my $found = $seq_map{$c1};
    if ($found && ($found eq $c2)) {
        $seq_count{$c1} ||= 0;
        my $count = ++$seq_count{$c1};
        my $loc = $i+1;
        print "${c1}->${c2} considered / location ${loc} / count ${count}\n";
    }
}
于 2011-02-03T07:38:41.703 回答
1

有很多方法可以做到这一点,就像 Perl 中的典型情况一样。

如果文件不大,您可以将文件逐行读入一个数组(或者如果它已经是每行一个条目,那么只需将整个文件读入一个数组)。然后使用while循环(和第二个文件的文件句柄)来比较二核苷酸的位置。

因为这是一个生物信息学问题,而且文件通常很大,所以我会很聪明地研究从每个文件句柄中逐行读取并进行比较。

对于您尝试执行的 3 个字符拆分,我会使用一个for循环,直到您要检查的字符串的长度除以 3 -1。然后创建一个正则表达式,继续抓取前三个字母,然后是下一个,依此类推……</p>

就像是/\d{$count}(\w{3})/

while循环可能看起来像这样:

#!/usr/bin/perl -w
use strict;

open FILE1, "file1.txt" or die "Cannot open file1.txt: $!\n";
open FILE2, "file2.txt" or die "Cannot open file2.txt: $!\n";

my $count = 0;
while (<FILE1>) {
    chomp(my $lineF1 = $_);
    chomp(my $lineF2 = <FILE2>);

    # some changes may need to be made to this if statement
    if ($lineF1 eq $lineF2) {
        # do something important here
        print "$lineF1\n";
    } else {
        print "Line $count mismatch\n";
    }
    $count++;
}

close(FILE1);
close(FILE2);
于 2011-02-03T06:58:19.860 回答
0

你能认为这两个文件中的密码子是“对齐的”吗?如果是这种情况,问题就很简单:您将有效转换列表加载到 2 级散列中:

 # of course, you load this from a file...
 $transitions{TTC}{TTT} = 1;
 $transitions{CTG}{UUA} = 1;
 ...

然后,逐行读取这两个文件(或者它们只是一个字符串?):

# of course, I'm leaving out all the file manipulation...
my $line1 = <FILE1>;
my $line2 = <FILE2>;

my $maxlen1 = length($line1);
my $maxlen2 = length($line2);
my $i = 0;

while($i < $maxlen1 && $i < $maxlen2){
  my $codon1 = substr($line1, $i, $i+3);
  if(exists($transitions{$codon1}){
    my $codon2 = substr($line2, $i, $i+3);
    if(exists($transitions{$codon1}{$codon2}){
      print "we have a match $codon1 -> $codon2 at index $i\n";
    }
  }
  $i += 3;
}

注意使用 'exists() 而不是 defined() 因为它会为你节省一些额外的计算。如果您不想使用下一个 if(),您可以计算 $codon1 和 $codon2 然后检查 if(exists($transitions{$codon1}{$codon2})) {} 使用 'exists' 避免自动激活问题...

于 2011-02-03T13:54:41.420 回答