blib/lib/Bio/Tradis/CommandLine/TradisBam.pm untested

filter: Statementstmt 0.0% 0 / 50 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 0.0% 0 / 9 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 84 CC 8 SCAR 29.4
CC
8
Cov
0%
BUILD
42.0
run
12.0
usage_text
2.0
CRAP 18.9
1 package Bio::Tradis::CommandLine::TradisBam;
2 $Bio::Tradis::CommandLine::TradisBam::VERSION = '1.4.5';
3 # ABSTRACT: Adds tags to sequences if tags are present
4  
5  
6 use Moose;
7 use Getopt::Long qw(GetOptionsFromArray);
8 use Cwd 'abs_path';
9 use Bio::Tradis::DetectTags;
10 use Bio::Tradis::AddTagsToSeq;
11  
12 has 'args' => ( is => 'ro', isa => 'ArrayRef', required => 1 );
13 has 'script_name' => ( is => 'ro', isa => 'Str', required => 1 );
14 has 'bamfile' => ( is => 'rw', isa => 'Str', required => 1 );
15 has 'outfile' => (
16 is => 'rw',
17 isa => 'Str',
18 required => 0,
19 );
20 has 'help' => ( is => 'rw', isa => 'Bool', required => 0 );
21 has 'verbose' => ( is => 'rw', isa => 'Bool', default => 0 );
22 has 'samtools_exec' => ( is => 'rw', isa => 'Str', default => 'samtools' );
23  
24 sub BUILD {
25 my ($self) = @_;
26  
27 my ( $bamfile, $help, $outfile, $verbose, $samtools_exec );
28  
29 GetOptionsFromArray(
30 $self->args,
31 'b|bamfile=s' => \$bamfile,
32 'o|outfile=s' => \$outfile,
33 'h|help' => \$help,
34 'v|verbose' => \$verbose,
35 'samtools_exec=s' => \$samtools_exec,
36 );
37  
38 $self->bamfile( abs_path($bamfile) ) if ( defined($bamfile) );
39 if (defined($outfile)) {
40 $self->outfile( abs_path($outfile) )
41 }
42 else {
43 my $o = $self->bamfile;
44 $o =~ s/\.bam/\.tr\.bam/;
45 $self->outfile( abs_path($o) );
46 }
47  
48 $self->help($help) if ( defined($help) );
49 $self->verbose($verbose) if ( defined($verbose) );
50 $self->samtools_exec($samtools_exec) if ( defined($samtools_exec) );
51  
52 # print usage text if required parameters are not present
53 ($bamfile) or die $self->usage_text;
54 }
55  
56 sub run {
57 my ($self) = @_;
58  
59 if ( defined( $self->help ) ) {
60 $self->usage_text;
61 }
62  
63 my $is_tradis =
64 Bio::Tradis::DetectTags->new(
65 bamfile => $self->bamfile,
66 samtools_exec => $self->samtools_exec
67 )->tags_present;
68 if ( defined($is_tradis) && $is_tradis == 1 ) {
69 my $add_tag_obj = Bio::Tradis::AddTagsToSeq->new(
70 bamfile => $self->bamfile,
71 outfile => $self->outfile,
72 verbose => $self->verbose,
73 samtools_exec => $self->samtools_exec
74 );
75 $add_tag_obj->add_tags_to_seq;
76 }
77 }
78  
79 sub usage_text {
80 print <<USAGE;
81 Checks for tradis tags in the BAM and outputs processed TraDIS BAM file
82 with tags attached
83  
84 Usage: bam_to_tradis_bam -b file.bam [options]
85  
86 Options:
87 -b : bam file
88 -o : output BAM name (optional. default: <file>.tr.bam)
89 -v : verbose debugging output
90 USAGE
91 exit;
92 }
93  
94 __PACKAGE__->meta->make_immutable;
95 no Moose;
96 1;
97  
98 __END__