| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package App::Fasops::Command::links; |
|
2
|
20
|
|
|
20
|
|
13859
|
use strict; |
|
|
20
|
|
|
|
|
49
|
|
|
|
20
|
|
|
|
|
638
|
|
|
3
|
20
|
|
|
20
|
|
113
|
use warnings; |
|
|
20
|
|
|
|
|
45
|
|
|
|
20
|
|
|
|
|
508
|
|
|
4
|
20
|
|
|
20
|
|
109
|
use autodie; |
|
|
20
|
|
|
|
|
37
|
|
|
|
20
|
|
|
|
|
123
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
20
|
|
|
20
|
|
105058
|
use App::Fasops -command; |
|
|
20
|
|
|
|
|
46
|
|
|
|
20
|
|
|
|
|
196
|
|
|
7
|
20
|
|
|
20
|
|
7139
|
use App::RL::Common; |
|
|
20
|
|
|
|
|
45
|
|
|
|
20
|
|
|
|
|
539
|
|
|
8
|
20
|
|
|
20
|
|
116
|
use App::Fasops::Common; |
|
|
20
|
|
|
|
|
38
|
|
|
|
20
|
|
|
|
|
25978
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub abstract { |
|
11
|
2
|
|
|
2
|
1
|
47
|
return 'scan blocked fasta files and output bi/multi-lateral range links'; |
|
12
|
|
|
|
|
|
|
} |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub opt_spec { |
|
15
|
|
|
|
|
|
|
return ( |
|
16
|
6
|
|
|
6
|
1
|
35
|
[ "outfile|o=s", "Output filename. [stdout] for screen." ], |
|
17
|
|
|
|
|
|
|
[ "pair|p", "pairwise links" ], |
|
18
|
|
|
|
|
|
|
[ "best|b", "best-to-best pairwise links" ], |
|
19
|
|
|
|
|
|
|
{ show_defaults => 1, } |
|
20
|
|
|
|
|
|
|
); |
|
21
|
|
|
|
|
|
|
} |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub usage_desc { |
|
24
|
6
|
|
|
6
|
1
|
54539
|
return "fasops links [options] [more infiles]"; |
|
25
|
|
|
|
|
|
|
} |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub description { |
|
28
|
1
|
|
|
1
|
1
|
943
|
my $desc; |
|
29
|
1
|
|
|
|
|
5
|
$desc .= ucfirst(abstract) . ".\n"; |
|
30
|
1
|
|
|
|
|
3
|
$desc .= <<'MARKDOWN'; |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
* are paths to axt files, .axt.gz is supported |
|
33
|
|
|
|
|
|
|
* infile == stdin means reading from STDIN |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
MARKDOWN |
|
36
|
|
|
|
|
|
|
|
|
37
|
1
|
|
|
|
|
3
|
return $desc; |
|
38
|
|
|
|
|
|
|
} |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub validate_args { |
|
41
|
5
|
|
|
5
|
1
|
5352
|
my ( $self, $opt, $args ) = @_; |
|
42
|
|
|
|
|
|
|
|
|
43
|
5
|
100
|
|
|
|
11
|
if ( !@{$args} ) { |
|
|
5
|
|
|
|
|
18
|
|
|
44
|
1
|
|
|
|
|
3
|
my $message = "This command need one or more input files.\n\tIt found"; |
|
45
|
1
|
|
|
|
|
2
|
$message .= sprintf " [%s]", $_ for @{$args}; |
|
|
1
|
|
|
|
|
3
|
|
|
46
|
1
|
|
|
|
|
3
|
$message .= ".\n"; |
|
47
|
1
|
|
|
|
|
14
|
$self->usage_error($message); |
|
48
|
|
|
|
|
|
|
} |
|
49
|
4
|
|
|
|
|
5
|
for ( @{$args} ) { |
|
|
4
|
|
|
|
|
10
|
|
|
50
|
4
|
50
|
|
|
|
14
|
next if lc $_ eq "stdin"; |
|
51
|
4
|
100
|
|
|
|
15
|
if ( !Path::Tiny::path($_)->is_file ) { |
|
52
|
1
|
|
|
|
|
117
|
$self->usage_error("The input file [$_] doesn't exist."); |
|
53
|
|
|
|
|
|
|
} |
|
54
|
|
|
|
|
|
|
} |
|
55
|
|
|
|
|
|
|
|
|
56
|
3
|
50
|
|
|
|
189
|
if ( !exists $opt->{outfile} ) { |
|
57
|
0
|
|
|
|
|
0
|
$opt->{outfile} = Path::Tiny::path( $args->[0] )->absolute . ".tsv"; |
|
58
|
|
|
|
|
|
|
} |
|
59
|
|
|
|
|
|
|
} |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub execute { |
|
62
|
3
|
|
|
3
|
1
|
18
|
my ( $self, $opt, $args ) = @_; |
|
63
|
|
|
|
|
|
|
|
|
64
|
3
|
|
|
|
|
6
|
my @links; |
|
65
|
3
|
|
|
|
|
4
|
for my $infile ( @{$args} ) { |
|
|
3
|
|
|
|
|
6
|
|
|
66
|
3
|
|
|
|
|
7
|
my $in_fh; |
|
67
|
3
|
50
|
|
|
|
10
|
if ( lc $infile eq "stdin" ) { |
|
68
|
0
|
|
|
|
|
0
|
$in_fh = *STDIN{IO}; |
|
69
|
|
|
|
|
|
|
} |
|
70
|
|
|
|
|
|
|
else { |
|
71
|
3
|
|
|
|
|
20
|
$in_fh = IO::Zlib->new( $infile, "rb" ); |
|
72
|
|
|
|
|
|
|
} |
|
73
|
|
|
|
|
|
|
|
|
74
|
3
|
|
|
|
|
4663
|
my $content = ''; # content of one block |
|
75
|
3
|
|
|
|
|
7
|
while (1) { |
|
76
|
84
|
100
|
66
|
|
|
349
|
last if $in_fh->eof and $content eq ''; |
|
77
|
81
|
|
|
|
|
3518
|
my $line = ''; |
|
78
|
81
|
50
|
|
|
|
248
|
if ( !$in_fh->eof ) { |
|
79
|
81
|
|
|
|
|
3220
|
$line = $in_fh->getline; |
|
80
|
|
|
|
|
|
|
} |
|
81
|
81
|
50
|
|
|
|
9410
|
next if substr( $line, 0, 1 ) eq "#"; |
|
82
|
|
|
|
|
|
|
|
|
83
|
81
|
100
|
66
|
|
|
442
|
if ( ( $line eq '' or $line =~ /^\s+$/ ) and $content ne '' ) { |
|
|
|
|
66
|
|
|
|
|
|
84
|
9
|
|
|
|
|
31
|
my $info_of = App::Fasops::Common::parse_block( $content, 1 ); |
|
85
|
9
|
|
|
|
|
18
|
$content = ''; |
|
86
|
|
|
|
|
|
|
|
|
87
|
9
|
|
|
|
|
12
|
my @headers = keys %{$info_of}; |
|
|
9
|
|
|
|
|
30
|
|
|
88
|
|
|
|
|
|
|
|
|
89
|
9
|
100
|
|
|
|
288
|
if ( $opt->{best} ) { |
|
|
|
100
|
|
|
|
|
|
|
90
|
3
|
|
|
|
|
13
|
my @matrix = map { [ (undef) x ( scalar @headers ) ] } 0 .. $#headers; |
|
|
12
|
|
|
|
|
28
|
|
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
# distance is 0 for same sequence |
|
93
|
3
|
|
|
|
|
11
|
for my $i ( 0 .. $#headers ) { |
|
94
|
12
|
|
|
|
|
20
|
$matrix[$i][$i] = 0; |
|
95
|
|
|
|
|
|
|
} |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
# compute a triangle, fill full matrix |
|
98
|
3
|
|
|
|
|
10
|
for ( my $i = 0; $i <= $#headers; $i++ ) { |
|
99
|
12
|
|
|
|
|
29
|
for ( my $j = $i + 1; $j <= $#headers; $j++ ) { |
|
100
|
|
|
|
|
|
|
my $D = App::Fasops::Common::pair_D( |
|
101
|
|
|
|
|
|
|
[ $info_of->{ $headers[$i] }{seq}, |
|
102
|
|
|
|
|
|
|
$info_of->{ $headers[$j] }{seq}, |
|
103
|
18
|
|
|
|
|
69
|
] |
|
104
|
|
|
|
|
|
|
); |
|
105
|
18
|
|
|
|
|
66
|
$matrix[$i][$j] = $D; |
|
106
|
18
|
|
|
|
|
50
|
$matrix[$j][$i] = $D; |
|
107
|
|
|
|
|
|
|
} |
|
108
|
|
|
|
|
|
|
} |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
# print YAML::Syck::Dump \@matrix; |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
# best_pairwise |
|
113
|
3
|
|
|
|
|
17
|
my @pair_ary; |
|
114
|
3
|
|
|
|
|
6
|
for my $i ( 0 .. $#headers ) { |
|
115
|
12
|
|
|
|
|
16
|
my @row = @{ $matrix[$i] }; |
|
|
12
|
|
|
|
|
26
|
|
|
116
|
12
|
|
|
|
|
18
|
$row[$i] = 999; # remove the score (zero) of this item |
|
117
|
12
|
|
|
|
|
30
|
my $min = List::Util::min(@row); |
|
118
|
12
|
|
|
19
|
|
47
|
my $min_idx = App::Fasops::Common::firstidx { $_ == $min } @row; |
|
|
19
|
|
|
|
|
72
|
|
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
# to remove duplications of a:b and b:a |
|
121
|
12
|
|
|
|
|
46
|
push @pair_ary, join ":", sort { $a <=> $b } ( $i, $min_idx ); |
|
|
12
|
|
|
|
|
45
|
|
|
122
|
|
|
|
|
|
|
} |
|
123
|
3
|
|
|
|
|
15
|
@pair_ary = App::Fasops::Common::uniq(@pair_ary); |
|
124
|
|
|
|
|
|
|
|
|
125
|
3
|
|
|
|
|
7
|
for (@pair_ary) { |
|
126
|
9
|
|
|
|
|
23
|
my ( $i, $j ) = split ":"; |
|
127
|
9
|
|
|
|
|
74
|
push @links, [ $headers[$i], $headers[$j] ]; |
|
128
|
|
|
|
|
|
|
} |
|
129
|
|
|
|
|
|
|
} |
|
130
|
|
|
|
|
|
|
elsif ( $opt->{pair} ) { |
|
131
|
3
|
|
|
|
|
12
|
for ( my $i = 0; $i <= $#headers; $i++ ) { |
|
132
|
12
|
|
|
|
|
70
|
for ( my $j = $i + 1; $j <= $#headers; $j++ ) { |
|
133
|
18
|
|
|
|
|
52
|
push @links, [ $headers[$i], $headers[$j] ]; |
|
134
|
|
|
|
|
|
|
} |
|
135
|
|
|
|
|
|
|
} |
|
136
|
|
|
|
|
|
|
} |
|
137
|
|
|
|
|
|
|
else { |
|
138
|
3
|
|
|
|
|
36
|
push @links, \@headers; |
|
139
|
|
|
|
|
|
|
} |
|
140
|
|
|
|
|
|
|
} |
|
141
|
|
|
|
|
|
|
else { |
|
142
|
72
|
|
|
|
|
138
|
$content .= $line; |
|
143
|
|
|
|
|
|
|
} |
|
144
|
|
|
|
|
|
|
} |
|
145
|
|
|
|
|
|
|
|
|
146
|
3
|
|
|
|
|
503
|
$in_fh->close; |
|
147
|
|
|
|
|
|
|
} |
|
148
|
|
|
|
|
|
|
|
|
149
|
3
|
|
|
|
|
448
|
my $out_fh; |
|
150
|
3
|
50
|
|
|
|
13
|
if ( lc( $opt->{outfile} ) eq "stdout" ) { |
|
151
|
3
|
|
|
|
|
8
|
$out_fh = *STDOUT{IO}; |
|
152
|
|
|
|
|
|
|
} |
|
153
|
|
|
|
|
|
|
else { |
|
154
|
0
|
|
|
|
|
0
|
open $out_fh, ">", $opt->{outfile}; |
|
155
|
|
|
|
|
|
|
} |
|
156
|
|
|
|
|
|
|
|
|
157
|
3
|
|
|
|
|
7
|
for my $link (@links) { |
|
158
|
30
|
|
|
|
|
419
|
printf {$out_fh} join( "\t", @{$link} ); |
|
|
30
|
|
|
|
|
62
|
|
|
|
30
|
|
|
|
|
89
|
|
|
159
|
30
|
|
|
|
|
495
|
printf {$out_fh} "\n"; |
|
|
30
|
|
|
|
|
79
|
|
|
160
|
|
|
|
|
|
|
} |
|
161
|
3
|
|
|
|
|
56
|
close $out_fh; |
|
162
|
|
|
|
|
|
|
} |
|
163
|
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
1; |