App-Anchr

 view release on metacpan or  search on metacpan

lib/App/Anchr/Command/overlap2.pm  view on Meta::CPAN

package App::Anchr::Command::overlap2;
use strict;
use warnings;
use autodie;

use App::Anchr -command;
use App::Anchr::Common;

use constant abstract => "detect overlaps between two (large) files by daligner";

sub opt_spec {
    return (
        [ "dir|d=s",      "working directory",            { default => "." }, ],
        [ "p1=s",         "prefix of first file",         { default => "anchor" }, ],
        [ "p2=s",         "prefix of second file",        { default => "long" }, ],
        [ "pd=s",         "prefix of result files", ],
        [ "block|b=i",    "block size in Mbp",            { default => 20 }, ],
        [ "len|l=i",      "minimal length of overlaps",   { default => 1000 }, ],
        [ "idt|i=f",      "minimal identity of overlaps", { default => 0.8 }, ],
        [ "all",          "all overlaps instead of proper overlaps", ],
        [ "parallel|p=i", "number of threads",            { default => 8 }, ],
        [ "verbose|v",    "verbose mode", ],
        { show_defaults => 1, }
    );
}

sub usage_desc {
    return "anchr overlap2 [options] <infile1> <infile2>";
}

sub description {
    my $desc;
    $desc .= ucfirst(abstract) . ".\n";
    $desc .= "\tAll intermediate files (.fasta, .replace.tsv, .db, .las, .show.txt, .ovlp.tsv)";
    $desc .= " are keept in the working directory.\n";
    return $desc;
}

sub validate_args {
    my ( $self, $opt, $args ) = @_;

    if ( @{$args} != 2 ) {
        my $message = "This command need two input files.\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.");
        }
    }

    $opt->{dir} = Path::Tiny::path( $opt->{dir} )->absolute()->stringify;

    if ( $opt->{p1} eq $opt->{p2} ) {
        $self->usage_error("Two prefixes shouldn't be same.");
    }

    if ( !exists $opt->{pd} ) {
        $opt->{pd} = $opt->{p1} . ucfirst( $opt->{p2} );
    }
}

sub execute {
    my ( $self, $opt, $args ) = @_;

    #@type Path::Tiny
    my $out_dir = Path::Tiny::path( $opt->{dir} );
    $out_dir->mkpath();

    # absolute paths before we chdir to $out_dir
    my $file1 = Path::Tiny::path( $args->[0] )->absolute->stringify;
    my $file2 = Path::Tiny::path( $args->[1] )->absolute->stringify;

    # enter out dir
    chdir $out_dir;

    {    # Preprocess first file for dazzler
        my $cmd;
        $cmd .= "faops filter -l 0 $file1 stdout";



( run in 0.437 second using v1.01-cache-2.11-cpan-39bf76dae61 )