t/AlignIO/AlignIO.t: fix number of tests in plan (fixup c523e6bed866)
[bioperl-live.git] / Bio / SeqIO / game / gameHandler.pm
blob559c5ca613994b790f37a9a351c3e5993484ec13
1 # $Id:
3 # BioPerl module for Bio::SeqIO::game::gameHandler
5 # Please direct questions and support issues to <bioperl-l@bioperl.org>
7 # Cared for by Sheldon McKay <mckays@cshl.edu>
9 # You may distribute this module under the same terms as perl itself
12 # POD documentation - main docs before the code
14 =head1 NAME
16 Bio::SeqIO::game::gameHandler -- PerlSAX handler for game-XML
18 =head1 SYNOPSIS
20 This modules is not used directly
22 =head1 DESCRIPTION
24 Bio::SeqIO::game::gameHandler is the top-level XML handler invoked by PerlSAX
26 =head1 FEEDBACK
28 =head2 Mailing Lists
30 User feedback is an integral part of the evolution of this
31 and other Bioperl modules. Send your comments and suggestions preferably
32 to one of the Bioperl mailing lists.
34 Your participation is much appreciated.
36 bioperl-l@bioperl.org - General discussion
37 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
39 =head2 Support
41 Please direct usage questions or support issues to the mailing list:
43 I<bioperl-l@bioperl.org>
45 rather than to the module maintainer directly. Many experienced and
46 reponsive experts will be able look at the problem and quickly
47 address it. Please include a thorough description of the problem
48 with code and data examples if at all possible.
50 =head2 Reporting Bugs
52 Report bugs to the Bioperl bug tracking system to help us keep track
53 of the bugs and their resolution. Bug reports can be submitted via the
54 web:
56 https://github.com/bioperl/bioperl-live/issues
58 =head1 AUTHOR - Sheldon McKay
60 Email mckays@cshl.edu
62 =head1 APPENDIX
64 The rest of the documentation details each of the object
65 methods. Internal methods are usually preceded with a _
67 =cut
69 package Bio::SeqIO::game::gameHandler;
71 use Bio::SeqIO::game::seqHandler;
72 use strict;
73 use vars qw {};
75 use base qw(Bio::SeqIO::game::gameSubs);
77 =head2 start_document
79 Title : start_document
80 Function: begin parsing the document
82 =cut
84 sub start_document {
85 my ($self, $document) = @_;
87 $self->SUPER::start_document($document);
89 $self->{sequences} = {};
90 $self->{annotations} = {};
91 $self->{computations} = {};
92 $self->{map_position} = {};
93 $self->{focus} = {};
96 =head2 end_document
98 Title : end_document
99 Function: finish parsing the document
101 =cut
103 sub end_document {
104 my ($self, $document) = @_;
106 $self->SUPER::end_document($document);
108 return $self;
111 =head2 load
113 Title : load
114 Usage : $seqs = $handler->load
115 Function: start parsing
116 Returns : a ref to a list of sequence objects
117 Args : an optional flag to suppress <computation_analysis> elements (not used yet)
119 =cut
121 sub load {
122 my $self = shift;
123 my $suppress_comps = shift;
124 my @seqs = ();
126 for ( 1..$self->{game} ) {
127 my $seq = $self->{sequences}->{$_}
128 or $self->throw("No sequences defined");
129 my $ann = $self->{annotations}->{$_};
130 my $comp = $self->{computations}->{$_};
131 my $map = $self->{map_position}->{$_};
132 my $foc = $self->{focus}->{$_}
133 or $self->throw("No main sequence defined");
134 my $src = $self->{has_source};
136 my $bio = Bio::SeqIO::game::seqHandler->new( $seq, $ann, $comp, $map, $src );
137 push @seqs, $bio->convert;
140 \@seqs;
143 =head2 s_game
145 Title : s_game
146 Function: begin parsing game element
148 =cut
150 sub s_game {
151 my ($self, $e) = @_;
152 my $el = $self->curr_element;
153 $self->{game}++;
155 my $version = $el->{Attributes}->{version};
157 unless ( defined $version ) {
158 $self->complain("No GAME-xml version specified -- guessing v1.2\n");
159 $version = 1.2;
161 if ( defined($version) && $version == 1.2) {
162 $self->{origin_offset} = 1;
163 } else {
164 $self->{origin_offset} = 0;
167 if (defined($version) && ($version != 1.2)) {
168 $self->complain("GAME version $version is not supported\n",
169 "I'll try anyway but I may fail!\n");
174 =head2 e_game
176 Title : e_game
177 Function: process the game element
179 =cut
181 sub e_game {
182 my ($self, $el) = @_;
183 $self->flush( $el );
186 =head2 e_seq
188 Title : e_seq
189 Function: process the sequence element
191 =cut
193 sub e_seq {
194 my ($self, $e) = @_;
195 my $el = $self->curr_element();
196 $self->{sequences}->{$self->{game}} ||= [];
197 my $seqs = $self->{sequences}->{$self->{game}};
199 if ( defined $el->{Attributes}->{focus} ) {
200 $self->{focus}->{$self->{game}} = $el;
202 push @{$seqs}, $el;
204 $self->flush;
207 =head2 e_map_position
209 Title : e_map_position
210 Function: process the map_position element
212 =cut
214 sub e_map_position {
215 my ($self, $e) = @_;
216 my $el = $self->curr_element;
217 $self->{map_position}->{$self->{game}} = $el;
220 =head2 e_annotation
222 Title : e_annotation
223 Function: process the annotation
225 =cut
227 sub e_annotation {
228 my ($self, $e) = shift;
229 my $el = $self->curr_element;
230 $self->{annotations}->{$self->{game}} ||= [];
231 my $anns = $self->{annotations}->{$self->{game}};
232 push @{$anns}, $el;