| 1 | # $Id: | ||
| 2 | # | ||
| 3 | # BioPerl module for Bio::SeqIO::game::gameHandler | ||
| 4 | # | ||
| 5 | # Please direct questions and support issues to <bioperl-l@bioperl.org> | ||
| 6 | # | ||
| 7 | # Cared for by Sheldon McKay <mckays@cshl.edu> | ||
| 8 | # | ||
| 9 | # You may distribute this module under the same terms as perl itself | ||
| 10 | # | ||
| 11 | |||
| 12 | # POD documentation - main docs before the code | ||
| 13 | |||
| 14 | =head1 NAME | ||
| 15 | |||
| 16 | Bio::SeqIO::game::gameHandler -- PerlSAX handler for game-XML | ||
| 17 | |||
| 18 | =head1 SYNOPSIS | ||
| 19 | |||
| 20 | This modules is not used directly | ||
| 21 | |||
| 22 | =head1 DESCRIPTION | ||
| 23 | |||
| 24 | Bio::SeqIO::game::gameHandler is the top-level XML handler invoked by PerlSAX | ||
| 25 | |||
| 26 | =head1 FEEDBACK | ||
| 27 | |||
| 28 | =head2 Mailing Lists | ||
| 29 | |||
| 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. | ||
| 33 | |||
| 34 | Your participation is much appreciated. | ||
| 35 | |||
| 36 | bioperl-l@bioperl.org - General discussion | ||
| 37 | http://bioperl.org/wiki/Mailing_lists - About the mailing lists | ||
| 38 | |||
| 39 | =head2 Support | ||
| 40 | |||
| 41 | Please direct usage questions or support issues to the mailing list: | ||
| 42 | |||
| 43 | I<bioperl-l@bioperl.org> | ||
| 44 | |||
| 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. | ||
| 49 | |||
| 50 | =head2 Reporting Bugs | ||
| 51 | |||
| 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: | ||
| 55 | |||
| 56 | https://github.com/bioperl/bioperl-live/issues | ||
| 57 | |||
| 58 | =head1 AUTHOR - Sheldon McKay | ||
| 59 | |||
| 60 | Email mckays@cshl.edu | ||
| 61 | |||
| 62 | =head1 APPENDIX | ||
| 63 | |||
| 64 | The rest of the documentation details each of the object | ||
| 65 | methods. Internal methods are usually preceded with a _ | ||
| 66 | |||
| 67 | =cut | ||
| 68 | |||
| 69 | package Bio::SeqIO::game::gameHandler; | ||
| 70 | $Bio::SeqIO::game::gameHandler::VERSION = '1.7.8'; | ||
| 71 | 0 | ▶ | use Bio::SeqIO::game::seqHandler; |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 72 | use strict; | ||
| 73 | use vars qw {}; | ||
| 74 | |||
| 75 | use base qw(Bio::SeqIO::game::gameSubs); | ||
| 76 | |||
| 77 | =head2 start_document | ||
| 78 | |||
| 79 | Title : start_document | ||
| 80 | Function: begin parsing the document | ||
| 81 | |||
| 82 | =cut | ||
| 83 | |||
| 84 | sub start_document { | ||
| 85 | my ($self, $document) = @_; | ||
| 86 | |||
| 87 | $self->SUPER::start_document($document); | ||
| 88 | |||
| 89 | $self->{sequences} = {}; | ||
| 90 | $self->{annotations} = {}; | ||
| 91 | $self->{computations} = {}; | ||
| 92 | $self->{map_position} = {}; | ||
| 93 | $self->{focus} = {}; | ||
| 94 | } | ||
| 95 | |||
| 96 | =head2 end_document | ||
| 97 | |||
| 98 | Title : end_document | ||
| 99 | Function: finish parsing the document | ||
| 100 | |||
| 101 | =cut | ||
| 102 | |||
| 103 | sub end_document { | ||
| 104 | my ($self, $document) = @_; | ||
| 105 | |||
| 106 | $self->SUPER::end_document($document); | ||
| 107 | |||
| 108 | return $self; | ||
| 109 | } | ||
| 110 | |||
| 111 | =head2 load | ||
| 112 | |||
| 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) | ||
| 118 | |||
| 119 | =cut | ||
| 120 | |||
| 121 | sub load { | ||
| 122 | my $self = shift; | ||
| 123 | my $suppress_comps = shift; | ||
| 124 | my @seqs = (); | ||
| 125 | |||
| 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}; | ||
| 135 | |||
| 136 | my $bio = Bio::SeqIO::game::seqHandler->new( $seq, $ann, $comp, $map, $src ); | ||
| 137 | push @seqs, $bio->convert; | ||
| 138 | } | ||
| 139 | |||
| 140 | \@seqs; | ||
| 141 | } | ||
| 142 | |||
| 143 | =head2 s_game | ||
| 144 | |||
| 145 | Title : s_game | ||
| 146 | Function: begin parsing game element | ||
| 147 | |||
| 148 | =cut | ||
| 149 | |||
| 150 | sub s_game { | ||
| 151 | my ($self, $e) = @_; | ||
| 152 | my $el = $self->curr_element; | ||
| 153 | $self->{game}++; | ||
| 154 | |||
| 155 | my $version = $el->{Attributes}->{version}; | ||
| 156 | |||
| 157 | unless ( defined $version ) { | ||
| 158 | $self->complain("No GAME-xml version specified -- guessing v1.2\n"); | ||
| 159 | $version = 1.2; | ||
| 160 | } | ||
| 161 | if ( defined($version) && $version == 1.2) { | ||
| 162 | $self->{origin_offset} = 1; | ||
| 163 | } else { | ||
| 164 | $self->{origin_offset} = 0; | ||
| 165 | } | ||
| 166 | |||
| 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"); | ||
| 170 | } | ||
| 171 | |||
| 172 | } | ||
| 173 | |||
| 174 | =head2 e_game | ||
| 175 | |||
| 176 | Title : e_game | ||
| 177 | Function: process the game element | ||
| 178 | |||
| 179 | =cut | ||
| 180 | |||
| 181 | sub e_game { | ||
| 182 | my ($self, $el) = @_; | ||
| 183 | $self->flush( $el ); | ||
| 184 | } | ||
| 185 | |||
| 186 | =head2 e_seq | ||
| 187 | |||
| 188 | Title : e_seq | ||
| 189 | Function: process the sequence element | ||
| 190 | |||
| 191 | =cut | ||
| 192 | |||
| 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}}; | ||
| 198 | |||
| 199 | if ( defined $el->{Attributes}->{focus} ) { | ||
| 200 | $self->{focus}->{$self->{game}} = $el; | ||
| 201 | } | ||
| 202 | push @{$seqs}, $el; | ||
| 203 | |||
| 204 | $self->flush; | ||
| 205 | } | ||
| 206 | |||
| 207 | =head2 e_map_position | ||
| 208 | |||
| 209 | Title : e_map_position | ||
| 210 | Function: process the map_position element | ||
| 211 | |||
| 212 | =cut | ||
| 213 | |||
| 214 | sub e_map_position { | ||
| 215 | my ($self, $e) = @_; | ||
| 216 | my $el = $self->curr_element; | ||
| 217 | $self->{map_position}->{$self->{game}} = $el; | ||
| 218 | } | ||
| 219 | |||
| 220 | =head2 e_annotation | ||
| 221 | |||
| 222 | Title : e_annotation | ||
| 223 | Function: process the annotation | ||
| 224 | |||
| 225 | =cut | ||
| 226 | |||
| 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; | ||
| 233 | } | ||
| 234 | |||
| 235 | 1; | ||