| 1 | # $Id: po.pm | ||||||||||||||||||||||||||||||||||||||||||||||
| 2 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 3 | # BioPerl module for Bio::AlignIO::po | ||||||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||||||
| 5 | # based on the Bio::AlignIO::fasta module | ||||||||||||||||||||||||||||||||||||||||||||||
| 6 | # by Peter Schattner (and others?) | ||||||||||||||||||||||||||||||||||||||||||||||
| 7 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 8 | # and the SimpleAlign.pm module of Ewan Birney | ||||||||||||||||||||||||||||||||||||||||||||||
| 9 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 10 | # You may distribute this module under the same terms as perl itself | ||||||||||||||||||||||||||||||||||||||||||||||
| 11 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 12 | # POD documentation - main docs before the code | ||||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||
| 14 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||||||
| 16 | Bio::AlignIO::po - po MSA Sequence input/output stream | ||||||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||||||
| 18 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||
| 20 | Do not use this module directly. Use it via the L<Bio::AlignIO> class. | ||||||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||||||
| 22 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||||||
| 24 | This object can transform L<Bio::SimpleAlign> objects to and from | ||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 'po' format flat file databases. 'po' format is the native format of | ||||||||||||||||||||||||||||||||||||||||||||||
| 26 | the POA alignment program (Lee C, Grasso C, Sharlow MF, 'Multiple | ||||||||||||||||||||||||||||||||||||||||||||||
| 27 | sequence alignment using partial order graphs', Bioinformatics (2002), | ||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 18(3):452-64). | ||||||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||||||
| 30 | =head1 FEEDBACK | ||||||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||||||
| 32 | =head2 Support | ||||||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||||||
| 34 | Please direct usage questions or support issues to the mailing list: | ||||||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||||||
| 36 | I<bioperl-l@bioperl.org> | ||||||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||||||
| 38 | rather than to the module maintainer directly. Many experienced and | ||||||||||||||||||||||||||||||||||||||||||||||
| 39 | reponsive experts will be able look at the problem and quickly | ||||||||||||||||||||||||||||||||||||||||||||||
| 40 | address it. Please include a thorough description of the problem | ||||||||||||||||||||||||||||||||||||||||||||||
| 41 | with code and data examples if at all possible. | ||||||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||||||
| 43 | =head2 Reporting Bugs | ||||||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||||||
| 45 | Report bugs to the Bioperl bug tracking system to help us keep track | ||||||||||||||||||||||||||||||||||||||||||||||
| 46 | the bugs and their resolution. Bug reports can be submitted via the | ||||||||||||||||||||||||||||||||||||||||||||||
| 47 | web: | ||||||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||||||
| 49 | https://github.com/bioperl/bioperl-live/issues | ||||||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||||||
| 51 | =head1 AUTHORS - Matthew Betts | ||||||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||||||
| 53 | Email: matthew.betts@ii.uib.no | ||||||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||||||
| 55 | =head1 APPENDIX | ||||||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||||||
| 57 | The rest of the documentation details each of the object | ||||||||||||||||||||||||||||||||||||||||||||||
| 58 | methods. Internal methods are usually preceded with a _ | ||||||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||||||
| 60 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||||||
| 62 | # Let the code begin... | ||||||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||||||
| 64 | package Bio::AlignIO::po; | ||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 3 | $Bio::AlignIO::po::VERSION = '1.7.8'; | |||||||||||||||||||||||||||||||||||||||||||||
| 66 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 3 | ▶ | use Bio::SimpleAlign; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 3 | ▶ | use base qw(Bio::AlignIO); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||||||
| 73 | =head2 next_aln | ||||||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||||||
| 75 | Title : next_aln | ||||||||||||||||||||||||||||||||||||||||||||||
| 76 | Usage : $aln = $stream->next_aln() | ||||||||||||||||||||||||||||||||||||||||||||||
| 77 | Function: returns the next alignment in the stream. | ||||||||||||||||||||||||||||||||||||||||||||||
| 78 | Returns : L<Bio::Align::AlignI> object - returns undef on end of file | ||||||||||||||||||||||||||||||||||||||||||||||
| 79 | or on error | ||||||||||||||||||||||||||||||||||||||||||||||
| 80 | Args : NONE | ||||||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||||||
| 82 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 4 | ▶ | sub next_aln { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
next_aln: called CC=24 SCAR=32.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 4 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 4 | my $aln; | |||||||||||||||||||||||||||||||||||||||||||||
| 88 | my $entry; | ||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 4 | my $name; | |||||||||||||||||||||||||||||||||||||||||||||
| 90 | 4 | my $seqs; | |||||||||||||||||||||||||||||||||||||||||||||
| 91 | 4 | my $seq; | |||||||||||||||||||||||||||||||||||||||||||||
| 92 | 4 | my $nodes; | |||||||||||||||||||||||||||||||||||||||||||||
| 93 | 4 | my $list; | |||||||||||||||||||||||||||||||||||||||||||||
| 94 | 4 | my $node; | |||||||||||||||||||||||||||||||||||||||||||||
| 95 | 4 | my @chars; | |||||||||||||||||||||||||||||||||||||||||||||
| 96 | 4 | my $s; | |||||||||||||||||||||||||||||||||||||||||||||
| 97 | 4 | my $a; | |||||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 4 | $aln = Bio::SimpleAlign->new(); | |||||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||||||
| 101 | # get to the first 'VERSION' line | ||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 4 | ▶ | while(defined($entry = $self->_readline)) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 4 | ▶ | if($entry =~ /^VERSION=(\S+)/) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 4 | $aln->source($1); | |||||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 4 | ▶ | if(defined($entry = $self->_readline) and $entry =~ /^NAME=(\S+)/) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined($entry = $self->_readline) and $entry =~ /^NAME=(\S+)/
MC/DC0%0/2
defined($entry = $self->_readline) and $entry =~ /^NAME=(\S+)/
defined($entry = $self->_readline)
$entry =~ /^NAME=(\S+)/
Truth table33%1/3
A and B
A= defined($entry = $self->_readline)B= $entry =~ /^NAME=(\S+)/
| |||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 4 | $aln->id($1); | |||||||||||||||||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 4 | last; | |||||||||||||||||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||||||
| 114 | # read in the sequence names and node data, up to the end of | ||||||||||||||||||||||||||||||||||||||||||||||
| 115 | # the file or the next 'VERSION' line, whichever comes first | ||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 4 | $seqs = []; | |||||||||||||||||||||||||||||||||||||||||||||
| 117 | 4 | $nodes = []; | |||||||||||||||||||||||||||||||||||||||||||||
| 118 | 4 | ▶ | while(defined($entry = $self->_readline)) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 3576 | ▶ | if($entry =~ /^VERSION/) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 120 | # start of a new alignment, so... | ||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | $self->_pushback($entry); | |||||||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 124 | elsif($entry =~ /^SOURCENAME=(\S+)/) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 24 | $name = $1; | |||||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 24 | ▶ | if($name =~ /(\S+)\/(\d+)-(\d+)/) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | $seq = Bio::LocatableSeq->new( | |||||||||||||||||||||||||||||||||||||||||||||
| 129 | '-display_id' => $1, | ||||||||||||||||||||||||||||||||||||||||||||||
| 130 | '-start' => $2, | ||||||||||||||||||||||||||||||||||||||||||||||
| 131 | '-end' => $3, | ||||||||||||||||||||||||||||||||||||||||||||||
| 132 | '-alphabet' => $self->alphabet, | ||||||||||||||||||||||||||||||||||||||||||||||
| 133 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||||||
| 135 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 24 | $seq = Bio::LocatableSeq->new('-display_id'=> $name, | |||||||||||||||||||||||||||||||||||||||||||||
| 137 | '-alphabet' => $self->alphabet); | ||||||||||||||||||||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||||||
| 140 | # store sequences in a list initially, because can't guarantee | ||||||||||||||||||||||||||||||||||||||||||||||
| 141 | # that will get them back from SimpleAlign object in the order | ||||||||||||||||||||||||||||||||||||||||||||||
| 142 | # they were read, and also can't add them to the SimpleAlign | ||||||||||||||||||||||||||||||||||||||||||||||
| 143 | # object here because their sequences are currently unknown | ||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 24 | push @{$seqs}, { | |||||||||||||||||||||||||||||||||||||||||||||
| 145 | 'seq' => $seq, | ||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 'str' => '', | ||||||||||||||||||||||||||||||||||||||||||||||
| 147 | }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 149 | elsif($entry =~ /^SOURCEINFO=(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(.*)/) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 24 | $seq->desc($5); | |||||||||||||||||||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 152 | elsif($entry =~ /^(\S):(\S+)/) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 3516 | $node = { | |||||||||||||||||||||||||||||||||||||||||||||
| 154 | 'aa' => $1, | ||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 'L' => [], | ||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 'S' => [], | ||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 'A' => [], | ||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 'status' => 'unvisited', | ||||||||||||||||||||||||||||||||||||||||||||||
| 159 | }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 3516 | $list = $2; | |||||||||||||||||||||||||||||||||||||||||||||
| 162 | 3516 | ▶ | if($list =~ /^([L\d]*)([S\d]*)([A\d]*)/) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 3516 | push(@{$node->{'L'}}, split(/L/, $1)); | |||||||||||||||||||||||||||||||||||||||||||||
| 164 | 3516 | push(@{$node->{'S'}}, split(/S/, $2)); | |||||||||||||||||||||||||||||||||||||||||||||
| 165 | 3516 | push(@{$node->{'A'}}, split(/A/, $3)); | |||||||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 3516 | ▶ | (@{$node->{'L'}} > 0) and shift @{$node->{'L'}}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 3516 | ▶ | (@{$node->{'S'}} > 0) and shift @{$node->{'S'}}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 3516 | ▶ | (@{$node->{'A'}} > 0) and shift @{$node->{'A'}}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 3516 | push @{$nodes}, $node; | |||||||||||||||||||||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||||||
| 176 | # process the nodes | ||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 4 | foreach $node (@{$nodes}) { | |||||||||||||||||||||||||||||||||||||||||||||
| 178 | 3516 | ▶ | ($node->{'status'} ne 'unvisited') and next; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 1688 | @chars = ($aln->gap_char) x @{$seqs}; # char for each seq defaults to a gap | |||||||||||||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||||||||||||||
| 182 | # set the character for each sequence represented by this node | ||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 1688 | foreach $s (@{$node->{'S'}}) { | |||||||||||||||||||||||||||||||||||||||||||||
| 184 | 3608 | $chars[$s] = $node->{'aa'}; | |||||||||||||||||||||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 1688 | $node->{'status'} = 'visited'; | |||||||||||||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||||||||||||||
| 188 | # do the same for each node in the same align ring | ||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 1688 | ▶ | while(defined($a = $node->{'A'}->[0])) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 3084 | $node = $nodes->[$a]; | |||||||||||||||||||||||||||||||||||||||||||||
| 191 | 3084 | ▶ | ($node->{'status'} ne 'unvisited') and last; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 1828 | foreach $s (@{$node->{'S'}}) { | |||||||||||||||||||||||||||||||||||||||||||||
| 194 | 2120 | $chars[$s] = $node->{'aa'}; | |||||||||||||||||||||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 1828 | $node->{'status'} = 'visited'; | |||||||||||||||||||||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||||||||||||||
| 200 | # update the sequences | ||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 1688 | foreach $seq (@{$seqs}) { | |||||||||||||||||||||||||||||||||||||||||||||
| 202 | 10128 | $seq->{'str'} .= shift @chars; | |||||||||||||||||||||||||||||||||||||||||||||
| 203 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||||||||||||
| 206 | # set the sequences of the bioperl objects | ||||||||||||||||||||||||||||||||||||||||||||||
| 207 | # and add them to the alignment | ||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 4 | foreach $seq (@{$seqs}) { | |||||||||||||||||||||||||||||||||||||||||||||
| 209 | 24 | $seq->{'seq'}->seq($seq->{'str'}); | |||||||||||||||||||||||||||||||||||||||||||||
| 210 | 24 | $aln->add_seq($seq->{'seq'}); | |||||||||||||||||||||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||||||||||||
| 213 | # has an alignment been read?... | ||||||||||||||||||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 4 | ▶ | return $aln if $aln->num_sequences; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||
| 217 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||||||||||||||
| 219 | =head2 write_aln | ||||||||||||||||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||||||||||||||
| 221 | Title : write_aln | ||||||||||||||||||||||||||||||||||||||||||||||
| 222 | Usage : $stream->write_aln(@aln) | ||||||||||||||||||||||||||||||||||||||||||||||
| 223 | Function: writes the $aln object into the stream in po format | ||||||||||||||||||||||||||||||||||||||||||||||
| 224 | Returns : 1 for success and 0 for error | ||||||||||||||||||||||||||||||||||||||||||||||
| 225 | Args : L<Bio::Align::AlignI> object | ||||||||||||||||||||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||||||||||||||||||||
| 227 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 2 | ▶ | sub write_aln { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
write_aln: called CC=24 SCAR=32.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 2 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 231 | 2 | my @alns = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 2 | my $aln; | |||||||||||||||||||||||||||||||||||||||||||||
| 234 | my $seqs; | ||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 2 | my $nodes; | |||||||||||||||||||||||||||||||||||||||||||||
| 236 | 2 | my $seq; | |||||||||||||||||||||||||||||||||||||||||||||
| 237 | 2 | my $node; | |||||||||||||||||||||||||||||||||||||||||||||
| 238 | 2 | my $col; | |||||||||||||||||||||||||||||||||||||||||||||
| 239 | 2 | my $ring; | |||||||||||||||||||||||||||||||||||||||||||||
| 240 | 2 | my $i; | |||||||||||||||||||||||||||||||||||||||||||||
| 241 | 2 | my $char; | |||||||||||||||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 2 | foreach $aln (@alns) { | |||||||||||||||||||||||||||||||||||||||||||||
| 244 | 2 | ▶ | if(!$aln or !$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")
| |||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 0 | $self->warn("Must provide a Bio::Align::AlignI object when calling write_aln"); | |||||||||||||||||||||||||||||||||||||||||||||
| 246 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||
| 247 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||||||||||||||||||
| 249 | # store the seqs on a list, because po format | ||||||||||||||||||||||||||||||||||||||||||||||
| 250 | # refers to them by position on this list | ||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 2 | $seqs = []; | |||||||||||||||||||||||||||||||||||||||||||||
| 252 | 2 | foreach $seq ($aln->each_seq()) { | |||||||||||||||||||||||||||||||||||||||||||||
| 253 | 12 | push @{$seqs}, { | |||||||||||||||||||||||||||||||||||||||||||||
| 254 | 'seq' => $seq, | ||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 'n_nodes' => 0, | ||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 'first' => undef, | ||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 'previous' => undef, | ||||||||||||||||||||||||||||||||||||||||||||||
| 258 | }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 259 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||||||||||||||||||
| 261 | # go through each column in the alignment and construct | ||||||||||||||||||||||||||||||||||||||||||||||
| 262 | # the nodes for the equivalent poa alignment ring | ||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 2 | $nodes = []; | |||||||||||||||||||||||||||||||||||||||||||||
| 264 | 2 | ▶ | for($col = 0; $col < $aln->length; $col++) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 265 | $ring = { | ||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 'nodes' => {}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 844 | 'first' => scalar @{$nodes}, | |||||||||||||||||||||||||||||||||||||||||||||
| 268 | 844 | 'last' => scalar @{$nodes}, | |||||||||||||||||||||||||||||||||||||||||||||
| 269 | }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 844 | ▶ | for($i = 0; $i < @{$seqs}; $i++) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 5064 | $seq = $seqs->[$i]; | |||||||||||||||||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 5064 | $char = $seq->{'seq'}->subseq($col + 1, $col + 1); | |||||||||||||||||||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 5064 | ▶ | ($char eq $aln->gap_char) and next; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 2864 | ▶ | if(!defined($node = $ring->{'nodes'}->{$char})) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 279 | $node = { | ||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 1758 | 'n' => scalar @{$nodes}, | |||||||||||||||||||||||||||||||||||||||||||||
| 281 | 'aa' => $char, | ||||||||||||||||||||||||||||||||||||||||||||||
| 282 | 'L' => {}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 'S' => [], | ||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 'A' => [], | ||||||||||||||||||||||||||||||||||||||||||||||
| 285 | }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||||||||||||||||
| 287 | # update the ring | ||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 1758 | $ring->{'nodes'}->{$char} = $node; | |||||||||||||||||||||||||||||||||||||||||||||
| 289 | 1758 | $ring->{'last'} = $node->{'n'}; | |||||||||||||||||||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||||||||||||||||||||
| 291 | # add the node to the node list | ||||||||||||||||||||||||||||||||||||||||||||||
| 292 | 1758 | push @{$nodes}, $node; | |||||||||||||||||||||||||||||||||||||||||||||
| 293 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||||||||||||||||||||
| 295 | # add the sequence to the node | ||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 2864 | push @{$node->{'S'}}, $i; | |||||||||||||||||||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||||||||||||||||||||
| 298 | # add the node to the sequence | ||||||||||||||||||||||||||||||||||||||||||||||
| 299 | 2864 | ▶ | defined($seq->{'first'}) or ($seq->{'first'} = $node); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 2864 | $seq->{'n_nodes'}++; | |||||||||||||||||||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||||||||||||||||||||
| 302 | # add an edge from the previous node in the sequence to this one. | ||||||||||||||||||||||||||||||||||||||||||||||
| 303 | # Then set the previous node to the current one, ready for the next | ||||||||||||||||||||||||||||||||||||||||||||||
| 304 | # residue in this sequence | ||||||||||||||||||||||||||||||||||||||||||||||
| 305 | 2864 | ▶ | defined($seq->{'previous'}) and ($node->{'L'}->{$seq->{'previous'}->{'n'}} = $seq->{'previous'}); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 306 | 2864 | $seq->{'previous'} = $node; | |||||||||||||||||||||||||||||||||||||||||||||
| 307 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||||||||||||||||||||
| 309 | # set the 'next node in ring' field for each node in the ring | ||||||||||||||||||||||||||||||||||||||||||||||
| 310 | 844 | ▶ | if($ring->{'first'} < $ring->{'last'}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 311 | 628 | ▶ | for($i = $ring->{'first'}; $i < $ring->{'last'}; $i++) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 312 | 914 | push @{$nodes->[$i]->{'A'}}, $i + 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 313 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 628 | push @{$nodes->[$ring->{'last'}]->{'A'}}, $ring->{'first'}; | |||||||||||||||||||||||||||||||||||||||||||||
| 315 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 316 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||||||||||||||||||||
| 318 | # print header information | ||||||||||||||||||||||||||||||||||||||||||||||
| 319 | $self->_print( | ||||||||||||||||||||||||||||||||||||||||||||||
| 320 | 'VERSION=', ($aln->source and ($aln->source !~ /\A\s*\Z/)) ? $aln->source : 'bioperl', "\n", | ||||||||||||||||||||||||||||||||||||||||||||||
| 321 | 'NAME=', $aln->id, "\n", | ||||||||||||||||||||||||||||||||||||||||||||||
| 322 | 'TITLE=', ($seqs->[0]->{'seq'}->description or $aln->id), "\n", | ||||||||||||||||||||||||||||||||||||||||||||||
| 323 | 2 | 'LENGTH=', scalar @{$nodes}, "\n", | |||||||||||||||||||||||||||||||||||||||||||||
| 324 | 2 | ▶ | 'SOURCECOUNT=', scalar @{$seqs}, "\n", | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$aln->source and not $aln->source =~ /\A\s*\Z/
$seqs->[0]{'seq'}->description || $aln->id
MC/DC0%0/2
$aln->source and not $aln->source =~ /\A\s*\Z/
$aln->source
not $aln->source =~ /\A\s*\Z/
MC/DC0%0/2
$seqs->[0]{'seq'}->description || $aln->id
$seqs->[0]{'seq'}->description
$aln->id
Truth table33%1/3
A and not(B)
A= $aln->sourceB= not $aln->source =~ /\A\s*\Z/
Truth table33%1/3
A || B
A= $seqs->[0]{'seq'}->descriptionB= $aln->id
| |||||||||||||||||||||||||||||||||||||||||||||||
| 325 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||||||||||||||||||||
| 327 | # print sequence information | ||||||||||||||||||||||||||||||||||||||||||||||
| 328 | 2 | foreach $seq (@{$seqs}) { | |||||||||||||||||||||||||||||||||||||||||||||
| 329 | $self->_print( | ||||||||||||||||||||||||||||||||||||||||||||||
| 330 | 'SOURCENAME=', $seq->{'seq'}->display_id, "\n", | ||||||||||||||||||||||||||||||||||||||||||||||
| 331 | 'SOURCEINFO=', | ||||||||||||||||||||||||||||||||||||||||||||||
| 332 | $seq->{'n_nodes'}, ' ', # number of nodes in the sequence | ||||||||||||||||||||||||||||||||||||||||||||||
| 333 | $seq->{'first'}->{'n'}, ' ', # index of first node containing the sequence | ||||||||||||||||||||||||||||||||||||||||||||||
| 334 | 0, ' ', # FIXME - sequence weight? | ||||||||||||||||||||||||||||||||||||||||||||||
| 335 | -1, ' ', # FIXME - index of bundle containing sequence? | ||||||||||||||||||||||||||||||||||||||||||||||
| 336 | 12 | ▶ | ($seq->{'seq'}->description or 'untitled'), "\n", | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$seq->{'seq'}->description || 'untitled'
MC/DC0%0/1
$seq->{'seq'}->description || 'untitled'
$seq->{'seq'}->description
Truth table50%1/2
A
A= $seq->{'seq'}->description
| |||||||||||||||||||||||||||||||||||||||||||||||
| 337 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 338 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||||||||||||||||||||
| 340 | # print node information | ||||||||||||||||||||||||||||||||||||||||||||||
| 341 | 2 | foreach $node (@{$nodes}) { | |||||||||||||||||||||||||||||||||||||||||||||
| 342 | 1758 | $self->_print($node->{'aa'}, ':'); | |||||||||||||||||||||||||||||||||||||||||||||
| 343 | 1758 | ▶ | (keys %{$node->{'L'}} > 0) and $self->_print('L', join('L', sort {$a <=> $b} keys %{$node->{'L'}})); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 1758 | ▶ | (@{$node->{'S'}} > 0) and $self->_print('S', join('S', @{$node->{'S'}})); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 345 | 1758 | ▶ | (@{$node->{'A'}} > 0) and $self->_print('A', join('A', @{$node->{'A'}})); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 346 | 1758 | $self->_print("\n"); | |||||||||||||||||||||||||||||||||||||||||||||
| 347 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 348 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 349 | 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||||||||||||||||||||
| 351 | 2 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 352 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||||||||||||||||||||
| 354 | 3 | 1; | |||||||||||||||||||||||||||||||||||||||||||||