3 # BioPerl module for Bio::PopGen::IO
5 # Please direct questions and support issues to <bioperl-l@bioperl.org>
7 # Cared for by Jason Stajich <jason-at-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
17 Bio::PopGen::IO - Input individual,marker,allele information
22 my $io = Bio::PopGen::IO->new(-format => 'csv',
25 # Some IO might support reading in a population at a time
28 while( my $ind = $io->next_individual ) {
29 push @population, $ind;
35 This is a generic interface to reading in population genetic data (of
36 which there really isn't too many standard formats). This implementation
37 makes it easy to provide your own parser for the data. You need to
38 only implement one function next_individual. You can also implement
39 next_population if your data has explicit information about population
40 memberhsip for the indidviduals.
46 User feedback is an integral part of the evolution of this and other
47 Bioperl modules. Send your comments and suggestions preferably to
48 the Bioperl mailing list. Your participation is much appreciated.
50 bioperl-l@bioperl.org - General discussion
51 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
55 Please direct usage questions or support issues to the mailing list:
57 L<bioperl-l@bioperl.org>
59 rather than to the module maintainer directly. Many experienced and
60 reponsive experts will be able look at the problem and quickly
61 address it. Please include a thorough description of the problem
62 with code and data examples if at all possible.
66 Report bugs to the Bioperl bug tracking system to help us keep track
67 of the bugs and their resolution. Bug reports can be submitted via
70 http://bugzilla.open-bio.org/
72 =head1 AUTHOR - Jason Stajich
74 Email jason-at-bioperl.org
78 The rest of the documentation details each of the object methods.
79 Internal methods are usually preceded with a _
84 # Let the code begin...
86 # Set the Individual creation as a factory rather than
89 package Bio
::PopGen
::IO
;
92 # Object preamble - inherits from Bio::Root::Root
96 use base
qw(Bio::Root::IO);
101 Usage : my $obj = Bio::PopGen::IO->new();
102 Function: Builds a new Bio::PopGen::IO object
103 Returns : an instance of Bio::PopGen::IO
110 my($class,@args) = @_;
112 if( $class =~ /Bio::PopGen::IO::(\S+)/ ) {
113 my ($self) = $class->SUPER::new
(@args);
114 $self->_initialize(@args);
118 @param{ map { lc $_ } keys %param } = values %param; # lowercase keys
119 my $format = $param{'-format'} ||
120 $class->_guess_format( $param{'-file'} || $ARGV[0] ) || 'csv';
122 # normalize capitalization to lower case
123 $format = "\L$format";
125 return unless( $class->_load_format_module($format) );
126 return "Bio::PopGen::IO::${format}"->new(@args);
130 # _initialize is chained for all PopGen::IO classes
133 my($self, @args) = @_;
134 # my ($indfact, $popfact) = $self->_rearrange([qw(INDIVIDUAL_FACTORY
135 # POPULATION_FACTORY)],
137 # $indfact = Bio::PopGen::IndividualBuilder->new() unless $indfact;
138 # $indfact = Bio::PopGen::PopulationBuilder->new() unless $indfact;
140 # initialize the IO part
141 $self->_initialize_io(@args);
145 =head2 next_individual
147 Title : next_individual
148 Usage : my $ind = $popgenio->next_individual;
149 Function: Retrieve the next individual from a dataset
150 Returns : L<Bio::PopGen::IndividualI> object
158 $self->throw_not_implemented();
162 =head2 next_population
164 Title : next_population
165 Usage : my $pop = $popgenio->next_population;
166 Function: Retrieve the next population from a dataset
167 Returns : L<Bio::PopGen::PopulationI> object
169 Note : Many implementation will not implement this
175 $self->throw_not_implemented();
178 =head2 write_individual
180 Title : write_individual
181 Usage : $popgenio->write_individual($ind);
182 Function: Write an individual out in the implementation format
184 Args : L<Bio::PopGen::PopulationI> object(s)
188 sub write_individual
{
190 $self->throw_not_implemented();
195 =head2 write_population
197 Title : write_population
198 Usage : $popgenio->write_population($pop);
199 Function: Write a population out in the implementation format
201 Args : L<Bio::PopGen::PopulationI> object(s)
202 Note : Many implementation will not implement this
206 sub write_population
{
208 $self->throw_not_implemented();
215 Usage : $fh = Bio::SeqIO->newFh(-file=>$filename,-format=>'Format')
216 Function: does a new() followed by an fh()
217 Example : $fh = Bio::SeqIO->newFh(-file=>$filename,-format=>'Format')
218 $sequence = <$fh>; # read a sequence object
219 print $fh $sequence; # write a sequence object
220 Returns : filehandle tied to the Bio::SeqIO::Fh class
223 See L<Bio::SeqIO::Fh>
229 return unless my $self = $class->new(@_);
238 Example : $fh = $obj->fh; # make a tied filehandle
239 $sequence = <$fh>; # read a sequence object
240 print $fh $sequence; # write a sequence object
241 Returns : filehandle tied to Bio::SeqIO class
249 my $class = ref($self) || $self;
250 my $s = Symbol
::gensym
;
251 tie
$$s,$class,$self;
255 =head2 _load_format_module
257 Title : _load_format_module
258 Usage : *INTERNAL Bio::PopGen::IO stuff*
259 Function: Loads up (like use) a module at run time on demand
266 sub _load_format_module
{
267 my ($self,$format) = @_;
268 my $module = "Bio::PopGen::IO::" . $format;
272 $ok = $self->_load_module($module);
276 $self: $format cannot be found
278 For more information about the Bio::PopGen::IO system please see the
279 Bio::PopGen::IO docs. This includes ways of checking for formats at
280 compile time, not run time
290 Title : _guess_format
291 Usage : $obj->_guess_format($filename)
294 Returns : guessed format of filename (lower case)
302 return unless $_ = shift;
303 return 'csv' if (/csv/i or /\.dat\w$/i);
308 $self->SUPER::close(@_);
318 return bless {processor
=> shift}, $class;
323 return $self->{'processor'}->next_result() unless wantarray;
325 push @list, $obj while $obj = $self->{'processor'}->next_result();
331 $self->{'processor'}->write_result(@_);