| 1 |
|
| 2 |
use strict; |
| 3 |
use warnings; |
| 4 |
use diagnostics; |
| 5 |
use Getopt::Long; |
| 6 |
use List::Util 'shuffle'; |
| 7 |
|
| 8 |
my ($percentage); |
| 9 |
|
| 10 |
GetOptions( "percentage|p=f" => \$percentage) or die("Error parsing options!"); |
| 11 |
|
| 12 |
my $skipping = 1; |
| 13 |
|
| 14 |
my @sequences = (); |
| 15 |
|
| 16 |
my $seqbuf = ""; |
| 17 |
while(my $line = <STDIN>) { |
| 18 |
|
| 19 |
if(substr($line,0,1) eq ">") { |
| 20 |
push @sequences, $seqbuf unless $seqbuf eq ""; |
| 21 |
$seqbuf = ""; |
| 22 |
} |
| 23 |
|
| 24 |
$seqbuf .= $line; |
| 25 |
} |
| 26 |
push @sequences, $seqbuf unless $seqbuf eq ""; |
| 27 |
my $seqcount = ((scalar @sequences) * $percentage) / 100; |
| 28 |
|
| 29 |
print STDERR "Got " . (scalar @sequences) . " sequences. Will take $seqcount ($percentage%) of them. \n"; |
| 30 |
|
| 31 |
my @shuffled = shuffle(@sequences); |
| 32 |
|
| 33 |
for(my $i = 0; $i < $seqcount; $i++) { |
| 34 |
print $shuffled[$i]; |
| 35 |
} |