Bio-MUST-Core

 view release on metacpan or  search on metacpan

bin/resample-ali.pl  view on Meta::CPAN

#!/usr/bin/env perl
# PODNAME: resample-ali.pl
# ABSTRACT: Resample ALI files using (variable length) bootstrap or jackknife

use Modern::Perl '2011';
use autodie;

use File::Basename;
use Getopt::Euclid qw(:vars);
use Path::Class qw(dir file);
use POSIX;
use Smart::Comments;

use Bio::MUST::Core;
use Bio::MUST::Core::Utils qw(change_suffix append_suffix);
use aliased 'Bio::MUST::Core::Ali';
use aliased 'Bio::MUST::Core::SeqMask::Weights';


# setup resampling method
my $method = $ARGV_resampling . '_masks';

# setup replicate numbering format
my $field = ceil( log($ARGV_replicates) / log(10) );

for my $infile (@ARGV_infiles) {

    ### Processing: $infile
    my $ali = Ali->load($infile);

    # create output directory named after input file and resampling mode
    my $outdir = append_suffix(
        change_suffix($infile, q{}), "-$ARGV_resampling"
    );

    for my $width (@ARGV_width) {

        # create output subdirectory named after width
        my $subdir = dir( $outdir, 'width-' . $width )->relative;
        ### REPDIR: $subdir->stringify
        $subdir->mkpath();

        # generate resampling masks for Ali
        my @masks = Weights->$method(
            $ali, { 'rep' => $ARGV_replicates, 'width' => $width }
        );

        # apply masks to generate pseudo-replicates
        for my $rep (0..$ARGV_replicates-1) {
            my $new_ali = $masks[$rep]->filtered_ali($ali);
            my $filename = sprintf 'replicate-%0*d.ali', $field, $rep;
            ### REP file: $filename
            my $outfile = file($subdir, $filename);
            $new_ali->store($outfile);
        }
    }
}

__END__

=pod

=head1 NAME

resample-ali.pl - Resample ALI files using (variable length) bootstrap or jackknife



( run in 0.448 second using v1.01-cache-2.11-cpan-437f7b0c052 )