lib/Bio/MUST/Core/Ali.pm

filter: Statementstmt 99.7% 387 / 388 Branchbran 90.4% 123 / 136 Conditioncond 76.0% 35 / 46 MC/DCmcdc 57.6% 15 / 26 Subroutinesub 98.4% 65 / 66 Podpod 100% 34 / 34 totaltotal 94.6% 659 / 696 CC 103 SCAR 17.8
CC
103
Cov
96%
store_phylip
14.0
store_fasta
14.0
load_phylip
11.0
CRAP 5.9
« lib/Bio/MUST/Core/SeqMask/Profiles.pm ↑ Summary lib/Bio/MUST/Core/Types.pm »
1 package Bio::MUST::Core::Ali;
2 # ABSTRACT: Multiple sequence alignment
3 # CONTRIBUTOR: Catherine COLSON <ccolson@doct.uliege.be>
4 # CONTRIBUTOR: Arnaud DI FRANCO <arnaud.difranco@gmail.com>
5 18 $Bio::MUST::Core::Ali::VERSION = '0.252040';
6 18 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 18 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 18 ▶use autodie;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 18 ▶use feature qw(say);
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 # use Smart::Comments;
13  
14 18 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 18 ▶use File::Temp;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 18 ▶use List::AllUtils qw(uniq indexes sum0);
Subroutine BEGIN: called CC=1 SCAR=0.0
17 18 ▶use Path::Class qw(file);
Subroutine BEGIN: called CC=1 SCAR=0.0
18 18 ▶use POSIX qw(ceil floor);
Subroutine BEGIN: called CC=1 SCAR=0.0
19 18 ▶use Statistics::Descriptive;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 18 ▶use Tie::IxHash;
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 18 ▶use Bio::MUST::Core::Types;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 18 ▶use Bio::MUST::Core::Constants qw(:ncbi :gaps :files);
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 18 ▶use aliased 'Bio::MUST::Core::Seq';
Subroutine BEGIN: called CC=1 SCAR=0.0
26 18 ▶use aliased 'Bio::MUST::Core::SeqId';
Subroutine BEGIN: called CC=1 SCAR=0.0
27 18 ▶use aliased 'Bio::MUST::Core::SeqMask';
Subroutine BEGIN: called CC=1 SCAR=0.0
28  
29 # TODO: add information about methods available in Ali-like objects
30  
31 # ATTRIBUTES
32  
33  
34 has 'seqs' => (
35 traits => ['Array'],
36 is => 'ro',
37 isa => 'ArrayRef[Bio::MUST::Core::Seq]',
38 263 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
39 18 writer => '_set_seqs',
40 handles => {
41 add_seq => 'push',
42 get_seq => 'get',
43 set_seq => 'set',
44 delete_seq => 'delete',
45 insert_seq => 'insert',
46 count_seqs => 'count',
47 all_seqs => 'elements',
48 first_seq => 'first',
49 filter_seqs => 'grep',
50 },
51 );
52  
53  
54 18 has 'file' => (
55 is => 'ro',
56 isa => 'Bio::MUST::Core::Types::File',
57 default => 'untitled.ali',
58 coerce => 1,
59 handles => {
60 filename => 'stringify',
61 },
62 );
63  
64  
65 18 has 'guessing' => (
66 traits => ['Bool'],
67 is => 'ro',
68 isa => 'Bool',
69 default => 1,
70 handles => {
71 dont_guess => 'unset',
72 guess => 'set',
73 },
74 );
75  
76  
77 18 with 'Bio::MUST::Core::Roles::Commentable',
78 'Bio::MUST::Core::Roles::Listable';
79 18 with 'Bio::MUST::Core::Roles::Aliable'; ## no critic (ProhibitMultipleWiths)
80  
81 # CONSTRUCTORS
82  
83  
84  
85 1 ▶sub clone {
Subroutine clone: called CC=1 SCAR=0.0
Pod documented
86 1 my $self = shift;
87  
88 return $self->new(
89 comments => [ $self->all_comments ],
90 1 seqs => [ map { $_->clone } $self->all_seqs ],
91 file => file( $self->filename ),
92 guessing => $self->guessing,
93 );
94 }
95  
96 # ACCESSORS
97  
98  
99 4 ▶sub get_seq_with_id {
Subroutine get_seq_with_id: called CC=2 SCAR=6.9
Pod documented
100 4 my $self = shift;
101 4 my $id = shift;
102  
103 4 ▶ my $seq = $self->first_seq( sub { $_->full_id eq $id } );
Subroutine __ANON__: called CC=1 SCAR=0.0
104 4 ▶ carp "[BMC] Warning: cannot find seq with id: $id; returning undef!"
Branch: 1 branch
BranchTrueFalseTotal
unless $seq 1 3 4
105 unless $seq;
106  
107 4 return $seq;
108 }
109  
110  
111 2 ▶sub all_new_seqs {
Subroutine all_new_seqs: called CC=1 SCAR=0.0
Pod documented
112 2 ▶ return shift->filter_seqs( sub { $_->is_new } );
Subroutine __ANON__: called CC=1 SCAR=0.0
113 }
114  
115  
116 1 ▶sub all_but_new_seqs {
Subroutine all_but_new_seqs: called CC=1 SCAR=0.0
Pod documented
117 1 ▶ return shift->filter_seqs( sub { not $_->is_new } );
Subroutine __ANON__: called CC=1 SCAR=0.0
118 }
119  
120  
121 102 ▶sub all_seq_ids {
Subroutine all_seq_ids: called CC=1 SCAR=0.0
Pod documented
122 102 my $self = shift;
123 102 return map { $_->seq_id } $self->all_seqs;
124 }
125  
126 # PROPERTIES
127  
128  
129 66 ▶sub has_uniq_ids {
Subroutine has_uniq_ids: called CC=2 SCAR=6.9
Pod documented
130 66 my $self = shift;
131  
132 66 my @ids = map { $_->full_id } $self->all_seq_ids;
133 66 ▶ return 1 if $self->count_seqs == uniq @ids;
Branch: 1 branch
BranchTrueFalseTotal
if $self->count_seqs == &uniq(@ids) 59 7 66
134 7 return 0;
135 }
136  
137  
138 79 ▶sub is_protein {
Subroutine is_protein: called CC=2 SCAR=6.9
Pod documented
139 79 my $self = shift;
140 79 ▶ return 1 if List::AllUtils::any { $_->is_protein } $self->all_seqs;
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
if &List::AllUtils::any(sub { $_->is_protein; } , $self->all_seqs) 72 7 79
141 7 return 0;
142 }
143  
144  
145 312 ▶sub is_aligned {
Subroutine is_aligned: called CC=3 SCAR=11.0
Pod documented
146 312 my $self = shift;
147 312 ▶ return 0 if not $self->guessing;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->guessing 3 309 312
148 309 ▶ return 1 if List::AllUtils::any { $_->is_aligned } $self->all_seqs;
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
if &List::AllUtils::any(sub { $_->is_aligned; } , $self->all_seqs) 191 118 309
149 118 return 0;
150 }
151  
152  
153 189 ▶sub width {
Subroutine width: called CC=2 SCAR=6.9
Pod documented
154 189 my $self = shift;
155 189 ▶ $self->uniformize if $self->is_aligned; # pad seqs for robustness
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_aligned 85 104 189
156 189 return $self->_max_seq_len;
157 }
158  
159 365 ▶sub _max_seq_len {
Subroutine _max_seq_len: called CC=2 SCAR=7.0
160 365 my $self = shift;
161 365 my @lengths = map { $_->seq_len } $self->all_seqs;
162 365 ▶ return (List::AllUtils::max @lengths) // 0; # to avoid warnings
Condition50%1/2
&List::AllUtils::max(@lengths) // 0
l!l
3650
MC/DC0%0/1
&List::AllUtils::max(@lengths) // 0
&List::AllUtils::max(@lengths)
Truth table50%1/2
A
A= &List::AllUtils::max(@lengths)
Aresult
11
00
163 }
164  
165  
166 1 ▶sub seq_len_stats {
Subroutine seq_len_stats: called CC=1 SCAR=0.0
Pod documented
167 1 my $self = shift;
168  
169 1 my @lengths = map { $_->nomiss_seq_len } $self->all_seqs;
170 1 my $stat = Statistics::Descriptive::Full->new;
171 1 $stat->add_data( \@lengths );
172 1 my @quantiles = map { $stat->quantile($_) } 0..4;
173  
174 1 return @quantiles;
175 }
176  
177  
178 2 ▶sub perc_miss {
Subroutine perc_miss: called CC=2 SCAR=7.0
Pod documented
179 2 my $self = shift;
180  
181 2 my $n = sum0 map { $_->nomiss_seq_len } $self->all_seqs;
182 2 ▶ return 0.0 unless $n;
Branch: 1 branch
BranchTrueFalseTotal
unless $n 0 2 2
183  
184 2 my $total = $self->width * $self->count_seqs;
185 2 return 100.0 * ($total - $n) / $total;
186 }
187  
188 # MUTATORS
189  
190  
191 1 ▶sub uc_seqs {
Subroutine uc_seqs: called CC=2 SCAR=6.9
Pod documented
192 1 my $self = shift;
193  
194 1 $_->uc for $self->all_seqs;
195 1 return $self;
196 }
197  
198  
199 1 ▶sub recode_seqs { ## no critic (RequireArgUnpacking)
Subroutine recode_seqs: called CC=2 SCAR=6.9
Pod documented
200 1 my $self = shift;
201  
202 1 $_->recode(@_) for $self->all_seqs;
203 1 return $self;
204 }
205  
206  
207 1 ▶sub degap_seqs {
Subroutine degap_seqs: called CC=2 SCAR=6.9
Pod documented
208 1 my $self = shift;
209  
210 1 $_->degap for $self->all_seqs;
211 1 return $self;
212 }
213  
214  
215 176 ▶sub spacify_seqs {
Subroutine spacify_seqs: called CC=2 SCAR=6.9
Pod documented
216 176 my $self = shift;
217  
218 176 $_->spacify for $self->all_seqs;
219 176 return $self;
220 }
221  
222  
223 2 ▶sub gapify_seqs { ## no critic (RequireArgUnpacking)
Subroutine gapify_seqs: called CC=2 SCAR=6.9
Pod documented
224 2 my $self = shift;
225 2 $_->gapify(@_) for $self->all_seqs;
226 2 return $self;
227 }
228  
229  
230 176 ▶sub trim_seqs {
Subroutine trim_seqs: called CC=2 SCAR=6.9
Pod documented
231 176 my $self = shift;
232  
233 176 $_->trim for $self->all_seqs;
234 176 return $self;
235 }
236  
237  
238 176 ▶sub pad_seqs {
Subroutine pad_seqs: called CC=2 SCAR=6.9
Pod documented
239 176 my $self = shift;
240  
241 176 my $bound = $self->_max_seq_len;
242 176 $_->pad_to($bound) for $self->all_seqs;
243 176 return $self;
244 }
245  
246  
247 175 ▶sub uniformize {
Subroutine uniformize: called CC=1 SCAR=0.0
Pod documented
248 175 my $self = shift;
249  
250 # TODO: profile code (triggers?) to avoid useless multiple calls
251  
252 175 $self->spacify_seqs;
253 175 $self->trim_seqs;
254 175 $self->pad_seqs;
255  
256 175 return $self;
257 }
258  
259  
260 1 ▶sub clear_new_tags {
Subroutine clear_new_tags: called CC=2 SCAR=6.9
Pod documented
261 1 my $self = shift;
262  
263 1 $_->clear_new_tag for $self->all_seqs;
264 1 return $self;
265 }
266  
267  
268 12 ▶sub shorten_ids { ## no critic (RequireArgUnpacking)
Subroutine shorten_ids: called CC=1 SCAR=0.0
Pod documented
269 12 return shift->_change_ids_(1, @_);
270 }
271  
272  
273 10 ▶sub restore_ids { ## no critic (RequireArgUnpacking)
Subroutine restore_ids: called CC=1 SCAR=0.0
Pod documented
274 10 return shift->_change_ids_(0, @_);
275 }
276  
277 22 ▶sub _change_ids_ {
Subroutine _change_ids_: called CC=4 SCAR=13.9
278 22 my $self = shift;
279 22 my $abbr = shift;
280 22 my $mapper = shift;
281  
282 22 for my $seq ($self->all_seqs) {
283 133 ▶ my $new_id = $abbr ? $mapper->abbr_id_for( $seq->full_id )
Branch: 1 branch
BranchTrueFalseTotal
$abbr ? : 78 55 133
284 : $mapper->long_id_for( $seq->full_id );
285 133 ▶ $seq->set_seq_id($new_id) if $new_id;
Branch: 1 branch
BranchTrueFalseTotal
if $new_id 133 0 133
286 } # Note: leave id alone if not found
287  
288 22 return $self;
289 }
290  
291  
292 1 ▶sub apply_list {
Subroutine apply_list: called CC=3 SCAR=11.0
Pod documented
293 1 my $self = shift;
294 1 my $list = shift;
295  
296 # loop through seqs from bottom to top
297 # ... and delete seq from Ali if not listed in list
298 1 my $seq_n = $self->count_seqs;
299  
300 1 ▶ for (my $i = $seq_n-1; $i >= 0; $i--) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i >= 0) 250 1 251
301 250 ▶ $self->delete_seq($i)
Branch: 1 branch
BranchTrueFalseTotal
unless $list->is_listed($self->get_seq($i)->full_id) 245 5 250
302 unless $list->is_listed( $self->get_seq($i)->full_id );
303 }
304  
305 1 return $self;
306 }
307  
308  
309 40 ▶sub _premask_check {
Subroutine :before: called CC=4 SCAR=13.9
310 40 my $self = shift;
311 40 my $mask = shift;
312  
313 # warn of unaligned Ali
314 40 ▶ carp '[BMC] Note: Ali does not look aligned!'
Branch: 1 branch
BranchTrueFalseTotal
unless $self->is_aligned 0 40 40
315 . ' This might not be an issue if seqs are ultra-conserved!'
316 unless $self->is_aligned;
317 40 $self->uniformize;
318  
319 # warn of empty SeqMask
320 carp '[BMC] Note: applying this mask will result in a zero-width Ali!'
321 40 ▶ unless List::AllUtils::any { $_ } $mask->all_states;
Subroutine __ANON__: called CC=1 SCAR=0.2
Branch: 1 branch
BranchTrueFalseTotal
unless &List::AllUtils::any(sub { $_; } , $mask->all_states) 0 40 40
322  
323 # check that SeqMask is compatible with Ali
324 # potential bugs could come from constant sites etc
325 40 my $a_width = $self->width;
326 40 my $m_width = $mask->mask_len;
327 40 ▶ carp "[BMC] Note: Ali width does not match mask len: $a_width vs. $m_width!"
Branch: 1 branch
BranchTrueFalseTotal
unless $a_width == $m_width 1 39 40
328 . ' This might not be an issue if the mask results from blocks.'
329 unless $a_width == $m_width;
330  
331 40 return; # return values of before subs are ignored
332 }
333  
334 18 before 'apply_mask' => \&_premask_check;
335  
336 14 ▶sub apply_mask {
Subroutine apply_mask: called CC=2 SCAR=6.9
337 14 my $self = shift;
338 14 my $mask = shift;
339  
340 # select sites for each seq using a precomputed array slice
341 14 ▶ my @indexes = indexes { $_ } $mask->all_states;
Subroutine __ANON__: called CC=1 SCAR=0.0
342 $_->_set_seq( join q{}, ( $_->all_states )[@indexes] )
343 14 for $self->all_seqs;
344  
345 14 return $self;
346 }
347  
348  
349 13 ▶sub idealize { ## no critic (RequireArgUnpacking)
Subroutine idealize: called CC=1 SCAR=0.0
Pod documented
350 13 my $self = shift;
351 13 return $self->apply_mask( SeqMask->ideal_mask($self, @_) );
352 }
353  
354 # MISC METHODS
355  
356  
357 # TODO: introduce miss_regex (without gaps?)
358 73 ▶sub gapmiss_regex {
Subroutine gapmiss_regex: called CC=2 SCAR=6.9
Pod documented
359 73 ▶ return shift->is_protein ? $GAPPROTMISS : $GAPDNAMISS;
Branch: 1 branch
BranchTrueFalseTotal
(shift())->is_protein ? : 69 4 73
360 }
361  
362  
363 1 ▶sub map_coords {
Subroutine map_coords: called CC=3 SCAR=11.0
Pod documented
364 1 my $self = shift;
365 1 my $id = shift;
366 1 my $coords_in = shift;
367  
368 1 my $seq = $self->get_seq_with_id($id);
369 1 my @states = $seq->all_states;
370  
371 1 my $count = 0;
372 1 my @index;
373 1 for my $state (@states) {
374 130 ▶ $count++ if $state !~ $GAP;
Branch: 1 branch
BranchTrueFalseTotal
unless $state =~ /$Bio::MUST::Core::Ali::GAP/msx 83 47 130
375 130 push @index, $count;
376 }
377  
378 1 my @coords_out = map { $index[$_-1] } @{$coords_in};
379  
380 1 return \@coords_out;
381 }
382  
383 # ALIASES
384  
385  
386 0 ▶sub height {
Subroutine height: not called CC=1 SCAR=6.9
Pod documented
387 0 return shift->count_seqs;
388 }
389  
390 # I/O METHODS
391  
392  
393 70 ▶sub load {
Subroutine load: called CC=7 SCAR=19.5
Pod documented
394 70 my $class = shift;
395 70 my $infile = shift;
396  
397 70 open my $in, '<', $infile;
398  
399 70 my $ali = $class->new( file => $infile );
400 70 my $seq_id;
401 my $seq;
402  
403 LINE:
404 70 ▶ while (my $line = <$in>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline $in)) 4113 70 4183
405 4113 chomp $line;
406  
407 # skip empty lines and process comments
408 4113 ▶ next LINE if $line =~ $EMPTY_LINE
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /$Bio::MUST::Core::Ali::EMPTY_LINE/msx or $ali->is_comment($line) 149 3964 4113
Condition100%3/3
$line =~ /$Bio::MUST::Core::Ali::EMPTY_LINE/msx or $ali->is_comment($line)
l!l&&r!l&&!r
41453964
MC/DC100%2/2
$line =~ /$Bio::MUST::Core::Ali::EMPTY_LINE/msx or $ali->is_comment($line)
$line =~ /$Bio::MUST::Core::Ali::EMPTY_LINE/msx $ali->is_comment($line)
Truth table100%3/3
A or B
A= $line =~ /$Bio::MUST::Core::Ali::EMPTY_LINE/msxB= $ali->is_comment($line)
ABresult
1X1
011
000
409 || $ali->is_comment($line);
410  
411 # at each '>' char...
412 3964 my ($defline) = $line =~ $DEF_LINE;
413 3964 ▶ if ($defline) {
Branch: 1 branch
BranchTrueFalseTotal
if ($defline) 1672 2292 3964
414  
415 # add current seq to ali (if any)
416 1672 ▶ if ($seq) {
Branch: 1 branch
BranchTrueFalseTotal
if ($seq) 1602 70 1672
417 1602 my $new_seq = Seq->new( seq_id => $seq_id, seq => $seq );
418 1602 $ali->add_seq($new_seq);
419 1602 $seq = q{};
420 }
421  
422 1672 $seq_id = $defline;
423 1672 next LINE;
424 }
425  
426 # elongate current seq (seqs can be broken on several lines)
427 2292 $seq .= $line;
428 }
429  
430 # add last seq to ali (if any)
431 70 ▶ if ($seq) {
Branch: 1 branch
BranchTrueFalseTotal
if ($seq) 70 0 70
432 70 my $new_seq = Seq->new( seq_id => $seq_id, seq => $seq );
433 70 $ali->add_seq($new_seq);
434 }
435  
436 70 return $ali;
437 }
438  
439  
440 63 ▶before qr{\Astore}xms => sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
441 63 my $self = shift;
442  
443 # perform pre-storage duties
444 63 ▶ carp '[BMC] Warning: non unique seq ids!' unless $self->has_uniq_ids;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->has_uniq_ids 6 57 63
445 63 ▶ $self->uniformize if $self->is_aligned;
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_aligned 49 14 63
446  
447 63 return;
448 18 };
449  
450  
451 43 ▶sub store { ## no critic (RequireArgUnpacking)
Subroutine store: called CC=3 SCAR=11.0
452 43 my $self = shift;
453 43 my $outfile = shift;
454  
455 # automatically redirect to store_fasta for non-Ali outfile names
456 43 ▶ return $self->store_fasta($outfile, @_) # note the currying
Branch: 1 branch
BranchTrueFalseTotal
unless $outfile =~ /$Bio::MUST::Core::Ali::ALI_SUFFIX/imsx 1 42 43
457 unless $outfile =~ $ALI_SUFFIX;
458  
459 42 open my $out, '>', $outfile;
460  
461 42 print {$out} $self->header;
462 42 for my $seq ($self->all_seqs) {
463 790 say {$out} '>' . $seq->full_id;
464 790 say {$out} $seq->seq;
465 }
466  
467 42 close $out;
468  
469 42 return;
470 }
471  
472  
473 17 ▶sub store_fasta {
Subroutine store_fasta: called CC=14 SCAR=26.4
474 17 my $self = shift;
475 17 my $outfile = shift;
476 17 ▶ my $args = shift // {}; # HashRef (should not be empty...)
Condition50%1/2
shift() // {}
l!l
170
MC/DC0%0/1
shift() // {}
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
477  
478 17 ▶ my $degap = $args->{degap} // 0;
Condition100%2/2
$args->{"degap"} // 0
l!l
710
MC/DC100%1/1
$args->{"degap"} // 0
$args->{"degap"}
Truth table100%2/2
A
A= $args->{"degap"}
Aresult
11
00
479 17 ▶ my $clean = $args->{clean} // 0;
Condition100%2/2
$args->{"clean"} // 0
l!l
512
MC/DC100%1/1
$args->{"clean"} // 0
$args->{"clean"}
Truth table100%2/2
A
A= $args->{"clean"}
Aresult
11
00
480 17 ▶ my $gap = $args->{gapify} // 'X';
Condition100%2/2
$args->{"gapify"} // "X"
l!l
116
MC/DC100%1/1
$args->{"gapify"} // "X"
$args->{"gapify"}
Truth table100%2/2
A
A= $args->{"gapify"}
Aresult
11
00
481 17 ▶ my $chunk = $args->{chunk} // 60;
Condition100%2/2
$args->{"chunk"} // 60
l!l
116
MC/DC100%1/1
$args->{"chunk"} // 60
$args->{"chunk"}
Truth table100%2/2
A
A= $args->{"chunk"}
Aresult
11
00
482 17 ▶ my $nowrap = $chunk < 0 ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$chunk < 0 ? : 1 16 17
483 17 my $is_aligned = $self->is_aligned;
484  
485 17 open my $out, '>', $outfile;
486  
487 17 for my $seq ($self->all_seqs) {
488 113 say {$out} '>' . $seq->foreign_id;
489  
490 # optionally clean and/or degap seq
491 113 ▶ $seq = $seq->clone if $clean || $degap; # clone seq only if needed
Branch: 1 branch
BranchTrueFalseTotal
if $clean or $degap 35 78 113
Condition100%3/3
$clean or $degap
l!l&&r!l&&!r
251078
MC/DC100%2/2
$clean or $degap
$clean $degap
Truth table100%3/3
A or B
A= $cleanB= $degap
ABresult
1X1
011
000
492 113 ▶ $seq->gapify($gap) if $clean;
Branch: 1 branch
BranchTrueFalseTotal
if $clean 25 88 113
493 113 ▶ $seq->degap if $degap;
Branch: 1 branch
BranchTrueFalseTotal
if $degap 25 88 113
494  
495 113 my $width = $seq->seq_len;
496 113 ▶ $chunk = $width if $nowrap; # optionally disable wrap
Branch: 1 branch
BranchTrueFalseTotal
if $nowrap 5 108 113
497  
498 113 my $str = $seq->wrapped_str($chunk);
499 113 ▶ $str =~ s{$GAP}{-}xmsg if $is_aligned; # restore '-' when aligned
Branch: 1 branch
BranchTrueFalseTotal
if $is_aligned 103 10 113
500 113 print {$out} $str;
501 }
502  
503 17 close $out;
504  
505 17 return;
506 }
507  
508  
509 9 ▶sub temp_fasta {
Subroutine temp_fasta: called CC=4 SCAR=14.2
Pod documented
510 9 my $self = shift;
511 9 ▶ my $args = shift // {}; # HashRef (should not be empty...)
Condition50%1/2
shift() // {}
l!l
90
MC/DC0%0/1
shift() // {}
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
512  
513 # abbreviate ids (possibly using a custom prefix, offset, or IdMapper)
514 9 ▶ my $mapper = $args->{mapper} // $self->std_mapper($args);
Condition33%1/3
$args->{"mapper"} // $self->std_mapper($args)
l!l&&r!l&&!r
090
MC/DC0%0/2
$args->{"mapper"} // $self->std_mapper($args)
$args->{"mapper"} $self->std_mapper($args)
Truth table33%1/3
A // B
A= $args->{"mapper"}B= $self->std_mapper($args)
ABresult
1X1
011
000
515 9 $self->shorten_ids($mapper);
516  
517 # write temporary .fasta file using standard abbr_ids
518 # ...and restore long_ids afterwards
519 9 my $out = File::Temp->new(UNLINK => 0, EXLOCK => 0, SUFFIX => '.fasta');
520 9 $self->store_fasta($out->filename, $args);
521 9 $self->restore_ids($mapper);
522 ### filename: $out->filename
523  
524 9 ▶ return wantarray ? ($out->filename, $mapper) : $out->filename;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 5 4 9
525 }
526  
527  
528 # TODO: add an option to remove trailing '_' in ids?
529  
530 105 ▶sub load_phylip {
Subroutine load_phylip: called CC=11 SCAR=24.0
Pod documented
531 105 my $class = shift;
532 105 my $infile = shift;
533  
534 105 open my $in, '<', $infile;
535  
536 105 my $ali = $class->new( file => $infile );
537 105 my $seq_n;
538 my $site_n;
539 105 my $n = 0;
540  
541 LINE:
542 105 ▶ while (my $line = <$in>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline $in)) 8557 105 8662
543 8557 chomp $line;
544  
545 # skip empty lines
546 8557 ▶ next LINE if $line =~ $EMPTY_LINE;
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /$Bio::MUST::Core::Ali::EMPTY_LINE/msx 33 8524 8557
547  
548 # get matrix dimensions
549 8524 ▶ if ($line =~ $DIM_LINE) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /$Bio::MUST::Core::Ali::DIM_LINE/msx) 105 8419 8524
550 105 ($seq_n, $site_n) = ($1, $2);
551 105 next LINE;
552 }
553  
554 # process regular line (identifier is optional)
555 8419 my ($seq_id, $seq) = $line =~ $PHY_LINE;
556  
557 # should never happen...
558 8419 ▶ croak "[BMC] Error: unable to parse PHYLIP file at line $.; aborting!"
Branch: 1 branch
BranchTrueFalseTotal
unless $seq 0 8419 8419
559 unless $seq;
560  
561 # delete optional spaces
562 8419 $seq =~ tr/ //d;
563  
564 # process first seq block
565 8419 ▶ if ($ali->count_seqs < $seq_n) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ali->count_seqs < $seq_n) { } 8089 330 8419
566  
567 # seq_id are mandatory in first block
568 8089 ▶ croak "[BMC] Error: missing id in PHILIP file at line $.; aborting!"
Branch: 1 branch
BranchTrueFalseTotal
unless $seq_id 0 8089 8089
569 unless $seq_id;
570  
571 # store first seq chunk along with seq_id
572 8089 my $new_seq = Seq->new( seq_id => $seq_id, seq => $seq );
573 8089 $ali->add_seq($new_seq);
574 }
575  
576 # process remaining seq blocks
577 else {
578 330 my $curr_seq = $ali->get_seq($n);
579  
580 # elongate current with partial seq chunk mistaken as seq_id
581 330 ▶ if ($seq_id && $seq_id ne $curr_seq->full_id) {
Branch: 1 branch
BranchTrueFalseTotal
if ($seq_id and $seq_id ne $curr_seq->full_id) 110 220 330
Condition100%3/3
$seq_id and $seq_id ne $curr_seq->full_id
!ll&&!rl&&r
110110110
MC/DC100%2/2
$seq_id and $seq_id ne $curr_seq->full_id
$seq_id $seq_id ne $curr_seq->full_id
Truth table100%3/3
A and B
A= $seq_idB= $seq_id ne $curr_seq->full_id
ABresult
0X0
100
111
582 110 $curr_seq->append_seq($seq_id);
583 }
584  
585 # elongate current seq with new seq chunk
586 330 $curr_seq->append_seq($seq);
587 }
588  
589 # prepare reading of next seq or next block
590 8419 ▶ $n = 0 if ++$n == $seq_n;
Branch: 1 branch
BranchTrueFalseTotal
if ++$n == $seq_n 138 8281 8419
591 }
592  
593 105 my $width = $ali->width;
594 105 ▶ croak "[BMC] Error: unexpected site number in PHYLIP file: $width;"
Branch: 1 branch
BranchTrueFalseTotal
if $width != $site_n 0 105 105
595 . ' aborting!' if $width != $site_n;
596  
597 105 return $ali;
598 }
599  
600 # PHYLIP: http://evolution.genetics.washington.edu/phylip/doc/main.html
601 # The information for each species follows, starting with a ten-character
602 # species name (which can include blanks and some punctuation marks), and
603 # continuing with the characters for that species. The name should be on the
604 # same line as the first character of the data for that species. (...) The
605 # name should be ten characters in length, filled out to the full ten
606 # characters by blanks if shorter. Any printable ASCII/ISO character is
607 # allowed in the name, except for parentheses ("(" and ")"), square brackets
608 # ("[" and "]"), colon (":"), semicolon (";") and comma (","). (...) Note that
609 # in these sequences we have a blank every ten sites to make them easier to
610 # read: any such blanks are allowed. The blank line which separates the two
611 # groups of lines (the ones containing sites 1-20 and ones containing sites
612 # 21-39) may or may not be present.
613  
614 # PhyML: http://www.atgc-montpellier.fr/phyml/usersguide.php?type=command
615 # The input sequence file is a standard PHYLIP file of aligned DNA or
616 # amino-acids sequences. (...) The maximum number of characters in species
617 # name MUST not exceed 100. Blanks and the symbols "(),:" are not allowed
618 # within sequence names because the Newick tree format makes special use of
619 # these symbols. However, blanks (one or more) MUST appear at the end of each
620 # species name.
621  
622 # TREE-FINDER: http://www.treefinder.de/tf-march2011-manual.pdf
623 # A sequence name may consist of 1 to 10 alphanumeric characters, dashes "-",
624 # dots ".", underscores "_", or some of "/", "?", "*", "+". No space is
625 # allowed inside the names. The first name character must be a letter or an
626 # underscore. A sequence fragment may start behind position 10 after a
627 # sequence name, or anywhere in a line without a name.
628  
629 # TREE-PUZZLE [data/globin.a]
630 # 7 128
631 # HBB_HUMAN HLTPEEKSAV TALWGKVNVD EVGGEALGRL LVVYPWTQRF FESFDLSMGN
632 # HBB_HORSE QLSGEEKAAV LALWDKVNEE EVGGEALGRL LVVYPWTQRF FDSFDLSMGN
633 # HBA_HUMAN VLSPADKTNV KAAWGKVGAG EYGAEALERM FLSFPTTKTY FPHFDLSHGS
634 # HBA_HORSE VLSAADKTNV KAAWSKVGAG EYGAEALERM FLGFPTTKTY FPHFDLSHGS
635 # MYG_PHYCA VLSEGEWQLV LHVWAKVEVA GHGQDILIRL FKSHPETLEK FDRFHLKKAS
636 # GLB5_PETMA PLSAAEKTKI RSAWAPVYYE TSGVDILVKF FTSTPAAQEF FPKFGLTKKS
637 # LGB2_LUPLU ALTESQAALV KSSWEEFNIP KHTHRFFILV LEIAPAAKDL FSFLGTSQNN
638  
639 # RAXML: http://sco.h-its.org/exelixis/oldPage/RAxML-Manual.7.0.4.pdf
640 # The input alignment format of RAxML is relaxed interleaved or sequential
641 # PHYLIP. "Relaxed" means that sequence names can be of variable length
642 # between 1 up to 256 characters. (...) Prohibited Character(s) in taxon names
643 # taxon names that contain any form of whitespace character, like blanks,
644 # tabulators, and carriage returns, as well as one of the following prohibited
645 # characters: :,();[].
646  
647 # PHYLOBAYES: http://megasun.bch.umontreal.ca/People/lartillot/www/phylobayes3.3e.pdf
648 # Taxon names may contain more than 10 characters. Avoid special characters
649 # such as ';' or ')', which will create problems when parsing trees. The best
650 # is to only use letters, digits and '_'. Sequences can be interrupted by
651 # space and tab, but not by return characters. Be sure that the lengths of the
652 # sequences are all the same, and identical to the lengths indicated in the
653 # header. Sequences can be interleaved, in which case the taxon names may or
654 # may not be repeated in each block.
655  
656  
657 3 ▶sub store_phylip {
Subroutine store_phylip: called CC=14 SCAR=26.4
658 3 my $self = shift;
659 3 my $outfile = shift;
660 3 ▶ my $args = shift // {}; # HashRef (should not be empty...)
Condition50%1/2
shift() // {}
l!l
30
MC/DC0%0/1
shift() // {}
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
661  
662 3 ▶ my $short = $args->{short} // 1;
Condition100%2/2
$args->{"short"} // 1
l!l
12
MC/DC100%1/1
$args->{"short"} // 1
$args->{"short"}
Truth table100%2/2
A
A= $args->{"short"}
Aresult
11
00
663 3 ▶ my $clean = $args->{clean} // 0;
Condition50%1/2
$args->{"clean"} // 0
l!l
30
MC/DC0%0/1
$args->{"clean"} // 0
$args->{"clean"}
Truth table50%1/2
A
A= $args->{"clean"}
Aresult
11
00
664 3 ▶ my $chunk = $args->{chunk} // 60;
Condition100%2/2
$args->{"chunk"} // 60
l!l
21
MC/DC100%1/1
$args->{"chunk"} // 60
$args->{"chunk"}
Truth table100%2/2
A
A= $args->{"chunk"}
Aresult
11
00
665  
666 3 open my $out, '>', $outfile;
667  
668 # print data matrix dimensions
669 3 my $height = $self->count_seqs;
670 3 my $width = $self->width;
671 3 say {$out} $height . q{ } . $width;
672  
673 # setup id format (this will also affect block-like structure)
674 3 ▶ my $format = $short ? "%-10.10s %s\n" : "%s %s\n";
Branch: 1 branch
BranchTrueFalseTotal
$short ? : 2 1 3
675 3 ▶ my $method = $short ? 'full_id' : 'foreign_id';
Branch: 1 branch
BranchTrueFalseTotal
$short ? : 2 1 3
676 3 ▶ my $sep = $short ? q{ } : q{};
Branch: 1 branch
BranchTrueFalseTotal
$short ? : 2 1 3
677  
678 # optionally disable wrapping
679 3 ▶ $chunk = $width if $chunk < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $chunk < 0 2 1 3
680  
681 # optionally clean seq
682 3 my @seqs = $self->all_seqs;
683 3 ▶ @seqs = map { $_->clone->gapify('X') } @seqs if $clean;
Branch: 1 branch
BranchTrueFalseTotal
if $clean 3 0 3
684  
685 # output Ali in sequential or interleaved format
686 3 ▶ for (my $site = 0; $site < $width; $site += $chunk) {
Branch: 1 branch
BranchTrueFalseTotal
if ($site < $width) 14 3 17
687  
688 # leave empty line between chunks (but not after last chunk)
689 14 ▶ print {$out} "\n" if $site;
Branch: 1 branch
BranchTrueFalseTotal
if $site 11 3 14
690  
691 14 for my $seq (@seqs) {
692  
693 # print 10-chars ids only once
694 # Note: full_ids are only truncated (use IdMapper for more)
695 138 ▶ my $id = $site == 0 ? $seq->$method : q{};
Branch: 1 branch
BranchTrueFalseTotal
$site == 0 ? : 28 110 138
696  
697 # print seq chunks in 10-state blocks
698 # Note: We insert a space in the 11th column to ensure that more
699 # software packages can read the written files. PHYLIP itself will
700 # ignore this spurious space in the 'sequences'.
701 138 ( my $str = $seq->edit_seq($site, $chunk) ) =~ s{$GAP}{-}xmsg;
702 138 printf {$out} $format, $id, join $sep,
703 138 map { substr($str, $_*10, 10) } 0..ceil(length($str)/10)-1;
704 }
705 }
706  
707 3 close $out;
708  
709 3 return;
710 }
711  
712  
713 2 ▶sub load_stockholm {
Subroutine load_stockholm: called CC=7 SCAR=19.5
Pod documented
714 2 my $class = shift;
715 2 my $infile = shift;
716  
717 2 open my $in, '<', $infile;
718  
719 2 my $ali = $class->new( file => $infile );
720 2 tie my %seq_for, 'Tie::IxHash';
721  
722 LINE:
723 2 ▶ while (my $line = <$in>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline $in)) 44 0 44
724 44 chomp $line;
725  
726 # process GF comments
727 44 ▶ next LINE if $ali->is_comment($line, $STK_COMMENT);
Branch: 1 branch
BranchTrueFalseTotal
if $ali->is_comment($line, $Bio::MUST::Core::Ali::STK_COMMENT) 17 27 44
728  
729 # skip empty lines and other comment lines
730 27 ▶ next LINE if $line =~ $EMPTY_LINE
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /$Bio::MUST::Core::Ali::EMPTY_LINE/msx or $line =~ /$Bio::MUST::Core::Ali::COMMENT_LINE/msx 16 11 27
Condition100%3/3
$line =~ /$Bio::MUST::Core::Ali::EMPTY_LINE/msx or $line =~ /$Bio::MUST::Core::Ali::COMMENT_LINE/msx
l!l&&r!l&&!r
11511
MC/DC100%2/2
$line =~ /$Bio::MUST::Core::Ali::EMPTY_LINE/msx or $line =~ /$Bio::MUST::Core::Ali::COMMENT_LINE/msx
$line =~ /$Bio::MUST::Core::Ali::EMPTY_LINE/msx $line =~ /$Bio::MUST::Core::Ali::COMMENT_LINE/msx
Truth table100%3/3
A or B
A= $line =~ /$Bio::MUST::Core::Ali::EMPTY_LINE/msxB= $line =~ /$Bio::MUST::Core::Ali::COMMENT_LINE/msx
ABresult
1X1
011
000
731 || $line =~ $COMMENT_LINE;
732 11 ▶ last LINE if $line =~ $END_LINE;
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /$Bio::MUST::Core::Ali::END_LINE/msx 2 9 11
733  
734 # parse stockholm seq
735 9 my ($seq_id, $seq) = $line =~ $STK_SEQ;
736  
737 # replace dots and gaps by stars
738 9 $seq =~ s/[\.\-]/*/xmsg;
739  
740 # elongate seq
741 9 $seq_for{$seq_id} .= $seq;
742 }
743  
744 # populate Ali object
745 2 ▶ while (my ($seq_id, $seq) = each %seq_for) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %seq_for) 9 2 11
746 9 my $new_seq = Seq->new( seq_id => $seq_id, seq => $seq );
747 9 $ali->add_seq($new_seq);
748 }
749  
750 2 return $ali;
751 }
752  
753  
754 # <TSeq>
755 # <TSeq_seqtype value="nucleotide"/>
756 # <TSeq_gi>160476623</TSeq_gi>
757 # <TSeq_accver>EY249574.1</TSeq_accver>
758 # <TSeq_sid>gnl|dbEST|50783737</TSeq_sid>
759 # <TSeq_taxid>5061</TSeq_taxid>
760 # <TSeq_orgname>Aspergillus niger</TSeq_orgname>
761 # <TSeq_defline>CATY7117.fwd CATY Aspergillus niger fungal ...</TSeq_defline>
762 # <TSeq_length>906</TSeq_length>
763 # <TSeq_sequence>ACGT...</TSeq_sequence>
764 # </TSeq>
765  
766 2 ▶sub load_tinyseq {
Subroutine load_tinyseq: called CC=9 SCAR=22.0
Pod documented
767 2 my $class = shift;
768 2 my $infile = shift;
769 2 ▶ my $args = shift // {}; # HashRef (should not be empty...)
Condition50%1/2
shift() // {}
l!l
20
MC/DC0%0/1
shift() // {}
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
770  
771 2 ▶ my $kps = $args->{keep_strain} // 0;
Condition50%1/2
$args->{"keep_strain"} // 0
l!l
20
MC/DC0%0/1
$args->{"keep_strain"} // 0
$args->{"keep_strain"}
Truth table50%1/2
A
A= $args->{"keep_strain"}
Aresult
11
00
772  
773 2 open my $in, '<', $infile;
774  
775 2 my $ali = $class->new( file => $infile );
776 2 my ($acc, $tax, $org, $seq);
777  
778 # Note: crude parser derived from old tseq2ali.pl
779 2 ▶ while (my $line = <$in>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline $in)) 104 2 106
780 104 chomp $line;
781  
782 # capture attributes
783 104 ▶ if ($line =~ m{<TSeq_accver> (.*?) </TSeq_accver> }xms) {
Branch: 4 branches
BranchTrueFalseTotal
if ($line =~ m[<TSeq_accver> (.*?) </TSeq_accver> ]msx) { } 10 94 104
elsif ($line =~ m[<TSeq_taxid> ($Bio::MUST::Core::Ali::NCBIPKEY) </TSeq_taxid> ]msx) { } 10 84 94
elsif ($line =~ m[<TSeq_orgname> (.*?) </TSeq_orgname> ]msx) { } 10 74 84
elsif ($line =~ m[<TSeq_sequence> (.*?) </TSeq_sequence>]msx) { } 10 64 74
784 10 $acc = $1;
785 } elsif ($line =~ m{<TSeq_taxid> ($NCBIPKEY) </TSeq_taxid> }xms) {
786 10 $tax = $1;
787 } elsif ($line =~ m{<TSeq_orgname> (.*?) </TSeq_orgname> }xms) {
788 10 $org = $1;
789 } elsif ($line =~ m{<TSeq_sequence> (.*?) </TSeq_sequence>}xms) {
790 10 $seq = $1;
791 }
792  
793 # process current seq (if any)
794 104 ▶ if ($seq) {
Branch: 1 branch
BranchTrueFalseTotal
if ($seq) 10 94 104
795  
796 # build full_id from NCBI org
797 10 my $seq_id = SeqId->new_with(
798 org => $org,
799 taxon_id => $tax,
800 accession => $acc,
801 keep_strain => $kps,
802 );
803  
804 # add current seq to ali
805 10 my $new_seq = Seq->new( seq_id => $seq_id, seq => $seq );
806 10 $ali->add_seq($new_seq);
807  
808 # clear attributes for next seq
809 10 ($acc, $tax, $org, $seq) = () x 4;
810 }
811 }
812  
813 2 return $ali;
814 }
815  
816  
817 1 ▶sub instant_store {
Subroutine instant_store: called CC=10 SCAR=23.1
Pod documented
818 1 my $class = shift;
819 1 my $outfile = shift;
820 1 ▶ my $args = shift // {}; # HashRef (should not be empty...)
Condition50%1/2
shift() // {}
l!l
10
MC/DC0%0/1
shift() // {}
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
821  
822 1 my $infile = $args->{infile};
823 1 ▶ croak '[BMC] Error: no infile specified for instant_store; aborting!'
Branch: 1 branch
BranchTrueFalseTotal
unless $infile 0 1 1
824 unless $infile;
825  
826 1 my $coderef = $args->{coderef};
827 1 ▶ croak '[BMC] Error: no coderef specified for instant_store; aborting!'
Branch: 1 branch
BranchTrueFalseTotal
unless $coderef 0 1 1
828 unless $coderef;
829  
830 1 open my $in, '<', $infile;
831 1 open my $out, '>', $outfile;
832  
833 1 my $seq_id;
834 my $seq;
835  
836 LINE:
837 1 ▶ while (my $line = <$in>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline $in)) 92 1 93
838 92 chomp $line;
839  
840 # skip empty lines and process comments
841 92 ▶ next LINE if $line =~ $EMPTY_LINE
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /$Bio::MUST::Core::Ali::EMPTY_LINE/msx or $line =~ /$Bio::MUST::Core::Ali::COMMENT_LINE/msx 2 90 92
Condition66%2/3
$line =~ /$Bio::MUST::Core::Ali::EMPTY_LINE/msx or $line =~ /$Bio::MUST::Core::Ali::COMMENT_LINE/msx
l!l&&r!l&&!r
2090
MC/DC50%1/2
$line =~ /$Bio::MUST::Core::Ali::EMPTY_LINE/msx or $line =~ /$Bio::MUST::Core::Ali::COMMENT_LINE/msx
$line =~ /$Bio::MUST::Core::Ali::EMPTY_LINE/msx $line =~ /$Bio::MUST::Core::Ali::COMMENT_LINE/msx
Truth table66%2/3
A or B
A= $line =~ /$Bio::MUST::Core::Ali::EMPTY_LINE/msxB= $line =~ /$Bio::MUST::Core::Ali::COMMENT_LINE/msx
ABresult
1X1
011
000
842 || $line =~ $COMMENT_LINE;
843  
844 # at each '>' char...
845 90 my ($defline) = $line =~ $DEF_LINE;
846 90 ▶ if ($defline) {
Branch: 1 branch
BranchTrueFalseTotal
if ($defline) 3 87 90
847  
848 # process current seq (if any)
849 3 ▶ if ($seq) {
Branch: 1 branch
BranchTrueFalseTotal
if ($seq) 2 1 3
850 2 my $new_seq = Seq->new( seq_id => $seq_id, seq => $seq );
851 2 print {$out} $coderef->($new_seq);
852 2 $seq = q{};
853 }
854  
855 3 $seq_id = $defline;
856 3 next LINE;
857 }
858  
859 # elongate current seq (seqs can be broken on several lines)
860 87 $seq .= $line;
861 }
862  
863 # process last seq (if any)
864 1 ▶ if ($seq) {
Branch: 1 branch
BranchTrueFalseTotal
if ($seq) 1 0 1
865 1 my $new_seq = Seq->new( seq_id => $seq_id, seq => $seq );
866 1 print {$out} $coderef->($new_seq);
867 }
868  
869 1 close $out;
870  
871 1 return;
872 }
873  
874  
875 1 ▶sub instant_count {
Subroutine instant_count: called CC=3 SCAR=11.0
Pod documented
876 1 my $class = shift;
877 1 my $infile = shift;
878  
879 1 my $seq_n = 0;
880  
881 1 open my $in, '<', $infile;
882 1 ▶ while (<$in>) { $seq_n++ if m/^>/xms }
Branch: 2 branches
BranchTrueFalseTotal
if (defined($_ = readline $in)) 502 1 503
if /^>/msx 250 252 502
883  
884 1 return $seq_n;
885 }
886  
887 18 __PACKAGE__->meta->make_immutable;
888 18 1;
889  
890 __END__
« lib/Bio/MUST/Core/SeqMask/Profiles.pm ↑ Summary lib/Bio/MUST/Core/Types.pm »