line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::Fasops::Command::axt2fas; |
2
|
20
|
|
|
20
|
|
387788
|
use strict; |
|
20
|
|
|
|
|
51
|
|
|
20
|
|
|
|
|
676
|
|
3
|
20
|
|
|
20
|
|
119
|
use warnings; |
|
20
|
|
|
|
|
38
|
|
|
20
|
|
|
|
|
561
|
|
4
|
20
|
|
|
20
|
|
8400
|
use autodie; |
|
20
|
|
|
|
|
283058
|
|
|
20
|
|
|
|
|
100
|
|
5
|
|
|
|
|
|
|
|
6
|
20
|
|
|
20
|
|
136386
|
use App::Fasops -command; |
|
20
|
|
|
|
|
55
|
|
|
20
|
|
|
|
|
260
|
|
7
|
20
|
|
|
20
|
|
18259
|
use App::RL::Common; |
|
20
|
|
|
|
|
2055911
|
|
|
20
|
|
|
|
|
825
|
|
8
|
20
|
|
|
20
|
|
11167
|
use App::Fasops::Common; |
|
20
|
|
|
|
|
79
|
|
|
20
|
|
|
|
|
23222
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub abstract { |
11
|
2
|
|
|
2
|
1
|
32652
|
return 'convert axt to blocked fasta'; |
12
|
|
|
|
|
|
|
} |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub opt_spec { |
15
|
|
|
|
|
|
|
return ( |
16
|
9
|
|
|
9
|
1
|
93
|
[ "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
|
68005
|
return "fasops axt2fas [options] [more infiles]"; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub description { |
30
|
1
|
|
|
1
|
1
|
1479
|
my $desc; |
31
|
1
|
|
|
|
|
5
|
$desc .= ucfirst(abstract) . ".\n"; |
32
|
1
|
|
|
|
|
4
|
$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
|
|
|
|
|
2
|
return $desc; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub validate_args { |
44
|
8
|
|
|
8
|
1
|
12575
|
my ( $self, $opt, $args ) = @_; |
45
|
|
|
|
|
|
|
|
46
|
8
|
100
|
|
|
|
14
|
if ( !@{$args} ) { |
|
8
|
|
|
|
|
33
|
|
47
|
1
|
|
|
|
|
4
|
my $message = "This command need one or more input files.\n\tIt found"; |
48
|
1
|
|
|
|
|
2
|
$message .= sprintf " [%s]", $_ for @{$args}; |
|
1
|
|
|
|
|
4
|
|
49
|
1
|
|
|
|
|
5
|
$message .= ".\n"; |
50
|
1
|
|
|
|
|
11
|
$self->usage_error($message); |
51
|
|
|
|
|
|
|
} |
52
|
7
|
|
|
|
|
11
|
for ( @{$args} ) { |
|
7
|
|
|
|
|
16
|
|
53
|
7
|
50
|
|
|
|
22
|
next if lc $_ eq "stdin"; |
54
|
7
|
100
|
|
|
|
24
|
if ( !Path::Tiny::path($_)->is_file ) { |
55
|
1
|
|
|
|
|
118
|
$self->usage_error("The input file [$_] doesn't exist."); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
6
|
100
|
|
|
|
387
|
if ( !exists $opt->{outfile} ) { |
60
|
3
|
|
|
|
|
11
|
$opt->{outfile} = Path::Tiny::path( $args->[0] )->absolute . ".fas"; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
6
|
50
|
|
|
|
348
|
if ( $opt->{tname} ) { |
64
|
6
|
100
|
|
|
|
33
|
if ( $opt->{tname} !~ /^[\w]+$/ ) { |
65
|
1
|
|
|
|
|
6
|
$self->usage_error("[--tname] should be an alphanumeric value."); |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
} |
68
|
5
|
50
|
|
|
|
19
|
if ( $opt->{qname} ) { |
69
|
5
|
100
|
|
|
|
21
|
if ( $opt->{qname} !~ /^[\w]+$/ ) { |
70
|
1
|
|
|
|
|
7
|
$self->usage_error("[--qname] should be an alphanumeric value."); |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
4
|
100
|
|
|
|
17
|
if ( $opt->{size} ) { |
75
|
2
|
100
|
|
|
|
8
|
if ( !Path::Tiny::path( $opt->{size} )->is_file ) { |
76
|
1
|
|
|
|
|
70
|
$self->usage_error("The size file [$opt->{size}] doesn't exist."); |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub execute { |
82
|
3
|
|
|
3
|
1
|
66
|
my ( $self, $opt, $args ) = @_; |
83
|
|
|
|
|
|
|
|
84
|
3
|
|
|
|
|
6
|
my $out_fh; |
85
|
3
|
50
|
|
|
|
13
|
if ( lc( $opt->{outfile} ) eq "stdout" ) { |
86
|
3
|
|
|
|
|
11
|
$out_fh = *STDOUT{IO}; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
else { |
89
|
0
|
|
|
|
|
0
|
open $out_fh, ">", $opt->{outfile}; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
3
|
|
|
|
|
4
|
my $length_of; |
93
|
3
|
100
|
|
|
|
11
|
if ( $opt->{size} ) { |
94
|
1
|
|
|
|
|
10
|
$length_of = App::RL::Common::read_sizes( $opt->{size} ); |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
3
|
|
|
|
|
4796
|
for my $infile ( @{$args} ) { |
|
3
|
|
|
|
|
16
|
|
98
|
3
|
|
|
|
|
12
|
my $in_fh; |
99
|
3
|
50
|
|
|
|
10
|
if ( lc $infile eq "stdin" ) { |
100
|
0
|
|
|
|
|
0
|
$in_fh = *STDIN{IO}; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
else { |
103
|
3
|
|
|
|
|
20
|
$in_fh = IO::Zlib->new( $infile, "rb" ); |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
3
|
|
|
|
|
4684
|
my $content = ''; # content of one block |
107
|
3
|
|
|
|
|
4
|
while (1) { |
108
|
48
|
100
|
100
|
|
|
269
|
last if $in_fh->eof and $content eq ''; |
109
|
45
|
|
|
|
|
2288
|
my $line = ''; |
110
|
45
|
100
|
|
|
|
199
|
if ( !$in_fh->eof ) { |
111
|
42
|
|
|
|
|
1715
|
$line = $in_fh->getline; |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
45
|
100
|
100
|
|
|
5611
|
if ( substr( $line, 0, 1 ) eq "#" ) { |
|
|
100
|
66
|
|
|
|
|
115
|
21
|
|
|
|
|
41
|
next; |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
elsif ( ( $line eq '' or $line =~ /^\s+$/ ) and $content ne '' ) { |
118
|
6
|
|
|
|
|
23
|
my $info_refs = App::Fasops::Common::parse_axt_block( $content, $length_of ); |
119
|
6
|
|
|
|
|
11
|
$content = ''; |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
next |
122
|
6
|
100
|
|
|
|
19
|
if App::Fasops::Common::seq_length( $info_refs->[0]{seq} ) < $opt->{length}; |
123
|
|
|
|
|
|
|
next |
124
|
5
|
50
|
|
|
|
15
|
if App::Fasops::Common::seq_length( $info_refs->[1]{seq} ) < $opt->{length}; |
125
|
|
|
|
|
|
|
|
126
|
5
|
|
|
|
|
12
|
$info_refs->[0]{name} = $opt->{tname}; |
127
|
5
|
|
|
|
|
7
|
$info_refs->[1]{name} = $opt->{qname}; |
128
|
|
|
|
|
|
|
|
129
|
5
|
|
|
|
|
12
|
for my $i ( 0, 1 ) { |
130
|
10
|
|
|
|
|
102
|
my $info = $info_refs->[$i]; |
131
|
10
|
|
|
|
|
20
|
printf {$out_fh} ">%s\n", App::RL::Common::encode_header($info); |
|
10
|
|
|
|
|
43
|
|
132
|
10
|
|
|
|
|
750
|
printf {$out_fh} "%s\n", $info->{seq}; |
|
10
|
|
|
|
|
36
|
|
133
|
|
|
|
|
|
|
} |
134
|
5
|
|
|
|
|
88
|
print {$out_fh} "\n"; |
|
5
|
|
|
|
|
16
|
|
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
else { |
137
|
18
|
|
|
|
|
40
|
$content .= $line; |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
|
141
|
3
|
|
|
|
|
505
|
$in_fh->close; |
142
|
|
|
|
|
|
|
} |
143
|
|
|
|
|
|
|
|
144
|
3
|
|
|
|
|
441
|
close $out_fh; |
145
|
|
|
|
|
|
|
} |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
1; |