App-Dazz

 view release on metacpan or  search on metacpan

lib/App/Dazz/Command/show2ovlp.pm  view on Meta::CPAN

package App::Dazz::Command::show2ovlp;
use strict;
use warnings;
use autodie;

use App::Dazz -command;
use App::Dazz::Common;

use constant abstract => 'LAshow outputs to overlaps';

sub opt_spec {
    return (
        [ "outfile|o=s", "output filename, [stdout] for screen" ],
        [ 'replace|r=s', 'original names of sequences', ],
        { show_defaults => 1, }
    );
}

sub usage_desc {
    return "dazz show2ovlp [options] <fasta file> <LAshow outputs>";
}

sub description {
    my $desc;
    $desc .= ucfirst(abstract) . ".\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} ) {
        next if lc $_ eq "stdin";
        if ( !Path::Tiny::path($_)->is_file ) {
            $self->usage_error("The input file [$_] doesn't exist.");
        }
    }

    if ( exists $opt->{replace} ) {
        if ( !Path::Tiny::path( $opt->{replace} )->is_file ) {
            $self->usage_error("The replace file [$opt->{replace}] doesn't exist.\n");
        }
    }

    if ( !exists $opt->{outfile} ) {
        $opt->{outfile} = Path::Tiny::path( $args->[1] )->absolute . ".ovlp.tsv";
    }
}

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

    my $len_of = App::Dazz::Common::get_len_from_header( $args->[0] );

    #    print STDERR "Get @{[scalar keys %{$len_of}]} records of sequence length\n";

    my $replace_of = {};
    if ( exists $opt->{replace} ) {
        $replace_of = App::Dazz::Common::get_replaces( $opt->{replace} );
    }

    # A stream from 'stdin' or a standard file.
    my $in_fh;
    if ( lc $args->[1] eq 'stdin' ) {
        $in_fh = *STDIN{IO};
    }
    else {
        open $in_fh, "<", $args->[1];
    }

    # A stream to 'stdout' or a standard file.
    my $out_fh;
    if ( lc $opt->{outfile} eq "stdout" ) {
        $out_fh = *STDOUT{IO};
    }
    else {
        open $out_fh, ">", $opt->{outfile};
    }

    while ( my $line = <$in_fh> ) {
        $line =~ s/,//g;
        $line =~ m{
            ^\D*



( run in 0.516 second using v1.01-cache-2.11-cpan-98e64b0badf )