line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::Fasops::Command::vars; |
2
|
21
|
|
|
21
|
|
14963
|
use strict; |
|
21
|
|
|
|
|
53
|
|
|
21
|
|
|
|
|
675
|
|
3
|
21
|
|
|
21
|
|
117
|
use warnings; |
|
21
|
|
|
|
|
51
|
|
|
21
|
|
|
|
|
606
|
|
4
|
21
|
|
|
21
|
|
113
|
use autodie; |
|
21
|
|
|
|
|
49
|
|
|
21
|
|
|
|
|
140
|
|
5
|
|
|
|
|
|
|
|
6
|
21
|
|
|
21
|
|
140419
|
use Excel::Writer::XLSX; |
|
21
|
|
|
|
|
3995546
|
|
|
21
|
|
|
|
|
1350
|
|
7
|
|
|
|
|
|
|
|
8
|
21
|
|
|
21
|
|
250
|
use App::Fasops -command; |
|
21
|
|
|
|
|
55
|
|
|
21
|
|
|
|
|
417
|
|
9
|
21
|
|
|
21
|
|
10318
|
use App::Fasops::Common; |
|
21
|
|
|
|
|
1402
|
|
|
21
|
|
|
|
|
30557
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub abstract { |
12
|
2
|
|
|
2
|
1
|
45
|
return 'list substitutions'; |
13
|
|
|
|
|
|
|
} |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub opt_spec { |
16
|
|
|
|
|
|
|
return ( |
17
|
10
|
|
|
10
|
1
|
96
|
[ "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
|
60127
|
return "fasops vars [options] "; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub description { |
32
|
1
|
|
|
1
|
1
|
1223
|
my $desc; |
33
|
1
|
|
|
|
|
4
|
$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
|
|
|
|
|
2
|
return $desc; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub validate_args { |
45
|
9
|
|
|
9
|
1
|
12788
|
my ( $self, $opt, $args ) = @_; |
46
|
|
|
|
|
|
|
|
47
|
9
|
100
|
|
|
|
14
|
if ( @{$args} != 1 ) { |
|
9
|
|
|
|
|
35
|
|
48
|
1
|
|
|
|
|
3
|
my $message = "This command need one input file.\n\tIt found"; |
49
|
1
|
|
|
|
|
2
|
$message .= sprintf " [%s]", $_ for @{$args}; |
|
1
|
|
|
|
|
3
|
|
50
|
1
|
|
|
|
|
3
|
$message .= ".\n"; |
51
|
1
|
|
|
|
|
10
|
$self->usage_error($message); |
52
|
|
|
|
|
|
|
} |
53
|
8
|
|
|
|
|
11
|
for ( @{$args} ) { |
|
8
|
|
|
|
|
21
|
|
54
|
8
|
50
|
|
|
|
28
|
next if lc $_ eq "stdin"; |
55
|
8
|
100
|
|
|
|
34
|
if ( !Path::Tiny::path($_)->is_file ) { |
56
|
1
|
|
|
|
|
105
|
$self->usage_error("The input file [$_] doesn't exist."); |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
7
|
100
|
|
|
|
860
|
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
|
|
|
|
68
|
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
|
39
|
my ( $self, $opt, $args ) = @_; |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
#@type IO::Handle |
75
|
7
|
|
|
|
|
12
|
my $in_fh; |
76
|
7
|
50
|
|
|
|
26
|
if ( lc $args->[0] eq "stdin" ) { |
77
|
0
|
|
|
|
|
0
|
$in_fh = *STDIN{IO}; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
else { |
80
|
7
|
|
|
|
|
49
|
$in_fh = IO::Zlib->new( $args->[0], "rb" ); |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
7
|
|
|
|
|
10760
|
my $out_fh; |
84
|
7
|
50
|
|
|
|
29
|
if ( lc( $opt->{outfile} ) eq "stdout" ) { |
85
|
7
|
|
|
|
|
15
|
$out_fh = *STDOUT{IO}; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
else { |
88
|
0
|
|
|
|
|
0
|
open $out_fh, ">", $opt->{outfile}; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
7
|
|
|
|
|
19
|
my $cds_set_of = {}; |
92
|
7
|
|
|
|
|
12
|
my $repeat_set_of = {}; |
93
|
7
|
100
|
|
|
|
23
|
if ( $opt->{annotation} ) { |
94
|
1
|
|
|
|
|
5
|
my $anno = YAML::Syck::LoadFile( $opt->{annotation} ); |
95
|
1
|
50
|
|
|
|
276
|
Carp::confess "Invalid annotation YAML. Need cds.\n" unless defined $anno->{cds}; |
96
|
1
|
50
|
|
|
|
5
|
Carp::confess "Invalid annotation YAML. Need repeat.\n" unless defined $anno->{repeat}; |
97
|
1
|
|
|
|
|
5
|
$cds_set_of = App::RL::Common::runlist2set( $anno->{cds} ); |
98
|
1
|
|
|
|
|
6861
|
$repeat_set_of = App::RL::Common::runlist2set( $anno->{repeat} ); |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
7
|
|
|
|
|
6570
|
my $content = ''; # content of one block |
102
|
7
|
|
|
|
|
12
|
while (1) { |
103
|
505
|
100
|
66
|
|
|
3486
|
last if $in_fh->eof and $content eq ''; |
104
|
498
|
|
|
|
|
17944
|
my $line = ''; |
105
|
498
|
50
|
|
|
|
1266
|
if ( !$in_fh->eof ) { |
106
|
498
|
|
|
|
|
15843
|
$line = $in_fh->getline; |
107
|
|
|
|
|
|
|
} |
108
|
498
|
50
|
|
|
|
79062
|
next if substr( $line, 0, 1 ) eq "#"; |
109
|
|
|
|
|
|
|
|
110
|
498
|
100
|
66
|
|
|
5733
|
if ( ( $line eq '' or $line =~ /^\s+$/ ) and $content ne '' ) { |
|
|
|
66
|
|
|
|
|
111
|
34
|
|
|
|
|
98
|
my $info_of = App::Fasops::Common::parse_block( $content, 1 ); |
112
|
34
|
|
|
|
|
60
|
$content = ''; |
113
|
|
|
|
|
|
|
|
114
|
34
|
|
|
|
|
52
|
my @full_names; |
115
|
34
|
|
|
|
|
43
|
my $seq_refs = []; |
116
|
|
|
|
|
|
|
|
117
|
34
|
|
|
|
|
49
|
for my $key ( keys %{$info_of} ) { |
|
34
|
|
|
|
|
127
|
|
118
|
232
|
|
|
|
|
2713
|
push @full_names, $key; |
119
|
232
|
|
|
|
|
276
|
push @{$seq_refs}, $info_of->{$key}{seq}; |
|
232
|
|
|
|
|
493
|
|
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
34
|
50
|
|
|
|
341
|
if ( $opt->{length} ) { |
123
|
34
|
100
|
|
|
|
94
|
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
|
|
|
|
|
232
|
my $align_set = AlignDB::IntSpan->new()->add_pair( 1, length $seq_refs->[0] ); |
128
|
19
|
|
|
|
|
1210
|
my $target_indel_set = App::Fasops::Common::indel_intspan( $seq_refs->[0] ); |
129
|
19
|
|
|
|
|
54
|
my $target_seq_set = $align_set->diff($target_indel_set); |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
# Write lines |
132
|
19
|
|
|
|
|
6694
|
my $vars = get_vars( $seq_refs, $opt ); |
133
|
|
|
|
|
|
|
|
134
|
19
|
|
|
|
|
30
|
for my $pos ( sort { $a <=> $b } keys %{$vars} ) { |
|
4308
|
|
|
|
|
4288
|
|
|
19
|
|
|
|
|
339
|
|
135
|
714
|
|
|
|
|
7060
|
my $var = $vars->{$pos}; |
136
|
|
|
|
|
|
|
|
137
|
714
|
|
|
|
|
1994
|
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
|
|
|
|
|
7112
|
); |
143
|
|
|
|
|
|
|
|
144
|
714
|
|
|
|
|
1547
|
my $snp_coding = ""; |
145
|
714
|
|
|
|
|
857
|
my $snp_repeats = ""; |
146
|
714
|
100
|
|
|
|
1137
|
if ( $opt->{annotation} ) { |
147
|
439
|
50
|
|
|
|
793
|
if ( defined $cds_set_of->{$chr_name} ) { |
148
|
439
|
|
|
|
|
815
|
$snp_coding = $cds_set_of->{$chr_name}->contains($snp_chr_pos); |
149
|
|
|
|
|
|
|
} |
150
|
439
|
50
|
|
|
|
19825
|
if ( defined $repeat_set_of->{$chr_name} ) { |
151
|
439
|
|
|
|
|
756
|
$snp_repeats = $repeat_set_of->{$chr_name}->contains($snp_chr_pos); |
152
|
|
|
|
|
|
|
} |
153
|
|
|
|
|
|
|
} |
154
|
|
|
|
|
|
|
|
155
|
714
|
|
|
|
|
4092
|
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
|
|
|
|
|
19121
|
$snp_coding, |
168
|
|
|
|
|
|
|
$snp_repeats; |
169
|
714
|
|
|
|
|
8891
|
print {$out_fh} "\n"; |
|
714
|
|
|
|
|
1631
|
|
170
|
|
|
|
|
|
|
} |
171
|
|
|
|
|
|
|
} |
172
|
|
|
|
|
|
|
else { |
173
|
464
|
|
|
|
|
1683
|
$content .= $line; |
174
|
|
|
|
|
|
|
} |
175
|
|
|
|
|
|
|
} |
176
|
|
|
|
|
|
|
|
177
|
7
|
|
|
|
|
1040
|
$in_fh->close; |
178
|
7
|
|
|
|
|
1108
|
$out_fh->close; |
179
|
|
|
|
|
|
|
|
180
|
0
|
|
|
|
|
0
|
return; |
181
|
|
|
|
|
|
|
} |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
# store all variations |
184
|
|
|
|
|
|
|
sub get_vars { |
185
|
19
|
|
|
19
|
0
|
28
|
my $seq_refs = shift; |
186
|
19
|
|
|
|
|
24
|
my $opt = shift; |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
# outgroup |
189
|
19
|
|
|
|
|
23
|
my $out_seq; |
190
|
19
|
100
|
|
|
|
41
|
if ( $opt->{outgroup} ) { |
191
|
9
|
|
|
|
|
12
|
$out_seq = pop @{$seq_refs}; |
|
9
|
|
|
|
|
14
|
|
192
|
|
|
|
|
|
|
} |
193
|
|
|
|
|
|
|
|
194
|
19
|
|
|
|
|
23
|
my $seq_count = scalar @{$seq_refs}; |
|
19
|
|
|
|
|
32
|
|
195
|
19
|
50
|
|
|
|
38
|
if ( $seq_count < 2 ) { |
196
|
0
|
|
|
|
|
0
|
Carp::confess "Too few sequences [$seq_count]\n"; |
197
|
|
|
|
|
|
|
} |
198
|
|
|
|
|
|
|
|
199
|
19
|
|
|
|
|
28
|
my %variations; |
200
|
|
|
|
|
|
|
|
201
|
19
|
|
|
|
|
46
|
my $snp_sites = App::Fasops::Common::get_snps($seq_refs); |
202
|
19
|
100
|
|
|
|
51
|
if ( $opt->{outgroup} ) { |
203
|
9
|
|
|
|
|
22
|
App::Fasops::Common::polarize_snp( $snp_sites, $out_seq ); |
204
|
|
|
|
|
|
|
} |
205
|
|
|
|
|
|
|
|
206
|
19
|
|
|
|
|
25
|
for my $site ( @{$snp_sites} ) { |
|
19
|
|
|
|
|
34
|
|
207
|
1163
|
100
|
100
|
|
|
2232
|
if ( $opt->{nocomplex} and $site->{snp_freq} == -1 ) { |
208
|
39
|
|
|
|
|
45
|
next; |
209
|
|
|
|
|
|
|
} |
210
|
1124
|
100
|
100
|
|
|
2205
|
if ( $opt->{nosingle} and $site->{snp_freq} <= 1 ) { |
211
|
410
|
|
|
|
|
461
|
next; |
212
|
|
|
|
|
|
|
} |
213
|
|
|
|
|
|
|
|
214
|
714
|
|
|
|
|
986
|
$variations{ $site->{snp_pos} } = $site; |
215
|
|
|
|
|
|
|
} |
216
|
|
|
|
|
|
|
|
217
|
19
|
|
|
|
|
281
|
return \%variations; |
218
|
|
|
|
|
|
|
} |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
1; |