line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::Rangeops::Command::sort; |
2
|
9
|
|
|
9
|
|
5736
|
use strict; |
|
9
|
|
|
|
|
22
|
|
|
9
|
|
|
|
|
235
|
|
3
|
9
|
|
|
9
|
|
44
|
use warnings; |
|
9
|
|
|
|
|
21
|
|
|
9
|
|
|
|
|
182
|
|
4
|
9
|
|
|
9
|
|
43
|
use autodie; |
|
9
|
|
|
|
|
22
|
|
|
9
|
|
|
|
|
66
|
|
5
|
|
|
|
|
|
|
|
6
|
9
|
|
|
9
|
|
43684
|
use App::Rangeops -command; |
|
9
|
|
|
|
|
21
|
|
|
9
|
|
|
|
|
82
|
|
7
|
9
|
|
|
9
|
|
2926
|
use App::Rangeops::Common; |
|
9
|
|
|
|
|
25
|
|
|
9
|
|
|
|
|
224
|
|
8
|
|
|
|
|
|
|
|
9
|
9
|
|
|
9
|
|
46
|
use constant abstract => 'sort links and ranges within links'; |
|
9
|
|
|
|
|
16
|
|
|
9
|
|
|
|
|
4715
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub opt_spec { |
12
|
|
|
|
|
|
|
return ( |
13
|
2
|
|
|
2
|
1
|
11
|
[ "outfile|o=s", "Output filename. [stdout] for screen." ], |
14
|
|
|
|
|
|
|
[ "numeric|n", "Sort chromosome names numerically.", ], |
15
|
|
|
|
|
|
|
); |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub usage_desc { |
19
|
2
|
|
|
2
|
1
|
26294
|
return "rangeops sort [options] "; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub description { |
23
|
1
|
|
|
1
|
1
|
648
|
my $desc; |
24
|
1
|
|
|
|
|
3
|
$desc .= ucfirst(abstract) . ".\n"; |
25
|
1
|
|
|
|
|
3
|
return $desc; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub validate_args { |
29
|
1
|
|
|
1
|
1
|
813
|
my ( $self, $opt, $args ) = @_; |
30
|
|
|
|
|
|
|
|
31
|
1
|
50
|
|
|
|
3
|
if ( !@{$args} ) { |
|
1
|
|
|
|
|
5
|
|
32
|
0
|
|
|
|
|
0
|
$self->usage_error("This command need one or more input files."); |
33
|
|
|
|
|
|
|
} |
34
|
1
|
|
|
|
|
3
|
for ( @{$args} ) { |
|
1
|
|
|
|
|
3
|
|
35
|
1
|
50
|
|
|
|
5
|
next if lc $_ eq "stdin"; |
36
|
1
|
50
|
|
|
|
8
|
if ( !Path::Tiny::path($_)->is_file ) { |
37
|
0
|
|
|
|
|
0
|
$self->usage_error("The input file [$_] doesn't exist."); |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
1
|
50
|
|
|
|
117
|
if ( !exists $opt->{outfile} ) { |
42
|
|
|
|
|
|
|
$opt->{outfile} |
43
|
0
|
|
|
|
|
0
|
= Path::Tiny::path( $args->[0] )->absolute . ".sort.tsv"; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub execute { |
48
|
1
|
|
|
1
|
1
|
6
|
my ( $self, $opt, $args ) = @_; |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
#----------------------------# |
51
|
|
|
|
|
|
|
# Loading |
52
|
|
|
|
|
|
|
#----------------------------# |
53
|
1
|
|
|
|
|
2
|
my @lines; |
54
|
1
|
|
|
|
|
3
|
for my $file ( @{$args} ) { |
|
1
|
|
|
|
|
3
|
|
55
|
1
|
|
|
|
|
7
|
for my $line ( App::RL::Common::read_lines($file) ) { |
56
|
29
|
|
|
|
|
3245
|
for my $part ( split /\t/, $line ) { |
57
|
87
|
|
|
|
|
189
|
my $info = App::RL::Common::decode_header($part); |
58
|
87
|
100
|
|
|
|
9821
|
next unless App::RL::Common::info_is_valid($info); |
59
|
|
|
|
|
|
|
|
60
|
58
|
|
|
|
|
1603
|
push @lines, $line; # May produce duplicated lines |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
} |
64
|
1
|
|
|
|
|
35
|
@lines = List::MoreUtils::PP::uniq(@lines); |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
#----------------------------# |
67
|
|
|
|
|
|
|
# Sort |
68
|
|
|
|
|
|
|
#----------------------------# |
69
|
|
|
|
|
|
|
my @sorted_lines |
70
|
1
|
|
|
|
|
136
|
= @{ App::Rangeops::Common::sort_links( \@lines, $opt->{numeric} ) }; |
|
1
|
|
|
|
|
8
|
|
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
#----------------------------# |
73
|
|
|
|
|
|
|
# Output |
74
|
|
|
|
|
|
|
#----------------------------# |
75
|
1
|
|
|
|
|
4
|
my $out_fh; |
76
|
1
|
50
|
|
|
|
5
|
if ( lc( $opt->{outfile} ) eq "stdout" ) { |
77
|
1
|
|
|
|
|
4
|
$out_fh = \*STDOUT; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
else { |
80
|
0
|
|
|
|
|
0
|
open $out_fh, ">", $opt->{outfile}; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
1
|
|
|
|
|
4
|
print {$out_fh} "$_\n" for @sorted_lines; |
|
15
|
|
|
|
|
189
|
|
84
|
|
|
|
|
|
|
|
85
|
1
|
|
|
|
|
16
|
close $out_fh; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
1; |