| 1 | #!/usr/bin/env perl | ||
| 2 | # PODNAME: resample-ali.pl | ||
| 3 | # ABSTRACT: Resample ALI files using (variable length) bootstrap or jackknife | ||
| 4 | |||
| 5 | use Modern::Perl '2011'; | ||
| 6 | use autodie; | ||
| 7 | |||
| 8 | use File::Basename; | ||
| 9 | use Getopt::Euclid qw(:vars); | ||
| 10 | use Path::Class qw(dir file); | ||
| 11 | use POSIX; | ||
| 12 | use Smart::Comments; | ||
| 13 | |||
| 14 | use Bio::MUST::Core; | ||
| 15 | use Bio::MUST::Core::Utils qw(change_suffix append_suffix); | ||
| 16 | use aliased 'Bio::MUST::Core::Ali'; | ||
| 17 | use aliased 'Bio::MUST::Core::SeqMask::Weights'; | ||
| 18 | |||
| 19 | |||
| 20 | # setup resampling method | ||
| 21 | my $method = $ARGV_resampling . '_masks'; | ||
| 22 | |||
| 23 | # setup replicate numbering format | ||
| 24 | my $field = ceil( log($ARGV_replicates) / log(10) ); | ||
| 25 | |||
| 26 | for my $infile (@ARGV_infiles) { | ||
| 27 | |||
| 28 | ### Processing: $infile | ||
| 29 | my $ali = Ali->load($infile); | ||
| 30 | |||
| 31 | # create output directory named after input file and resampling mode | ||
| 32 | my $outdir = append_suffix( | ||
| 33 | change_suffix($infile, q{}), "-$ARGV_resampling" | ||
| 34 | ); | ||
| 35 | |||
| 36 | for my $width (@ARGV_width) { | ||
| 37 | |||
| 38 | # create output subdirectory named after width | ||
| 39 | my $subdir = dir( $outdir, 'width-' . $width )->relative; | ||
| 40 | ### REPDIR: $subdir->stringify | ||
| 41 | $subdir->mkpath(); | ||
| 42 | |||
| 43 | # generate resampling masks for Ali | ||
| 44 | my @masks = Weights->$method( | ||
| 45 | $ali, { 'rep' => $ARGV_replicates, 'width' => $width } | ||
| 46 | ); | ||
| 47 | |||
| 48 | # apply masks to generate pseudo-replicates | ||
| 49 | for my $rep (0..$ARGV_replicates-1) { | ||
| 50 | my $new_ali = $masks[$rep]->filtered_ali($ali); | ||
| 51 | my $filename = sprintf 'replicate-%0*d.ali', $field, $rep; | ||
| 52 | ### REP file: $filename | ||
| 53 | my $outfile = file($subdir, $filename); | ||
| 54 | $new_ali->store($outfile); | ||
| 55 | } | ||
| 56 | } | ||
| 57 | } | ||
| 58 | |||
| 59 | __END__ |