Method one (not using modules, by Agonyr)
Copy Code code as follows:
#!/usr/bin/perl-w
Use strict;
My @seq = ("A", "T", "C", "G");
my $length = 10000;
undef my%hash;
$hash {"A"} = Int ($length * 0.3);
$hash {"C"} = Int ($length * 0.3);
$hash {"G"} = Int ($length * 0.2);
$hash {"T"} = Int ($length * 0.2);
my $i = 0;
while ($i $length) {
My $word = $seq [rand (@seq)];
if ($hash {$word}) {
print "$word";
$i + +;
}
$hash {$word}--;
}
Print "n";
Method Two (Use module, by YIXF)
Copy Code code as follows:
#!/usr/bin/perl
Use strict;
Use warnings;
Use biox::sequtils::randomsequence;
My $randomizer = biox::sequtils::randomsequence-"New" (
{
L = "10000,
s = "1,
y = "DNA",
A = "3,
c = "3,
g = "2,
t = "2
}
);
Print $randomizer-"rand_seq" (), "n";
Comparison of two methods
The ratio of set length to 10000,ACGT is 3:3:2:2.
Copy Code code as follows:
Withoutmodule length=10000 gc=49.42% a=2558,c=2503,g=2439,t=2500,others=0
Withmodule length=10000 gc=50.00% a=3000,c=3000,g=2000,t=2000,others=0