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