| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package App::Fasops::Command::concat; |
|
2
|
21
|
|
|
21
|
|
14824
|
use strict; |
|
|
21
|
|
|
|
|
50
|
|
|
|
21
|
|
|
|
|
692
|
|
|
3
|
21
|
|
|
21
|
|
121
|
use warnings; |
|
|
21
|
|
|
|
|
45
|
|
|
|
21
|
|
|
|
|
580
|
|
|
4
|
21
|
|
|
21
|
|
111
|
use autodie; |
|
|
21
|
|
|
|
|
40
|
|
|
|
21
|
|
|
|
|
121
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
21
|
|
|
21
|
|
107050
|
use App::Fasops -command; |
|
|
21
|
|
|
|
|
68
|
|
|
|
21
|
|
|
|
|
235
|
|
|
7
|
21
|
|
|
21
|
|
7395
|
use App::RL::Common; |
|
|
21
|
|
|
|
|
54
|
|
|
|
21
|
|
|
|
|
574
|
|
|
8
|
21
|
|
|
21
|
|
117
|
use App::Fasops::Common; |
|
|
21
|
|
|
|
|
42
|
|
|
|
21
|
|
|
|
|
22250
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub abstract { |
|
11
|
2
|
|
|
2
|
1
|
52
|
return 'concatenate sequence pieces in blocked fasta files'; |
|
12
|
|
|
|
|
|
|
} |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub opt_spec { |
|
15
|
|
|
|
|
|
|
return ( |
|
16
|
7
|
|
|
7
|
1
|
67
|
[ "outfile|o=s", "Output filename. [stdout] for screen" ], |
|
17
|
|
|
|
|
|
|
[ "total|t=i", "Stop when exceed this length", { default => 10_000_000, }, ], |
|
18
|
|
|
|
|
|
|
[ "relaxed", "output relaxed phylip instead of fasta" ], |
|
19
|
|
|
|
|
|
|
{ show_defaults => 1, } |
|
20
|
|
|
|
|
|
|
); |
|
21
|
|
|
|
|
|
|
} |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub usage_desc { |
|
24
|
7
|
|
|
7
|
1
|
58939
|
return "fasops concat [options] "; |
|
25
|
|
|
|
|
|
|
} |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub description { |
|
28
|
1
|
|
|
1
|
1
|
943
|
my $desc; |
|
29
|
1
|
|
|
|
|
6
|
$desc .= ucfirst(abstract) . ".\n"; |
|
30
|
1
|
|
|
|
|
4
|
$desc .= <<'MARKDOWN'; |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
* is the path to blocked fasta file, .fas.gz is supported |
|
33
|
|
|
|
|
|
|
* infile == stdin means reading from STDIN |
|
34
|
|
|
|
|
|
|
* is a file with a list of names to keep, one per line |
|
35
|
|
|
|
|
|
|
* Names in the output file will following the order in |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
MARKDOWN |
|
38
|
|
|
|
|
|
|
|
|
39
|
1
|
|
|
|
|
3
|
return $desc; |
|
40
|
|
|
|
|
|
|
} |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub validate_args { |
|
43
|
6
|
|
|
6
|
1
|
6072
|
my ( $self, $opt, $args ) = @_; |
|
44
|
|
|
|
|
|
|
|
|
45
|
6
|
100
|
|
|
|
26
|
if ( @{$args} != 2 ) { |
|
|
6
|
|
|
|
|
26
|
|
|
46
|
2
|
|
|
|
|
6
|
my $message = "This command need two input files.\n\tIt found"; |
|
47
|
2
|
|
|
|
|
4
|
$message .= sprintf " [%s]", $_ for @{$args}; |
|
|
2
|
|
|
|
|
10
|
|
|
48
|
2
|
|
|
|
|
5
|
$message .= ".\n"; |
|
49
|
2
|
|
|
|
|
11
|
$self->usage_error($message); |
|
50
|
|
|
|
|
|
|
} |
|
51
|
4
|
|
|
|
|
9
|
for ( @{$args} ) { |
|
|
4
|
|
|
|
|
13
|
|
|
52
|
7
|
50
|
|
|
|
274
|
next if lc $_ eq "stdin"; |
|
53
|
7
|
100
|
|
|
|
31
|
if ( !Path::Tiny::path($_)->is_file ) { |
|
54
|
1
|
|
|
|
|
119
|
$self->usage_error("The input file [$_] doesn't exist."); |
|
55
|
|
|
|
|
|
|
} |
|
56
|
|
|
|
|
|
|
} |
|
57
|
|
|
|
|
|
|
|
|
58
|
3
|
50
|
|
|
|
152
|
if ( !exists $opt->{outfile} ) { |
|
59
|
|
|
|
|
|
|
$opt->{outfile} = Path::Tiny::path( $args->[0] )->absolute |
|
60
|
0
|
0
|
|
|
|
0
|
. ( $opt->{relaxed} ? ".concat.phy" : ".concat.fasta" ); |
|
61
|
|
|
|
|
|
|
} |
|
62
|
|
|
|
|
|
|
} |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub execute { |
|
65
|
3
|
|
|
3
|
1
|
23
|
my ( $self, $opt, $args ) = @_; |
|
66
|
|
|
|
|
|
|
|
|
67
|
3
|
|
|
|
|
31
|
my @names = @{ App::RL::Common::read_names( $args->[1] ) }; |
|
|
3
|
|
|
|
|
21
|
|
|
68
|
|
|
|
|
|
|
|
|
69
|
3
|
|
|
|
|
9157
|
my $in_fh; |
|
70
|
3
|
50
|
|
|
|
16
|
if ( lc $args->[0] eq "stdin" ) { |
|
71
|
0
|
|
|
|
|
0
|
$in_fh = *STDIN{IO}; |
|
72
|
|
|
|
|
|
|
} |
|
73
|
|
|
|
|
|
|
else { |
|
74
|
3
|
|
|
|
|
11
|
$in_fh = IO::Zlib->new( $args->[0], "rb" ); |
|
75
|
|
|
|
|
|
|
} |
|
76
|
|
|
|
|
|
|
|
|
77
|
3
|
|
|
|
|
3879
|
my $out_fh; |
|
78
|
3
|
50
|
|
|
|
14
|
if ( lc( $opt->{outfile} ) eq "stdout" ) { |
|
79
|
3
|
|
|
|
|
9
|
$out_fh = *STDOUT{IO}; |
|
80
|
|
|
|
|
|
|
} |
|
81
|
|
|
|
|
|
|
else { |
|
82
|
0
|
|
|
|
|
0
|
open $out_fh, ">", $opt->{outfile}; |
|
83
|
|
|
|
|
|
|
} |
|
84
|
|
|
|
|
|
|
|
|
85
|
3
|
|
|
|
|
10
|
my $all_seq_of = { map { $_ => "" } @names }; |
|
|
6
|
|
|
|
|
21
|
|
|
86
|
|
|
|
|
|
|
{ |
|
87
|
3
|
|
|
|
|
7
|
my $content = ''; # content of one block |
|
|
3
|
|
|
|
|
8
|
|
|
88
|
3
|
|
|
|
|
5
|
BLOCK: while (1) { |
|
89
|
74
|
100
|
66
|
|
|
305
|
last if $in_fh->eof and $content eq ''; |
|
90
|
72
|
|
|
|
|
2879
|
my $line = ''; |
|
91
|
72
|
50
|
|
|
|
245
|
if ( !$in_fh->eof ) { |
|
92
|
72
|
|
|
|
|
2547
|
$line = $in_fh->getline; |
|
93
|
|
|
|
|
|
|
} |
|
94
|
72
|
100
|
66
|
|
|
7739
|
if ( ( $line eq '' or $line =~ /^\s+$/ ) and $content ne '' ) { |
|
|
|
|
66
|
|
|
|
|
|
95
|
8
|
|
|
|
|
40
|
my $info_of = App::Fasops::Common::parse_block($content); |
|
96
|
8
|
|
|
|
|
15
|
$content = ''; |
|
97
|
|
|
|
|
|
|
|
|
98
|
8
|
|
|
|
|
24
|
my $first_name = ( keys %{$info_of} )[0]; |
|
|
8
|
|
|
|
|
27
|
|
|
99
|
8
|
|
|
|
|
227
|
my $align_length = length $info_of->{$first_name}{seq}; |
|
100
|
|
|
|
|
|
|
|
|
101
|
8
|
|
|
|
|
85
|
for my $name (@names) { |
|
102
|
16
|
50
|
|
|
|
115
|
if ( exists $info_of->{$name} ) { |
|
103
|
16
|
|
|
|
|
97
|
$all_seq_of->{$name} .= $info_of->{$name}{seq}; |
|
104
|
|
|
|
|
|
|
} |
|
105
|
|
|
|
|
|
|
else { |
|
106
|
|
|
|
|
|
|
# fill absent names with ------ |
|
107
|
0
|
|
|
|
|
0
|
$all_seq_of->{$name} .= '-' x $align_length; |
|
108
|
|
|
|
|
|
|
} |
|
109
|
|
|
|
|
|
|
} |
|
110
|
|
|
|
|
|
|
|
|
111
|
8
|
100
|
66
|
|
|
184
|
if ( $opt->{total} and $opt->{total} < length $all_seq_of->{ $names[0] } ) { |
|
112
|
1
|
|
|
|
|
12
|
last BLOCK; |
|
113
|
|
|
|
|
|
|
} |
|
114
|
|
|
|
|
|
|
} |
|
115
|
|
|
|
|
|
|
else { |
|
116
|
64
|
|
|
|
|
133
|
$content .= $line; |
|
117
|
|
|
|
|
|
|
} |
|
118
|
|
|
|
|
|
|
} |
|
119
|
|
|
|
|
|
|
} |
|
120
|
|
|
|
|
|
|
|
|
121
|
3
|
|
|
|
|
351
|
my $all_seq_length = length $all_seq_of->{ $names[0] }; |
|
122
|
3
|
100
|
|
|
|
10
|
if ( $opt->{relaxed} ) { |
|
123
|
1
|
|
|
|
|
2
|
print {$out_fh} scalar @names, " $all_seq_length\n"; |
|
|
1
|
|
|
|
|
10
|
|
|
124
|
1
|
|
|
|
|
20
|
for my $name (@names) { |
|
125
|
2
|
|
|
|
|
14
|
print {$out_fh} "$name "; |
|
|
2
|
|
|
|
|
21
|
|
|
126
|
2
|
|
|
|
|
25
|
print {$out_fh} $all_seq_of->{$name}, "\n"; |
|
|
2
|
|
|
|
|
6
|
|
|
127
|
|
|
|
|
|
|
} |
|
128
|
|
|
|
|
|
|
} |
|
129
|
|
|
|
|
|
|
else { |
|
130
|
2
|
|
|
|
|
7
|
for my $name (@names) { |
|
131
|
4
|
|
|
|
|
39
|
print {$out_fh} ">$name\n"; |
|
|
4
|
|
|
|
|
28
|
|
|
132
|
4
|
|
|
|
|
58
|
print {$out_fh} $all_seq_of->{$name}, "\n"; |
|
|
4
|
|
|
|
|
13
|
|
|
133
|
|
|
|
|
|
|
} |
|
134
|
|
|
|
|
|
|
} |
|
135
|
|
|
|
|
|
|
|
|
136
|
3
|
|
|
|
|
61
|
close $out_fh; |
|
137
|
0
|
|
|
|
|
|
$in_fh->close; |
|
138
|
|
|
|
|
|
|
} |
|
139
|
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
1; |