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