App-Dazz
view release on metacpan or search on metacpan
lib/App/Dazz/Command/cover.pm view on Meta::CPAN
package App::Dazz::Command::cover;
use strict;
use warnings;
use autodie;
use App::Dazz -command;
use App::Dazz::Common;
use constant abstract => "trusted regions in the first file covered by the second";
sub opt_spec {
return (
[ "outfile|o=s", "output filename, [stdout] for screen", ],
[ "range|r=s", "ranges of first sequences", { required => 1 }, ],
[ 'coverage|c=i', 'minimal coverage', { default => 2 }, ],
[ 'max|m=i', 'maximal coverage', { default => 200 }, ],
[ "len|l=i", "minimal length of overlaps", { default => 1000 }, ],
[ "idt|i=f", "minimal identity of overlaps", { default => 0.85 }, ],
[ "tmp=s", "user defined tempdir", ],
[ "verbose|v", "verbose mode", ],
{ show_defaults => 1, }
);
}
sub usage_desc {
return "dazz cover [options] <.ovlp.tsv>";
}
sub description {
my $desc;
$desc .= ucfirst(abstract) . ".\n";
$desc .= "\tAll operations are running in a tempdir and no intermediate files are kept.\n";
return $desc;
}
sub validate_args {
my ( $self, $opt, $args ) = @_;
if ( @{$args} != 1 ) {
my $message = "This command need one input file.\n\tIt found";
$message .= sprintf " [%s]", $_ for @{$args};
$message .= ".\n";
$self->usage_error($message);
}
for ( @{$args} ) {
if ( !Path::Tiny::path($_)->is_file ) {
$self->usage_error("The input file [$_] doesn't exist.");
}
}
if ( !exists $opt->{outfile} ) {
$opt->{outfile} = Path::Tiny::path( $args->[0] )->absolute . ".cover.json";
}
}
sub execute {
my ( $self, $opt, $args ) = @_;
# make paths absolute before we chdir
my $infile = Path::Tiny::path( $args->[0] )->absolute->stringify;
if ( lc $opt->{outfile} ne "stdout" ) {
$opt->{outfile} = Path::Tiny::path( $opt->{outfile} )->absolute->stringify;
}
# record cwd, we'll return there
my $cwd = Path::Tiny->cwd;
my $tempdir;
if ( $opt->{tmp} ) {
$tempdir = Path::Tiny->tempdir(
TEMPLATE => "dazz_cover_XXXXXXXX",
DIR => $opt->{tmp},
);
}
else {
$tempdir = Path::Tiny->tempdir("dazz_cover_XXXXXXXX");
}
chdir $tempdir;
my $basename = $tempdir->basename();
$basename =~ s/\W+/_/g;
#@type AlignDB::IntSpan
my $first_range = AlignDB::IntSpan->new->add_runlist( $opt->{range} );
{
# paf to meancov
my $cmd;
$cmd .= "ovlpr covered";
$cmd .= " $infile";
$cmd .= " --coverage $opt->{max}";
$cmd .= " --mean";
$cmd .= " --len $opt->{len} --idt $opt->{idt}";
$cmd .= " -o $basename.meancov.txt";
App::Dazz::Common::exec_cmd( $cmd, { verbose => $opt->{verbose}, } );
( run in 0.990 second using v1.01-cache-2.11-cpan-97f6503c9c8 )