line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Bio::Tradis::Samtools; |
2
|
|
|
|
|
|
|
$Bio::Tradis::Samtools::VERSION = '1.3.2'; |
3
|
|
|
|
|
|
|
# ABSTRACT: Change samtools syntax depending on version found |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
10
|
use Moose; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
13
|
|
7
|
2
|
|
|
2
|
|
12357
|
use File::Spec; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
751
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
has 'exec' => ( is => 'ro', isa => 'Str', default => 'samtools' ); |
10
|
|
|
|
|
|
|
has 'threads' => ( is => 'ro', isa => 'Int', default => 1 ); |
11
|
|
|
|
|
|
|
has 'exec_version' => ( is => 'ro', isa => 'Str', lazy => 1, builder => '_build_exec_version' ); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub _build_exec_version { |
14
|
2
|
|
|
2
|
|
6
|
my ($self) = @_; |
15
|
|
|
|
|
|
|
|
16
|
2
|
|
|
|
|
45
|
my $fp = $self->find_exe($self->exec); |
17
|
2
|
50
|
|
|
|
9
|
if(!$fp) |
18
|
|
|
|
|
|
|
{ |
19
|
2
|
|
|
|
|
85
|
exit("ERROR: Can't find required ".$self->exec." in your \$PATH"); |
20
|
|
|
|
|
|
|
} |
21
|
0
|
|
|
|
|
0
|
my $cmd_version = $self->exec." 2>&1 | grep Version"; |
22
|
0
|
|
|
|
|
0
|
my ($version_string) = qx($cmd_version); |
23
|
|
|
|
|
|
|
|
24
|
0
|
0
|
|
|
|
0
|
if(defined($version_string)) |
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
|
0
|
|
|
|
0
|
if($version_string =~ /Version:[\t\s]+(\d+)\.(\d+)/) |
30
|
|
|
|
|
|
|
{ |
31
|
0
|
|
|
|
|
0
|
return $1.'.'.$2; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
else |
34
|
|
|
|
|
|
|
{ |
35
|
0
|
|
|
|
|
0
|
print STDERR "ERROR: Couldn't identify samtools version"; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
else |
39
|
|
|
|
|
|
|
{ |
40
|
0
|
|
|
|
|
0
|
print STDERR "ERROR: Couldn't identify samtools version"; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
# reasonable fallback |
43
|
0
|
|
|
|
|
0
|
return '0.1'; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub find_exe { |
47
|
2
|
|
|
2
|
0
|
8
|
my ( $self, $bin ) = @_; |
48
|
2
|
|
|
|
|
63
|
for my $dir ( File::Spec->path ) { |
49
|
14
|
|
|
|
|
89
|
my $exe = File::Spec->catfile( $dir, $bin ); |
50
|
14
|
50
|
|
|
|
104
|
return $exe if -x $exe; |
51
|
|
|
|
|
|
|
} |
52
|
2
|
|
|
|
|
41
|
return; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub _is_version_less_than_1 { |
56
|
2
|
|
|
2
|
|
6
|
my ($self) = @_; |
57
|
2
|
0
|
|
|
|
46
|
if($self->exec_version < 1.0) |
58
|
|
|
|
|
|
|
{ |
59
|
0
|
|
|
|
|
0
|
return 1; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
else |
62
|
|
|
|
|
|
|
{ |
63
|
0
|
|
|
|
|
0
|
return 0; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub run_sort { |
68
|
2
|
|
|
2
|
0
|
6
|
my ( $self, $input_file, $output_file ) = @_; |
69
|
|
|
|
|
|
|
|
70
|
2
|
|
|
|
|
3
|
my $cmd; |
71
|
2
|
0
|
|
|
|
12
|
if ( $self->_is_version_less_than_1 ) { |
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
|
|
|
0
|
0
|
|
my ( $self, $input_file ) = @_; |
83
|
0
|
|
|
|
|
|
system( $self->exec . " index $input_file" ); |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
2
|
|
|
2
|
|
12
|
no Moose; |
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
8
|
|
87
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
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.3.2 |
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 |