一个从 fasta 文件中随机抽取序列的脚本。
#!/usr/bin/perl -w
use strict;
open IN, $ARGV[0] || die $!;
$/ = ">";<IN>;
my %random_num = &random(37843083);
while(<IN>){
chomp;
if (exists $random_num{$.} ){
print ">$_";
}else{
next;
}
}
close IN;
sub random{
my $max = shift @_;
my %hash;
while ((keys %hash) < 10000000) {
$hash{int(rand($max))} = 1;
}
return %hash;
}