3 # BioPerl module for Bio::Matrix::IO
5 # Cared for by Jason Stajich <jason-at-bioperl-dot-org>
7 # Copyright Jason Stajich
9 # You may distribute this module under the same terms as perl itself
11 # POD documentation - main docs before the code
15 Bio::Matrix::IO - A factory for Matrix parsing
20 my $parser = Bio::Matrix::IO->new(-format => 'scoring',
21 -file => 'BLOSUMN50');
23 my $matrix = $parser->next_matrix;
27 This is a general factory framework for writing parsers for Matricies.
28 This includes parsing output from distance output like PHYLIP's
29 ProtDist. Additionally it should be possible to fit parsers for PWM
30 and PSSMs once their Matrix objects are written.
36 User feedback is an integral part of the evolution of this and other
37 Bioperl modules. Send your comments and suggestions preferably to
38 the Bioperl mailing list. Your participation is much appreciated.
40 bioperl-l@bioperl.org - General discussion
41 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
45 Report bugs to the Bioperl bug tracking system to help us keep track
46 of the bugs and their resolution. Bug reports can be submitted via
49 http://bugzilla.open-bio.org/
51 =head1 AUTHOR - Jason Stajich
53 Email jason-at-bioperl-dot-org
57 The rest of the documentation details each of the object methods.
58 Internal methods are usually preceded with a _
63 # Let the code begin...
66 package Bio
::Matrix
::IO
;
70 use base
qw(Bio::Root::IO);
75 Usage : my $obj = Bio::Matrix::IO->new();
76 Function: Builds a new Bio::Matrix::IO object
77 Returns : an instance of Bio::Matrix::IO
84 my($caller,@args) = @_;
85 my $class = ref($caller) || $caller;
87 # or do we want to call SUPER on an object if $caller is an
89 if( $class =~ /Bio::Matrix::IO::(\S+)/ ) {
90 my ($self) = $class->SUPER::new
(@args);
91 $self->_initialize(@args);
96 @param{ map { lc $_ } keys %param } = values %param; # lowercase keys
97 my $format = $param{'-format'} ||
98 $class->_guess_format( $param{'-file'} || $ARGV[0] ) ||
100 $format = "\L$format"; # normalize capitalization to lower case
102 # normalize capitalization
103 return unless( $class->_load_format_module($format) );
104 return "Bio::Matrix::IO::$format"->new(@args);
111 Usage : $fh = Bio::Matrix::IO->newFh(-file=>$filename,-format=>'Format')
112 Function: does a new() followed by an fh()
113 Example : $fh = Bio::Matrix::IO->newFh(-file=>$filename,-format=>'Format')
114 $matrix = <$fh>; # read a matrix object
115 print $fh $matrix; # write a matrix object
116 Returns : filehandle tied to the Bio::SeqIO::Fh class
123 return unless my $self = $class->new(@_);
131 Function: Get a filehandle type access to the matrix parser
132 Example : $fh = $obj->fh; # make a tied filehandle
133 $matrix = <$fh>; # read a matrix object
134 print $fh $matrix; # write a matrix object
135 Returns : filehandle tied to Bio::Matrix::IO class
143 my $class = ref($self) || $self;
144 my $s = Symbol
::gensym
;
145 tie
$$s,$class,$self;
153 Usage : my $matrix = $matixio->next_matrix;
154 Function: Parse the next matrix from the data stream
155 Returns : L<Bio::Matrix::MatrixI> type object or undef when finished
163 $self->throw_not_implemented();
169 Usage : $io->write_matrix($matrix)
170 Function: Writes a matrix out to the data stream
172 Args : Array of Bio::Matrix::MatrixI object
173 - note that not all matricies can be converted to
174 each format, beware with mixing matrix types and output formats
180 $self->throw_not_implemented();
184 my ($self,@args) = @_;
185 $self->_initialize_io(@args);
188 =head2 _load_format_module
190 Title : _load_format_module
191 Usage : *INTERNAL Matrix::IO stuff*
192 Function: Loads up (like use) a module at run time on demand
196 sub _load_format_module
{
197 my ($self,$format) = @_;
198 my $module = "Bio::Matrix::IO::" . $format;
202 $ok = $self->_load_module($module);
206 $self: $format cannot be found
208 For more information about the Matrix::IO system please see the
209 Matrix::IO docs. This includes ways of checking for formats at
210 compile time, not run time
220 Title : _guess_format
221 Usage : $obj->_guess_format($filename)
222 Returns : guessed format of filename (lower case)
229 return unless $_ = shift;
230 return 'scoring' if /BLOSUM|PAM$/i;
231 return 'phylip' if /\.dist$/i;
241 return bless {'matrixio' => shift},$class;
246 return $self->{'matrixio'}->next_tree() unless wantarray;
248 push @list,$obj while $obj = $self->{'treeio'}->next_tree();
254 $self->{'matrixio'}->write_tree(@_);