Bio/AlignIO/emboss.pm

filter: Statementstmt 95.5% 86 / 90 Branchbran 91.6% 44 / 48 Conditioncond 88.4% 23 / 26 MC/DCmcdc 70.5% 12 / 17 Subroutinesub 87.5% 7 / 8 Podpod 100% 2 / 2 totaltotal 91.1% 174 / 191 CC 35 SCAR 33.9
CC
35
Cov
93%
next_aln
35.3
write_aln
2.0
BEGIN
1.0
CRAP 29.6
« Bio/PullParserI.pm ↑ Summary Bio/Index/SwissPfam.pm »
1 #
2 # BioPerl module for Bio::AlignIO::emboss
3 #
4 # Please direct questions and support issues to <bioperl-l@bioperl.org>
5 #
6 # Cared for by Jason Stajich <jason@bioperl.org>
7 #
8 # Copyright Jason Stajich
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::emboss - Parse EMBOSS alignment output (from applications water and needle)
17  
18 =head1 SYNOPSIS
19  
20 # do not use the object directly
21 use Bio::AlignIO;
22 # read in an alignment from the EMBOSS program water
23 my $in = Bio::AlignIO->new(-format => 'emboss',
24 -file => 'seq.water');
25 while( my $aln = $in->next_aln ) {
26 # do something with the alignment
27 }
28  
29 =head1 DESCRIPTION
30  
31 This object handles parsing and writing pairwise sequence alignments
32 from the EMBOSS suite.
33  
34 =head1 FEEDBACK
35  
36 =head2 Mailing Lists
37  
38 User feedback is an integral part of the evolution of this and other
39 Bioperl modules. Send your comments and suggestions preferably to
40 the Bioperl mailing list. Your participation is much appreciated.
41  
42 bioperl-l@bioperl.org - General discussion
43 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
44  
45 =head2 Support
46  
47 Please direct usage questions or support issues to the mailing list:
48  
49 I<bioperl-l@bioperl.org>
50  
51 rather than to the module maintainer directly. Many experienced and
52 reponsive experts will be able look at the problem and quickly
53 address it. Please include a thorough description of the problem
54 with code and data examples if at all possible.
55  
56 =head2 Reporting Bugs
57  
58 Report bugs to the Bioperl bug tracking system to help us keep track
59 of the bugs and their resolution. Bug reports can be submitted via the
60 web:
61  
62 https://github.com/bioperl/bioperl-live/issues
63  
64 =head1 AUTHOR - Jason Stajich
65  
66 Email jason@bioperl.org
67  
68 =head1 APPENDIX
69  
70 The rest of the documentation details each of the object methods.
71 Internal methods are usually preceded with a _
72  
73 =cut
74  
75  
76 # Let the code begin...
77  
78  
79 package Bio::AlignIO::emboss;
80 3 $Bio::AlignIO::emboss::VERSION = '1.7.8';
81 3 ▶use vars qw($EMBOSSTitleLen $EMBOSSLineLen);
Subroutine BEGIN: called CC=1 SCAR=0.0
82 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
83  
84 3 ▶use Bio::LocatableSeq;
Subroutine BEGIN: called CC=1 SCAR=0.0
85  
86 3 ▶use base qw(Bio::AlignIO);
Subroutine BEGIN: called CC=1 SCAR=0.0
87  
88 3 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
89 3 $EMBOSSTitleLen = 13;
90 3 $EMBOSSLineLen = 50;
91 }
92  
93 6 ▶sub _initialize {
Subroutine _initialize: called CC=1 SCAR=0.0
94 6 my($self,@args) = @_;
95 6 $self->SUPER::_initialize(@args);
96 6 $self->{'_type'} = undef;
97 }
98  
99 =head2 next_aln
100  
101 Title : next_aln
102 Usage : $aln = $stream->next_aln()
103 Function: returns the next alignment in the stream.
104 Returns : L<Bio::Align::AlignI> object - returns 0 on end of file
105 or on error
106 Args : NONE
107  
108 =cut
109  
110 7 ▶sub next_aln {
Subroutine next_aln: called CC=35 SCAR=35.6
Pod documented
111 7 my ($self) = @_;
112 7 my $seenbegin = 0;
113 my %data = ( 'seq1' => {
114 'start'=> undef,
115 'end'=> undef,
116 'name' => '',
117 'data' => '' },
118 'seq2' => {
119 'start'=> undef,
120 'end'=> undef,
121 'name' => '',
122 'data' => '' },
123 'align' => '',
124 7 'type' => $self->{'_type'}, # to restore type from
125 # previous aln if possible
126 );
127 7 my %names;
128 7 ▶ while( defined($_ = $self->_readline) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = $self->_readline)) 226 3 229
129 226 ▶ next if( /^\#?\s+$/ || /^\#+\s*$/ );
Branch: 1 branch
BranchTrueFalseTotal
if /^\#?\s+$/ or /^\#+\s*$/ 87 139 226
Condition100%3/3
/^\#?\s+$/ or /^\#+\s*$/
l!l&&r!l&&!r
798139
MC/DC100%2/2
/^\#?\s+$/ or /^\#+\s*$/
/^\#?\s+$/ /^\#+\s*$/
Truth table100%3/3
A or B
A= /^\#?\s+$/B= /^\#+\s*$/
ABresult
1X1
011
000
130 139 ▶ if( /^\#(\=|\-)+\s*$/) {
Branch: 5 branches
BranchTrueFalseTotal
if (/^\#(\=|\-)+\s*$/) { } 13 126 139
elsif (/(Local|Global):\s*(\S+)\s+vs\s+(\S+)/ or /^\#\s+Program:\s+(\S+)/) { } 6 120 126
elsif (/Score:\s+(\S+)/) { } 7 113 120
elsif (/^\#\s+(1|2):\s+(\S+)/ and not $data{"seq$1"}{'name'}) { } 9 104 113
elsif ($data{'seq1'}{'name'} and /^\Q$data{'seq1'}{'name'}\E/) { } 51 66 117
131 13 ▶ last if( $seenbegin);
Branch: 1 branch
BranchTrueFalseTotal
if $seenbegin 4 9 13
132 ▶ } elsif( /(Local|Global):\s*(\S+)\s+vs\s+(\S+)/ ||
Condition100%3/3
/(Local|Global):\s*(\S+)\s+vs\s+(\S+)/ or /^\#\s+Program:\s+(\S+)/
l!l&&r!l&&!r
24120
MC/DC100%2/2
/(Local|Global):\s*(\S+)\s+vs\s+(\S+)/ or /^\#\s+Program:\s+(\S+)/
/(Local|Global):\s*(\S+)\s+vs\s+(\S+)/ /^\#\s+Program:\s+(\S+)/
Truth table100%3/3
A or B
A= /(Local|Global):\s*(\S+)\s+vs\s+(\S+)/B= /^\#\s+Program:\s+(\S+)/
ABresult
1X1
011
000
133 /^\#\s+Program:\s+(\S+)/ )
134 {
135 6 my ($name1,$name2) = ($2,$3);
136 6 ▶ if( ! defined $name1 ) { # Handle EMBOSS 2.2.X
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $name1) { } 4 2 6
137 4 $data{'type'} = $1;
138 4 $name1 = $name2 = '';
139 } else {
140 2 ▶ $data{'type'} = $1 eq 'Local' ? 'water' : 'needle';
Branch: 1 branch
BranchTrueFalseTotal
$1 eq 'Local' ? : 1 1 2
141 }
142 6 $data{'seq1'}->{'name'} = $name1;
143 6 $data{'seq2'}->{'name'} = $name2;
144  
145 6 $self->{'_type'} = $data{'type'};
146  
147 } elsif( /Score:\s+(\S+)/ ) {
148 7 $data{'score'} = $1;
149 ▶ } elsif( /^\#\s+(1|2):\s+(\S+)/ && ! $data{"seq$1"}->{'name'} ) {
Condition66%2/3
/^\#\s+(1|2):\s+(\S+)/ and not $data{"seq$1"}{"name"}
!ll&&!rl&&r
10409
MC/DC50%1/2
/^\#\s+(1|2):\s+(\S+)/ and not $data{"seq$1"}{"name"}
/^\#\s+(1|2):\s+(\S+)/ not $data{"seq$1"}{"name"}
Truth table66%2/3
A and not(B)
A= /^\#\s+(1|2):\s+(\S+)/B= not $data{"seq$1"}{"name"}
ABresult
0X0
100
111
150 9 my $nm = $2;
151 9 $nm = substr($nm,0,$EMBOSSTitleLen); # emboss has a max seq length
152 9 ▶ if( $names{$nm} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($names{$nm}) 1 8 9
153 1 $nm .= "-". $names{$nm};
154 }
155 9 $names{$nm}++;
156 9 $data{"seq$1"}->{'name'} = $nm;
157 ▶ } elsif( $data{'seq1'}->{'name'} &&
Condition100%3/3
$data{"seq1"}{"name"} and /^\Q$data{"seq1"}{"name"}\E/
!ll&&!rl&&r
134051
MC/DC100%2/2
$data{"seq1"}{"name"} and /^\Q$data{"seq1"}{"name"}\E/
$data{"seq1"}{"name"} /^\Q$data{"seq1"}{"name"}\E/
Truth table100%3/3
A and B
A= $data{"seq1"}{"name"}B= /^\Q$data{"seq1"}{"name"}\E/
ABresult
0X0
100
111
158 /^\Q$data{'seq1'}->{'name'}/ ) {
159 51 my $count = 0;
160 51 $seenbegin = 1;
161 51 my @current;
162 51 ▶ while( defined ($_) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_) 153 0 153
163 153 my $align_other = '';
164 153 my $delayed;
165 153 ▶ if($count == 0 || $count == 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($count == 0 or $count == 2) { } 102 51 153
Condition100%3/3
$count == 0 or $count == 2
l!l&&r!l&&!r
515151
MC/DC100%2/2
$count == 0 or $count == 2
$count == 0 $count == 2
Truth table100%3/3
A or B
A= $count == 0B= $count == 2
ABresult
1X1
011
000
166 102 my @l = split;
167 102 my ($seq,$align,$start,$end);
168 102 ▶ if( $count == 2 && $data{'seq2'}->{'name'} eq '' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($count == 2 and $data{'seq2'}{'name'} eq '') { } 4 98 102
elsif (@l == 3) { } 4 94 98
Condition100%3/3
$count == 2 and $data{"seq2"}{"name"} eq ""
!ll&&!rl&&r
51474
MC/DC100%2/2
$count == 2 and $data{"seq2"}{"name"} eq ""
$count == 2 $data{"seq2"}{"name"} eq ""
Truth table100%3/3
A and B
A= $count == 2B= $data{"seq2"}{"name"} eq ""
ABresult
0X0
100
111
169 # weird boundary condition
170 4 ($start,$align,$end) = @l;
171 } elsif( @l == 3 ) {
172 4 $align = '';
173 4 ($seq,$start,$end) = @l
174 } else {
175 94 ($seq,$start,$align,$end) = @l;
176 }
177  
178 102 ▶ my $seqname = sprintf("seq%d", ($count == 0) ? '1' : '2');
Branch: 1 branch
BranchTrueFalseTotal
$count == 0 ? : 51 51 102
179 102 $data{$seqname}->{'data'} .= $align;
180 102 ▶ $data{$seqname}->{'start'} ||= $start;
Condition66%2/3
$data{$seqname}{"start"} ||= $start
l!l&&r!l&&!r
88140
MC/DC0%0/2
$data{$seqname}{"start"} ||= $start
$data{$seqname}{"start"} $start
Truth table66%2/3
A ||= B
A= $data{$seqname}{"start"}B= $start
ABresult
1X1
011
000
181 102 $data{$seqname}->{'end'} = $end;
182 102 ▶ $current[$count] = [ $start,$align || ''];
Condition100%2/2
$align || ''
l!l
984
MC/DC100%1/1
$align || ''
$align
Truth table100%2/2
A
A= $align
Aresult
11
00
183 } else {
184 51 s/^\s+//;
185 51 s/\s+$//;
186 51 $data{'align'} .= $_;
187 }
188  
189 153 ▶ BOTTOM:
Branch: 1 branch
BranchTrueFalseTotal
if $count++ == 2 51 102 153
190 last if( $count++ == 2);
191 102 $_ = $self->_readline();
192 }
193  
194 51 ▶ if( $data{'type'} eq 'needle' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($data{"type"} eq "needle") 24 27 51
195 # which ever one is shorter we want to bring it up to
196 # length. Man this stinks.
197 24 my ($s1,$s2) = ($data{'seq1'}, $data{'seq2'});
198  
199 24 my $d = length($current[0]->[1]) - length($current[2]->[1]);
200 24 ▶ if( $d < 0 ) { # s1 is smaller, need to add some
Branch: 2 branches
BranchTrueFalseTotal
if ($d < 0) { } 3 21 24
elsif ($d > 0) { } 6 15 21
201 # compare the starting points for this alignment line
202 3 ▶ if( $current[0]->[0] <= 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($current[0][0] <= 1) { } 0 3 3
203 0 $s1->{'data'} = ('-' x abs($d)) . $s1->{'data'};
204 0 $data{'align'} = (' 'x abs($d)).$data{'align'};
205 } else {
206 3 $s1->{'data'} .= '-' x abs($d);
207 3 $data{'align'} .= ' 'x abs($d);
208 }
209 } elsif( $d > 0) { # s2 is smaller, need to add some
210 6 ▶ if( $current[2]->[0] <= 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($current[2][0] <= 1) { } 3 3 6
211 3 $s2->{'data'} = ('-' x abs($d)) . $s2->{'data'};
212 3 $data{'align'} = (' 'x abs($d)).$data{'align'};
213 } else {
214 3 $s2->{'data'} .= '-' x abs($d);
215 3 $data{'align'} .= ' 'x abs($d);
216 }
217 }
218 }
219  
220 }
221 }
222 7 ▶ return unless $seenbegin;
Branch: 1 branch
BranchTrueFalseTotal
unless $seenbegin 0 7 7
223 my $aln = Bio::SimpleAlign->new(-verbose => $self->verbose(),
224 -score => $data{'score'},
225 7 -source => "EMBOSS-".$data{'type'});
226  
227 7 foreach my $seqname ( qw(seq1 seq2) ) {
228 14 ▶ return unless ( defined $data{$seqname} );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $data{$seqname} 0 14 14
229 14 ▶ $data{$seqname}->{'name'} ||= $seqname;
Condition66%2/3
$data{$seqname}{"name"} ||= $seqname
l!l&&r!l&&!r
1310
MC/DC0%0/2
$data{$seqname}{"name"} ||= $seqname
$data{$seqname}{"name"} $seqname
Truth table66%2/3
A ||= B
A= $data{$seqname}{"name"}B= $seqname
ABresult
1X1
011
000
230 my $seq = Bio::LocatableSeq->new
231 ('-seq' => $data{$seqname}->{'data'},
232 '-display_id' => $data{$seqname}->{'name'},
233 '-start' => $data{$seqname}->{'start'},
234 14 '-end' => $data{$seqname}->{'end'},
235 '-alphabet' => $self->alphabet,
236 );
237 14 $aln->add_seq($seq);
238 }
239 7 return $aln;
240 }
241  
242 =head2 write_aln
243  
244 Title : write_aln
245 Usage : $stream->write_aln(@aln)
246 Function: writes the $aln object into the stream in emboss format
247 Returns : 1 for success and 0 for error
248 Args : L<Bio::Align::AlignI> object
249  
250  
251 =cut
252  
253 0 ▶sub write_aln {
Subroutine write_aln: not called CC=1 SCAR=6.9
Pod documented
254 0 my ($self,@aln) = @_;
255  
256 0 $self->throw("Sorry: writing emboss output is not currently available! \n");
257 }
258  
259 3 1;
« Bio/PullParserI.pm ↑ Summary Bio/Index/SwissPfam.pm »