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
« blib/lib/Bio/Tradis/Parser/Bam.pm ↑ Summary blib/lib/Bio/Tradis/Analysis/InsertSite.pm »
1 package Bio::Tradis::Samtools;
2 2 $Bio::Tradis::Samtools::VERSION = '1.4.1';
3 # ABSTRACT: Change samtools syntax depending on version found
4  
5  
6 2 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 2 has 'exec' => ( is => 'ro', isa => 'Str', default => 'samtools' );
10 2 has 'threads' => ( is => 'ro', isa => 'Int', default => 1 );
11 2 has 'exec_version' => ( is => 'ro', isa => 'Str', lazy => 1, builder => '_build_exec_version' );
12  
13 sub _build_exec_version {
14 2 ▶ my ($self) = @_;
Subroutine _build_exec_version: called CC=4 SCAR=23.1
15
16 2 my $fp = $self->find_exe($self->exec);
17 2 ▶ if(!$fp)
Branch: 1 branch
BranchTrueFalseTotal
unless ($fp) 2 0 2
18 {
19 2 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 sub find_exe {
47 2 ▶ my ( $self, $bin ) = @_;
Subroutine find_exe: called CC=3 SCAR=11.1
Pod undocumented
48 2 for my $dir ( File::Spec->path ) {
49 18 my $exe = File::Spec->catfile( $dir, $bin );
50 18 ▶ return $exe if -x $exe;
Branch: 1 branch
BranchTrueFalseTotal
if -x $exe 0 18 18
51 }
52 2 return;
53 }
54  
55 sub _is_version_less_than_1 {
56 2 ▶ my ($self) = @_;
Subroutine _is_version_less_than_1: called CC=2 SCAR=11.6
57 2 ▶ 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 sub run_sort {
68 2 ▶ my ( $self, $input_file, $output_file ) = @_;
Subroutine run_sort: called CC=2 SCAR=11.6
Pod undocumented
69  
70 2 my $cmd;
71 2 ▶ 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 sub run_index {
82 0 ▶ my ( $self, $input_file ) = @_;
Subroutine run_index: not called CC=1 SCAR=6.9
Pod undocumented
83 0 system( $self->exec . " index $input_file" );
84 }
85  
86 2 ▶no Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
87 2 __PACKAGE__->meta->make_immutable;
88  
89 2 1;
90  
91 __END__
92  
93 =pod
94  
95 =encoding UTF-8
96  
97 =head1 NAME
98  
99 Bio::Tradis::Samtools - Change samtools syntax depending on version found
100  
101 =head1 VERSION
102  
103 version 1.4.1
104  
105 =head1 SYNOPSIS
106  
107 Change samtools syntax depending on version found
108 use Bio::Tradis::Samtools;
109  
110 my $obj = Bio::Tradis::Samtools->new(
111 exec => 'samtools'
112 );
113  
114 $obj->run_sort();
115  
116 =head1 AUTHOR
117  
118 Carla Cummins <path-help@sanger.ac.uk>
119  
120 =head1 COPYRIGHT AND LICENSE
121  
122 This software is Copyright (c) 2013 by Wellcome Trust Sanger Institute.
123  
124 This is free software, licensed under:
125  
126 The GNU General Public License, Version 3, June 2007
127  
128 =cut
« blib/lib/Bio/Tradis/Parser/Bam.pm ↑ Summary blib/lib/Bio/Tradis/Analysis/InsertSite.pm »