Bio-Tradis

 view release on metacpan or  search on metacpan

lib/Bio/Tradis/CommandLine/TradisBam.pm  view on Meta::CPAN

package Bio::Tradis::CommandLine::TradisBam;
$Bio::Tradis::CommandLine::TradisBam::VERSION = '1.4.5';
# ABSTRACT: Adds tags to sequences if tags are present


use Moose;
use Getopt::Long qw(GetOptionsFromArray);
use Cwd 'abs_path';
use Bio::Tradis::DetectTags;
use Bio::Tradis::AddTagsToSeq;

has 'args'        => ( is => 'ro', isa => 'ArrayRef', required => 1 );
has 'script_name' => ( is => 'ro', isa => 'Str',      required => 1 );
has 'bamfile'     => ( is => 'rw', isa => 'Str',      required => 1 );
has 'outfile'     => (
    is       => 'rw',
    isa      => 'Str',
    required => 0,
);
has 'help' => ( is => 'rw', isa => 'Bool', required => 0 );
has 'verbose'       => ( is => 'rw', isa => 'Bool', default => 0 );
has 'samtools_exec' => ( is => 'rw', isa => 'Str', default => 'samtools' );

sub BUILD {
    my ($self) = @_;

    my ( $bamfile, $help, $outfile, $verbose, $samtools_exec );

    GetOptionsFromArray(
        $self->args,
        'b|bamfile=s' => \$bamfile,
        'o|outfile=s' => \$outfile,
        'h|help'      => \$help,
        'v|verbose'         => \$verbose,
        'samtools_exec=s'   => \$samtools_exec,
    );

    $self->bamfile( abs_path($bamfile) ) if ( defined($bamfile) );
    if (defined($outfile)) {
        $self->outfile( abs_path($outfile) )
    }
    else {
        my $o = $self->bamfile;
        $o =~ s/\.bam/\.tr\.bam/;
        $self->outfile( abs_path($o) );
    }

    $self->help($help)                   if ( defined($help) );
    $self->verbose($verbose)             if ( defined($verbose) );
    $self->samtools_exec($samtools_exec) if ( defined($samtools_exec) );

	# print usage text if required parameters are not present
	($bamfile) or die $self->usage_text;
}

sub run {
    my ($self) = @_;

    if ( defined( $self->help ) ) {
        $self->usage_text;
    }

    my $is_tradis =
      Bio::Tradis::DetectTags->new( 
        bamfile       => $self->bamfile, 
        samtools_exec => $self->samtools_exec 
      )->tags_present;
    if ( defined($is_tradis) && $is_tradis == 1 ) {
        my $add_tag_obj = Bio::Tradis::AddTagsToSeq->new(
            bamfile       => $self->bamfile,
            outfile       => $self->outfile,
            verbose       => $self->verbose,



( run in 0.629 second using v1.01-cache-2.11-cpan-0bb4e1dffa6 )