以您的代码为基础:(我更改了核苷酸序列,以便更容易查看终止和起始密码子,但对您的序列的工作方式完全相同......)我还将您匹配的序列存储在一个数组哈希中的数组,如下所示:
#!/usr/bin/perl
use warnings;
use strict;
use Data::Dumper;
my @file = qw(ATGcgcgcgcgcgcgTAAATGatatatatataTAG ATGcccccccccTAAgggggggggATGtttttttttttTAG atATGaggggaTAGaaaatttttttctttct);
my (@match, %hash, @sequence, $line);
my $line_number = 0;
foreach (@file){
push @match, /(ATG\w+?TA[AG])/g;
push @sequence, @file for 0 .. $#match;
}
push @ { $hash{$sequence[$_]}}, [$match[$_] ] for 0 .. $#match; # Hasho of arrays
for my $key (sort keys %hash){
for my $orf (@ { $hash{$key}}){
my ($match) = @$orf;
print "Sequence:$key contains ORFs: $match\n";
}
}
输出:
Sequence:ATGcccccccccTAAgggggggggATGtttttttttttTAG contains ORFs: ATGatatatatataTAG
Sequence:ATGcccccccccTAAgggggggggATGtttttttttttTAG contains ORFs: ATGaggggaTAG
Sequence:ATGcgcgcgcgcgcgTAAATGatatatatataTAG contains ORFs: ATGcgcgcgcgcgcgTAA
Sequence:ATGcgcgcgcgcgcgTAAATGatatatatataTAG contains ORFs: ATGtttttttttttTAG
Sequence:atATGaggggaTAGaaaatttttttctttct contains ORFs: ATGcccccccccTAA