| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package App::Fasops::Command::split; |
|
2
|
20
|
|
|
20
|
|
14422
|
use strict; |
|
|
20
|
|
|
|
|
53
|
|
|
|
20
|
|
|
|
|
647
|
|
|
3
|
20
|
|
|
20
|
|
121
|
use warnings; |
|
|
20
|
|
|
|
|
54
|
|
|
|
20
|
|
|
|
|
512
|
|
|
4
|
20
|
|
|
20
|
|
106
|
use autodie; |
|
|
20
|
|
|
|
|
55
|
|
|
|
20
|
|
|
|
|
130
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
20
|
|
|
20
|
|
106728
|
use App::Fasops -command; |
|
|
20
|
|
|
|
|
55
|
|
|
|
20
|
|
|
|
|
231
|
|
|
7
|
20
|
|
|
20
|
|
7165
|
use App::RL::Common; |
|
|
20
|
|
|
|
|
55
|
|
|
|
20
|
|
|
|
|
640
|
|
|
8
|
20
|
|
|
20
|
|
117
|
use App::Fasops::Common; |
|
|
20
|
|
|
|
|
40
|
|
|
|
20
|
|
|
|
|
23923
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub abstract { |
|
11
|
2
|
|
|
2
|
1
|
48
|
return 'split blocked fasta files to per-alignment files'; |
|
12
|
|
|
|
|
|
|
} |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub opt_spec { |
|
15
|
|
|
|
|
|
|
return ( |
|
16
|
6
|
|
|
6
|
1
|
37
|
[ "outdir|o=s", "Output location, [stdout] for screen" ], |
|
17
|
|
|
|
|
|
|
[ "rm|r", "if outdir exists, remove it before operating." ], |
|
18
|
|
|
|
|
|
|
[ "chr", "split by chromosomes." ], |
|
19
|
|
|
|
|
|
|
[ "simple", "only keep names in headers" ], |
|
20
|
|
|
|
|
|
|
{ show_defaults => 1, } |
|
21
|
|
|
|
|
|
|
); |
|
22
|
|
|
|
|
|
|
} |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub usage_desc { |
|
25
|
6
|
|
|
6
|
1
|
53160
|
return "fasops split [options] [more infiles]"; |
|
26
|
|
|
|
|
|
|
} |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub description { |
|
29
|
1
|
|
|
1
|
1
|
1169
|
my $desc; |
|
30
|
1
|
|
|
|
|
5
|
$desc .= ucfirst(abstract) . ".\n"; |
|
31
|
1
|
|
|
|
|
3
|
$desc .= <<'MARKDOWN'; |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
* are paths to blocked fasta files, .fas.gz is supported |
|
34
|
|
|
|
|
|
|
* infile == stdin means reading from STDIN |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
MARKDOWN |
|
37
|
|
|
|
|
|
|
|
|
38
|
1
|
|
|
|
|
3
|
return $desc; |
|
39
|
|
|
|
|
|
|
} |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub validate_args { |
|
42
|
5
|
|
|
5
|
1
|
6034
|
my ( $self, $opt, $args ) = @_; |
|
43
|
|
|
|
|
|
|
|
|
44
|
5
|
100
|
|
|
|
9
|
if ( !@{$args} ) { |
|
|
5
|
|
|
|
|
17
|
|
|
45
|
1
|
|
|
|
|
2
|
my $message = "This command need one or more input files.\n\tIt found"; |
|
46
|
1
|
|
|
|
|
3
|
$message .= sprintf " [%s]", $_ for @{$args}; |
|
|
1
|
|
|
|
|
4
|
|
|
47
|
1
|
|
|
|
|
3
|
$message .= ".\n"; |
|
48
|
1
|
|
|
|
|
20
|
$self->usage_error($message); |
|
49
|
|
|
|
|
|
|
} |
|
50
|
4
|
|
|
|
|
18
|
for ( @{$args} ) { |
|
|
4
|
|
|
|
|
12
|
|
|
51
|
4
|
50
|
|
|
|
14
|
next if lc $_ eq "stdin"; |
|
52
|
4
|
100
|
|
|
|
16
|
if ( !Path::Tiny::path($_)->is_file ) { |
|
53
|
1
|
|
|
|
|
141
|
$self->usage_error("The input file [$_] doesn't exist."); |
|
54
|
|
|
|
|
|
|
} |
|
55
|
|
|
|
|
|
|
} |
|
56
|
|
|
|
|
|
|
|
|
57
|
3
|
50
|
|
|
|
197
|
if ( !exists $opt->{outdir} ) { |
|
58
|
0
|
|
|
|
|
0
|
$opt->{outdir} = Path::Tiny::path( $args->[0] )->absolute . ".split"; |
|
59
|
|
|
|
|
|
|
} |
|
60
|
3
|
100
|
|
|
|
31
|
if ( -e $opt->{outdir} ) { |
|
61
|
1
|
50
|
|
|
|
6
|
if ( $opt->{rm} ) { |
|
62
|
0
|
|
|
|
|
0
|
Path::Tiny::path( $opt->{outdir} )->remove_tree; |
|
63
|
|
|
|
|
|
|
} |
|
64
|
|
|
|
|
|
|
} |
|
65
|
|
|
|
|
|
|
|
|
66
|
3
|
100
|
|
|
|
20
|
if ( lc( $opt->{outdir} ) ne "stdout" ) { |
|
67
|
1
|
|
|
|
|
7
|
Path::Tiny::path( $opt->{outdir} )->mkpath; |
|
68
|
|
|
|
|
|
|
} |
|
69
|
|
|
|
|
|
|
} |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub execute { |
|
72
|
3
|
|
|
3
|
1
|
142
|
my ( $self, $opt, $args ) = @_; |
|
73
|
|
|
|
|
|
|
|
|
74
|
3
|
|
|
|
|
5
|
for my $infile ( @{$args} ) { |
|
|
3
|
|
|
|
|
7
|
|
|
75
|
3
|
|
|
|
|
6
|
my $in_fh; |
|
76
|
3
|
50
|
|
|
|
10
|
if ( lc $infile eq "stdin" ) { |
|
77
|
0
|
|
|
|
|
0
|
$in_fh = *STDIN{IO}; |
|
78
|
|
|
|
|
|
|
} |
|
79
|
|
|
|
|
|
|
else { |
|
80
|
3
|
|
|
|
|
21
|
$in_fh = IO::Zlib->new( $infile, "rb" ); |
|
81
|
|
|
|
|
|
|
} |
|
82
|
|
|
|
|
|
|
|
|
83
|
3
|
|
|
|
|
4711
|
my $content = ''; # content of one block |
|
84
|
3
|
|
|
|
|
6
|
while (1) { |
|
85
|
84
|
100
|
66
|
|
|
1696
|
last if $in_fh->eof and $content eq ''; |
|
86
|
81
|
|
|
|
|
3473
|
my $line = ''; |
|
87
|
81
|
50
|
|
|
|
254
|
if ( !$in_fh->eof ) { |
|
88
|
81
|
|
|
|
|
3223
|
$line = $in_fh->getline; |
|
89
|
|
|
|
|
|
|
} |
|
90
|
81
|
100
|
66
|
|
|
9478
|
if ( ( $line eq '' or $line =~ /^\s+$/ ) and $content ne '' ) { |
|
|
|
|
66
|
|
|
|
|
|
91
|
9
|
|
|
|
|
34
|
my $info_of = App::Fasops::Common::parse_block($content); |
|
92
|
9
|
|
|
|
|
18
|
$content = ''; |
|
93
|
|
|
|
|
|
|
|
|
94
|
9
|
100
|
|
|
|
25
|
if ( lc( $opt->{outdir} ) eq "stdout" ) { |
|
95
|
6
|
|
|
|
|
10
|
for my $key ( keys %{$info_of} ) { |
|
|
6
|
|
|
|
|
21
|
|
|
96
|
24
|
100
|
|
|
|
614
|
if ( $opt->{simple} ) { |
|
97
|
12
|
|
|
|
|
35
|
printf ">%s\n", $info_of->{$key}{name}; |
|
98
|
|
|
|
|
|
|
} |
|
99
|
|
|
|
|
|
|
else { |
|
100
|
12
|
|
|
|
|
37
|
printf ">%s\n", App::RL::Common::encode_header( $info_of->{$key} ); |
|
101
|
|
|
|
|
|
|
} |
|
102
|
24
|
|
|
|
|
2499
|
print $info_of->{$key}{seq} . "\n"; |
|
103
|
|
|
|
|
|
|
} |
|
104
|
|
|
|
|
|
|
} |
|
105
|
|
|
|
|
|
|
else { |
|
106
|
3
|
|
|
|
|
8
|
my $target = ( keys %{$info_of} )[0]; |
|
|
3
|
|
|
|
|
10
|
|
|
107
|
3
|
|
|
|
|
81
|
my $filename; |
|
108
|
3
|
50
|
|
|
|
10
|
if ( $opt->{chr} ) { |
|
109
|
3
|
|
|
|
|
10
|
$filename = $info_of->{$target}{chr}; |
|
110
|
3
|
|
|
|
|
38
|
$filename .= '.fas'; |
|
111
|
|
|
|
|
|
|
} |
|
112
|
|
|
|
|
|
|
else { |
|
113
|
0
|
|
|
|
|
0
|
$filename = App::RL::Common::encode_header( $info_of->{$target} ); |
|
114
|
0
|
|
|
|
|
0
|
$filename =~ s/\|.+//; # remove addtional fields |
|
115
|
0
|
|
|
|
|
0
|
$filename =~ s/[\(\)\:]+/./g; |
|
116
|
0
|
|
|
|
|
0
|
$filename .= '.fas'; |
|
117
|
|
|
|
|
|
|
} |
|
118
|
3
|
|
|
|
|
14
|
$filename = Path::Tiny::path( $opt->{outdir}, $filename ); |
|
119
|
|
|
|
|
|
|
|
|
120
|
3
|
|
|
|
|
120
|
open my $out_fh, ">>", $filename; |
|
121
|
3
|
|
|
|
|
2389
|
for my $key ( keys %{$info_of} ) { |
|
|
3
|
|
|
|
|
14
|
|
|
122
|
12
|
50
|
|
|
|
212
|
if ( $opt->{simple} ) { |
|
123
|
0
|
|
|
|
|
0
|
printf {$out_fh} ">%s\n", $info_of->{$key}{name}; |
|
|
0
|
|
|
|
|
0
|
|
|
124
|
|
|
|
|
|
|
} |
|
125
|
|
|
|
|
|
|
else { |
|
126
|
12
|
|
|
|
|
41
|
printf {$out_fh} ">%s\n", |
|
127
|
12
|
|
|
|
|
21
|
App::RL::Common::encode_header( $info_of->{$key} ); |
|
128
|
|
|
|
|
|
|
} |
|
129
|
12
|
|
|
|
|
1881
|
print {$out_fh} $info_of->{$key}{seq} . "\n"; |
|
|
12
|
|
|
|
|
42
|
|
|
130
|
|
|
|
|
|
|
} |
|
131
|
3
|
|
|
|
|
36
|
print {$out_fh} "\n"; |
|
|
3
|
|
|
|
|
6
|
|
|
132
|
3
|
|
|
|
|
11
|
close $out_fh; |
|
133
|
|
|
|
|
|
|
} |
|
134
|
|
|
|
|
|
|
} |
|
135
|
|
|
|
|
|
|
else { |
|
136
|
72
|
|
|
|
|
149
|
$content .= $line; |
|
137
|
|
|
|
|
|
|
} |
|
138
|
|
|
|
|
|
|
} |
|
139
|
|
|
|
|
|
|
|
|
140
|
3
|
|
|
|
|
503
|
$in_fh->close; |
|
141
|
|
|
|
|
|
|
} |
|
142
|
|
|
|
|
|
|
} |
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
1; |