line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::Fasops::Command::vars; |
2
|
20
|
|
|
20
|
|
13464
|
use strict; |
|
20
|
|
|
|
|
50
|
|
|
20
|
|
|
|
|
684
|
|
3
|
20
|
|
|
20
|
|
129
|
use warnings; |
|
20
|
|
|
|
|
55
|
|
|
20
|
|
|
|
|
493
|
|
4
|
20
|
|
|
20
|
|
123
|
use autodie; |
|
20
|
|
|
|
|
40
|
|
|
20
|
|
|
|
|
121
|
|
5
|
|
|
|
|
|
|
|
6
|
20
|
|
|
20
|
|
132568
|
use Excel::Writer::XLSX; |
|
20
|
|
|
|
|
3710086
|
|
|
20
|
|
|
|
|
1309
|
|
7
|
|
|
|
|
|
|
|
8
|
20
|
|
|
20
|
|
256
|
use App::Fasops -command; |
|
20
|
|
|
|
|
55
|
|
|
20
|
|
|
|
|
394
|
|
9
|
20
|
|
|
20
|
|
9544
|
use App::Fasops::Common; |
|
20
|
|
|
|
|
54
|
|
|
20
|
|
|
|
|
29242
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub abstract { |
12
|
2
|
|
|
2
|
1
|
50
|
return 'list substitutions'; |
13
|
|
|
|
|
|
|
} |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub opt_spec { |
16
|
|
|
|
|
|
|
return ( |
17
|
10
|
|
|
10
|
1
|
101
|
[ "outfile|o=s", "Output filename. [stdout] for screen" ], |
18
|
|
|
|
|
|
|
[ "annotation|a=s", "YAML file for cds/repeat" ], |
19
|
|
|
|
|
|
|
[ "length|l=i", "the threshold of alignment length", { default => 1 } ], |
20
|
|
|
|
|
|
|
[ 'outgroup', 'alignments have an outgroup', ], |
21
|
|
|
|
|
|
|
[ 'nosingle', 'omit singleton', ], |
22
|
|
|
|
|
|
|
[ 'nocomplex', 'omit complex', ], |
23
|
|
|
|
|
|
|
{ show_defaults => 1, } |
24
|
|
|
|
|
|
|
); |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub usage_desc { |
28
|
10
|
|
|
10
|
1
|
73526
|
return "fasops vars [options] "; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub description { |
32
|
1
|
|
|
1
|
1
|
1441
|
my $desc; |
33
|
1
|
|
|
|
|
5
|
$desc .= ucfirst(abstract) . ".\n"; |
34
|
1
|
|
|
|
|
3
|
$desc .= <<'MARKDOWN'; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
* are paths to axt files, .fas.gz is supported |
37
|
|
|
|
|
|
|
* infile == stdin means reading from STDIN |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
MARKDOWN |
40
|
|
|
|
|
|
|
|
41
|
1
|
|
|
|
|
3
|
return $desc; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub validate_args { |
45
|
9
|
|
|
9
|
1
|
15855
|
my ( $self, $opt, $args ) = @_; |
46
|
|
|
|
|
|
|
|
47
|
9
|
100
|
|
|
|
19
|
if ( @{$args} != 1 ) { |
|
9
|
|
|
|
|
31
|
|
48
|
1
|
|
|
|
|
3
|
my $message = "This command need one input file.\n\tIt found"; |
49
|
1
|
|
|
|
|
2
|
$message .= sprintf " [%s]", $_ for @{$args}; |
|
1
|
|
|
|
|
4
|
|
50
|
1
|
|
|
|
|
3
|
$message .= ".\n"; |
51
|
1
|
|
|
|
|
13
|
$self->usage_error($message); |
52
|
|
|
|
|
|
|
} |
53
|
8
|
|
|
|
|
25
|
for ( @{$args} ) { |
|
8
|
|
|
|
|
22
|
|
54
|
8
|
50
|
|
|
|
28
|
next if lc $_ eq "stdin"; |
55
|
8
|
100
|
|
|
|
38
|
if ( !Path::Tiny::path($_)->is_file ) { |
56
|
1
|
|
|
|
|
111
|
$self->usage_error("The input file [$_] doesn't exist."); |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
7
|
100
|
|
|
|
617
|
if ( exists $opt->{annotation} ) { |
61
|
1
|
50
|
|
|
|
5
|
if ( !Path::Tiny::path( $opt->{annotation} )->is_file ) { |
62
|
0
|
|
|
|
|
0
|
$self->usage_error("The annotation file [$opt->{annotation}] doesn't exist."); |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
7
|
50
|
|
|
|
84
|
if ( !exists $opt->{outfile} ) { |
67
|
0
|
|
|
|
|
0
|
$opt->{outfile} = Path::Tiny::path( $args->[0] )->absolute . ".tsv"; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub execute { |
72
|
7
|
|
|
7
|
1
|
48
|
my ( $self, $opt, $args ) = @_; |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
#@type IO::Handle |
75
|
7
|
|
|
|
|
13
|
my $in_fh; |
76
|
7
|
50
|
|
|
|
31
|
if ( lc $args->[0] eq "stdin" ) { |
77
|
0
|
|
|
|
|
0
|
$in_fh = *STDIN{IO}; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
else { |
80
|
7
|
|
|
|
|
54
|
$in_fh = IO::Zlib->new( $args->[0], "rb" ); |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
7
|
|
|
|
|
13146
|
my $out_fh; |
84
|
7
|
50
|
|
|
|
33
|
if ( lc( $opt->{outfile} ) eq "stdout" ) { |
85
|
7
|
|
|
|
|
22
|
$out_fh = *STDOUT{IO}; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
else { |
88
|
0
|
|
|
|
|
0
|
open $out_fh, ">", $opt->{outfile}; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
7
|
|
|
|
|
18
|
my $cds_set_of = {}; |
92
|
7
|
|
|
|
|
12
|
my $repeat_set_of = {}; |
93
|
7
|
100
|
|
|
|
28
|
if ( $opt->{annotation} ) { |
94
|
1
|
|
|
|
|
8
|
my $anno = YAML::Syck::LoadFile( $opt->{annotation} ); |
95
|
1
|
50
|
|
|
|
362
|
Carp::confess "Invalid annotation YAML. Need cds.\n" unless defined $anno->{cds}; |
96
|
1
|
50
|
|
|
|
6
|
Carp::confess "Invalid annotation YAML. Need repeat.\n" unless defined $anno->{repeat}; |
97
|
1
|
|
|
|
|
8
|
$cds_set_of = App::RL::Common::runlist2set( $anno->{cds} ); |
98
|
1
|
|
|
|
|
8414
|
$repeat_set_of = App::RL::Common::runlist2set( $anno->{repeat} ); |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
7
|
|
|
|
|
8079
|
my $content = ''; # content of one block |
102
|
7
|
|
|
|
|
10
|
while (1) { |
103
|
505
|
100
|
66
|
|
|
4057
|
last if $in_fh->eof and $content eq ''; |
104
|
498
|
|
|
|
|
21576
|
my $line = ''; |
105
|
498
|
50
|
|
|
|
1666
|
if ( !$in_fh->eof ) { |
106
|
498
|
|
|
|
|
19513
|
$line = $in_fh->getline; |
107
|
|
|
|
|
|
|
} |
108
|
498
|
50
|
|
|
|
97011
|
next if substr( $line, 0, 1 ) eq "#"; |
109
|
|
|
|
|
|
|
|
110
|
498
|
100
|
66
|
|
|
7066
|
if ( ( $line eq '' or $line =~ /^\s+$/ ) and $content ne '' ) { |
|
|
|
66
|
|
|
|
|
111
|
34
|
|
|
|
|
142
|
my $info_of = App::Fasops::Common::parse_block( $content, 1 ); |
112
|
34
|
|
|
|
|
67
|
$content = ''; |
113
|
|
|
|
|
|
|
|
114
|
34
|
|
|
|
|
50
|
my @full_names; |
115
|
34
|
|
|
|
|
65
|
my $seq_refs = []; |
116
|
|
|
|
|
|
|
|
117
|
34
|
|
|
|
|
64
|
for my $key ( keys %{$info_of} ) { |
|
34
|
|
|
|
|
124
|
|
118
|
232
|
|
|
|
|
3336
|
push @full_names, $key; |
119
|
232
|
|
|
|
|
338
|
push @{$seq_refs}, $info_of->{$key}{seq}; |
|
232
|
|
|
|
|
599
|
|
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
34
|
50
|
|
|
|
431
|
if ( $opt->{length} ) { |
123
|
34
|
100
|
|
|
|
105
|
next if length $info_of->{ $full_names[0] }{seq} < $opt->{length}; |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
# Use $target_seq_set to transform align positions to chr positions |
127
|
19
|
|
|
|
|
282
|
my $align_set = AlignDB::IntSpan->new()->add_pair( 1, length $seq_refs->[0] ); |
128
|
19
|
|
|
|
|
1503
|
my $target_indel_set = App::Fasops::Common::indel_intspan( $seq_refs->[0] ); |
129
|
19
|
|
|
|
|
62
|
my $target_seq_set = $align_set->diff($target_indel_set); |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
# Write lines |
132
|
19
|
|
|
|
|
8227
|
my $vars = get_vars( $seq_refs, $opt ); |
133
|
|
|
|
|
|
|
|
134
|
19
|
|
|
|
|
41
|
for my $pos ( sort { $a <=> $b } keys %{$vars} ) { |
|
4319
|
|
|
|
|
5421
|
|
|
19
|
|
|
|
|
465
|
|
135
|
714
|
|
|
|
|
9049
|
my $var = $vars->{$pos}; |
136
|
|
|
|
|
|
|
|
137
|
714
|
|
|
|
|
2699
|
my $chr_name = $info_of->{ $full_names[0] }{chr}; |
138
|
|
|
|
|
|
|
my $snp_chr_pos = App::Fasops::Common::align_to_chr( |
139
|
|
|
|
|
|
|
$target_seq_set, $var->{snp_pos}, |
140
|
|
|
|
|
|
|
$info_of->{ $full_names[0] }{start}, |
141
|
|
|
|
|
|
|
$info_of->{ $full_names[0] }{strand}, |
142
|
714
|
|
|
|
|
8925
|
); |
143
|
|
|
|
|
|
|
|
144
|
714
|
|
|
|
|
2061
|
my $snp_coding = ""; |
145
|
714
|
|
|
|
|
1026
|
my $snp_repeats = ""; |
146
|
714
|
100
|
|
|
|
1447
|
if ( $opt->{annotation} ) { |
147
|
439
|
50
|
|
|
|
911
|
if ( defined $cds_set_of->{$chr_name} ) { |
148
|
439
|
|
|
|
|
983
|
$snp_coding = $cds_set_of->{$chr_name}->contains($snp_chr_pos); |
149
|
|
|
|
|
|
|
} |
150
|
439
|
50
|
|
|
|
24226
|
if ( defined $repeat_set_of->{$chr_name} ) { |
151
|
439
|
|
|
|
|
897
|
$snp_repeats = $repeat_set_of->{$chr_name}->contains($snp_chr_pos); |
152
|
|
|
|
|
|
|
} |
153
|
|
|
|
|
|
|
} |
154
|
|
|
|
|
|
|
|
155
|
714
|
|
|
|
|
5720
|
print {$out_fh} join "\t", |
156
|
|
|
|
|
|
|
$full_names[0], |
157
|
|
|
|
|
|
|
$chr_name, |
158
|
|
|
|
|
|
|
$var->{snp_pos}, |
159
|
|
|
|
|
|
|
$snp_chr_pos, |
160
|
|
|
|
|
|
|
"$chr_name:$snp_chr_pos", |
161
|
|
|
|
|
|
|
$var->{snp_target_base}, |
162
|
|
|
|
|
|
|
$var->{snp_query_base}, |
163
|
|
|
|
|
|
|
$var->{snp_all_bases}, |
164
|
|
|
|
|
|
|
$var->{snp_mutant_to}, |
165
|
|
|
|
|
|
|
$var->{snp_freq}, |
166
|
|
|
|
|
|
|
$var->{snp_occured}, |
167
|
714
|
|
|
|
|
23616
|
$snp_coding, |
168
|
|
|
|
|
|
|
$snp_repeats; |
169
|
714
|
|
|
|
|
10529
|
print {$out_fh} "\n"; |
|
714
|
|
|
|
|
1949
|
|
170
|
|
|
|
|
|
|
} |
171
|
|
|
|
|
|
|
} |
172
|
|
|
|
|
|
|
else { |
173
|
464
|
|
|
|
|
1955
|
$content .= $line; |
174
|
|
|
|
|
|
|
} |
175
|
|
|
|
|
|
|
} |
176
|
|
|
|
|
|
|
|
177
|
7
|
|
|
|
|
1354
|
$in_fh->close; |
178
|
7
|
|
|
|
|
1306
|
$out_fh->close; |
179
|
|
|
|
|
|
|
|
180
|
0
|
|
|
|
|
0
|
return; |
181
|
|
|
|
|
|
|
} |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
# store all variations |
184
|
|
|
|
|
|
|
sub get_vars { |
185
|
19
|
|
|
19
|
0
|
38
|
my $seq_refs = shift; |
186
|
19
|
|
|
|
|
34
|
my $opt = shift; |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
# outgroup |
189
|
19
|
|
|
|
|
50
|
my $out_seq; |
190
|
19
|
100
|
|
|
|
55
|
if ( $opt->{outgroup} ) { |
191
|
9
|
|
|
|
|
14
|
$out_seq = pop @{$seq_refs}; |
|
9
|
|
|
|
|
18
|
|
192
|
|
|
|
|
|
|
} |
193
|
|
|
|
|
|
|
|
194
|
19
|
|
|
|
|
32
|
my $seq_count = scalar @{$seq_refs}; |
|
19
|
|
|
|
|
34
|
|
195
|
19
|
50
|
|
|
|
52
|
if ( $seq_count < 2 ) { |
196
|
0
|
|
|
|
|
0
|
Carp::confess "Too few sequences [$seq_count]\n"; |
197
|
|
|
|
|
|
|
} |
198
|
|
|
|
|
|
|
|
199
|
19
|
|
|
|
|
34
|
my %variations; |
200
|
|
|
|
|
|
|
|
201
|
19
|
|
|
|
|
63
|
my $snp_sites = App::Fasops::Common::get_snps($seq_refs); |
202
|
19
|
100
|
|
|
|
65
|
if ( $opt->{outgroup} ) { |
203
|
9
|
|
|
|
|
26
|
App::Fasops::Common::polarize_snp( $snp_sites, $out_seq ); |
204
|
|
|
|
|
|
|
} |
205
|
|
|
|
|
|
|
|
206
|
19
|
|
|
|
|
35
|
for my $site ( @{$snp_sites} ) { |
|
19
|
|
|
|
|
39
|
|
207
|
1163
|
100
|
100
|
|
|
2912
|
if ( $opt->{nocomplex} and $site->{snp_freq} == -1 ) { |
208
|
39
|
|
|
|
|
54
|
next; |
209
|
|
|
|
|
|
|
} |
210
|
1124
|
100
|
100
|
|
|
2691
|
if ( $opt->{nosingle} and $site->{snp_freq} <= 1 ) { |
211
|
410
|
|
|
|
|
593
|
next; |
212
|
|
|
|
|
|
|
} |
213
|
|
|
|
|
|
|
|
214
|
714
|
|
|
|
|
1285
|
$variations{ $site->{snp_pos} } = $site; |
215
|
|
|
|
|
|
|
} |
216
|
|
|
|
|
|
|
|
217
|
19
|
|
|
|
|
367
|
return \%variations; |
218
|
|
|
|
|
|
|
} |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
1; |