| 1 |
#!/usr/bin/env perl |
| 2 |
|
| 3 |
use strict; |
| 4 |
use warnings; |
| 5 |
use Data::Dumper; |
| 6 |
use File::Basename; |
| 7 |
use File::Path; |
| 8 |
use List::Util qw(shuffle); |
| 9 |
|
| 10 |
my $compr_extr_results_dir = $ARGV[0]; |
| 11 |
my $concat_results_dir = $ARGV[1]; |
| 12 |
my $binaries_dir = $ARGV[2]; |
| 13 |
|
| 14 |
my @archive_types = qw(bzip2 |
| 15 |
gzip); |
| 16 |
|
| 17 |
my @version_dirs = qw(v1.2 |
| 18 |
v1.5 |
| 19 |
v2.0 |
| 20 |
v2.1 |
| 21 |
v2.2); |
| 22 |
|
| 23 |
my @bzip2_fns = qw(random_1p2p0_bzip2.starch |
| 24 |
random_1p5p0_bzip2.starch |
| 25 |
random_2p0p0_bzip2.starch |
| 26 |
random_2p1p0_bzip2.starch |
| 27 |
random_2p2p0_bzip2.starch); |
| 28 |
|
| 29 |
my @gzip_fns = qw(random_1p2p0_gzip.starch |
| 30 |
random_1p5p0_gzip.starch |
| 31 |
random_2p0p0_gzip.starch |
| 32 |
random_2p1p0_gzip.starch |
| 33 |
random_2p2p0_gzip.starch); |
| 34 |
|
| 35 |
my @elem_counts = qw(200000 |
| 36 |
200000 |
| 37 |
200000 |
| 38 |
200000 |
| 39 |
200000); |
| 40 |
|
| 41 |
my $version_str = "v2.2"; |
| 42 |
|
| 43 |
# this script will randomly pick five archives from the bzip2- and gzip-based starch archive pool |
| 44 |
# and pull disjoint sets of 200K elements from these files, respectively. the resulting elements |
| 45 |
# are then starch'ed into archives. |
| 46 |
|
| 47 |
foreach my $archive_type (@archive_types) { |
| 48 |
#print STDERR "making $archive_type archive...\n"; |
| 49 |
# total of ten files |
| 50 |
my @fn_indices = (0..9); |
| 51 |
my @shuffled_indices = shuffle (@fn_indices); |
| 52 |
# we grab the first five indices |
| 53 |
my @inds = @shuffled_indices[0..4]; |
| 54 |
my @fns = (); |
| 55 |
undef @fns; |
| 56 |
# grab either a bzip2 or gzip archive at random |
| 57 |
foreach my $ind (@inds) { |
| 58 |
if ($ind < 5) { |
| 59 |
push (@fns, $bzip2_fns[$ind]); |
| 60 |
} |
| 61 |
else { |
| 62 |
push (@fns, $gzip_fns[$ind - 5]); |
| 63 |
} |
| 64 |
} |
| 65 |
my @select_inds = (0..4); |
| 66 |
my $total_line_count = 0; |
| 67 |
foreach my $ind (@select_inds) { |
| 68 |
my $real_line_count = 0; |
| 69 |
my $current_line_count = $total_line_count; |
| 70 |
my $elem_count = $elem_counts[$ind]; |
| 71 |
$total_line_count += $elem_count; |
| 72 |
# extract |
| 73 |
#print STDERR "extracting $elem_count elements from $fns[$ind] | $real_line_count | $current_line_count | $elem_count | $total_line_count\n"; |
| 74 |
my $unstarch_binary = "$binaries_dir/$version_str/bin/unstarch"; |
| 75 |
open ARCH, "$unstarch_binary $compr_extr_results_dir/$fns[$ind] |" or die "could not unstarch: $compr_extr_results_dir/$fns[$ind]\n"; |
| 76 |
my $intermediate_out_fn = "$concat_results_dir/version_test_"."$archive_type"."_"."$current_line_count-$total_line_count.bed"; |
| 77 |
open OUT, "> $intermediate_out_fn" or die "could not open handle to intermediate output: $intermediate_out_fn\n"; |
| 78 |
while (<ARCH>) { |
| 79 |
if ($real_line_count == $total_line_count) { |
| 80 |
next; |
| 81 |
} |
| 82 |
if (($real_line_count >= $current_line_count) && ($real_line_count < $total_line_count)) { |
| 83 |
print OUT $_; |
| 84 |
} |
| 85 |
$real_line_count++; |
| 86 |
} |
| 87 |
close OUT; |
| 88 |
close ARCH; |
| 89 |
# compress |
| 90 |
my $starch_binary = "$binaries_dir/$version_dirs[$ind]/bin/starch"; |
| 91 |
#print STDERR "starch binary: $starch_binary\n"; |
| 92 |
my $final_out_fn = "$intermediate_out_fn.starch"; |
| 93 |
system ("$starch_binary --$archive_type $intermediate_out_fn > $final_out_fn") == 0 or die "could not create final starch output!\n$?\n"; |
| 94 |
# cleanup |
| 95 |
system ("rm $intermediate_out_fn") == 0 or die "could not delete intermediate file: $intermediate_out_fn\n$?\n"; |
| 96 |
} |
| 97 |
} |