App-Egaz

 view release on metacpan or  search on metacpan

lib/App/Egaz/Command/blastmatch.pm  view on Meta::CPAN

package App::Egaz::Command::blastmatch;
use strict;
use warnings;
use autodie;

use MCE;
use MCE::Flow;

use App::Egaz -command;
use App::Egaz::Common;

sub abstract {
    return 'matched positions by blastn in genome sequences';
}

sub opt_spec {
    return (
        [ "outfile|o=s",  "Output filename. [stdout] for screen", { default => "stdout" }, ],
        [ "perchr",       "one (fake) runlist per chromosome", ],
        [ "coverage|c=f", "coverage of identical matches",        { default => 0.9 }, ],
        [ "batch=i",      "batch size of blast records",          { default => 500000 }, ],
        [ "parallel|p=i", "number of threads",                    { default => 2 }, ],
        [ "verbose|v",    "verbose mode", ],
        { show_defaults => 1, }
    );
}

sub usage_desc {
    return "egaz blastmatch [options] <infile>";
}

sub description {
    my $desc;
    $desc .= ucfirst(abstract) . ".\n";
    $desc .= <<'MARKDOWN';

* <infile> is reports produced by `egaz blastn`
* <infile> can't be stdin
* --perchr produces fake runlists, there might be overlaps, e.g. I:17221-25234,21428-25459

MARKDOWN

    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.");
        }
    }

}

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

    #----------------------------#
    # Parse reports
    #----------------------------#
    print STDERR "Parse reports\n";
    my $worker = sub {
        my ( $self, $chunk_ref, $chunk_id ) = @_;

        my $wid = MCE->wid;
        print STDERR "* Process task [$chunk_id] by worker #$wid\n" if $opt->{verbose};

        my @lines = @{$chunk_ref};
        my %heads;
        for my $line (@lines) {
            next if $line =~ /^#/;
            chomp $line;

            # qseqid sseqid qstart qend sstart send qlen slen nident



( run in 0.548 second using v1.01-cache-2.11-cpan-75ffa21a3d4 )