2 # BioPerl module for Bio::Matrix::IO
4 # Please direct questions and support issues to <bioperl-l@bioperl.org>
6 # Cared for by Jason Stajich <jason-at-bioperl-dot-org>
8 # Copyright Jason Stajich
10 # You may distribute this module under the same terms as perl itself
12 # POD documentation - main docs before the code
16 Bio::Matrix::IO - A factory for Matrix parsing
21 my $parser = Bio::Matrix::IO->new(-format => 'scoring',
22 -file => 'BLOSUMN50');
24 my $matrix = $parser->next_matrix;
28 This is a general factory framework for writing parsers for Matricies.
29 This includes parsing output from distance output like PHYLIP's
30 ProtDist. Additionally it should be possible to fit parsers for PWM
31 and PSSMs once their Matrix objects are written.
37 User feedback is an integral part of the evolution of this and other
38 Bioperl modules. Send your comments and suggestions preferably to
39 the Bioperl mailing list. Your participation is much appreciated.
41 bioperl-l@bioperl.org - General discussion
42 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
46 Please direct usage questions or support issues to the mailing list:
48 I<bioperl-l@bioperl.org>
50 rather than to the module maintainer directly. Many experienced and
51 reponsive experts will be able look at the problem and quickly
52 address it. Please include a thorough description of the problem
53 with code and data examples if at all possible.
57 Report bugs to the Bioperl bug tracking system to help us keep track
58 of the bugs and their resolution. Bug reports can be submitted via
61 https://github.com/bioperl/bioperl-live/issues
63 =head1 AUTHOR - Jason Stajich
65 Email jason-at-bioperl-dot-org
69 The rest of the documentation details each of the object methods.
70 Internal methods are usually preceded with a _
75 # Let the code begin...
78 package Bio
::Matrix
::IO
;
83 use base
qw(Bio::Root::IO);
88 Usage : my $obj = Bio::Matrix::IO->new();
89 Function: Builds a new Bio::Matrix::IO object
90 Returns : an instance of Bio::Matrix::IO
97 my($caller,@args) = @_;
98 my $class = ref($caller) || $caller;
100 # or do we want to call SUPER on an object if $caller is an
102 if( $class =~ /Bio::Matrix::IO::(\S+)/ ) {
103 my ($self) = $class->SUPER::new
(@args);
104 $self->_initialize(@args);
109 @param{ map { lc $_ } keys %param } = values %param; # lowercase keys
110 my $format = $param{'-format'} ||
111 $class->_guess_format( $param{'-file'} || $ARGV[0] ) ||
113 $format = "\L$format"; # normalize capitalization to lower case
115 # normalize capitalization
116 return unless( $class->_load_format_module($format) );
117 return "Bio::Matrix::IO::$format"->new(@args);
124 Usage : $fh = Bio::Matrix::IO->newFh(-file=>$filename,-format=>'Format')
125 Function: does a new() followed by an fh()
126 Example : $fh = Bio::Matrix::IO->newFh(-file=>$filename,-format=>'Format')
127 $matrix = <$fh>; # read a matrix object
128 print $fh $matrix; # write a matrix object
129 Returns : filehandle tied to the Bio::SeqIO::Fh class
136 return unless my $self = $class->new(@_);
144 Function: Get a filehandle type access to the matrix parser
145 Example : $fh = $obj->fh; # make a tied filehandle
146 $matrix = <$fh>; # read a matrix object
147 print $fh $matrix; # write a matrix object
148 Returns : filehandle tied to Bio::Matrix::IO class
156 my $class = ref($self) || $self;
157 my $s = Symbol
::gensym
;
158 tie
$$s,$class,$self;
166 Usage : $format = $obj->format()
167 Function: Get the matrix format
168 Returns : matrix format
173 # format() method inherited from Bio::Root::IO
179 Usage : my $matrix = $matixio->next_matrix;
180 Function: Parse the next matrix from the data stream
181 Returns : L<Bio::Matrix::MatrixI> type object or undef when finished
189 $self->throw_not_implemented();
195 Usage : $io->write_matrix($matrix)
196 Function: Writes a matrix out to the data stream
198 Args : Array of Bio::Matrix::MatrixI object
199 - note that not all matricies can be converted to
200 each format, beware with mixing matrix types and output formats
206 $self->throw_not_implemented();
210 my ($self,@args) = @_;
211 $self->_initialize_io(@args);
214 =head2 _load_format_module
216 Title : _load_format_module
217 Usage : *INTERNAL Matrix::IO stuff*
218 Function: Loads up (like use) a module at run time on demand
222 sub _load_format_module
{
223 my ($self,$format) = @_;
224 my $module = "Bio::Matrix::IO::" . $format;
228 $ok = $self->_load_module($module);
232 $self: $format cannot be found
234 For more information about the Matrix::IO system please see the
235 Matrix::IO docs. This includes ways of checking for formats at
236 compile time, not run time
246 Title : _guess_format
247 Usage : $obj->_guess_format($filename)
248 Returns : guessed format of filename (lower case)
255 return unless $_ = shift;
256 return 'scoring' if /BLOSUM|PAM$/i;
257 return 'phylip' if /\.dist$/i;
267 return bless {'matrixio' => shift},$class;
272 return $self->{'matrixio'}->next_tree() || undef unless wantarray;
274 push @list,$obj while $obj = $self->{'treeio'}->next_tree();
280 $self->{'matrixio'}->write_tree(@_);