鉴于这些输入:
my $init_seq = "AAAAAAAAAA" #length 10 bp
my $sub_rate = 0.003;
my $nof_tags = 1000;
my @dna = qw( A C G T );
我想生成:
一千个长度 - 10 个标签
标签中每个位置的替换率是 0.003
产生输出如:
AAAAAAAAAA
AATAACAAAA
.....
AAGGAAAAGA # 1000th tags
在 Perl 中有一种紧凑的方法吗?
我坚持将此脚本的逻辑作为核心:
#!/usr/bin/perl
my $init_seq = "AAAAAAAAAA" #length 10 bp
my $sub_rate = 0.003;
my $nof_tags = 1000;
my @dna = qw( A C G T );
$i = 0;
while ($i < length($init_seq)) {
$roll = int(rand 4) + 1; # $roll is now an integer between 1 and 4
if ($roll == 1) {$base = A;}
elsif ($roll == 2) {$base = T;}
elsif ($roll == 3) {$base = C;}
elsif ($roll == 4) {$base = G;};
print $base;
}
continue {
$i++;
}