Bio/SeqIO/tinyseq/tinyseqHandler.pm

filter: Statementstmt 29.4% 15 / 51 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 30.7% 4 / 13 Podpod 87.5% 7 / 8 totaltotal 27.0% 26 / 96 CC 10 SCAR 23.6
CC
10
Cov
21%
TSeq
30.0
characters
12.0
new
6.0
CRAP 10.6
« Bio/WebAgent.pm ↑ Summary Bio/TreeIO/newick.pm »
1 # BioPerl module for Bio::SeqIO::tinyseqHandler
2 #
3 # Please direct questions and support issues to <bioperl-l@bioperl.org>
4 #
5 # Cared for by Donald Jackson, donald.jackson@bms.com
6 #
7 # Copyright Bristol-Myers Squibb
8 #
9 # You may distribute this module under the same terms as perl itself
10  
11 # POD documentation - main docs before the code
12  
13 =head1 NAME
14  
15 Bio::SeqIO::tinyseq::tinyseqHandler - XML event handlers to support NCBI TinySeq XML parsing
16  
17 =head1 SYNOPSIS
18  
19 Do not use this module directly; use the SeqIO handler system:
20  
21 $stream = Bio::SeqIO->new( -file => $filename, -format => 'tinyseq' );
22  
23 while ( my $seq = $stream->next_seq ) {
24 ....
25 }
26  
27 =head1 DESCRIPTION
28  
29 This object provides event handler methods for parsing sequence files
30 in the NCBI TinySeq XML format. A TinySeq is a lightweight XML file
31 of sequence information on one or more sequences, analgous to FASTA
32 format.
33  
34 See L<https://www.ncbi.nlm.nih.gov/dtd/NCBI_TSeq.mod.dtd> for the DTD.
35  
36 =head1 FEEDBACK
37  
38 =head2 Mailing Lists
39  
40 User feedback is an integral part of the evolution of this and other
41 Bioperl modules. Send your comments and suggestions preferably to
42 the Bioperl mailing list. Your participation is much appreciated.
43  
44 bioperl-l@bioperl.org - General discussion
45 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
46  
47 =head2 Support
48  
49 Please direct usage questions or support issues to the mailing list:
50  
51 I<bioperl-l@bioperl.org>
52  
53 rather than to the module maintainer directly. Many experienced and
54 reponsive experts will be able look at the problem and quickly
55 address it. Please include a thorough description of the problem
56 with code and data examples if at all possible.
57  
58 =head2 Reporting Bugs
59  
60 Report bugs to the Bioperl bug tracking system to help us keep track
61 of the bugs and their resolution. Bug reports can be submitted via
62 the web:
63  
64 https://github.com/bioperl/bioperl-live/issues
65  
66 =head1 SEE ALSO
67  
68 L<Bio::SeqIO>, L<Bio::Seq>.
69  
70 =head1 AUTHOR
71  
72 Donald Jackson, E<lt>donald.jackson@bms.comE<gt>
73  
74 =head1 APPENDIX
75  
76 The rest of the documentation details each of the object methods.
77 Internal methods are usually preceded with a _
78  
79 =cut
80  
81 package Bio::SeqIO::tinyseq::tinyseqHandler;
82 2 $Bio::SeqIO::tinyseq::tinyseqHandler::VERSION = '1.7.8';
83 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
84 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
85  
86  
87 2 ▶use vars qw(%ATTMAP);
Subroutine BEGIN: called CC=1 SCAR=0.0
88  
89 2 ▶use base qw(Bio::Root::Root);
Subroutine BEGIN: called CC=1 SCAR=0.0
90  
91 # %ATTMAP defines correspondence between TSeq elements, PrimarySeq attributes
92 # Format: element_name => { xml_attname => pseq_attname }
93 2 %ATTMAP = ( TSeq_sequence => { Data => '-seq'},
94 TSeq_gi => { Data => '-primary_id' },
95 TSeq_defline => { Data => '-desc' },
96 TSeq_sid => { Data => '-sid' },
97 TSeq_accver => { Data => '-accver' },
98 TSeq_taxid => { Data => '-taxid' },
99 TSeq_orgname => { Data => '-organism' }
100 );
101  
102 =head2 new
103  
104 Title : new
105 Usage : $handler = Bio::SeqIO::tinyseq::tinyseqHandler->new()
106 Function : instantiates a tinyseqHandler for use by
107 XML::Parser::PerlSAX
108 Returns : Bio::SeqIO::tinyseq::tinyseqHandler object
109 Args : NONE
110  
111 =cut
112  
113 0 ▶sub new {
Subroutine new: not called CC=2 SCAR=17.9
Pod documented
114 0 my ($proto, @args) = @_;
115 0 ▶ my $class = ref($proto) || $proto;
Condition0%0/3
ref $proto || $proto
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $proto || $proto
ref $proto $proto
Truth table0%0/3
A || B
A= ref $protoB= $proto
ABresult
1X1
011
000
116  
117 0 my $self = bless({}, $class);
118  
119 0 return $self;
120 }
121  
122 #######################################
123 # Event handling methods for PerlSax #
124 #######################################
125  
126 0 ▶sub doctype_decl {
Subroutine doctype_decl: not called CC=2 SCAR=17.9
Pod undocumented
127 0 my ($self, $doctype) = @_;
128 # make sure we have a tinyseq
129 0 ▶ unless ($doctype->{'SystemId'} eq 'https://www.ncbi.nlm.nih.gov/dtd/NCBI_TSeq.dtd') {
Branch: 1 branch
BranchTrueFalseTotal
unless ($doctype->{"SystemId"} eq "https://www.ncbi.nlm.nih.gov/dtd/NCBI_TSeq.dtd") 0 0 0
130 0 $self->throw("This document doesn't use the NCBI TinySeq dtd; it's a ", $doctype->{'SystemId'} );
131 }
132  
133 }
134  
135 =head2 start_document
136  
137 Title : start_document
138 Usage : NONE
139 Function : start_document handler for use by XML::Parser::PerlSAX
140 Returns : NONE
141 Args : NONE
142  
143 =cut
144  
145 0 ▶sub start_document {
Subroutine start_document: not called CC=1 SCAR=6.9
Pod documented
146 0 my ($self) = @_;
147  
148 0 $self->{'_seqatts'} = [];
149 0 $self->{'_elements'} = [];
150 }
151  
152 =head2 end_document
153  
154 Title : end_document
155 Usage : NONE
156 Function : end_document handler for use by XML::Parser::PerlSAX
157 Returns : NONE
158 Args : NONE
159  
160 =cut
161  
162 0 ▶sub end_document {
Subroutine end_document: not called CC=1 SCAR=6.9
Pod documented
163 0 my ($self) = @_;
164 0 return $self->{'_seqatts'};
165 }
166  
167 =head2 start_element
168  
169 Title : start_element
170 Usage : NONE
171 Function : start_element handler for use by XML::Parser::PerlSAX
172 Returns : NONE
173 Args : NONE
174  
175 =cut
176  
177 0 ▶sub start_element {
Subroutine start_element: not called CC=1 SCAR=6.9
Pod documented
178 0 my ($self, $starting) = @_;
179  
180 0 push(@{$self->{'_elements'}}, $starting);
181 }
182  
183 =head2 end_element
184  
185 Title : end_element
186 Usage : NONE
187 Function : end_element handler for use by XML::Parser::PerlSAX
188 Returns : NONE
189 Args : NONE
190  
191 =cut
192  
193 0 ▶sub end_element {
Subroutine end_element: not called CC=2 SCAR=17.9
Pod documented
194 0 my ($self, $ending) = @_;
195  
196 # do I have a handler for this element?
197 0 my $ename = $ending->{'Name'};
198 0 ▶ $self->$ename if ($self->can($ename));
Branch: 1 branch
BranchTrueFalseTotal
if $self->can($ename) 0 0 0
199 }
200  
201 =head2 characters
202  
203 Title : characters
204 Usage : NONE
205 Function : characters handler for use by XML::Parser::PerlSAX
206 Returns : NONE
207 Args : NONE
208  
209 =cut
210  
211 0 ▶sub characters {
Subroutine characters: not called CC=3 SCAR=24.8
Pod documented
212 0 my ($self, $characters) = @_;
213  
214 0 my $data = $characters->{'Data'};
215  
216 0 ▶ return unless (defined($data) and $data =~ /\S/);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $data and $data =~ /\S/ 0 0 0
Condition0%0/3
defined $data and $data =~ /\S/
!ll&&!rl&&r
000
MC/DC0%0/2
defined $data and $data =~ /\S/
defined $data $data =~ /\S/
Truth table0%0/3
A and B
A= defined $dataB= $data =~ /\S/
ABresult
0X0
100
111
217  
218 0 my $current = $self->_current_element;
219 0 $current->{'Data'} = $data;
220 }
221  
222  
223 ###########################################
224 # Element-specific handlers
225 # called at END of element name
226 ##########################################
227  
228 =head2 TSeq
229  
230 Title : TSeq
231 Usage : NONE
232 Function : event handler for END of a TSeq element
233 Returns : loh of parsed sequence atts for Bio::SeqIO::tinyseq
234 Args : NONE
235  
236 =cut
237  
238 0 ▶sub TSeq {
Subroutine TSeq: not called CC=5 SCAR=34.0
Pod documented
239 0 my ($self) = @_;
240  
241 0 my %seqatts;
242  
243 # map elements onto PrimarySeq keys
244 0 ▶ while (my $element = pop @{ $self->{'_elements'} }) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $element = pop @{$$self{"_elements"};}) 0 0 0
245 0 my $element_name = $element->{'Name'};
246 0 ▶ last if ($element_name eq 'TSeq');
Branch: 1 branch
BranchTrueFalseTotal
if $element_name eq "TSeq" 0 0 0
247  
248 0 ▶ my $conversion = $ATTMAP{$element_name} or next;
Branch: 1 branch
BranchTrueFalseTotal
my $conversion = $Bio::SeqIO::tinyseq::tinyseqHandler::ATTMAP{$element_name} or next 0 0 0
249  
250 0 ▶ while(my($element_att, $pseq_att) = each %$conversion) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$conversion) 0 0 0
251 0 $seqatts{$pseq_att} = $element->{$element_att};
252 }
253 }
254  
255 0 push(@{ $self->{'_seqatts'} }, \%seqatts);
256  
257 }
258  
259 #############################################
260 # Utility method to return current element info
261 ##############################################
262  
263 =head2 _current_element
264  
265 Title : _current_element
266 Usage : Internal method
267 Function : Utility method to return current element info
268 Returns : XML::Parser::PerlSAX hash for current element
269 Args : NONE
270  
271 =cut
272  
273 0 ▶sub _current_element {
Subroutine _current_element: not called CC=1 SCAR=6.9
274 0 my ($self) = @_;
275 0 return $self->{'_elements'}->[-1];
276 }
277  
278  
279  
280  
281 2 1;
« Bio/WebAgent.pm ↑ Summary Bio/TreeIO/newick.pm »