Bio/SeqIO/bsml_sax.pm

filter: Statementstmt 96.9% 126 / 130 Branchbran 89.2% 50 / 56 Conditioncond 62.5% 5 / 8 MC/DCmcdc 40.0% 2 / 5 Subroutinesub 100% 18 / 18 Podpod 100% 6 / 6 totaltotal 92.8% 207 / 223 CC 33 SCAR 24.3
CC
33
Cov
93%
start_element
22.0
characters
6.0
next_seq
5.0
CRAP 11.3
« Bio/Seq/Meta.pm ↑ Summary Bio/Search/Result/CrossMatchResult.pm »
1 # BioPerl module for Bio::SeqIO::bsml_sax
2 #
3 # Please direct questions and support issues to <bioperl-l@bioperl.org>
4 #
5 # Cared for by Jason Stajich
6 #
7  
8 =head1 NAME
9  
10 Bio::SeqIO::bsml_sax - BSML sequence input/output stream using SAX
11  
12 =head1 SYNOPSIS
13  
14 It is probably best not to use this object directly, but rather go
15 through the SeqIO handler system. To read a BSML file:
16  
17 $stream = Bio::SeqIO->new( -file => $filename, -format => 'bsml');
18  
19 while ( my $bioSeqObj = $stream->next_seq() ) {
20 # do something with $bioSeqObj
21 }
22  
23 To write a Seq object to the current file handle in BSML XML format:
24  
25 $stream->write_seq( -seq => $seqObj);
26  
27 If instead you would like a XML::DOM object containing the BSML, use:
28  
29 my $newXmlObject = $stream->to_bsml( -seq => $seqObj);
30  
31 =head1 DEPENDENCIES
32  
33 In addition to parts of the Bio:: hierarchy, this module uses:
34  
35 XML::SAX
36  
37 =head1 DESCRIPTION
38  
39 This object can transform Bio::Seq objects to and from BSML (XML)
40 flatfiles.
41  
42 =head1 FEEDBACK
43  
44 =head2 Mailing Lists
45  
46 User feedback is an integral part of the evolution of this and other
47 Bioperl modules. Send your comments and suggestions preferably to one
48 of the Bioperl mailing lists. Your participation is much appreciated.
49  
50 bioperl-l@bioperl.org - General discussion
51 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
52  
53 =head2 Support
54  
55 Please direct usage questions or support issues to the mailing list:
56  
57 I<bioperl-l@bioperl.org>
58  
59 rather than to the module maintainer directly. Many experienced and
60 reponsive experts will be able look at the problem and quickly
61 address it. Please include a thorough description of the problem
62 with code and data examples if at all possible.
63  
64 =head2 Reporting Bugs
65  
66 Report bugs to the Bioperl bug tracking system to help us keep track
67 the bugs and their resolution. Bug reports can be submitted via the
68 web:
69  
70 https://github.com/bioperl/bioperl-live/issues
71  
72 =head1 AUTHOR - Jason Stajich
73  
74 Email jason-at-bioperl-dot-org
75  
76 =cut
77  
78 package Bio::SeqIO::bsml_sax;
79 2 $Bio::SeqIO::bsml_sax::VERSION = '1.7.8';
80 2 ▶use vars qw($Default_Source);
Subroutine BEGIN: called CC=1 SCAR=0.0
81 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
82  
83 2 ▶use Bio::SeqFeature::Generic;
Subroutine BEGIN: called CC=1 SCAR=0.0
84 2 ▶use Bio::Species;
Subroutine BEGIN: called CC=1 SCAR=0.0
85 2 ▶use XML::SAX;
Subroutine BEGIN: called CC=1 SCAR=0.0
86 2 ▶use Bio::Seq::SeqFactory;
Subroutine BEGIN: called CC=1 SCAR=0.0
87 2 ▶use Bio::Annotation::Collection;
Subroutine BEGIN: called CC=1 SCAR=0.0
88 2 ▶use Bio::Annotation::Comment;
Subroutine BEGIN: called CC=1 SCAR=0.0
89 2 ▶use Bio::Annotation::Reference;
Subroutine BEGIN: called CC=1 SCAR=0.0
90 2 ▶use Bio::Annotation::DBLink;
Subroutine BEGIN: called CC=1 SCAR=0.0
91  
92 2 ▶use base qw(Bio::SeqIO XML::SAX::Base);
Subroutine BEGIN: called CC=1 SCAR=0.0
93  
94 2 $Default_Source = 'BSML';
95  
96 1 ▶sub _initialize {
Subroutine _initialize: called CC=2 SCAR=7.0
97 1 my ($self) = shift;
98 1 $self->SUPER::_initialize(@_);
99 1 $self->{'_parser'} = XML::SAX::ParserFactory->parser('Handler' => $self);
100 1 ▶ if( ! defined $self->sequence_factory ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->sequence_factory) 1 0 1
101 1 $self->sequence_factory(Bio::Seq::SeqFactory->new
102 (-verbose => $self->verbose(),
103 -type => 'Bio::Seq::RichSeq'));
104 }
105 1 return;
106 }
107  
108 =head1 METHODS
109  
110 =cut
111  
112 =head2 next_seq
113  
114 Title : next_seq
115 Usage : my $bioSeqObj = $stream->next_seq
116 Function: Retrieves the next sequence from a SeqIO::bsml stream.
117 Returns : A reference to a Bio::Seq::RichSeq object
118 Args :
119  
120 =cut
121  
122 1 ▶sub next_seq {
Subroutine next_seq: called CC=4 SCAR=16.1
Pod documented
123 1 my $self = shift;
124 1 ▶ if( @{$self->{'_seendata'}->{'_seqs'} || []} ||
Branch: 1 branch
BranchTrueFalseTotal
if (@{$self->{"_seendata"}{"_seqs"} or [];} or eof $self->_fh) 0 1 1
Condition40%2/5
@{$self->{"_seendata"}{"_seqs"} or [];} or eof $self->_fh
l!l&&r!l&&!r
001
$self->{'_seendata'}{'_seqs'} || []
l!l
01
MC/DC0%0/2
@{$self->{"_seendata"}{"_seqs"} or [];} or eof $self->_fh
@{$self->{"_seendata"}{"_seqs"} or [];} eof $self->_fh
MC/DC0%0/1
$self->{'_seendata'}{'_seqs'} || []
$self->{'_seendata'}{'_seqs'}
Truth table33%1/3
A or B
A= @{$self->{"_seendata"}{"_seqs"} or [];}B= eof $self->_fh
ABresult
1X1
011
000
Truth table50%1/2
A
A= $self->{'_seendata'}{'_seqs'}
Aresult
11
00
125 eof($self->_fh)) {
126 0 return shift @{$self->{'_seendata'}->{'_seqs'}};
127 }
128 1 $self->{'_parser'}->parse_file($self->_fh);
129 1 return shift @{$self->{'_seendata'}->{'_seqs'}};
130 }
131  
132 # XML::SAX::Base methods
133  
134 1 ▶sub start_document {
Subroutine start_document: called CC=1 SCAR=0.0
Pod documented
135 1 my ($self,$doc) = @_;
136 1 $self->{'_seendata'} = {'_seqs' => [],
137 '_authors' => [],
138 '_feats' => [] };
139 1 $self->SUPER::start_document($doc);
140 }
141  
142 1 ▶sub end_document {
Subroutine end_document: called CC=1 SCAR=0.0
Pod documented
143 1 my ($self,$doc) = @_;
144 1 $self->SUPER::end_document($doc);
145 }
146  
147  
148 36 ▶sub start_element {
Subroutine start_element: called CC=22 SCAR=30.9
Pod documented
149 36 my ($self,$ele) = @_;
150 36 my $name = uc($ele->{'LocalName'});
151 36 my $attr = $ele->{'Attributes'};
152 my $seqid = defined $self->{'_seendata'}->{'_seqs'}->[-1] ?
153 36 ▶ $self->{'_seendata'}->{'_seqs'}->[-1]->display_id : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'_seendata'}{'_seqs'}[-1] ? : 32 4 36
154 36 for my $k ( keys %$attr ) {
155 59 $attr->{uc $k} = $attr->{$k};
156 59 delete $attr->{$k};
157 }
158 36 ▶ if( $name eq 'BSML' ) {
Branch: 10 branches
BranchTrueFalseTotal
if ($name eq 'BSML') { } 1 35 36
elsif ($name eq 'DEFINITIONS') { } 1 34 35
elsif ($name eq 'SEQUENCES') { } 1 33 34
elsif ($name eq 'SEQUENCE') { } 1 32 33
elsif ($name eq 'FEATURE-TABLES') { } 1 31 32
elsif ($name eq 'ATTRIBUTE') { } 8 23 31
elsif ($name eq 'FEATURE') { } 2 21 23
elsif ($name eq 'QUALIFIER') { } 10 11 21
elsif ($name eq 'INTERVAL-LOC') { } 2 9 11
elsif ($name eq 'REFERENCE') { } 2 7 9
159  
160 } elsif( $name eq 'DEFINITIONS' ) {
161 } elsif( $name eq 'SEQUENCES' ) {
162  
163 } elsif( $name eq 'SEQUENCE' ) {
164 my ($id,$acc,$title,
165 $desc,$length,$topology,
166 1 $mol) = map { $attr->{'{}'.$_}->{'Value'} } qw(ID IC-ACCKEY
167 TITLE COMMENT
168 LENGTH
169 TOPOLOGY
170 MOLECULE);
171 1 ▶ push @{$self->{'_seendata'}->{'_seqs'}},
Branch: 1 branch
BranchTrueFalseTotal
$topology =~ /^linear$/i ? : 1 0 1
172 $self->sequence_factory->create
173 (
174 -display_id => $id,
175 -accession_number => $acc,
176 -description => $desc,
177 -length => $length,
178 -is_circular => ($topology =~ /^linear$/i) ? 0 : 1,
179 -molecule => $mol,
180 );
181  
182 } elsif( $name eq 'FEATURE-TABLES' ) {
183 } elsif( $name eq 'ATTRIBUTE' ) {
184 8 my $curseq = $self->{'_seendata'}->{'_seqs'}->[-1];
185 8 my ($name,$content) = map { $attr->{'{}'.$_}->{'Value'} } qw(NAME CONTENT);
186 8 ▶ if($name =~ /^version$/i ) {
Branch: 5 branches
BranchTrueFalseTotal
if ($name =~ /^version$/i) { } 1 7 8
elsif ($name eq 'organism-species') { } 1 6 7
elsif ($name eq 'organism-classification') { } 1 5 6
elsif ($name eq 'database-xref') { } 2 3 5
elsif ($name eq 'date-created' or $name eq 'date-last-updated') { } 2 1 3
187 1 my ($version);
188 1 ▶ if($content =~ /^[^\.]+\.(\d+)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($content =~ /^[^\.]+\.(\d+)/) { } 1 0 1
189 1 $version = $1;
190 0 } else { $version = $content }
191 1 $curseq->seq_version($version);
192 } elsif( $name eq 'organism-species') {
193 1 my ($genus,$species,$subsp) = split(/\s+/,$content,3);
194 1 $curseq->species(Bio::Species->new(-sub_species => $subsp,
195 -classification =>
196 [$species,$genus]));
197 } elsif( $name eq 'organism-classification' ) {
198 1 my (@class) =(split(/\s*;\s*/,$content),$curseq->species->species);
199 1 $curseq->species->classification([reverse @class]);
200 } elsif( $name eq 'database-xref' ) {
201 2 my ($db,$id) = split(/:/,$content);
202 2 $curseq->annotation->add_Annotation('dblink',
203 Bio::Annotation::DBLink->new
204 ( -database => $db,
205 -primary_id=> $id));
206 ▶ } elsif( $name eq 'date-created' ||
Condition100%3/3
$name eq "date-created" or $name eq "date-last-updated"
l!l&&r!l&&!r
111
MC/DC100%2/2
$name eq "date-created" or $name eq "date-last-updated"
$name eq "date-created" $name eq "date-last-updated"
Truth table100%3/3
A or B
A= $name eq "date-created"B= $name eq "date-last-updated"
ABresult
1X1
011
000
207 $name eq 'date-last-updated' ) {
208 2 $curseq->add_date($content);
209 }
210 } elsif( $name eq 'FEATURE' ) {
211 my ($id,$class,$type,$title,$display_auto)
212 2 = map { $attr->{'{}'.$_}->{'Value'} } qw(ID CLASS VALUE-TYPE
213 TITLE DISPLAY-AUTO);
214  
215 2 push @{$self->{'_seendata'}->{'_feats'}},
216 Bio::SeqFeature::Generic->new
217 2 ( -seq_id => $self->{'_seendata'}->{'_seqs'}->[-1]->display_id,
218 -source_tag => $Default_Source,
219 -primary_tag => $type,
220 -tag => {'ID' => $id,
221 });
222  
223 } elsif( $name eq 'QUALIFIER') {
224 10 my ($type,$value) = map { $attr->{'{}'.$_}->{'Value'} } qw(VALUE-TYPE
225 VALUE);
226 10 my $curfeat = $self->{'_seendata'}->{'_feats'}->[-1];
227 10 $curfeat->add_tag_value($type,$value);
228 } elsif( $name eq 'INTERVAL-LOC' ) {
229 2 my $curfeat = $self->{'_seendata'}->{'_feats'}->[-1];
230 my ($start,$end,$strand) =
231 2 map { $attr->{'{}'.$_}->{'Value'} } qw(STARTPOS
232 ENDPOS
233 COMPLEMENT);
234  
235 2 $curfeat->start($start);
236 2 $curfeat->end($end);
237 2 ▶ $curfeat->strand(-1) if($strand);
Branch: 1 branch
BranchTrueFalseTotal
if $strand 0 2 2
238 } elsif( $name eq 'REFERENCE' ) {
239 2 push @{$self->{'_seendata'}->{'_annot'}},
240 Bio::Annotation::Reference->new();
241 }
242  
243 36 push @{$self->{'_state'}}, $name;
244 36 $self->SUPER::start_element($ele);
245 }
246  
247 36 ▶sub end_element {
Subroutine end_element: called CC=3 SCAR=11.0
Pod documented
248 36 my ($self,$ele) = @_;
249 36 pop @{$self->{'_state'}};
250 36 my $name = uc $ele->{'LocalName'};
251 36 my $curseq = $self->{'_seendata'}->{'_seqs'}->[-1];
252 36 ▶ if( $name eq 'REFERENCE') {
Branch: 2 branches
BranchTrueFalseTotal
if ($name eq 'REFERENCE') { } 2 34 36
elsif ($name eq 'FEATURE') { } 2 32 34
253 2 my $ref = pop @{$self->{'_seendata'}->{'_annot'}};
254 2 $curseq->annotation->add_Annotation('reference',$ref);
255 } elsif( $name eq 'FEATURE' ) {
256 2 my $feat = pop @{$self->{'_seendata'}->{'_feats'}};
257 2 $curseq->add_SeqFeature($feat);
258 }
259 36 $self->SUPER::end_element($ele);
260 }
261  
262 52 ▶sub characters {
Subroutine characters: called CC=6 SCAR=17.9
Pod documented
263 52 my ($self,$data) = @_;
264 52 ▶ if( ! @{$self->{'_state'}} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not @{$self->{'_state'};}) { } 0 52 52
265 0 $self->warn("Calling characters with no previous start_element call. Ignoring data");
266 } else {
267 52 my $curseq = $self->{'_seendata'}->{'_seqs'}->[-1];
268 52 my $curfeat = $self->{'_seendata'}->{'_feats'}->[-1];
269 52 my $curannot = $self->{'_seendata'}->{'_annot'}->[-1];
270 52 my $name = $self->{'_state'}->[-1];
271 52 ▶ if( $name eq 'REFAUTHORS' ) {
Branch: 4 branches
BranchTrueFalseTotal
if ($name eq 'REFAUTHORS') { } 2 50 52
elsif ($name eq 'REFTITLE') { } 1 49 50
elsif ($name eq 'REFJOURNAL') { } 2 47 49
elsif ($name eq 'SEQ-DATA') { } 2 45 47
272 2 $curannot->authors($data->{'Data'});
273 } elsif( $name eq 'REFTITLE') {
274 1 $curannot->title($data->{'Data'});
275 } elsif( $name eq 'REFJOURNAL') {
276 2 $curannot->location($data->{'Data'});
277 } elsif( $name eq 'SEQ-DATA') {
278 2 $data->{'Data'} =~ s/\s+//g;
279 2 $curseq->seq($data->{'Data'});
280 }
281 }
282 52 $self->SUPER::characters($data);
283 }
284  
285 2 1;
« Bio/Seq/Meta.pm ↑ Summary Bio/Search/Result/CrossMatchResult.pm »