line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::Rangeops::Common; |
2
|
9
|
|
|
9
|
|
1080
|
use strict; |
|
9
|
|
|
|
|
14
|
|
|
9
|
|
|
|
|
246
|
|
3
|
9
|
|
|
9
|
|
37
|
use warnings; |
|
9
|
|
|
|
|
16
|
|
|
9
|
|
|
|
|
180
|
|
4
|
9
|
|
|
9
|
|
410
|
use autodie; |
|
9
|
|
|
|
|
12346
|
|
|
9
|
|
|
|
|
33
|
|
5
|
|
|
|
|
|
|
|
6
|
9
|
|
|
9
|
|
40105
|
use 5.018001; |
|
9
|
|
|
|
|
49
|
|
7
|
|
|
|
|
|
|
|
8
|
9
|
|
|
9
|
|
42
|
use Carp; |
|
9
|
|
|
|
|
96
|
|
|
9
|
|
|
|
|
470
|
|
9
|
9
|
|
|
9
|
|
5637
|
use Graph; |
|
9
|
|
|
|
|
797935
|
|
|
9
|
|
|
|
|
276
|
|
10
|
9
|
|
|
9
|
|
4941
|
use IPC::Cmd; |
|
9
|
|
|
|
|
425859
|
|
|
9
|
|
|
|
|
376
|
|
11
|
9
|
|
|
9
|
|
4175
|
use List::MoreUtils; |
|
9
|
|
|
|
|
90220
|
|
|
9
|
|
|
|
|
47
|
|
12
|
9
|
|
|
9
|
|
12632
|
use Path::Tiny; |
|
9
|
|
|
|
|
80732
|
|
|
9
|
|
|
|
|
467
|
|
13
|
9
|
|
|
9
|
|
3496
|
use YAML::Syck; |
|
9
|
|
|
|
|
13614
|
|
|
9
|
|
|
|
|
477
|
|
14
|
|
|
|
|
|
|
|
15
|
9
|
|
|
9
|
|
4009
|
use AlignDB::IntSpan; |
|
9
|
|
|
|
|
52768
|
|
|
9
|
|
|
|
|
228
|
|
16
|
9
|
|
|
9
|
|
3292
|
use App::RL::Common; |
|
9
|
|
|
|
|
595394
|
|
|
9
|
|
|
|
|
298
|
|
17
|
9
|
|
|
9
|
|
4444
|
use App::Fasops::Common; |
|
9
|
|
|
|
|
170286
|
|
|
9
|
|
|
|
|
11200
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub build_info { |
20
|
161
|
|
|
161
|
0
|
197
|
my $line_refs = shift; |
21
|
161
|
|
|
|
|
177
|
my $info_of = shift; |
22
|
|
|
|
|
|
|
|
23
|
161
|
100
|
|
|
|
273
|
if ( !defined $info_of ) { |
24
|
12
|
|
|
|
|
22
|
$info_of = {}; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
161
|
|
|
|
|
185
|
for my $line ( @{$line_refs} ) { |
|
161
|
|
|
|
|
236
|
|
28
|
265
|
|
|
|
|
1222
|
for my $part ( split /\t/, $line ) { |
29
|
653
|
|
|
|
|
1087
|
my $info = App::RL::Common::decode_header($part); |
30
|
653
|
100
|
|
|
|
66471
|
next unless App::RL::Common::info_is_valid($info); |
31
|
|
|
|
|
|
|
|
32
|
534
|
100
|
|
|
|
12232
|
if ( !exists $info_of->{$part} ) { |
33
|
262
|
|
|
|
|
574
|
$info_of->{$part} = $info; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
161
|
|
|
|
|
2323
|
return $info_of; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub build_info_intspan { |
42
|
5
|
|
|
5
|
0
|
8
|
my $line_refs = shift; |
43
|
5
|
|
|
|
|
7
|
my $info_of = shift; |
44
|
|
|
|
|
|
|
|
45
|
5
|
100
|
|
|
|
11
|
if ( !defined $info_of ) { |
46
|
4
|
|
|
|
|
6
|
$info_of = {}; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
5
|
|
|
|
|
8
|
for my $line ( @{$line_refs} ) { |
|
5
|
|
|
|
|
11
|
|
50
|
36
|
|
|
|
|
87
|
for my $part ( split /\t/, $line ) { |
51
|
72
|
|
|
|
|
136
|
my $info = App::RL::Common::decode_header($part); |
52
|
72
|
50
|
|
|
|
7919
|
next unless App::RL::Common::info_is_valid($info); |
53
|
|
|
|
|
|
|
|
54
|
72
|
|
|
|
|
1585
|
$info->{intspan} = AlignDB::IntSpan->new; |
55
|
72
|
|
|
|
|
1524
|
$info->{intspan}->add_pair( $info->{start}, $info->{end} ); |
56
|
|
|
|
|
|
|
|
57
|
72
|
100
|
|
|
|
4310
|
if ( !exists $info_of->{$part} ) { |
58
|
57
|
|
|
|
|
127
|
$info_of->{$part} = $info; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
5
|
|
|
|
|
66
|
return $info_of; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub sort_links { |
67
|
12
|
|
|
12
|
0
|
21
|
my $line_refs = shift; |
68
|
12
|
|
|
|
|
37
|
my $numeric = shift; |
69
|
|
|
|
|
|
|
|
70
|
12
|
|
|
|
|
19
|
my @lines = @{$line_refs}; |
|
12
|
|
|
|
|
31
|
|
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
#----------------------------# |
73
|
|
|
|
|
|
|
# Cache info |
74
|
|
|
|
|
|
|
#----------------------------# |
75
|
12
|
|
|
|
|
29
|
my $info_of = build_info( \@lines ); |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
#----------------------------# |
78
|
|
|
|
|
|
|
# Sort within links |
79
|
|
|
|
|
|
|
#----------------------------# |
80
|
12
|
|
|
|
|
23
|
for my $line (@lines) { |
81
|
116
|
|
|
|
|
234
|
my @parts = split /\t/, $line; |
82
|
116
|
|
|
|
|
144
|
my @invalids = grep { !exists $info_of->{$_} } @parts; |
|
265
|
|
|
|
|
442
|
|
83
|
116
|
|
|
|
|
138
|
my @ranges = grep { exists $info_of->{$_} } @parts; |
|
265
|
|
|
|
|
405
|
|
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
# chromosome strand |
86
|
236
|
|
|
|
|
356
|
@ranges = map { $_->[0] } |
87
|
124
|
|
|
|
|
804
|
sort { $a->[1] cmp $b->[1] } |
88
|
116
|
|
|
|
|
164
|
map { [ $_, $info_of->{$_}{strand} ] } @ranges; |
|
236
|
|
|
|
|
1035
|
|
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
# start point on chromosomes |
91
|
236
|
|
|
|
|
343
|
@ranges = map { $_->[0] } |
92
|
122
|
|
|
|
|
750
|
sort { $a->[1] <=> $b->[1] } |
93
|
116
|
|
|
|
|
179
|
map { [ $_, $info_of->{$_}{start} ] } @ranges; |
|
236
|
|
|
|
|
980
|
|
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
# chromosome name |
96
|
116
|
50
|
|
|
|
206
|
if ($numeric) { |
97
|
0
|
|
|
|
|
0
|
@ranges = map { $_->[0] } |
98
|
0
|
|
|
|
|
0
|
sort { $a->[1] <=> $b->[1] } |
99
|
0
|
|
|
|
|
0
|
map { [ $_, $info_of->{$_}{chr} ] } @ranges; |
|
0
|
|
|
|
|
0
|
|
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
else { |
102
|
236
|
|
|
|
|
332
|
@ranges = map { $_->[0] } |
103
|
122
|
|
|
|
|
727
|
sort { $a->[1] cmp $b->[1] } |
104
|
116
|
|
|
|
|
143
|
map { [ $_, $info_of->{$_}{chr} ] } @ranges; |
|
236
|
|
|
|
|
1019
|
|
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
116
|
|
|
|
|
327
|
$line = join "\t", ( @ranges, @invalids ); |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
#----------------------------# |
111
|
|
|
|
|
|
|
# Sort by first range's chromosome order among links |
112
|
|
|
|
|
|
|
#----------------------------# |
113
|
|
|
|
|
|
|
{ |
114
|
|
|
|
|
|
|
# after swapping, remove dups again |
115
|
12
|
|
|
|
|
48
|
@lines = sort @lines; |
116
|
12
|
|
|
|
|
31
|
@lines = List::MoreUtils::PP::uniq(@lines); |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
# strand |
119
|
102
|
|
|
|
|
150
|
@lines = map { $_->[0] } |
120
|
200
|
|
|
|
|
270
|
sort { $a->[1] cmp $b->[1] } |
121
|
|
|
|
|
|
|
map { |
122
|
12
|
|
|
|
|
329
|
my $first = ( split /\t/ )[0]; |
|
102
|
|
|
|
|
630
|
|
123
|
102
|
|
|
|
|
259
|
[ $_, $info_of->{$first}{strand} ] |
124
|
|
|
|
|
|
|
} @lines; |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
# start |
127
|
102
|
|
|
|
|
124
|
@lines = map { $_->[0] } |
128
|
204
|
|
|
|
|
281
|
sort { $a->[1] <=> $b->[1] } |
129
|
|
|
|
|
|
|
map { |
130
|
12
|
|
|
|
|
50
|
my $first = ( split /\t/ )[0]; |
|
102
|
|
|
|
|
549
|
|
131
|
102
|
|
|
|
|
237
|
[ $_, $info_of->{$first}{start} ] |
132
|
|
|
|
|
|
|
} @lines; |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
# chromosome name |
135
|
12
|
50
|
|
|
|
33
|
if ($numeric) { |
136
|
0
|
|
|
|
|
0
|
@lines = map { $_->[0] } |
137
|
0
|
|
|
|
|
0
|
sort { $a->[1] <=> $b->[1] } |
138
|
|
|
|
|
|
|
map { |
139
|
0
|
|
|
|
|
0
|
my $first = ( split /\t/ )[0]; |
|
0
|
|
|
|
|
0
|
|
140
|
0
|
|
|
|
|
0
|
[ $_, $info_of->{$first}{chr} ] |
141
|
|
|
|
|
|
|
} @lines; |
142
|
|
|
|
|
|
|
} |
143
|
|
|
|
|
|
|
else { |
144
|
102
|
|
|
|
|
126
|
@lines = map { $_->[0] } |
145
|
200
|
|
|
|
|
264
|
sort { $a->[1] cmp $b->[1] } |
146
|
|
|
|
|
|
|
map { |
147
|
12
|
|
|
|
|
22
|
my $first = ( split /\t/ )[0]; |
|
102
|
|
|
|
|
518
|
|
148
|
102
|
|
|
|
|
250
|
[ $_, $info_of->{$first}{chr} ] |
149
|
|
|
|
|
|
|
} @lines; |
150
|
|
|
|
|
|
|
} |
151
|
|
|
|
|
|
|
} |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
#----------------------------# |
154
|
|
|
|
|
|
|
# Sort by copy number among links (desc) |
155
|
|
|
|
|
|
|
#----------------------------# |
156
|
|
|
|
|
|
|
{ |
157
|
12
|
|
|
|
|
16
|
@lines = map { $_->[0] } |
|
12
|
|
|
|
|
25
|
|
|
102
|
|
|
|
|
135
|
|
158
|
202
|
|
|
|
|
237
|
sort { $b->[1] <=> $a->[1] } |
159
|
|
|
|
|
|
|
map { |
160
|
12
|
|
|
|
|
23
|
[ $_, scalar( grep { exists $info_of->{$_} } split( /\t/, $_ ) ) ] |
|
102
|
|
|
|
|
164
|
|
|
223
|
|
|
|
|
358
|
|
161
|
|
|
|
|
|
|
} @lines; |
162
|
|
|
|
|
|
|
} |
163
|
|
|
|
|
|
|
|
164
|
12
|
|
|
|
|
233
|
return \@lines; |
165
|
|
|
|
|
|
|
} |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
sub get_seq_faidx { |
168
|
0
|
|
|
0
|
0
|
|
my $filename = shift; |
169
|
0
|
|
|
|
|
|
my $location = shift; # I:1-100 |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
# get executable |
172
|
0
|
|
|
|
|
|
my $bin; |
173
|
0
|
|
|
|
|
|
for my $e (qw{samtools}) { |
174
|
0
|
0
|
|
|
|
|
if ( IPC::Cmd::can_run($e) ) { |
175
|
0
|
|
|
|
|
|
$bin = $e; |
176
|
0
|
|
|
|
|
|
last; |
177
|
|
|
|
|
|
|
} |
178
|
|
|
|
|
|
|
} |
179
|
0
|
0
|
|
|
|
|
if ( !defined $bin ) { |
180
|
0
|
|
|
|
|
|
confess "Could not find the executable for [samtools]\n"; |
181
|
|
|
|
|
|
|
} |
182
|
|
|
|
|
|
|
|
183
|
0
|
|
|
|
|
|
my $cmd = sprintf "%s faidx %s %s", $bin, $filename, $location; |
184
|
0
|
|
|
|
|
|
open my $pipe_fh, '-|', $cmd; |
185
|
|
|
|
|
|
|
|
186
|
0
|
|
|
|
|
|
my $seq; |
187
|
0
|
|
|
|
|
|
while ( my $line = <$pipe_fh> ) { |
188
|
0
|
|
|
|
|
|
chomp $line; |
189
|
0
|
0
|
|
|
|
|
if ( $line =~ /^[\w-]+/ ) { |
190
|
0
|
|
|
|
|
|
$seq .= $line; |
191
|
|
|
|
|
|
|
} |
192
|
|
|
|
|
|
|
} |
193
|
0
|
|
|
|
|
|
close $pipe_fh; |
194
|
|
|
|
|
|
|
|
195
|
0
|
|
|
|
|
|
return $seq; |
196
|
|
|
|
|
|
|
} |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
1; |