lib/Bio/Tradis/Samtools.pm

filter: Statementstmt 64.4% 29 / 45 Branchbran 16.6% 2 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 87.5% 7 / 8 Podpod 0.0% 0 / 3 totaltotal 55.8% 38 / 68 CC 8 SCAR 15.0
CC
8
Cov
54%
_build_exec_version
10.0
_is_version_less_than_1
3.2
run_sort
3.2
CRAP 4.5
« lib/Bio/Tradis/Analysis/InsertSite.pm ↑ Summary lib/Bio/Tradis/FilterTags.pm »
1 package Bio::Tradis::Samtools;
2 5 $Bio::Tradis::Samtools::VERSION = '1.4.5';
3 # ABSTRACT: Change samtools syntax depending on version found
4  
5  
6 5 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 5 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 5 has 'exec' => ( is => 'ro', isa => 'Str', default => 'samtools' );
10 5 has 'threads' => ( is => 'ro', isa => 'Int', default => 1 );
11 5 has 'exec_version' => ( is => 'ro', isa => 'Str', lazy => 1, builder => '_build_exec_version' );
12  
13 5 ▶sub _build_exec_version {
Subroutine _build_exec_version: called CC=4 SCAR=23.1
14 5 my ($self) = @_;
15
16 5 my $fp = $self->find_exe($self->exec);
17 5 ▶ if(!$fp)
Branch: 1 branch
BranchTrueFalseTotal
unless ($fp) 5 0 5
18 {
19 5 exit("ERROR: Can't find required ".$self->exec." in your \$PATH");
20 }
21 0 my $cmd_version = $self->exec." 2>&1 | grep Version";
22 0 my ($version_string) = qx($cmd_version);
23
24 0 ▶ if(defined($version_string))
Branch: 1 branch
BranchTrueFalseTotal
if (defined $version_string) { } 0 0 0
25 {
26 #Version: 0.1.19-44428cd
27 #Version: 1.2 (using htslib 1.2)
28 # we dont use 3rd number in version so just look for 0.1, 1.2
29 0 ▶ if($version_string =~ /Version:[\t\s]+(\d+)\.(\d+)/)
Branch: 1 branch
BranchTrueFalseTotal
if ($version_string =~ /Version:[\t\s]+(\d+)\.(\d+)/) { } 0 0 0
30 {
31 0 return $1.'.'.$2;
32 }
33 else
34 {
35 0 print STDERR "ERROR: Couldn't identify samtools version";
36 }
37 }
38 else
39 {
40 0 print STDERR "ERROR: Couldn't identify samtools version";
41 }
42 # reasonable fallback
43 0 return '0.1';
44 }
45  
46 5 ▶sub find_exe {
Subroutine find_exe: called CC=3 SCAR=11.1
Pod undocumented
47 5 my ( $self, $bin ) = @_;
48 5 for my $dir ( File::Spec->path ) {
49 50 my $exe = File::Spec->catfile( $dir, $bin );
50 50 ▶ return $exe if -x $exe;
Branch: 1 branch
BranchTrueFalseTotal
if -x $exe 0 50 50
51 }
52 5 return;
53 }
54  
55 5 ▶sub _is_version_less_than_1 {
Subroutine _is_version_less_than_1: called CC=2 SCAR=11.6
56 5 my ($self) = @_;
57 5 ▶ if($self->exec_version < 1.0)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->exec_version < 1.0) { } 0 0 0
58 {
59 0 return 1;
60 }
61 else
62 {
63 0 return 0;
64 }
65 }
66  
67 5 ▶sub run_sort {
Subroutine run_sort: called CC=2 SCAR=11.6
Pod undocumented
68 5 my ( $self, $input_file, $output_file ) = @_;
69  
70 5 my $cmd;
71 5 ▶ if ( $self->_is_version_less_than_1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_is_version_less_than_1) { } 0 0 0
72 0 $output_file =~ s/\.bam//i;
73 0 $cmd = join( ' ', ( $self->exec, 'sort', $input_file, $output_file) );
74 }
75 else {
76 0 $cmd = join( ' ', ( $self->exec, 'sort', '-@', $self->threads, '-O', 'bam', '-T', $input_file.'.tmp', '-o', $output_file, $input_file ) );
77 }
78 0 system($cmd);
79 }
80  
81 0 ▶sub run_index {
Subroutine run_index: not called CC=1 SCAR=6.9
Pod undocumented
82 0 my ( $self, $input_file ) = @_;
83 0 system( $self->exec . " index $input_file" );
84 }
85  
86 5 ▶no Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
87 5 __PACKAGE__->meta->make_immutable;
88  
89 5 1;
90  
91 __END__
« lib/Bio/Tradis/Analysis/InsertSite.pm ↑ Summary lib/Bio/Tradis/FilterTags.pm »