tag fourth (and hopefully last) alpha
[bioperl-live.git] / branch-1-6 / Bio / MapIO.pm
blobc5f0b0809c6e776b8ef1303fc4fd8f214e62e47f
1 # $Id$
3 # BioPerl module for Bio::MapIO
5 # Please direct questions and support issues to <bioperl-l@bioperl.org>
7 # Cared for by Jason Stajich <jason@bioperl.org>
9 # Copyright Jason Stajich
11 # You may distribute this module under the same terms as perl itself
13 # POD documentation - main docs before the code
15 =head1 NAME
17 Bio::MapIO - A Map Factory object
19 =head1 SYNOPSIS
21 use Bio::MapIO;
22 my $mapio = Bio::MapIO->new(-format => "mapmaker",
23 -file => "mapfile.map");
25 while( my $map = $mapio->next_map ) {
26 # get each map
27 foreach my $marker ( $map->each_element ) {
28 # loop through the markers associated with the map
32 =head1 DESCRIPTION
34 This is the Factory object for reading Maps from a data stream or file.
36 =head1 FEEDBACK
38 =head2 Mailing Lists
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.
44 bioperl-l@bioperl.org - General discussion
45 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
47 =head2 Support
49 Please direct usage questions or support issues to the mailing list:
51 I<bioperl-l@bioperl.org>
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.
58 =head2 Reporting Bugs
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 the web:
63 http://bugzilla.open-bio.org/
65 =head1 AUTHOR - Jason Stajich
67 Email jason@bioperl.org
69 =head1 APPENDIX
71 The rest of the documentation details each of the object methods.
72 Internal methods are usually preceded with a _
74 =cut
77 # Let the code begin...
80 package Bio::MapIO;
81 use strict;
84 use base qw(Bio::Root::Root Bio::Root::IO Bio::Factory::MapFactoryI);
86 =head2 new
88 Title : new
89 Usage : my $obj = Bio::MapIO->new();
90 Function: Builds a new Bio::MapIO object
91 Returns : Bio::MapIO
92 Args :
95 =cut
97 sub new {
98 my($caller,@args) = @_;
100 my $class = ref($caller) || $caller;
102 # or do we want to call SUPER on an object if $caller is an
103 # object?
104 if( $class =~ /Bio::MapIO::(\S+)/ ) {
105 my ($self) = $class->SUPER::new(@args);
106 $self->_initialize(@args);
107 return $self;
108 } else {
110 my %param = @args;
111 @param{ map { lc $_ } keys %param } = values %param; # lowercase keys
112 my $format = $param{'-format'} ||
113 $class->_guess_format( $param{'-file'} || $ARGV[0] ) ||
114 'mapmaker';
115 $format = "\L$format"; # normalize capitalization to lower case
117 # normalize capitalization
118 return unless( $class->_load_format_module($format) );
119 return "Bio::MapIO::$format"->new(@args);
124 =head2 Bio::Factory::MapFactoryI methods
126 =cut
128 =head2 next_map
130 Title : next_tree
131 Usage : my $map = $factory->next_map;
132 Function: Get a map from the factory
133 Returns : L<Bio::Map::MapI>
134 Args : none
137 =head2 write_map
139 Title : write_tree
140 Usage : $factory->write_map($map);
141 Function: Write a map out through the factory
142 Returns : none
143 Args : L<Bio::Map::MapI>
145 =cut
148 =head2 attach_EventHandler
150 Title : attach_EventHandler
151 Usage : $parser->attatch_EventHandler($handler)
152 Function: Adds an event handler to listen for events
153 Returns : none
154 Args : L<Bio::Event::EventHandlerI>
156 =cut
158 sub attach_EventHandler{
159 my ($self,$handler) = @_;
160 return if( ! $handler );
161 if( ! $handler->isa('Bio::Event::EventHandlerI') ) {
162 $self->warn("Ignoring request to attatch handler ".ref($handler). ' because it is not a Bio::Event::EventHandlerI');
164 $self->{'_handler'} = $handler;
165 return;
168 =head2 _eventHandler
170 Title : _eventHandler
171 Usage : private
172 Function: Get the EventHandler
173 Returns : L<Bio::Event::EventHandlerI>
174 Args : none
177 =cut
179 sub _eventHandler{
180 my ($self) = @_;
181 return $self->{'_handler'};
184 sub _initialize {
185 my($self, @args) = @_;
186 $self->{'_handler'} = undef;
188 # initialize the IO part
189 $self->_initialize_io(@args);
190 # $self->attach_EventHandler(Bio::MapIO::MapEventBuilder->new());
193 =head2 _load_format_module
195 Title : _load_format_module
196 Usage : *INTERNAL MapIO stuff*
197 Function: Loads up (like use) a module at run time on demand
198 Example :
199 Returns :
200 Args :
202 =cut
204 sub _load_format_module {
205 my ($self,$format) = @_;
206 my $module = "Bio::MapIO::" . $format;
207 my $ok;
208 eval {
209 $ok = $self->_load_module($module);
211 if ( $@ ) {
212 print STDERR <<END;
213 $self: $format cannot be found
214 Exception $@
215 For more information about the MapIO system please see the MapIO docs.
216 This includes ways of checking for formats at compile time, not run time
220 return $ok;
224 =head2 _guess_format
226 Title : _guess_format
227 Usage : $obj->_guess_format($filename)
228 Function:
229 Example :
230 Returns : guessed format of filename (lower case)
231 Args :
233 =cut
235 sub _guess_format {
236 my $class = shift;
237 return unless $_ = shift;
238 return 'mapmaker' if /\.(map)$/i;
239 return 'mapxml' if /\.(xml)$/i;
242 sub DESTROY {
243 my $self = shift;
245 $self->close();