| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package App::Fasops::Command::axt2fas; |
|
2
|
20
|
|
|
20
|
|
391890
|
use strict; |
|
|
20
|
|
|
|
|
54
|
|
|
|
20
|
|
|
|
|
672
|
|
|
3
|
20
|
|
|
20
|
|
108
|
use warnings; |
|
|
20
|
|
|
|
|
55
|
|
|
|
20
|
|
|
|
|
593
|
|
|
4
|
20
|
|
|
20
|
|
8461
|
use autodie; |
|
|
20
|
|
|
|
|
288976
|
|
|
|
20
|
|
|
|
|
109
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
20
|
|
|
20
|
|
135872
|
use App::Fasops -command; |
|
|
20
|
|
|
|
|
46
|
|
|
|
20
|
|
|
|
|
302
|
|
|
7
|
20
|
|
|
20
|
|
18675
|
use App::RL::Common; |
|
|
20
|
|
|
|
|
2077737
|
|
|
|
20
|
|
|
|
|
830
|
|
|
8
|
20
|
|
|
20
|
|
11326
|
use App::Fasops::Common; |
|
|
20
|
|
|
|
|
80
|
|
|
|
20
|
|
|
|
|
23132
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub abstract { |
|
11
|
2
|
|
|
2
|
1
|
32435
|
return 'convert axt to blocked fasta'; |
|
12
|
|
|
|
|
|
|
} |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub opt_spec { |
|
15
|
|
|
|
|
|
|
return ( |
|
16
|
9
|
|
|
9
|
1
|
86
|
[ "outfile|o=s", "Output filename, [stdout] for screen" ], |
|
17
|
|
|
|
|
|
|
[ "length|l=i", "the threshold of alignment length", { default => 1 }, ], |
|
18
|
|
|
|
|
|
|
[ "tname|t=s", "target name", { default => "target" }, ], |
|
19
|
|
|
|
|
|
|
[ "qname|q=s", "query name", { default => "query" }, ], |
|
20
|
|
|
|
|
|
|
[ "size|s=s", "query chr.sizes", ], |
|
21
|
|
|
|
|
|
|
{ show_defaults => 1, } |
|
22
|
|
|
|
|
|
|
); |
|
23
|
|
|
|
|
|
|
} |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub usage_desc { |
|
26
|
9
|
|
|
9
|
1
|
67784
|
return "fasops axt2fas [options] [more infiles]"; |
|
27
|
|
|
|
|
|
|
} |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub description { |
|
30
|
1
|
|
|
1
|
1
|
1427
|
my $desc; |
|
31
|
1
|
|
|
|
|
4
|
$desc .= ucfirst(abstract) . ".\n"; |
|
32
|
1
|
|
|
|
|
3
|
$desc .= <<'MARKDOWN'; |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
* are paths to axt files, .axt.gz is supported |
|
35
|
|
|
|
|
|
|
* infile == stdin means reading from STDIN |
|
36
|
|
|
|
|
|
|
* Without query chr.sizes file, positions on negative strand of query will be wrong |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
MARKDOWN |
|
39
|
|
|
|
|
|
|
|
|
40
|
1
|
|
|
|
|
4
|
return $desc; |
|
41
|
|
|
|
|
|
|
} |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub validate_args { |
|
44
|
8
|
|
|
8
|
1
|
12673
|
my ( $self, $opt, $args ) = @_; |
|
45
|
|
|
|
|
|
|
|
|
46
|
8
|
100
|
|
|
|
15
|
if ( !@{$args} ) { |
|
|
8
|
|
|
|
|
24
|
|
|
47
|
1
|
|
|
|
|
2
|
my $message = "This command need one or more input files.\n\tIt found"; |
|
48
|
1
|
|
|
|
|
3
|
$message .= sprintf " [%s]", $_ for @{$args}; |
|
|
1
|
|
|
|
|
3
|
|
|
49
|
1
|
|
|
|
|
3
|
$message .= ".\n"; |
|
50
|
1
|
|
|
|
|
10
|
$self->usage_error($message); |
|
51
|
|
|
|
|
|
|
} |
|
52
|
7
|
|
|
|
|
13
|
for ( @{$args} ) { |
|
|
7
|
|
|
|
|
15
|
|
|
53
|
7
|
50
|
|
|
|
23
|
next if lc $_ eq "stdin"; |
|
54
|
7
|
100
|
|
|
|
27
|
if ( !Path::Tiny::path($_)->is_file ) { |
|
55
|
1
|
|
|
|
|
109
|
$self->usage_error("The input file [$_] doesn't exist."); |
|
56
|
|
|
|
|
|
|
} |
|
57
|
|
|
|
|
|
|
} |
|
58
|
|
|
|
|
|
|
|
|
59
|
6
|
100
|
|
|
|
427
|
if ( !exists $opt->{outfile} ) { |
|
60
|
3
|
|
|
|
|
13
|
$opt->{outfile} = Path::Tiny::path( $args->[0] )->absolute . ".fas"; |
|
61
|
|
|
|
|
|
|
} |
|
62
|
|
|
|
|
|
|
|
|
63
|
6
|
50
|
|
|
|
369
|
if ( $opt->{tname} ) { |
|
64
|
6
|
100
|
|
|
|
35
|
if ( $opt->{tname} !~ /^[\w]+$/ ) { |
|
65
|
1
|
|
|
|
|
5
|
$self->usage_error("[--tname] should be an alphanumeric value."); |
|
66
|
|
|
|
|
|
|
} |
|
67
|
|
|
|
|
|
|
} |
|
68
|
5
|
50
|
|
|
|
19
|
if ( $opt->{qname} ) { |
|
69
|
5
|
100
|
|
|
|
20
|
if ( $opt->{qname} !~ /^[\w]+$/ ) { |
|
70
|
1
|
|
|
|
|
4
|
$self->usage_error("[--qname] should be an alphanumeric value."); |
|
71
|
|
|
|
|
|
|
} |
|
72
|
|
|
|
|
|
|
} |
|
73
|
|
|
|
|
|
|
|
|
74
|
4
|
100
|
|
|
|
15
|
if ( $opt->{size} ) { |
|
75
|
2
|
100
|
|
|
|
10
|
if ( !Path::Tiny::path( $opt->{size} )->is_file ) { |
|
76
|
1
|
|
|
|
|
73
|
$self->usage_error("The size file [$opt->{size}] doesn't exist."); |
|
77
|
|
|
|
|
|
|
} |
|
78
|
|
|
|
|
|
|
} |
|
79
|
|
|
|
|
|
|
} |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub execute { |
|
82
|
3
|
|
|
3
|
1
|
74
|
my ( $self, $opt, $args ) = @_; |
|
83
|
|
|
|
|
|
|
|
|
84
|
3
|
|
|
|
|
7
|
my $out_fh; |
|
85
|
3
|
50
|
|
|
|
10
|
if ( lc( $opt->{outfile} ) eq "stdout" ) { |
|
86
|
3
|
|
|
|
|
9
|
$out_fh = *STDOUT{IO}; |
|
87
|
|
|
|
|
|
|
} |
|
88
|
|
|
|
|
|
|
else { |
|
89
|
0
|
|
|
|
|
0
|
open $out_fh, ">", $opt->{outfile}; |
|
90
|
|
|
|
|
|
|
} |
|
91
|
|
|
|
|
|
|
|
|
92
|
3
|
|
|
|
|
8
|
my $length_of; |
|
93
|
3
|
100
|
|
|
|
9
|
if ( $opt->{size} ) { |
|
94
|
1
|
|
|
|
|
7
|
$length_of = App::RL::Common::read_sizes( $opt->{size} ); |
|
95
|
|
|
|
|
|
|
} |
|
96
|
|
|
|
|
|
|
|
|
97
|
3
|
|
|
|
|
4897
|
for my $infile ( @{$args} ) { |
|
|
3
|
|
|
|
|
6
|
|
|
98
|
3
|
|
|
|
|
5
|
my $in_fh; |
|
99
|
3
|
50
|
|
|
|
22
|
if ( lc $infile eq "stdin" ) { |
|
100
|
0
|
|
|
|
|
0
|
$in_fh = *STDIN{IO}; |
|
101
|
|
|
|
|
|
|
} |
|
102
|
|
|
|
|
|
|
else { |
|
103
|
3
|
|
|
|
|
22
|
$in_fh = IO::Zlib->new( $infile, "rb" ); |
|
104
|
|
|
|
|
|
|
} |
|
105
|
|
|
|
|
|
|
|
|
106
|
3
|
|
|
|
|
4689
|
my $content = ''; # content of one block |
|
107
|
3
|
|
|
|
|
5
|
while (1) { |
|
108
|
48
|
100
|
100
|
|
|
284
|
last if $in_fh->eof and $content eq ''; |
|
109
|
45
|
|
|
|
|
2277
|
my $line = ''; |
|
110
|
45
|
100
|
|
|
|
146
|
if ( !$in_fh->eof ) { |
|
111
|
42
|
|
|
|
|
1663
|
$line = $in_fh->getline; |
|
112
|
|
|
|
|
|
|
} |
|
113
|
|
|
|
|
|
|
|
|
114
|
45
|
100
|
100
|
|
|
5680
|
if ( substr( $line, 0, 1 ) eq "#" ) { |
|
|
|
100
|
66
|
|
|
|
|
|
115
|
21
|
|
|
|
|
38
|
next; |
|
116
|
|
|
|
|
|
|
} |
|
117
|
|
|
|
|
|
|
elsif ( ( $line eq '' or $line =~ /^\s+$/ ) and $content ne '' ) { |
|
118
|
6
|
|
|
|
|
24
|
my $info_refs = App::Fasops::Common::parse_axt_block( $content, $length_of ); |
|
119
|
6
|
|
|
|
|
12
|
$content = ''; |
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
next |
|
122
|
6
|
100
|
|
|
|
18
|
if App::Fasops::Common::seq_length( $info_refs->[0]{seq} ) < $opt->{length}; |
|
123
|
|
|
|
|
|
|
next |
|
124
|
5
|
50
|
|
|
|
21
|
if App::Fasops::Common::seq_length( $info_refs->[1]{seq} ) < $opt->{length}; |
|
125
|
|
|
|
|
|
|
|
|
126
|
5
|
|
|
|
|
14
|
$info_refs->[0]{name} = $opt->{tname}; |
|
127
|
5
|
|
|
|
|
8
|
$info_refs->[1]{name} = $opt->{qname}; |
|
128
|
|
|
|
|
|
|
|
|
129
|
5
|
|
|
|
|
11
|
for my $i ( 0, 1 ) { |
|
130
|
10
|
|
|
|
|
118
|
my $info = $info_refs->[$i]; |
|
131
|
10
|
|
|
|
|
13
|
printf {$out_fh} ">%s\n", App::RL::Common::encode_header($info); |
|
|
10
|
|
|
|
|
39
|
|
|
132
|
10
|
|
|
|
|
758
|
printf {$out_fh} "%s\n", $info->{seq}; |
|
|
10
|
|
|
|
|
35
|
|
|
133
|
|
|
|
|
|
|
} |
|
134
|
5
|
|
|
|
|
90
|
print {$out_fh} "\n"; |
|
|
5
|
|
|
|
|
16
|
|
|
135
|
|
|
|
|
|
|
} |
|
136
|
|
|
|
|
|
|
else { |
|
137
|
18
|
|
|
|
|
43
|
$content .= $line; |
|
138
|
|
|
|
|
|
|
} |
|
139
|
|
|
|
|
|
|
} |
|
140
|
|
|
|
|
|
|
|
|
141
|
3
|
|
|
|
|
478
|
$in_fh->close; |
|
142
|
|
|
|
|
|
|
} |
|
143
|
|
|
|
|
|
|
|
|
144
|
3
|
|
|
|
|
444
|
close $out_fh; |
|
145
|
|
|
|
|
|
|
} |
|
146
|
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
1; |