App-Anchr

 view release on metacpan or  search on metacpan

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

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

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

use constant abstract => "create k-unitigs from corrected reads";

sub opt_spec {
    return (
        [ "outfile|o=s",  "output filename, [stdout] for screen", { default => "kunitigs.sh" }, ],
        [ 'jf=s',         'jellyfish hash size',                  { default => "auto", }, ],
        [ 'estsize=s',    'estimated genome size',                { default => "auto", }, ],
        [ 'kmer=s',       'kmer size to be used for super reads', { default => "auto", }, ],
        [ 'min=i',        'minimal length of k-unitigs',          { default => 500, }, ],
        [ 'parallel|p=i', 'number of threads',                    { default => 8, }, ],
        { show_defaults => 1, }
    );
}

sub usage_desc {
    return "anchr kunitigs [options] <pe.cor.fa> <environment.json>";
}

sub description {
    my $desc;
    $desc .= ucfirst(abstract) . ".\n";
    $desc .= "\tFasta files can be gzipped\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.");
        }
    }

    if ( $opt->{kmer} ne 'auto' ) {
        unless ( $opt->{kmer} =~ /^[\d,]+$/ ) {
            $self->usage_error("Invalid k-mer [$opt->{kmer}].");
        }
        $opt->{kmer} = [ sort { $a <=> $b } grep {defined} split ",", $opt->{kmer} ];
    }
}

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

    # 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};
    }

    my $tt   = Template->new;
    my $text = <<'EOF';
#!/usr/bin/env bash

#----------------------------#
# Colors in term
#----------------------------#
# http://stackoverflow.com/questions/5947742/how-to-change-the-output-color-of-echo-in-linux
GREEN=
RED=



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