| 1 | # | ||||||||||||||||||||||||||||
| 2 | # BioPerl module for Bio::AlignIO::clustalw | ||||||||||||||||||||||||||||
| 3 | # | ||||||||||||||||||||||||||||
| 4 | # based on the Bio::SeqIO modules | ||||||||||||||||||||||||||||
| 5 | # by Ewan Birney <birney@ebi.ac.uk> | ||||||||||||||||||||||||||||
| 6 | # and Lincoln Stein <lstein@cshl.org> | ||||||||||||||||||||||||||||
| 7 | # and the Bio::SimpleAlign module of Ewan Birney | ||||||||||||||||||||||||||||
| 8 | # | ||||||||||||||||||||||||||||
| 9 | # Copyright Peter Schattner | ||||||||||||||||||||||||||||
| 10 | # | ||||||||||||||||||||||||||||
| 11 | # You may distribute this module under the same terms as perl itself | ||||||||||||||||||||||||||||
| 12 | # History | ||||||||||||||||||||||||||||
| 13 | # September 5, 2000 | ||||||||||||||||||||||||||||
| 14 | # POD documentation - main docs before the code | ||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | =head1 NAME | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | Bio::AlignIO::clustalw - clustalw sequence input/output stream | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | Do not use this module directly. Use it via the Bio::AlignIO class. | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | This object can transform Bio::Align::AlignI objects to and from clustalw | ||||||||||||||||||||||||||||
| 27 | files. | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | =head1 FEEDBACK | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | =head2 Mailing Lists | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | User feedback is an integral part of the evolution of this and other | ||||||||||||||||||||||||||||
| 34 | Bioperl modules. Send your comments and suggestions preferably to one | ||||||||||||||||||||||||||||
| 35 | of the Bioperl mailing lists. Your participation is much appreciated. | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | bioperl-l@bioperl.org - General discussion | ||||||||||||||||||||||||||||
| 38 | http://bioperl.org/wiki/Mailing_lists - About the mailing lists | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | =head2 Support | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | Please direct usage questions or support issues to the mailing list: | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | I<bioperl-l@bioperl.org> | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | rather than to the module maintainer directly. Many experienced and | ||||||||||||||||||||||||||||
| 47 | reponsive experts will be able look at the problem and quickly | ||||||||||||||||||||||||||||
| 48 | address it. Please include a thorough description of the problem | ||||||||||||||||||||||||||||
| 49 | with code and data examples if at all possible. | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | =head2 Reporting Bugs | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | Report bugs to the Bioperl bug tracking system to help us keep track | ||||||||||||||||||||||||||||
| 54 | the bugs and their resolution. Bug reports can be submitted via the | ||||||||||||||||||||||||||||
| 55 | web: | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | https://github.com/bioperl/bioperl-live/issues | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | =head1 AUTHORS - Peter Schattner | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | Email: schattner@alum.mit.edu | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | =head1 APPENDIX | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | The rest of the documentation details each of the object | ||||||||||||||||||||||||||||
| 67 | methods. Internal methods are usually preceded with a _ | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | =cut | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | # Let the code begin... | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | package Bio::AlignIO::clustalw; | ||||||||||||||||||||||||||||
| 74 | 8 | $Bio::AlignIO::clustalw::VERSION = '1.7.8'; | |||||||||||||||||||||||||||
| 75 | 8 | ▶ | use vars qw($LINELENGTH $CLUSTALPRINTVERSION); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 76 | 8 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 8 | $LINELENGTH = 60; | |||||||||||||||||||||||||||
| 80 | 8 | $CLUSTALPRINTVERSION = '1.81'; | |||||||||||||||||||||||||||
| 81 | 8 | ▶ | use base qw(Bio::AlignIO); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | =head2 new | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | Title : new | ||||||||||||||||||||||||||||
| 86 | Usage : $alignio = Bio::AlignIO->new(-format => 'clustalw', | ||||||||||||||||||||||||||||
| 87 | -file => 'filename'); | ||||||||||||||||||||||||||||
| 88 | Function: returns a new Bio::AlignIO object to handle clustalw files | ||||||||||||||||||||||||||||
| 89 | Returns : Bio::AlignIO::clustalw object | ||||||||||||||||||||||||||||
| 90 | Args : -verbose => verbosity setting (-1, 0, 1, 2) | ||||||||||||||||||||||||||||
| 91 | -file => name of file to read in or to write, with ">" | ||||||||||||||||||||||||||||
| 92 | -fh => alternative to -file param - provide a filehandle | ||||||||||||||||||||||||||||
| 93 | to read from or write to | ||||||||||||||||||||||||||||
| 94 | -format => alignment format to process or produce | ||||||||||||||||||||||||||||
| 95 | -percentages => display a percentage of identity | ||||||||||||||||||||||||||||
| 96 | in each line of the alignment (clustalw only) | ||||||||||||||||||||||||||||
| 97 | -linelength=> alignment output line length (default 60) | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | =cut | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | 150 | ▶ | sub _initialize { | ||||||||||||||||||||||||||
|
Subroutine
_initialize: called CC=3 SCAR=11.8
| |||||||||||||||||||||||||||||
| 102 | 150 | my ( $self, @args ) = @_; | |||||||||||||||||||||||||||
| 103 | 150 | $self->SUPER::_initialize(@args); | |||||||||||||||||||||||||||
| 104 | 150 | my ( $percentages, $ll ) = | |||||||||||||||||||||||||||
| 105 | $self->_rearrange( [qw(PERCENTAGES LINELENGTH)], @args ); | ||||||||||||||||||||||||||||
| 106 | 150 | ▶ | defined $percentages && $self->percentages($percentages); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 107 | 150 | ▶ | $self->line_length( $ll || $LINELENGTH ); | ||||||||||||||||||||||||||
|
Condition33%1/3
$ll || $Bio::AlignIO::clustalw::LINELENGTH
MC/DC0%0/2
$ll || $Bio::AlignIO::clustalw::LINELENGTH
$ll
$Bio::AlignIO::clustalw::LINELENGTH
Truth table33%1/3
A || B
A= $llB= $Bio::AlignIO::clustalw::LINELENGTH
| |||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | =head2 next_aln | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | Title : next_aln | ||||||||||||||||||||||||||||
| 113 | Usage : $aln = $stream->next_aln() | ||||||||||||||||||||||||||||
| 114 | Function: returns the next alignment in the stream | ||||||||||||||||||||||||||||
| 115 | Returns : Bio::Align::AlignI object | ||||||||||||||||||||||||||||
| 116 | Args : NONE | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | See L<Bio::Align::AlignI> for details | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | =cut | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | 32 | ▶ | sub next_aln { | ||||||||||||||||||||||||||
|
Subroutine
next_aln: called CC=18 SCAR=30.1
Pod
documented
| |||||||||||||||||||||||||||||
| 123 | 32 | my ($self) = @_; | |||||||||||||||||||||||||||
| 124 | 32 | my $first_line; | |||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | 32 | ▶ | while ( $first_line = $self->_readline ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 127 | 32 | ▶ | last if $first_line !~ /^$/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||
| 129 | 32 | $self->_pushback($first_line); | |||||||||||||||||||||||||||
| 130 | 32 | ▶ | if ( defined( $first_line = $self->_readline ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined($first_line = $self->_readline) and not $first_line =~ /CLUSTAL/
MC/DC0%0/2
defined($first_line = $self->_readline) and not $first_line =~ /CLUSTAL/
defined($first_line = $self->_readline)
not $first_line =~ /CLUSTAL/
Truth table33%1/3
A and not(B)
A= defined($first_line = $self->_readline)B= not $first_line =~ /CLUSTAL/
| |||||||||||||||||||||||||||||
| 131 | && $first_line !~ /CLUSTAL/ ) | ||||||||||||||||||||||||||||
| 132 | { | ||||||||||||||||||||||||||||
| 133 | 0 | $self->throw( | |||||||||||||||||||||||||||
| 134 | "trying to parse a file which does not start with a CLUSTAL header" | ||||||||||||||||||||||||||||
| 135 | ); | ||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||
| 137 | 32 | my %alignments; | |||||||||||||||||||||||||||
| 138 | 32 | my $aln = Bio::SimpleAlign->new( | |||||||||||||||||||||||||||
| 139 | -source => 'clustalw', | ||||||||||||||||||||||||||||
| 140 | -verbose => $self->verbose | ||||||||||||||||||||||||||||
| 141 | ); | ||||||||||||||||||||||||||||
| 142 | 32 | my $order = 0; | |||||||||||||||||||||||||||
| 143 | 32 | my %order; | |||||||||||||||||||||||||||
| 144 | 32 | $self->{_lastline} = ''; | |||||||||||||||||||||||||||
| 145 | 32 | my ($first_block, $seen_block) = (0,0); | |||||||||||||||||||||||||||
| 146 | 32 | ▶ | while ( defined( $_ = $self->_readline ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 147 | 2233 | ▶ | next if (/^\s+$/ && !$first_block); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
/^\s+$/ and not $first_block
MC/DC100%2/2
/^\s+$/ and not $first_block
/^\s+$/
not $first_block
Truth table100%3/3
A and not(B)
A= /^\s+$/B= not $first_block
| |||||||||||||||||||||||||||||
| 148 | 2169 | ▶ | if (/^\s$/) { # line contains no description | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 149 | 225 | $seen_block = 1; | |||||||||||||||||||||||||||
| 150 | 225 | next; | |||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||
| 152 | 1944 | $first_block = 1; | |||||||||||||||||||||||||||
| 153 | # break the loop if we come to the end of the current alignment | ||||||||||||||||||||||||||||
| 154 | # and push back the CLUSTAL header | ||||||||||||||||||||||||||||
| 155 | 1944 | ▶ | if (/CLUSTAL/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 156 | 0 | $self->_pushback($_); | |||||||||||||||||||||||||||
| 157 | 0 | last; | |||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | 1944 | my ( $seqname, $aln_line ) = ( '', '' ); | |||||||||||||||||||||||||||
| 161 | 1944 | ▶ | if (/^\s*(\S+)\s*\/\s*(\d+)-(\d+)\s+(\S+)\s*$/ox) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||
| 163 | # clustal 1.4 format | ||||||||||||||||||||||||||||
| 164 | 48 | ( $seqname, $aln_line ) = ( "$1:$2-$3", $4 ); | |||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||
| 166 | # } elsif( /^\s*(\S+)\s+(\S+)\s*$/ox ) { without trailing numbers | ||||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||
| 168 | elsif (/^\s*(\S+)\s+(\S+)\s*\d*\s*$/ox) { # with numbers | ||||||||||||||||||||||||||||
| 169 | 1648 | ( $seqname, $aln_line ) = ( $1, $2 ); | |||||||||||||||||||||||||||
| 170 | 1648 | ▶ | if ( $seqname =~ /^[\*\.\+\:]+$/ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 171 | 0 | $self->{_lastline} = $_; | |||||||||||||||||||||||||||
| 172 | 0 | next; | |||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||
| 175 | else { | ||||||||||||||||||||||||||||
| 176 | 248 | $self->{_lastline} = $_; | |||||||||||||||||||||||||||
| 177 | 248 | next; | |||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||
| 180 | 1696 | ▶ | if ( !$seen_block ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 181 | 220 | ▶ | if (exists $order{$seqname}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 182 | 0 | $self->warn("Duplicate sequence : $seqname\n". | |||||||||||||||||||||||||||
| 183 | "Can't guarantee alignment quality"); | ||||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||
| 185 | else { | ||||||||||||||||||||||||||||
| 186 | 220 | $order{$seqname} = $order++; | |||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||
| 190 | 1696 | $alignments{$seqname} .= $aln_line; | |||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||
| 193 | 32 | my ( $sname, $start, $end ); | |||||||||||||||||||||||||||
| 194 | 32 | foreach my $name ( sort { $order{$a} <=> $order{$b} } keys %alignments ) { | |||||||||||||||||||||||||||
| 195 | 220 | ▶ | if ( $name =~ /(\S+):(\d+)-(\d+)/ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 196 | 6 | ( $sname, $start, $end ) = ( $1, $2, $3 ); | |||||||||||||||||||||||||||
| 197 | } | ||||||||||||||||||||||||||||
| 198 | else { | ||||||||||||||||||||||||||||
| 199 | 214 | ( $sname, $start ) = ( $name, 1 ); | |||||||||||||||||||||||||||
| 200 | 214 | my $str = $alignments{$name}; | |||||||||||||||||||||||||||
| 201 | 214 | $str =~ s/[^A-Za-z]//g; | |||||||||||||||||||||||||||
| 202 | 214 | $end = length($str); | |||||||||||||||||||||||||||
| 203 | } | ||||||||||||||||||||||||||||
| 204 | my $seq = Bio::LocatableSeq->new | ||||||||||||||||||||||||||||
| 205 | ( | ||||||||||||||||||||||||||||
| 206 | 220 | '-seq' => $alignments{$name}, | |||||||||||||||||||||||||||
| 207 | '-display_id' => $sname, | ||||||||||||||||||||||||||||
| 208 | '-start' => $start, | ||||||||||||||||||||||||||||
| 209 | '-end' => $end, | ||||||||||||||||||||||||||||
| 210 | '-alphabet' => $self->alphabet, | ||||||||||||||||||||||||||||
| 211 | ); | ||||||||||||||||||||||||||||
| 212 | 220 | $aln->add_seq($seq); | |||||||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||
| 215 | # not sure if this should be a default option - or we can pass in | ||||||||||||||||||||||||||||
| 216 | # an option to do this in the future? --jason stajich | ||||||||||||||||||||||||||||
| 217 | # $aln->map_chars('\.','-'); | ||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||
| 219 | # no sequences added, so just return | ||||||||||||||||||||||||||||
| 220 | 32 | ▶ | return $aln if $aln->num_sequences; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 221 | 0 | return; | |||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||
| 224 | =head2 write_aln | ||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||
| 226 | Title : write_aln | ||||||||||||||||||||||||||||
| 227 | Usage : $stream->write_aln(@aln) | ||||||||||||||||||||||||||||
| 228 | Function: writes the clustalw-format object (.aln) into the stream | ||||||||||||||||||||||||||||
| 229 | Returns : 1 for success and 0 for error | ||||||||||||||||||||||||||||
| 230 | Args : Bio::Align::AlignI object | ||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||
| 232 | =cut | ||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||
| 234 | 2 | ▶ | sub write_aln { | ||||||||||||||||||||||||||
|
Subroutine
write_aln: called CC=20 SCAR=33.3
Pod
documented
| |||||||||||||||||||||||||||||
| 235 | 2 | my ( $self, @aln ) = @_; | |||||||||||||||||||||||||||
| 236 | 2 | my ( $count, $length, $seq, @seq, $tempcount, $line_len ); | |||||||||||||||||||||||||||
| 237 | 2 | ▶ | $line_len = $self->line_length || $LINELENGTH; | ||||||||||||||||||||||||||
|
Condition33%1/3
$self->line_length || $Bio::AlignIO::clustalw::LINELENGTH
MC/DC0%0/2
$self->line_length || $Bio::AlignIO::clustalw::LINELENGTH
$self->line_length
$Bio::AlignIO::clustalw::LINELENGTH
Truth table33%1/3
A || B
A= $self->line_lengthB= $Bio::AlignIO::clustalw::LINELENGTH
| |||||||||||||||||||||||||||||
| 238 | 2 | foreach my $aln (@aln) { | |||||||||||||||||||||||||||
| 239 | 2 | ▶ | if ( !$aln || !$aln->isa('Bio::Align::AlignI') ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$aln and $aln->isa("Bio::Align::AlignI")
MC/DC0%0/2
$aln and $aln->isa("Bio::Align::AlignI")
$aln
$aln->isa("Bio::Align::AlignI")
Truth table33%1/3
A and B
A= $alnB= $aln->isa("Bio::Align::AlignI")
| |||||||||||||||||||||||||||||
| 240 | 0 | $self->warn( | |||||||||||||||||||||||||||
| 241 | "Must provide a Bio::Align::AlignI object when calling write_aln" | ||||||||||||||||||||||||||||
| 242 | ); | ||||||||||||||||||||||||||||
| 243 | 0 | next; | |||||||||||||||||||||||||||
| 244 | } | ||||||||||||||||||||||||||||
| 245 | 2 | my $matchline = $aln->match_line; | |||||||||||||||||||||||||||
| 246 | 2 | ▶ | if ( $self->force_displayname_flat ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 247 | 0 | $aln->set_displayname_flat(1); | |||||||||||||||||||||||||||
| 248 | } | ||||||||||||||||||||||||||||
| 249 | $self->_print( | ||||||||||||||||||||||||||||
| 250 | 2 | ▶ | sprintf( "CLUSTAL W (%s) multiple sequence alignment\n\n\n", | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 251 | $CLUSTALPRINTVERSION ) | ||||||||||||||||||||||||||||
| 252 | ) or return; | ||||||||||||||||||||||||||||
| 253 | 2 | $length = $aln->length(); | |||||||||||||||||||||||||||
| 254 | 2 | $count = $tempcount = 0; | |||||||||||||||||||||||||||
| 255 | 2 | @seq = $aln->each_seq(); | |||||||||||||||||||||||||||
| 256 | 2 | my $max = 22; | |||||||||||||||||||||||||||
| 257 | 2 | foreach $seq (@seq) { | |||||||||||||||||||||||||||
| 258 | 12 | ▶ | $max = length( $aln->displayname( $seq->get_nse() ) ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 259 | if ( length( $aln->displayname( $seq->get_nse() ) ) > $max ); | ||||||||||||||||||||||||||||
| 260 | } | ||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||
| 262 | 2 | ▶ | while ( $count < $length ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 263 | 16 | my ( $linesubstr, $first ) = ( '', 1 ); | |||||||||||||||||||||||||||
| 264 | 16 | foreach $seq (@seq) { | |||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||
| 266 | # | ||||||||||||||||||||||||||||
| 267 | # Following lines are to suppress warnings | ||||||||||||||||||||||||||||
| 268 | # if some sequences in the alignment are much longer than others. | ||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||
| 270 | 96 | my ($substring); | |||||||||||||||||||||||||||
| 271 | 96 | my $seqchars = $seq->seq(); | |||||||||||||||||||||||||||
| 272 | SWITCH: { | ||||||||||||||||||||||||||||
| 273 | 96 | ▶ | if ( length($seqchars) >= ( $count + $line_len ) ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 274 | 84 | $substring = substr( $seqchars, $count, $line_len ); | |||||||||||||||||||||||||||
| 275 | 84 | ▶ | if ($first) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 276 | 14 | $linesubstr = | |||||||||||||||||||||||||||
| 277 | substr( $matchline, $count, $line_len ); | ||||||||||||||||||||||||||||
| 278 | 14 | $first = 0; | |||||||||||||||||||||||||||
| 279 | } | ||||||||||||||||||||||||||||
| 280 | 84 | last SWITCH; | |||||||||||||||||||||||||||
| 281 | } | ||||||||||||||||||||||||||||
| 282 | elsif ( length($seqchars) >= $count ) { | ||||||||||||||||||||||||||||
| 283 | 12 | $substring = substr( $seqchars, $count ); | |||||||||||||||||||||||||||
| 284 | 12 | ▶ | if ($first) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 285 | 2 | $linesubstr = substr( $matchline, $count ); | |||||||||||||||||||||||||||
| 286 | 2 | $first = 0; | |||||||||||||||||||||||||||
| 287 | } | ||||||||||||||||||||||||||||
| 288 | 12 | last SWITCH; | |||||||||||||||||||||||||||
| 289 | } | ||||||||||||||||||||||||||||
| 290 | 0 | $substring = ""; | |||||||||||||||||||||||||||
| 291 | } | ||||||||||||||||||||||||||||
| 292 | $self->_print( | ||||||||||||||||||||||||||||
| 293 | 96 | ▶ | sprintf( | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 294 | "%-" . $max . "s %s\n", | ||||||||||||||||||||||||||||
| 295 | $aln->displayname( $seq->get_nse() ), $substring | ||||||||||||||||||||||||||||
| 296 | ) | ||||||||||||||||||||||||||||
| 297 | ) or return; | ||||||||||||||||||||||||||||
| 298 | } | ||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||
| 300 | 16 | my $percentages = ''; | |||||||||||||||||||||||||||
| 301 | 16 | ▶ | if ( $self->percentages ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 302 | 0 | my ($strcpy) = ($linesubstr); | |||||||||||||||||||||||||||
| 303 | 0 | my $count = ( $strcpy =~ tr/\*// ); | |||||||||||||||||||||||||||
| 304 | 0 | $percentages = | |||||||||||||||||||||||||||
| 305 | sprintf( "\t%d%%", 100 * ( $count / length($linesubstr) ) ); | ||||||||||||||||||||||||||||
| 306 | } | ||||||||||||||||||||||||||||
| 307 | $self->_print( | ||||||||||||||||||||||||||||
| 308 | 16 | sprintf( | |||||||||||||||||||||||||||
| 309 | "%-" . $max . "s %s%s\n", | ||||||||||||||||||||||||||||
| 310 | '', $linesubstr, $percentages | ||||||||||||||||||||||||||||
| 311 | ) | ||||||||||||||||||||||||||||
| 312 | ); | ||||||||||||||||||||||||||||
| 313 | 16 | ▶ | $self->_print( sprintf("\n\n") ) or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 314 | 16 | $count += $line_len; | |||||||||||||||||||||||||||
| 315 | } | ||||||||||||||||||||||||||||
| 316 | } | ||||||||||||||||||||||||||||
| 317 | 2 | ▶ | $self->flush if $self->_flush_on_write && defined $self->_fh; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->_flush_on_write and defined $self->_fh
MC/DC0%0/2
$self->_flush_on_write and defined $self->_fh
$self->_flush_on_write
defined $self->_fh
Truth table33%1/3
A and B
A= $self->_flush_on_writeB= defined $self->_fh
| |||||||||||||||||||||||||||||
| 318 | 2 | return 1; | |||||||||||||||||||||||||||
| 319 | } | ||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||
| 321 | =head2 percentages | ||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||
| 323 | Title : percentages | ||||||||||||||||||||||||||||
| 324 | Usage : $obj->percentages($newval) | ||||||||||||||||||||||||||||
| 325 | Function: Set the percentages flag - whether or not to show percentages in | ||||||||||||||||||||||||||||
| 326 | each output line | ||||||||||||||||||||||||||||
| 327 | Returns : value of percentages | ||||||||||||||||||||||||||||
| 328 | Args : newvalue (optional) | ||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||
| 331 | =cut | ||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||
| 333 | 16 | ▶ | sub percentages { | ||||||||||||||||||||||||||
|
Subroutine
percentages: called CC=2 SCAR=7.6
Pod
documented
| |||||||||||||||||||||||||||||
| 334 | 16 | my ( $self, $value ) = @_; | |||||||||||||||||||||||||||
| 335 | 16 | ▶ | if ( defined $value ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 336 | 0 | $self->{'_percentages'} = $value; | |||||||||||||||||||||||||||
| 337 | } | ||||||||||||||||||||||||||||
| 338 | 16 | return $self->{'_percentages'}; | |||||||||||||||||||||||||||
| 339 | } | ||||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||
| 341 | =head2 line_length | ||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||
| 343 | Title : line_length | ||||||||||||||||||||||||||||
| 344 | Usage : $obj->line_length($newval) | ||||||||||||||||||||||||||||
| 345 | Function: Set the alignment output line length | ||||||||||||||||||||||||||||
| 346 | Returns : value of line_length | ||||||||||||||||||||||||||||
| 347 | Args : newvalue (optional) | ||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||
| 350 | =cut | ||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||
| 352 | 152 | ▶ | sub line_length { | ||||||||||||||||||||||||||
|
Subroutine
line_length: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 353 | 152 | my ( $self, $value ) = @_; | |||||||||||||||||||||||||||
| 354 | 152 | ▶ | if ( defined $value ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 355 | 150 | $self->{'_line_length'} = $value; | |||||||||||||||||||||||||||
| 356 | } | ||||||||||||||||||||||||||||
| 357 | 152 | return $self->{'_line_length'}; | |||||||||||||||||||||||||||
| 358 | } | ||||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||
| 360 | 8 | 1; | |||||||||||||||||||||||||||