App-Anchr

 view release on metacpan or  search on metacpan

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

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

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

use constant abstract => "trim PE Illumina fastq files";

sub opt_spec {
    return (
        [ "outfile|o=s",  "output filename, [stdout] for screen",      { default => "trim.sh" }, ],
        [ "basename|b=s", "prefix of fastq filenames",                 { default => "R" }, ],
        [ "len|l=i",      "filter reads less or equal to this length", { default => 80 }, ],
        [ "qual|q=i",     "quality threshold",                         { default => 20 }, ],
        [   "adapter|a=s", "adapter file",
            { default => File::ShareDir::dist_file( 'App-Anchr', 'illumina_adapters.fa' ) },
        ],
        [ "noscythe", "skip the scythe step", ],
        [ "parallel|p=i", "number of threads", { default => 8 }, ],
        { show_defaults => 1, }
    );
}

sub usage_desc {
    return "anchr trim [options] <PE file1> <PE file2>";
}

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

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=
NC=



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