#!/user/bin/perl -w # Use your own path use strict; # always use strict my $file = "josh_vamps_seqs_ALL.fa"; open (FILE, $file) or die "$0: $!"; # printing errors is a Good Thing (tm) my @file = ; # Store all the lines in an array close FILE; open OUT, ">rarefaction.fa" or die "$0: $!"; # Caution: will overwrite any existing files my $i; for ($i = 0; $i<4266;$i++) { # Start sampling loop my $rand = int(rand($#file)); # rand gives you a random number between 0 and the number of lines remaining in the array, note # that this number is by necessity dynamic, it will drop 1000, 999, 998, etc. my $sample = splice @file, $rand, 1; # Cut out the $rand-th line, offset 1 means just one line print OUT $sample; } # end of for loop