| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Bio::MUST::Core::Utils; |
|
2
|
|
|
|
|
|
|
# ABSTRACT: Utility functions for enabling multiple file processing |
|
3
|
|
|
|
|
|
|
$Bio::MUST::Core::Utils::VERSION = '0.212650'; |
|
4
|
18
|
|
|
18
|
|
219505
|
use strict; |
|
|
18
|
|
|
|
|
60
|
|
|
|
18
|
|
|
|
|
542
|
|
|
5
|
18
|
|
|
18
|
|
101
|
use warnings; |
|
|
18
|
|
|
|
|
47
|
|
|
|
18
|
|
|
|
|
471
|
|
|
6
|
18
|
|
|
18
|
|
103
|
use autodie; |
|
|
18
|
|
|
|
|
43
|
|
|
|
18
|
|
|
|
|
145
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
18
|
|
|
18
|
|
96111
|
use File::Basename; |
|
|
18
|
|
|
|
|
59
|
|
|
|
18
|
|
|
|
|
1569
|
|
|
9
|
18
|
|
|
18
|
|
130
|
use Path::Class qw(file); |
|
|
18
|
|
|
|
|
46
|
|
|
|
18
|
|
|
|
|
873
|
|
|
10
|
18
|
|
|
18
|
|
8512
|
use Test::Files; |
|
|
18
|
|
|
|
|
33568
|
|
|
|
18
|
|
|
|
|
1552
|
|
|
11
|
18
|
|
|
18
|
|
168
|
use Test::Most; |
|
|
18
|
|
|
|
|
40
|
|
|
|
18
|
|
|
|
|
198
|
|
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
# TODO: use :filenames in some binaries |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
use Exporter::Easy ( |
|
16
|
18
|
|
|
|
|
244
|
OK => [ qw(secure_outfile :filenames :tests) ], |
|
17
|
|
|
|
|
|
|
TAGS => [ |
|
18
|
|
|
|
|
|
|
filenames => [ qw(insert_suffix change_suffix append_suffix) ], |
|
19
|
|
|
|
|
|
|
tests => [ qw(cmp_store cmp_float) ], |
|
20
|
|
|
|
|
|
|
], |
|
21
|
18
|
|
|
18
|
|
36759
|
); |
|
|
18
|
|
|
|
|
1646
|
|
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub secure_outfile { |
|
25
|
2
|
|
|
2
|
0
|
4768
|
my $infile = shift; |
|
26
|
2
|
|
|
|
|
5
|
my $suffix = shift; |
|
27
|
|
|
|
|
|
|
|
|
28
|
2
|
100
|
|
|
|
36
|
return insert_suffix($infile, $suffix) if defined $suffix; |
|
29
|
|
|
|
|
|
|
|
|
30
|
1
|
50
|
|
|
|
4
|
rename $infile, append_suffix($infile, '.bak') if -e $infile; |
|
31
|
1
|
|
|
|
|
1575
|
return $infile; |
|
32
|
|
|
|
|
|
|
} |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub insert_suffix { |
|
36
|
6
|
|
|
6
|
0
|
2659
|
my $infile = shift; |
|
37
|
6
|
|
|
|
|
11
|
my $string = shift; |
|
38
|
|
|
|
|
|
|
|
|
39
|
6
|
|
|
|
|
233
|
my ($filename, $directories, $suffix) = fileparse($infile, qr{\.[^.]*}xms); |
|
40
|
6
|
|
|
|
|
108
|
return $directories . $filename . $string . $suffix; |
|
41
|
|
|
|
|
|
|
} |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub change_suffix { |
|
45
|
5
|
|
|
5
|
0
|
8
|
my $infile = shift; |
|
46
|
5
|
|
|
|
|
11
|
my $suffix = shift; |
|
47
|
|
|
|
|
|
|
|
|
48
|
5
|
|
|
|
|
84
|
my ($filename, $directories) = fileparse($infile, qr{\.[^.]*}xms); |
|
49
|
5
|
|
|
|
|
22
|
return $directories . $filename . $suffix; |
|
50
|
|
|
|
|
|
|
} |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub append_suffix { |
|
54
|
6
|
|
|
6
|
0
|
119
|
my $infile = shift; |
|
55
|
6
|
|
|
|
|
10
|
my $suffix = shift; |
|
56
|
|
|
|
|
|
|
|
|
57
|
6
|
|
|
|
|
58
|
my ($filename, $directories) = fileparse($infile); |
|
58
|
6
|
|
|
|
|
92
|
return $directories . $filename . $suffix; |
|
59
|
|
|
|
|
|
|
} |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub cmp_store { |
|
63
|
84
|
|
|
84
|
0
|
5100
|
my %args = @_; |
|
64
|
|
|
|
|
|
|
my ($obj, $method, $file, $test, $args) |
|
65
|
84
|
|
|
|
|
435
|
= @args{ qw(obj method file test args) }; |
|
66
|
|
|
|
|
|
|
|
|
67
|
84
|
|
100
|
|
|
527
|
$args //= {}; # optional hash reference |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
# named output file |
|
70
|
84
|
|
|
|
|
159
|
my $outfile; |
|
71
|
84
|
100
|
|
|
|
343
|
unless ($method =~ m/\A temp_/xms) { |
|
72
|
80
|
|
|
|
|
496
|
$outfile = file('test', "my_$file"); |
|
73
|
80
|
100
|
|
|
|
9682
|
( file($outfile) )->remove if -e $outfile; |
|
74
|
80
|
|
|
|
|
8505
|
$obj->$method($outfile, $args); |
|
75
|
|
|
|
|
|
|
} |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
# anonymous temporary file |
|
78
|
84
|
|
66
|
|
|
683
|
$outfile //= $obj->$method($args); |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
# compare file contents |
|
81
|
84
|
|
|
|
|
801
|
compare_ok($outfile, file('test', $file), "$test: $file"); |
|
82
|
|
|
|
|
|
|
|
|
83
|
84
|
|
|
|
|
6033949
|
return; |
|
84
|
|
|
|
|
|
|
} |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub cmp_float { |
|
88
|
84
|
|
|
84
|
0
|
923
|
my ($got, $expect, $epsilon, $test) = @_; |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
# compare got and expect to epsilon precision |
|
91
|
84
|
|
|
|
|
350
|
cmp_ok abs($got - $expect), '<', $epsilon, $test; |
|
92
|
|
|
|
|
|
|
|
|
93
|
84
|
|
|
|
|
28065
|
return; |
|
94
|
|
|
|
|
|
|
} |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
1; |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
__END__ |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=pod |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=head1 NAME |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
Bio::MUST::Core::Utils - Utility functions for enabling multiple file processing |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=head1 VERSION |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
version 0.212650 |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
# TODO |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
# TODO |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=head1 AUTHOR |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
Denis BAURAIN <denis.baurain@uliege.be> |
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
This software is copyright (c) 2013 by University of Liege / Unit of Eukaryotic Phylogenomics / Denis BAURAIN. |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
|
127
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=cut |