Bio/AlignIO/proda.pm

filter: Statementstmt 13.1% 12 / 91 Branchbran 0.0% 0 / 42 Conditioncond 0.0% 0 / 15 MC/DCmcdc 0.0% 0 / 10 Subroutinesub 33.3% 3 / 9 Podpod 100% 5 / 5 totaltotal 11.6% 20 / 172 CC 28 SCAR 58.7
CC
28
Cov
8%
next_aln
552.0
_initialize
12.0
percentages
6.0
CRAP 354.8
« Bio/Root/IO.pm ↑ Summary Bio/SeqUtils.pm »
1 #
2 # BioPerl module for Bio::AlignIO::proda
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 Albert Vilella
10 #
11 # You may distribute this module under the same terms as perl itself
12 # POD documentation - main docs before the code
13  
14 =head1 NAME
15  
16 Bio::AlignIO::proda - proda sequence input/output stream
17  
18 This provides the basic capabilities to parse the output alignments
19 from the ProDA multiple sequence alignment program
20 (http://proda.stanford.edu)
21  
22 =head1 SYNOPSIS
23  
24 Do not use this module directly. Use it via the Bio::AlignIO class.
25  
26 =head1 DESCRIPTION
27  
28 This object can transform Bio::Align::AlignI objects to and from proda
29 files.
30  
31 =head1 FEEDBACK
32  
33 =head2 Mailing Lists
34  
35 User feedback is an integral part of the evolution of this and other
36 Bioperl modules. Send your comments and suggestions preferably to one
37 of the Bioperl mailing lists. Your participation is much appreciated.
38  
39 bioperl-l@bioperl.org - General discussion
40 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
41  
42 =head2 Support
43  
44 Please direct usage questions or support issues to the mailing list:
45  
46 I<bioperl-l@bioperl.org>
47  
48 rather than to the module maintainer directly. Many experienced and
49 reponsive experts will be able look at the problem and quickly
50 address it. Please include a thorough description of the problem
51 with code and data examples if at all possible.
52  
53 =head2 Reporting Bugs
54  
55 Report bugs to the Bioperl bug tracking system to help us keep track
56 the bugs and their resolution. Bug reports can be submitted via the
57 web:
58  
59 https://github.com/bioperl/bioperl-live/issues
60  
61 =head1 AUTHORS - Albert Vilella
62  
63 Email: avilella-at-gmail-dot-com
64  
65  
66 =head1 APPENDIX
67  
68 The rest of the documentation details each of the object
69 methods. Internal methods are usually preceded with a _
70  
71 =cut
72  
73 # Let the code begin...
74  
75 package Bio::AlignIO::proda;
76 1 $Bio::AlignIO::proda::VERSION = '1.7.8';
77 1 ▶use vars qw($LINELENGTH);
Subroutine BEGIN: called CC=1 SCAR=0.0
78 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
79  
80  
81 1 $LINELENGTH = 60;
82 1 ▶use base qw(Bio::AlignIO);
Subroutine BEGIN: called CC=1 SCAR=0.0
83  
84 =head2 new
85  
86 Title : new
87 Usage : $alignio = Bio::AlignIO->new(-format => 'proda',
88 -file => 'filename');
89 Function: returns a new Bio::AlignIO object to handle proda files
90 Returns : Bio::AlignIO::proda object
91 Args : -verbose => verbosity setting (-1, 0, 1, 2)
92 -file => name of file to read in or to write, with ">"
93 -fh => alternative to -file param - provide a filehandle
94 to read from or write to
95 -format => alignment format to process or produce
96 -percentages => display a percentage of identity
97 in each line of the alignment (proda only)
98 -linelength=> alignment output line length (default 60)
99  
100 =cut
101  
102 0 ▶sub _initialize {
Subroutine _initialize: not called CC=3 SCAR=24.8
103 0 my ( $self, @args ) = @_;
104 0 $self->SUPER::_initialize(@args);
105 0 my ( $percentages, $ll ) =
106 $self->_rearrange( [qw(PERCENTAGES LINELENGTH)], @args );
107 0 ▶ defined $percentages && $self->percentages($percentages);
Branch: 1 branch
BranchTrueFalseTotal
defined $percentages and $self->percentages($percentages) 0 0 0
108 0 ▶ $self->line_length( $ll || $LINELENGTH );
Condition0%0/3
$ll || $Bio::AlignIO::proda::LINELENGTH
l!l&&r!l&&!r
000
MC/DC0%0/2
$ll || $Bio::AlignIO::proda::LINELENGTH
$ll $Bio::AlignIO::proda::LINELENGTH
Truth table0%0/3
A || B
A= $llB= $Bio::AlignIO::proda::LINELENGTH
ABresult
1X1
011
000
109 }
110  
111 =head2 next_aln
112  
113 Title : next_aln
114 Usage : $aln = $stream->next_aln()
115 Function: returns the next alignment in the stream
116 Returns : Bio::Align::AlignI object
117 Args : NONE
118  
119 See L<Bio::Align::AlignI> for details
120  
121 =cut
122  
123 0 ▶sub next_aln {
Subroutine next_aln: not called CC=23 SCAR=63.1
Pod documented
124 0 my ($self) = @_;
125 0 my $first_line;
126  
127 0 ▶ while ( $first_line = $self->_readline ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($first_line = $self->_readline) 0 0 0
128 0 ▶ last if $first_line !~ /^$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $first_line =~ /^$/ 0 0 0
129 }
130 0 $self->_pushback($first_line);
131 0 ▶ if ( defined( $first_line = $self->_readline )
Branch: 1 branch
BranchTrueFalseTotal
if (defined($first_line = $self->_readline) and not $first_line =~ /\(/) { } 0 0 0
Condition0%0/3
defined($first_line = $self->_readline) and not $first_line =~ /\(/
!ll&&!rl&&r
000
MC/DC0%0/2
defined($first_line = $self->_readline) and not $first_line =~ /\(/
defined($first_line = $self->_readline) not $first_line =~ /\(/
Truth table0%0/3
A and not(B)
A= defined($first_line = $self->_readline)B= not $first_line =~ /\(/
ABresult
0X0
100
111
132 && $first_line !~ /\(/ )
133 {
134 0 $self->throw(
135 "trying to parse a file which does not start with proda headers"
136 );
137 } else {
138 # use it inside the loop
139 0 $self->_pushback($first_line);
140 }
141 0 my %alignments;
142 0 my $aln = Bio::SimpleAlign->new(
143 -source => 'proda',
144 -verbose => $self->verbose
145 );
146 0 my $order = 0;
147 0 my %order;
148 0 $self->{_lastline} = '';
149 0 my ($first_block, $seen_block, $seen_header) = (0,0,0);
150 0 my @ids; my @ids_copy;
151 0 ▶ while ( defined( $_ = $self->_readline ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = $self->_readline)) 0 0 0
152 0 ▶ next if (/^\s+$/ && !$first_block);
Branch: 1 branch
BranchTrueFalseTotal
if /^\s+$/ and not $first_block 0 0 0
Condition0%0/3
/^\s+$/ and not $first_block
!ll&&!rl&&r
000
MC/DC0%0/2
/^\s+$/ and not $first_block
/^\s+$/ not $first_block
Truth table0%0/3
A and not(B)
A= /^\s+$/B= not $first_block
ABresult
0X0
100
111
153 0 ▶ if (/^\s$/) { # line contains no description
Branch: 1 branch
BranchTrueFalseTotal
if (/^\s$/) 0 0 0
154 0 $seen_block = 1;
155 0 next;
156 }
157 0 $first_block = 1;
158  
159 # break the loop if we come to the end of the current alignment
160 # and push back the proda header
161 0 ▶ if (/\(/ && $seen_header) {
Branch: 1 branch
BranchTrueFalseTotal
if (/\(/ and $seen_header) 0 0 0
Condition0%0/3
/\(/ and $seen_header
!ll&&!rl&&r
000
MC/DC0%0/2
/\(/ and $seen_header
/\(/ $seen_header
Truth table0%0/3
A and B
A= /\(/B= $seen_header
ABresult
0X0
100
111
162 0 $self->_pushback($_);
163 0 last;
164 }
165  
166 0 ▶ if (/\(/ && !$seen_header) {
Branch: 1 branch
BranchTrueFalseTotal
if (/\(/ and not $seen_header) 0 0 0
Condition0%0/3
/\(/ and not $seen_header
!ll&&!rl&&r
000
MC/DC0%0/2
/\(/ and not $seen_header
/\(/ not $seen_header
Truth table0%0/3
A and not(B)
A= /\(/B= not $seen_header
ABresult
0X0
100
111
167 0 @ids = split(' ', $_);
168 0 $seen_header = 1;
169 0 next;
170 }
171  
172 0 my ( $seqname, $aln_line ) = ( '', '' );
173 0 ▶ if (/^\s*(\S+)\s*\/\s*(\d+)-(\d+)\s+(\S+)\s*$/ox) {
Branch: 2 branches
BranchTrueFalseTotal
if (m[^\s*(\S+)\s*/\s*(\d+)-(\d+)\s+(\S+)\s*$]ox) { } 0 0 0
elsif (/^\s*(\S+)\s+(\S+)\s*\d*\s*$/ox) { } 0 0 0
174  
175 # clustal 1.4 format
176 0 ( $seqname, $aln_line ) = ( "$1:$2-$3", $4 );
177  
178 # } elsif( /^\s*(\S+)\s+(\S+)\s*$/ox ) { without trailing numbers
179 }
180 elsif (/^\s*(\S+)\s+(\S+)\s*\d*\s*$/ox) { # with numbers
181 0 ( $seqname, $aln_line ) = ( $1, $2 );
182 0 ▶ if ( $seqname =~ /^[\*\.\+\:]+$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($seqname =~ /^[\*\.\+\:]+$/) 0 0 0
183 0 $self->{_lastline} = $_;
184 0 next;
185 }
186 }
187 else {
188 0 $self->{_lastline} = $_;
189 0 next;
190 }
191  
192 # we ended up the first block and now are on the second
193 0 ▶ @ids_copy = @ids unless(defined($ids_copy[0])); #FIXME - hacky
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ids_copy[0] 0 0 0
194 0 my $seqname_with_coords = shift(@ids_copy);
195 0 ▶ if ($seqname_with_coords !~ /$seqname/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($seqname_with_coords =~ /$seqname/) 0 0 0
196 {
197 0 $self->throw("header and body of the alignment dont match");
198 }
199 }
200 0 $alignments{$seqname_with_coords} .= $aln_line;
201  
202 0 ▶ if ( !$seen_block ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($seen_block) 0 0 0
203 0 ▶ if (exists $order{$seqname_with_coords}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $order{$seqname_with_coords}) { } 0 0 0
204 0 $self->warn("Duplicate sequence : $seqname\n".
205 "Can't guarantee alignment quality");
206 }
207 else {
208 0 $order{$seqname_with_coords} = $order++;
209 }
210 }
211  
212 }
213  
214 0 my ( $sname, $start, $end );
215 0 foreach my $name ( sort { $order{$a} <=> $order{$b} } keys %alignments ) {
216 0 ▶ if ( $name =~ /(\S+):(\d+)-(\d+)/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name =~ /(\S+):(\d+)-(\d+)/) { } 0 0 0
217 0 ( $sname, $start, $end ) = ( $1, $2, $3 );
218 }
219 else {
220 0 ( $sname, $start ) = ( $name, 1 );
221 0 my $str = $alignments{$name};
222 0 $str =~ s/[^A-Za-z]//g;
223 0 $end = length($str);
224 }
225 my $seq = Bio::LocatableSeq->new(
226 0 -seq => $alignments{$name},
227 -id => $sname,
228 -start => $start,
229 -end => $end,
230 -alphabet => $self->alphabet,
231 );
232 0 $aln->add_seq($seq);
233 }
234
235 0 ▶ return $aln if $aln->num_sequences;
Branch: 1 branch
BranchTrueFalseTotal
if $aln->num_sequences 0 0 0
236 0 return;
237 }
238  
239 =head2 write_aln
240  
241 Title : write_aln
242 Usage : $stream->write_aln(@aln)
243 Function: writes the proda-format object (.aln) into the stream
244 Returns : 1 for success and 0 for error
245 Args : Bio::Align::AlignI object
246  
247 =cut
248  
249 0 ▶sub write_aln {
Subroutine write_aln: not called CC=1 SCAR=6.9
Pod documented
250 0 my ($self,@aln) = @_;
251 0 $self->throw_not_implemented();
252 }
253  
254 =head2 percentages
255  
256 Title : percentages
257 Usage : $obj->percentages($newval)
258 Function: Set the percentages flag - whether or not to show percentages in
259 each output line
260 Returns : value of percentages
261 Args : newvalue (optional)
262  
263  
264 =cut
265  
266 0 ▶sub percentages {
Subroutine percentages: not called CC=2 SCAR=17.9
Pod documented
267 0 my ( $self, $value ) = @_;
268 0 ▶ if ( defined $value ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 0 0 0
269 0 $self->{'_percentages'} = $value;
270 }
271 0 return $self->{'_percentages'};
272 }
273  
274 =head2 line_length
275  
276 Title : line_length
277 Usage : $obj->line_length($newval)
278 Function: Set the alignment output line length
279 Returns : value of line_length
280 Args : newvalue (optional)
281  
282  
283 =cut
284  
285 0 ▶sub line_length {
Subroutine line_length: not called CC=2 SCAR=17.9
Pod documented
286 0 my ( $self, $value ) = @_;
287 0 ▶ if ( defined $value ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 0 0 0
288 0 $self->{'_line_length'} = $value;
289 }
290 0 return $self->{'_line_length'};
291 }
292  
293 =head2 no_header
294  
295 Title : no_header
296 Usage : $obj->no_header($newval)
297 Function: Set if the alignment input has a CLUSTAL header or not
298 Returns : value of no_header
299 Args : newvalue (optional)
300  
301  
302 =cut
303  
304 0 ▶sub no_header {
Subroutine no_header: not called CC=2 SCAR=17.9
Pod documented
305 0 my ( $self, $value ) = @_;
306 0 ▶ if ( defined $value ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 0 0 0
307 0 $self->{'_no_header'} = $value;
308 }
309 0 return $self->{'_no_header'};
310 }
311  
312  
313 1 1;
« Bio/Root/IO.pm ↑ Summary Bio/SeqUtils.pm »