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
;
82 use base
qw(Bio::Root::IO);
87 Usage : my $obj = Bio::Matrix::IO->new();
88 Function: Builds a new Bio::Matrix::IO object
89 Returns : an instance of Bio::Matrix::IO
96 my($caller,@args) = @_;
97 my $class = ref($caller) || $caller;
99 # or do we want to call SUPER on an object if $caller is an
101 if( $class =~ /Bio::Matrix::IO::(\S+)/ ) {
102 my ($self) = $class->SUPER::new
(@args);
103 $self->_initialize(@args);
108 @param{ map { lc $_ } keys %param } = values %param; # lowercase keys
109 my $format = $param{'-format'} ||
110 $class->_guess_format( $param{'-file'} || $ARGV[0] ) ||
112 $format = "\L$format"; # normalize capitalization to lower case
114 # normalize capitalization
115 return unless( $class->_load_format_module($format) );
116 return "Bio::Matrix::IO::$format"->new(@args);
123 Usage : $fh = Bio::Matrix::IO->newFh(-file=>$filename,-format=>'Format')
124 Function: does a new() followed by an fh()
125 Example : $fh = Bio::Matrix::IO->newFh(-file=>$filename,-format=>'Format')
126 $matrix = <$fh>; # read a matrix object
127 print $fh $matrix; # write a matrix object
128 Returns : filehandle tied to the Bio::SeqIO::Fh class
135 return unless my $self = $class->new(@_);
143 Function: Get a filehandle type access to the matrix parser
144 Example : $fh = $obj->fh; # make a tied filehandle
145 $matrix = <$fh>; # read a matrix object
146 print $fh $matrix; # write a matrix object
147 Returns : filehandle tied to Bio::Matrix::IO class
155 my $class = ref($self) || $self;
156 my $s = Symbol
::gensym
;
157 tie
$$s,$class,$self;
165 Usage : $format = $obj->format()
166 Function: Get the matrix format
167 Returns : matrix format
172 # format() method inherited from Bio::Root::IO
178 Usage : my $matrix = $matixio->next_matrix;
179 Function: Parse the next matrix from the data stream
180 Returns : L<Bio::Matrix::MatrixI> type object or undef when finished
188 $self->throw_not_implemented();
194 Usage : $io->write_matrix($matrix)
195 Function: Writes a matrix out to the data stream
197 Args : Array of Bio::Matrix::MatrixI object
198 - note that not all matricies can be converted to
199 each format, beware with mixing matrix types and output formats
205 $self->throw_not_implemented();
209 my ($self,@args) = @_;
210 $self->_initialize_io(@args);
213 =head2 _load_format_module
215 Title : _load_format_module
216 Usage : *INTERNAL Matrix::IO stuff*
217 Function: Loads up (like use) a module at run time on demand
221 sub _load_format_module
{
222 my ($self,$format) = @_;
223 my $module = "Bio::Matrix::IO::" . $format;
227 $ok = $self->_load_module($module);
231 $self: $format cannot be found
233 For more information about the Matrix::IO system please see the
234 Matrix::IO docs. This includes ways of checking for formats at
235 compile time, not run time
245 Title : _guess_format
246 Usage : $obj->_guess_format($filename)
247 Returns : guessed format of filename (lower case)
254 return unless $_ = shift;
255 return 'scoring' if /BLOSUM|PAM$/i;
256 return 'phylip' if /\.dist$/i;
266 return bless {'matrixio' => shift},$class;
271 return $self->{'matrixio'}->next_tree() unless wantarray;
273 push @list,$obj while $obj = $self->{'treeio'}->next_tree();
279 $self->{'matrixio'}->write_tree(@_);