| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package App::Fasops::Command::xlsx; |
|
2
|
21
|
|
|
21
|
|
19050
|
use strict; |
|
|
21
|
|
|
|
|
67
|
|
|
|
21
|
|
|
|
|
744
|
|
|
3
|
21
|
|
|
21
|
|
130
|
use warnings; |
|
|
21
|
|
|
|
|
37
|
|
|
|
21
|
|
|
|
|
638
|
|
|
4
|
21
|
|
|
21
|
|
117
|
use autodie; |
|
|
21
|
|
|
|
|
43
|
|
|
|
21
|
|
|
|
|
173
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
21
|
|
|
21
|
|
108967
|
use Excel::Writer::XLSX; |
|
|
21
|
|
|
|
|
67
|
|
|
|
21
|
|
|
|
|
1272
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
21
|
|
|
21
|
|
166
|
use App::Fasops -command; |
|
|
21
|
|
|
|
|
40
|
|
|
|
21
|
|
|
|
|
226
|
|
|
9
|
21
|
|
|
21
|
|
7394
|
use App::Fasops::Common; |
|
|
21
|
|
|
|
|
89
|
|
|
|
21
|
|
|
|
|
57335
|
|
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub abstract { |
|
12
|
2
|
|
|
2
|
1
|
48
|
return 'paint substitutions and indels to an excel file'; |
|
13
|
|
|
|
|
|
|
} |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub opt_spec { |
|
16
|
|
|
|
|
|
|
return ( |
|
17
|
9
|
|
|
9
|
1
|
158
|
[ "outfile|o=s", "Output filename" ], |
|
18
|
|
|
|
|
|
|
[ "length|l=i", "the threshold of alignment length", { default => 1 }, ], |
|
19
|
|
|
|
|
|
|
[ 'wrap=i', 'wrap length', { default => 50 }, ], |
|
20
|
|
|
|
|
|
|
[ 'spacing=i', 'wrapped line spacing', { default => 1 }, ], |
|
21
|
|
|
|
|
|
|
[ 'colors=i', 'number of colors', { default => 15 }, ], |
|
22
|
|
|
|
|
|
|
[ 'section=i', 'start section', { default => 1, hidden => 1 }, ], |
|
23
|
|
|
|
|
|
|
[ 'outgroup', 'alignments have an outgroup', ], |
|
24
|
|
|
|
|
|
|
[ 'noindel', 'omit indels', ], |
|
25
|
|
|
|
|
|
|
[ 'nosingle', 'omit singleton SNPs and indels', ], |
|
26
|
|
|
|
|
|
|
[ 'nocomplex', 'omit complex SNPs and indels', ], |
|
27
|
|
|
|
|
|
|
[ 'min=f', 'minimal frequency', ], |
|
28
|
|
|
|
|
|
|
[ 'max=f', 'maximal frequency', ], |
|
29
|
|
|
|
|
|
|
{ show_defaults => 1, } |
|
30
|
|
|
|
|
|
|
); |
|
31
|
|
|
|
|
|
|
} |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub usage_desc { |
|
34
|
9
|
|
|
9
|
1
|
852855
|
return "fasops xlsx [options] "; |
|
35
|
|
|
|
|
|
|
} |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub description { |
|
38
|
1
|
|
|
1
|
1
|
2618
|
my $desc; |
|
39
|
1
|
|
|
|
|
6
|
$desc .= ucfirst(abstract) . ".\n"; |
|
40
|
1
|
|
|
|
|
4
|
$desc .= <<'MARKDOWN'; |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
* are paths to axt files, .fas.gz is supported |
|
43
|
|
|
|
|
|
|
* infile == stdin means reading from STDIN |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
MARKDOWN |
|
46
|
|
|
|
|
|
|
|
|
47
|
1
|
|
|
|
|
3
|
return $desc; |
|
48
|
|
|
|
|
|
|
} |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub validate_args { |
|
51
|
8
|
|
|
8
|
1
|
23066
|
my ( $self, $opt, $args ) = @_; |
|
52
|
|
|
|
|
|
|
|
|
53
|
8
|
100
|
|
|
|
20
|
if ( @{$args} != 1 ) { |
|
|
8
|
|
|
|
|
41
|
|
|
54
|
1
|
|
|
|
|
4
|
my $message = "This command need one input file.\n\tIt found"; |
|
55
|
1
|
|
|
|
|
2
|
$message .= sprintf " [%s]", $_ for @{$args}; |
|
|
1
|
|
|
|
|
4
|
|
|
56
|
1
|
|
|
|
|
3
|
$message .= ".\n"; |
|
57
|
1
|
|
|
|
|
12
|
$self->usage_error($message); |
|
58
|
|
|
|
|
|
|
} |
|
59
|
7
|
|
|
|
|
23
|
for ( @{$args} ) { |
|
|
7
|
|
|
|
|
23
|
|
|
60
|
7
|
50
|
|
|
|
37
|
next if lc $_ eq "stdin"; |
|
61
|
7
|
100
|
|
|
|
37
|
if ( !Path::Tiny::path($_)->is_file ) { |
|
62
|
1
|
|
|
|
|
119
|
$self->usage_error("The input file [$_] doesn't exist."); |
|
63
|
|
|
|
|
|
|
} |
|
64
|
|
|
|
|
|
|
} |
|
65
|
|
|
|
|
|
|
|
|
66
|
6
|
50
|
|
|
|
499
|
if ( !exists $opt->{outfile} ) { |
|
67
|
0
|
|
|
|
|
0
|
$opt->{outfile} = Path::Tiny::path( $args->[0] )->absolute . ".xlsx"; |
|
68
|
|
|
|
|
|
|
} |
|
69
|
|
|
|
|
|
|
|
|
70
|
6
|
50
|
|
|
|
30
|
if ( $opt->{colors} ) { |
|
71
|
6
|
|
|
|
|
47
|
$opt->{colors} = List::Util::min( $opt->{colors}, 15 ); |
|
72
|
|
|
|
|
|
|
} |
|
73
|
|
|
|
|
|
|
} |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub execute { |
|
76
|
6
|
|
|
6
|
1
|
49
|
my ( $self, $opt, $args ) = @_; |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
#@type IO::Handle |
|
79
|
6
|
|
|
|
|
16
|
my $in_fh; |
|
80
|
6
|
50
|
|
|
|
50
|
if ( lc $args->[0] eq "stdin" ) { |
|
81
|
0
|
|
|
|
|
0
|
$in_fh = *STDIN{IO}; |
|
82
|
|
|
|
|
|
|
} |
|
83
|
|
|
|
|
|
|
else { |
|
84
|
6
|
|
|
|
|
76
|
$in_fh = IO::Zlib->new( $args->[0], "rb" ); |
|
85
|
|
|
|
|
|
|
} |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
# Create workbook and worksheet objects |
|
88
|
|
|
|
|
|
|
#@type Excel::Writer::XLSX |
|
89
|
6
|
|
|
|
|
11073
|
my $workbook = Excel::Writer::XLSX->new( $opt->{outfile} ); |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
#@type Excel::Writer::XLSX::Worksheet |
|
92
|
6
|
|
|
|
|
3532
|
my $worksheet = $workbook->add_worksheet; |
|
93
|
|
|
|
|
|
|
|
|
94
|
6
|
|
|
|
|
2251
|
my $format_of = create_formats($workbook); |
|
95
|
6
|
|
|
|
|
14
|
my $max_name_length = 1; |
|
96
|
|
|
|
|
|
|
|
|
97
|
6
|
|
|
|
|
18
|
my $content = ''; # content of one block |
|
98
|
6
|
|
|
|
|
11
|
while (1) { |
|
99
|
168
|
100
|
66
|
|
|
818
|
last if $in_fh->eof and $content eq ''; |
|
100
|
162
|
|
|
|
|
7350
|
my $line = ''; |
|
101
|
162
|
50
|
|
|
|
500
|
if ( !$in_fh->eof ) { |
|
102
|
162
|
|
|
|
|
6385
|
$line = $in_fh->getline; |
|
103
|
|
|
|
|
|
|
} |
|
104
|
162
|
50
|
|
|
|
19651
|
next if substr( $line, 0, 1 ) eq "#"; |
|
105
|
|
|
|
|
|
|
|
|
106
|
162
|
100
|
66
|
|
|
918
|
if ( ( $line eq '' or $line =~ /^\s+$/ ) and $content ne '' ) { |
|
|
|
|
66
|
|
|
|
|
|
107
|
18
|
|
|
|
|
105
|
my $info_of = App::Fasops::Common::parse_block( $content, 1 ); |
|
108
|
18
|
|
|
|
|
50
|
$content = ''; |
|
109
|
|
|
|
|
|
|
|
|
110
|
18
|
|
|
|
|
40
|
my @full_names; |
|
111
|
18
|
|
|
|
|
44
|
my $seq_refs = []; |
|
112
|
|
|
|
|
|
|
|
|
113
|
18
|
|
|
|
|
36
|
for my $key ( keys %{$info_of} ) { |
|
|
18
|
|
|
|
|
71
|
|
|
114
|
72
|
|
|
|
|
1124
|
push @full_names, $key; |
|
115
|
72
|
|
|
|
|
104
|
push @{$seq_refs}, $info_of->{$key}{seq}; |
|
|
72
|
|
|
|
|
197
|
|
|
116
|
|
|
|
|
|
|
} |
|
117
|
|
|
|
|
|
|
|
|
118
|
18
|
50
|
|
|
|
247
|
if ( $opt->{length} ) { |
|
119
|
18
|
100
|
|
|
|
63
|
next if length $info_of->{ $full_names[0] }{seq} < $opt->{length}; |
|
120
|
|
|
|
|
|
|
} |
|
121
|
|
|
|
|
|
|
|
|
122
|
17
|
|
|
|
|
339
|
print "Section [$opt->{section}]\n"; |
|
123
|
17
|
|
|
|
|
340
|
$max_name_length = List::Util::max( $max_name_length, map {length} @full_names ); |
|
|
68
|
|
|
|
|
152
|
|
|
124
|
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
# including indels and snps |
|
126
|
17
|
|
|
|
|
65
|
my $vars = get_vars( $seq_refs, $opt ); |
|
127
|
17
|
|
|
|
|
60
|
$opt->{section} = paint_vars( $worksheet, $format_of, $opt, $vars, \@full_names ); |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
} |
|
130
|
|
|
|
|
|
|
else { |
|
131
|
144
|
|
|
|
|
320
|
$content .= $line; |
|
132
|
|
|
|
|
|
|
} |
|
133
|
|
|
|
|
|
|
} |
|
134
|
|
|
|
|
|
|
|
|
135
|
6
|
|
|
|
|
1212
|
$in_fh->close; |
|
136
|
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
# format column |
|
138
|
6
|
|
|
|
|
1413
|
$worksheet->set_column( 0, 0, $max_name_length + 1 ); |
|
139
|
6
|
|
|
|
|
981
|
$worksheet->set_column( 1, $opt->{wrap} + 3, 1.6 ); |
|
140
|
|
|
|
|
|
|
|
|
141
|
6
|
|
|
|
|
1629
|
return; |
|
142
|
|
|
|
|
|
|
} |
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
# Excel formats |
|
145
|
|
|
|
|
|
|
sub create_formats { |
|
146
|
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
#@type Excel::Writer::XLSX |
|
148
|
6
|
|
|
6
|
0
|
19
|
my $workbook = shift; |
|
149
|
|
|
|
|
|
|
|
|
150
|
6
|
|
|
|
|
14
|
my $format_of = {}; |
|
151
|
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
# species name |
|
153
|
6
|
|
|
|
|
28
|
$format_of->{name} = $workbook->add_format( |
|
154
|
|
|
|
|
|
|
font => 'Courier New', |
|
155
|
|
|
|
|
|
|
size => 10, |
|
156
|
|
|
|
|
|
|
); |
|
157
|
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
# variation position |
|
159
|
6
|
|
|
|
|
915
|
$format_of->{pos} = $workbook->add_format( |
|
160
|
|
|
|
|
|
|
font => 'Courier New', |
|
161
|
|
|
|
|
|
|
size => 8, |
|
162
|
|
|
|
|
|
|
align => 'center', |
|
163
|
|
|
|
|
|
|
valign => 'vcenter', |
|
164
|
|
|
|
|
|
|
rotation => 90, |
|
165
|
|
|
|
|
|
|
); |
|
166
|
|
|
|
|
|
|
|
|
167
|
6
|
|
|
|
|
1308
|
$format_of->{snp} = {}; |
|
168
|
6
|
|
|
|
|
21
|
$format_of->{indel} = {}; |
|
169
|
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
# background |
|
171
|
6
|
|
|
|
|
16
|
my $bg_of = {}; |
|
172
|
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
# 15 |
|
174
|
6
|
|
|
|
|
31
|
my @colors = ( |
|
175
|
|
|
|
|
|
|
22, # Gray-25%, silver |
|
176
|
|
|
|
|
|
|
43, # Light Yellow 0b001 |
|
177
|
|
|
|
|
|
|
42, # Light Green 0b010 |
|
178
|
|
|
|
|
|
|
27, # Lite Turquoise |
|
179
|
|
|
|
|
|
|
44, # Pale Blue 0b100 |
|
180
|
|
|
|
|
|
|
46, # Lavender |
|
181
|
|
|
|
|
|
|
47, # Tan |
|
182
|
|
|
|
|
|
|
24, # Periwinkle |
|
183
|
|
|
|
|
|
|
49, # Aqua |
|
184
|
|
|
|
|
|
|
51, # Gold |
|
185
|
|
|
|
|
|
|
45, # Rose |
|
186
|
|
|
|
|
|
|
52, # Light Orange |
|
187
|
|
|
|
|
|
|
26, # Ivory |
|
188
|
|
|
|
|
|
|
29, # Coral |
|
189
|
|
|
|
|
|
|
31, # Ice Blue |
|
190
|
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
# 30, # Ocean Blue |
|
192
|
|
|
|
|
|
|
# 41, # Light Turquoise, again |
|
193
|
|
|
|
|
|
|
# 48, # Light Blue |
|
194
|
|
|
|
|
|
|
# 50, # Lime |
|
195
|
|
|
|
|
|
|
# 54, # Blue-Gray |
|
196
|
|
|
|
|
|
|
# 62, # Indigo |
|
197
|
|
|
|
|
|
|
); |
|
198
|
|
|
|
|
|
|
|
|
199
|
6
|
|
|
|
|
38
|
for my $i ( 0 .. $#colors ) { |
|
200
|
90
|
|
|
|
|
261
|
$bg_of->{$i}{bg_color} = $colors[$i]; |
|
201
|
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
} |
|
203
|
6
|
|
|
|
|
26
|
$bg_of->{unknown}{bg_color} = 9; # White |
|
204
|
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
# snp base |
|
206
|
6
|
|
|
|
|
77
|
my $snp_fg_of = { |
|
207
|
|
|
|
|
|
|
'A' => { color => 58, }, # Dark Green |
|
208
|
|
|
|
|
|
|
'C' => { color => 18, }, # Dark Blue |
|
209
|
|
|
|
|
|
|
'G' => { color => 28, }, # Dark Purple |
|
210
|
|
|
|
|
|
|
'T' => { color => 16, }, # Dark Red |
|
211
|
|
|
|
|
|
|
'N' => { color => 8, }, # Black |
|
212
|
|
|
|
|
|
|
'-' => { color => 8, }, # Black |
|
213
|
|
|
|
|
|
|
}; |
|
214
|
|
|
|
|
|
|
|
|
215
|
6
|
|
|
|
|
14
|
for my $fg ( keys %{$snp_fg_of} ) { |
|
|
6
|
|
|
|
|
25
|
|
|
216
|
36
|
|
|
|
|
6324
|
for my $bg ( keys %{$bg_of} ) { |
|
|
36
|
|
|
|
|
138
|
|
|
217
|
|
|
|
|
|
|
$format_of->{snp}{"$fg$bg"} = $workbook->add_format( |
|
218
|
|
|
|
|
|
|
font => 'Courier New', |
|
219
|
|
|
|
|
|
|
size => 10, |
|
220
|
|
|
|
|
|
|
align => 'center', |
|
221
|
|
|
|
|
|
|
valign => 'vcenter', |
|
222
|
576
|
|
|
|
|
1222
|
%{ $snp_fg_of->{$fg} }, |
|
223
|
576
|
|
|
|
|
112735
|
%{ $bg_of->{$bg} }, |
|
|
576
|
|
|
|
|
1492
|
|
|
224
|
|
|
|
|
|
|
); |
|
225
|
|
|
|
|
|
|
} |
|
226
|
|
|
|
|
|
|
} |
|
227
|
6
|
|
|
|
|
1250
|
$format_of->{snp}{'-'} = $workbook->add_format( |
|
228
|
|
|
|
|
|
|
font => 'Courier New', |
|
229
|
|
|
|
|
|
|
size => 10, |
|
230
|
|
|
|
|
|
|
align => 'center', |
|
231
|
|
|
|
|
|
|
valign => 'vcenter', |
|
232
|
|
|
|
|
|
|
); |
|
233
|
|
|
|
|
|
|
|
|
234
|
6
|
|
|
|
|
970
|
for my $bg ( keys %{$bg_of} ) { |
|
|
6
|
|
|
|
|
33
|
|
|
235
|
|
|
|
|
|
|
$format_of->{indel}->{$bg} = $workbook->add_format( |
|
236
|
|
|
|
|
|
|
font => 'Courier New', |
|
237
|
|
|
|
|
|
|
size => 10, |
|
238
|
|
|
|
|
|
|
bold => 1, |
|
239
|
|
|
|
|
|
|
align => 'center', |
|
240
|
|
|
|
|
|
|
valign => 'vcenter', |
|
241
|
96
|
|
|
|
|
17939
|
%{ $bg_of->{$bg} }, |
|
|
96
|
|
|
|
|
290
|
|
|
242
|
|
|
|
|
|
|
); |
|
243
|
|
|
|
|
|
|
} |
|
244
|
|
|
|
|
|
|
|
|
245
|
6
|
|
|
|
|
1256
|
return $format_of; |
|
246
|
|
|
|
|
|
|
} |
|
247
|
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
# store all variations |
|
249
|
|
|
|
|
|
|
sub get_vars { |
|
250
|
17
|
|
|
17
|
0
|
31
|
my $seq_refs = shift; |
|
251
|
17
|
|
|
|
|
29
|
my $opt = shift; |
|
252
|
|
|
|
|
|
|
|
|
253
|
|
|
|
|
|
|
# outgroup |
|
254
|
17
|
|
|
|
|
27
|
my $out_seq; |
|
255
|
17
|
100
|
|
|
|
59
|
if ( $opt->{outgroup} ) { |
|
256
|
2
|
|
|
|
|
5
|
$out_seq = pop @{$seq_refs}; |
|
|
2
|
|
|
|
|
8
|
|
|
257
|
|
|
|
|
|
|
} |
|
258
|
|
|
|
|
|
|
|
|
259
|
17
|
|
|
|
|
28
|
my $seq_count = scalar @{$seq_refs}; |
|
|
17
|
|
|
|
|
38
|
|
|
260
|
17
|
50
|
|
|
|
52
|
if ( $seq_count < 2 ) { |
|
261
|
0
|
|
|
|
|
0
|
Carp::confess "Too few sequences [$seq_count]\n"; |
|
262
|
|
|
|
|
|
|
} |
|
263
|
|
|
|
|
|
|
|
|
264
|
17
|
|
|
|
|
70
|
my $indel_sites = App::Fasops::Common::get_indels($seq_refs); |
|
265
|
17
|
100
|
|
|
|
75
|
if ( $opt->{outgroup} ) { |
|
266
|
2
|
|
|
|
|
11
|
App::Fasops::Common::polarize_indel( $indel_sites, $out_seq ); |
|
267
|
|
|
|
|
|
|
} |
|
268
|
|
|
|
|
|
|
|
|
269
|
17
|
|
|
|
|
68
|
my $snp_sites = App::Fasops::Common::get_snps($seq_refs); |
|
270
|
17
|
100
|
|
|
|
66
|
if ( $opt->{outgroup} ) { |
|
271
|
2
|
|
|
|
|
16
|
App::Fasops::Common::polarize_snp( $snp_sites, $out_seq ); |
|
272
|
|
|
|
|
|
|
} |
|
273
|
|
|
|
|
|
|
|
|
274
|
17
|
|
|
|
|
27
|
my %variations; |
|
275
|
17
|
|
|
|
|
32
|
for my $site ( @{$indel_sites} ) { |
|
|
17
|
|
|
|
|
47
|
|
|
276
|
33
|
100
|
100
|
|
|
88
|
if ( $opt->{nocomplex} and $site->{indel_freq} == -1 ) { |
|
277
|
2
|
|
|
|
|
5
|
next; |
|
278
|
|
|
|
|
|
|
} |
|
279
|
|
|
|
|
|
|
|
|
280
|
31
|
100
|
100
|
|
|
77
|
if ( $opt->{nosingle} and $site->{indel_freq} <= 1 ) { |
|
281
|
4
|
|
|
|
|
8
|
next; |
|
282
|
|
|
|
|
|
|
} |
|
283
|
|
|
|
|
|
|
|
|
284
|
27
|
100
|
|
|
|
56
|
if ( $opt->{noindel} ) { |
|
285
|
6
|
|
|
|
|
10
|
next; |
|
286
|
|
|
|
|
|
|
} |
|
287
|
|
|
|
|
|
|
|
|
288
|
21
|
100
|
100
|
|
|
84
|
if ( defined $opt->{min} and $site->{indel_freq} / $seq_count < $opt->{min} ) { |
|
289
|
4
|
|
|
|
|
8
|
next; |
|
290
|
|
|
|
|
|
|
} |
|
291
|
17
|
50
|
66
|
|
|
44
|
if ( defined $opt->{max} and $site->{indel_freq} / $seq_count > $opt->{max} ) { |
|
292
|
0
|
|
|
|
|
0
|
next; |
|
293
|
|
|
|
|
|
|
} |
|
294
|
|
|
|
|
|
|
|
|
295
|
17
|
|
|
|
|
32
|
$site->{var_type} = 'indel'; |
|
296
|
17
|
|
|
|
|
41
|
$variations{ $site->{indel_start} } = $site; |
|
297
|
|
|
|
|
|
|
} |
|
298
|
|
|
|
|
|
|
|
|
299
|
17
|
|
|
|
|
34
|
for my $site ( @{$snp_sites} ) { |
|
|
17
|
|
|
|
|
40
|
|
|
300
|
448
|
100
|
100
|
|
|
875
|
if ( $opt->{nocomplex} and $site->{snp_freq} == -1 ) { |
|
301
|
7
|
|
|
|
|
12
|
next; |
|
302
|
|
|
|
|
|
|
} |
|
303
|
|
|
|
|
|
|
|
|
304
|
441
|
100
|
100
|
|
|
825
|
if ( $opt->{nosingle} and $site->{snp_freq} <= 1 ) { |
|
305
|
63
|
|
|
|
|
95
|
next; |
|
306
|
|
|
|
|
|
|
} |
|
307
|
|
|
|
|
|
|
|
|
308
|
378
|
100
|
100
|
|
|
785
|
if ( defined $opt->{min} and $site->{snp_freq} / $seq_count < $opt->{min} ) { |
|
309
|
63
|
|
|
|
|
93
|
next; |
|
310
|
|
|
|
|
|
|
} |
|
311
|
315
|
50
|
66
|
|
|
587
|
if ( defined $opt->{max} and $site->{snp_freq} / $seq_count > $opt->{max} ) { |
|
312
|
0
|
|
|
|
|
0
|
next; |
|
313
|
|
|
|
|
|
|
} |
|
314
|
|
|
|
|
|
|
|
|
315
|
315
|
|
|
|
|
583
|
$site->{var_type} = 'snp'; |
|
316
|
315
|
|
|
|
|
540
|
$variations{ $site->{snp_pos} } = $site; |
|
317
|
|
|
|
|
|
|
} |
|
318
|
|
|
|
|
|
|
|
|
319
|
17
|
|
|
|
|
185
|
return \%variations; |
|
320
|
|
|
|
|
|
|
} |
|
321
|
|
|
|
|
|
|
|
|
322
|
|
|
|
|
|
|
# write excel |
|
323
|
|
|
|
|
|
|
sub paint_vars { |
|
324
|
|
|
|
|
|
|
|
|
325
|
|
|
|
|
|
|
#@type Excel::Writer::XLSX::Worksheet |
|
326
|
17
|
|
|
17
|
0
|
30
|
my $sheet = shift; |
|
327
|
17
|
|
|
|
|
26
|
my $format_of = shift; |
|
328
|
17
|
|
|
|
|
29
|
my $opt = shift; |
|
329
|
17
|
|
|
|
|
29
|
my $vars = shift; |
|
330
|
17
|
|
|
|
|
22
|
my $name_refs = shift; |
|
331
|
|
|
|
|
|
|
|
|
332
|
17
|
|
|
|
|
41
|
my $section_start = $opt->{section}; |
|
333
|
17
|
|
|
|
|
37
|
my $color_loop = $opt->{colors}; |
|
334
|
|
|
|
|
|
|
|
|
335
|
17
|
|
|
|
|
22
|
my %variations = %{$vars}; |
|
|
17
|
|
|
|
|
207
|
|
|
336
|
17
|
|
|
|
|
53
|
my $section_cur = $section_start; |
|
337
|
17
|
|
|
|
|
32
|
my $col_cursor = 1; |
|
338
|
17
|
|
|
|
|
31
|
my $section_height = ( scalar( @{$name_refs} ) + 1 ) + $opt->{spacing}; |
|
|
17
|
|
|
|
|
60
|
|
|
339
|
17
|
|
|
|
|
25
|
my $seq_count = scalar @{$name_refs}; |
|
|
17
|
|
|
|
|
29
|
|
|
340
|
17
|
100
|
|
|
|
46
|
$seq_count-- if $opt->{outgroup}; |
|
341
|
|
|
|
|
|
|
|
|
342
|
17
|
|
|
|
|
112
|
for my $pos ( sort { $a <=> $b } keys %variations ) { |
|
|
1266
|
|
|
|
|
1588
|
|
|
343
|
332
|
|
|
|
|
538
|
my $var = $variations{$pos}; |
|
344
|
332
|
|
|
|
|
594
|
my $pos_row = $section_height * ( $section_cur - 1 ); |
|
345
|
|
|
|
|
|
|
|
|
346
|
|
|
|
|
|
|
# write SNPs |
|
347
|
332
|
100
|
|
|
|
701
|
if ( $var->{var_type} eq 'snp' ) { |
|
348
|
|
|
|
|
|
|
|
|
349
|
|
|
|
|
|
|
# write position |
|
350
|
315
|
|
|
|
|
939
|
$sheet->write( $pos_row, $col_cursor, $var->{snp_pos}, $format_of->{pos} ); |
|
351
|
|
|
|
|
|
|
|
|
352
|
315
|
|
|
|
|
18793
|
for my $i ( 1 .. $seq_count ) { |
|
353
|
1212
|
|
|
|
|
67508
|
my $base = substr $var->{snp_all_bases}, $i - 1, 1; |
|
354
|
|
|
|
|
|
|
|
|
355
|
|
|
|
|
|
|
my $occ |
|
356
|
|
|
|
|
|
|
= $var->{snp_occured} eq "unknown" |
|
357
|
|
|
|
|
|
|
? 0 |
|
358
|
1212
|
100
|
|
|
|
2559
|
: substr( $var->{snp_occured}, $i - 1, 1 ); |
|
359
|
|
|
|
|
|
|
|
|
360
|
1212
|
100
|
|
|
|
1984
|
if ( $occ eq "1" ) { |
|
361
|
725
|
|
|
|
|
1505
|
my $bg_idx = oct( '0b' . $var->{snp_occured} ) % $color_loop; |
|
362
|
725
|
|
|
|
|
1068
|
my $base_color = $base . $bg_idx; |
|
363
|
|
|
|
|
|
|
$sheet->write( $pos_row + $i, |
|
364
|
725
|
|
|
|
|
1859
|
$col_cursor, $base, $format_of->{snp}{$base_color} ); |
|
365
|
|
|
|
|
|
|
} |
|
366
|
|
|
|
|
|
|
else { |
|
367
|
487
|
|
|
|
|
753
|
my $base_color = $base . "unknown"; |
|
368
|
|
|
|
|
|
|
$sheet->write( $pos_row + $i, |
|
369
|
487
|
|
|
|
|
1248
|
$col_cursor, $base, $format_of->{snp}{$base_color} ); |
|
370
|
|
|
|
|
|
|
} |
|
371
|
|
|
|
|
|
|
} |
|
372
|
|
|
|
|
|
|
|
|
373
|
|
|
|
|
|
|
# outgroup bases with no background colors |
|
374
|
315
|
100
|
|
|
|
23126
|
if ( $opt->{outgroup} ) { |
|
375
|
48
|
|
|
|
|
100
|
my $base_color = $var->{snp_outgroup_base} . "unknown"; |
|
376
|
|
|
|
|
|
|
$sheet->write( |
|
377
|
|
|
|
|
|
|
$pos_row + $seq_count + 1, |
|
378
|
|
|
|
|
|
|
$col_cursor, |
|
379
|
|
|
|
|
|
|
$var->{snp_outgroup_base}, |
|
380
|
48
|
|
|
|
|
139
|
$format_of->{snp}{$base_color} |
|
381
|
|
|
|
|
|
|
); |
|
382
|
|
|
|
|
|
|
} |
|
383
|
|
|
|
|
|
|
|
|
384
|
|
|
|
|
|
|
# increase column cursor |
|
385
|
315
|
|
|
|
|
3850
|
$col_cursor++; |
|
386
|
|
|
|
|
|
|
} |
|
387
|
|
|
|
|
|
|
|
|
388
|
|
|
|
|
|
|
# write indels |
|
389
|
332
|
100
|
|
|
|
689
|
if ( $var->{var_type} eq 'indel' ) { |
|
390
|
|
|
|
|
|
|
|
|
391
|
|
|
|
|
|
|
# how many column does this indel take up |
|
392
|
17
|
|
|
|
|
51
|
my $col_taken = List::Util::min( $var->{indel_length}, 3 ); |
|
393
|
|
|
|
|
|
|
|
|
394
|
|
|
|
|
|
|
# if exceed the wrap limit, start a new section |
|
395
|
17
|
50
|
|
|
|
44
|
if ( $col_cursor + $col_taken > $opt->{wrap} ) { |
|
396
|
0
|
|
|
|
|
0
|
$col_cursor = 1; |
|
397
|
0
|
|
|
|
|
0
|
$section_cur++; |
|
398
|
0
|
|
|
|
|
0
|
$pos_row = $section_height * ( $section_cur - 1 ); |
|
399
|
|
|
|
|
|
|
} |
|
400
|
|
|
|
|
|
|
|
|
401
|
17
|
|
|
|
|
46
|
my $indel_string = "$var->{indel_type}$var->{indel_length}"; |
|
402
|
|
|
|
|
|
|
|
|
403
|
17
|
|
|
|
|
34
|
my $bg_idx = 'unknown'; |
|
404
|
17
|
100
|
|
|
|
44
|
if ( $var->{indel_occured} ne 'unknown' ) { |
|
405
|
14
|
|
|
|
|
39
|
$bg_idx = oct( '0b' . $var->{indel_occured} ) % $color_loop; |
|
406
|
|
|
|
|
|
|
} |
|
407
|
|
|
|
|
|
|
|
|
408
|
17
|
|
|
|
|
37
|
for my $i ( 1 .. $seq_count ) { |
|
409
|
65
|
|
|
|
|
3375
|
my $flag = 0; |
|
410
|
65
|
100
|
|
|
|
134
|
if ( $var->{indel_occured} eq "unknown" ) { |
|
411
|
11
|
|
|
|
|
16
|
$flag = 1; |
|
412
|
|
|
|
|
|
|
} |
|
413
|
|
|
|
|
|
|
else { |
|
414
|
54
|
|
|
|
|
110
|
my $occ = substr $var->{indel_occured}, $i - 1, 1; |
|
415
|
54
|
100
|
|
|
|
109
|
if ( $occ eq '1' ) { |
|
416
|
32
|
|
|
|
|
45
|
$flag = 1; |
|
417
|
|
|
|
|
|
|
} |
|
418
|
|
|
|
|
|
|
} |
|
419
|
|
|
|
|
|
|
|
|
420
|
65
|
100
|
|
|
|
120
|
if ($flag) { |
|
421
|
43
|
100
|
|
|
|
97
|
if ( $col_taken == 1 ) { |
|
|
|
50
|
|
|
|
|
|
|
422
|
|
|
|
|
|
|
|
|
423
|
|
|
|
|
|
|
# write position |
|
424
|
|
|
|
|
|
|
$sheet->write( $pos_row, $col_cursor, $var->{indel_start}, |
|
425
|
37
|
|
|
|
|
122
|
$format_of->{pos} ); |
|
426
|
|
|
|
|
|
|
|
|
427
|
|
|
|
|
|
|
# write in indel occured lineage |
|
428
|
|
|
|
|
|
|
$sheet->write( $pos_row + $i, |
|
429
|
37
|
|
|
|
|
2176
|
$col_cursor, $indel_string, $format_of->{indel}{$bg_idx} ); |
|
430
|
|
|
|
|
|
|
} |
|
431
|
|
|
|
|
|
|
elsif ( $col_taken == 2 ) { |
|
432
|
|
|
|
|
|
|
|
|
433
|
|
|
|
|
|
|
# write indel_start position |
|
434
|
|
|
|
|
|
|
$sheet->write( $pos_row, $col_cursor, $var->{indel_start}, |
|
435
|
6
|
|
|
|
|
25
|
$format_of->{pos} ); |
|
436
|
|
|
|
|
|
|
|
|
437
|
|
|
|
|
|
|
# write indel_end position |
|
438
|
|
|
|
|
|
|
$sheet->write( $pos_row, $col_cursor + 1, |
|
439
|
6
|
|
|
|
|
364
|
$var->{indel_end}, $format_of->{pos} ); |
|
440
|
|
|
|
|
|
|
|
|
441
|
|
|
|
|
|
|
# merge two indel position |
|
442
|
|
|
|
|
|
|
$sheet->merge_range( |
|
443
|
|
|
|
|
|
|
$pos_row + $i, |
|
444
|
|
|
|
|
|
|
$col_cursor, |
|
445
|
|
|
|
|
|
|
$pos_row + $i, |
|
446
|
|
|
|
|
|
|
$col_cursor + 1, |
|
447
|
6
|
|
|
|
|
339
|
$indel_string, $format_of->{indel}{$bg_idx}, |
|
448
|
|
|
|
|
|
|
); |
|
449
|
|
|
|
|
|
|
} |
|
450
|
|
|
|
|
|
|
else { |
|
451
|
|
|
|
|
|
|
|
|
452
|
|
|
|
|
|
|
# write indel_start position |
|
453
|
|
|
|
|
|
|
$sheet->write( $pos_row, $col_cursor, $var->{indel_start}, |
|
454
|
0
|
|
|
|
|
0
|
$format_of->{pos} ); |
|
455
|
|
|
|
|
|
|
|
|
456
|
|
|
|
|
|
|
# write middle sign |
|
457
|
0
|
|
|
|
|
0
|
$sheet->write( $pos_row, $col_cursor + 1, '|', $format_of->{pos} ); |
|
458
|
|
|
|
|
|
|
|
|
459
|
|
|
|
|
|
|
# write indel_end position |
|
460
|
|
|
|
|
|
|
$sheet->write( $pos_row, $col_cursor + 2, |
|
461
|
0
|
|
|
|
|
0
|
$var->{indel_end}, $format_of->{pos} ); |
|
462
|
|
|
|
|
|
|
|
|
463
|
|
|
|
|
|
|
# merge two indel position |
|
464
|
|
|
|
|
|
|
$sheet->merge_range( |
|
465
|
|
|
|
|
|
|
$pos_row + $i, |
|
466
|
|
|
|
|
|
|
$col_cursor, |
|
467
|
|
|
|
|
|
|
$pos_row + $i, |
|
468
|
|
|
|
|
|
|
$col_cursor + 2, |
|
469
|
0
|
|
|
|
|
0
|
$indel_string, $format_of->{indel}{$bg_idx}, |
|
470
|
|
|
|
|
|
|
); |
|
471
|
|
|
|
|
|
|
} |
|
472
|
|
|
|
|
|
|
} |
|
473
|
|
|
|
|
|
|
} |
|
474
|
|
|
|
|
|
|
|
|
475
|
|
|
|
|
|
|
# increase column cursor |
|
476
|
17
|
|
|
|
|
636
|
$col_cursor += $col_taken; |
|
477
|
|
|
|
|
|
|
} |
|
478
|
|
|
|
|
|
|
|
|
479
|
332
|
100
|
|
|
|
711
|
if ( $col_cursor > $opt->{wrap} ) { |
|
480
|
2
|
|
|
|
|
8
|
$col_cursor = 1; |
|
481
|
2
|
|
|
|
|
9
|
$section_cur++; |
|
482
|
|
|
|
|
|
|
} |
|
483
|
|
|
|
|
|
|
} |
|
484
|
|
|
|
|
|
|
|
|
485
|
|
|
|
|
|
|
# write names |
|
486
|
17
|
|
|
|
|
75
|
for my $i ( $section_start .. $section_cur ) { |
|
487
|
19
|
|
|
|
|
194
|
my $pos_row = $section_height * ( $i - 1 ); |
|
488
|
|
|
|
|
|
|
|
|
489
|
19
|
|
|
|
|
36
|
for my $j ( 1 .. scalar @{$name_refs} ) { |
|
|
19
|
|
|
|
|
43
|
|
|
490
|
76
|
|
|
|
|
4873
|
$sheet->write( $pos_row + $j, 0, $name_refs->[ $j - 1 ], $format_of->{name} ); |
|
491
|
|
|
|
|
|
|
} |
|
492
|
|
|
|
|
|
|
} |
|
493
|
|
|
|
|
|
|
|
|
494
|
17
|
|
|
|
|
1329
|
$section_cur++; |
|
495
|
17
|
|
|
|
|
845
|
return $section_cur; |
|
496
|
|
|
|
|
|
|
} |
|
497
|
|
|
|
|
|
|
|
|
498
|
|
|
|
|
|
|
1; |