Bio::Gonzales::Matrix::IO - Library for simple matrix IO
use Bio::Gonzales::Matrix::IO qw(lspew mslurp lslurp mspew);
Provides functions for common matrix/list IO.
Save the values in @matrix to a $filename or $filehandle. @matrix is an array of arrayrefs:
@matrix
$filename
$filehandle
@matrix = ( [ l11, l12, l13 ], [ l21, l22, l23 ], [ l31, l32, l33 ] );
Options:
Supply a header. Same as
mspew($file, [ \@header, @matrix ])
Supply row names or if not an array but true, use the header as row names
mspew( $file, $matrix, { row_names => 1 } ); #use header mspew( $file, $matrix, { row_names => [ 'row1', '...', 'rown' ] } ); #use supplied row names
If a row has less columns than the longest row of the matrix, fill it up with empty strings.
Use this value in case undefined values are found. Default is 'NA'.
Set a separator for the output file
Add empty columns to fill up to a square.
Reads in the contents of $file and puts it in a array of arrayrefs.
$file
You can set the delimiter via the configuration by supplying { sep => qr/\t/ } as config hash.
{ sep => qr/\t/ }
Further options with defaults:
%config = ( sep => qr/\t/, # set column separator header => 0, # parse header skip => 0, # skip the first N lines (without header) row_names => 0, # parse row names comment => qr/^#/ # the comment character );
spews out a list of values to a file. It can handle filenames and filehandles, but if you supply a handle, you have to close it on your own. The $list can be a
$list
results in keya avalue0 avalue1 keyb bvalue0 bvalue1 ...
results in keya valuea keyb valueb ...
results in value0 value1 ...
$config_options is a hash ref. It can take the options:
$config_options
$config_options = { delim => "\t", };
Reads the context of a file, splits the input lines acording to mslurp rules and takes the first element as hash reference. The remaining part of the line is stored as array reference under the key (first element). The configuration options are the same as in mslurp.
The default behaviour can be influenced by
%config = ( idx_col => 0, # set a different index column as hash key, 0-based has_duplicates => 0, # allow duplicate entries in the index column. ... );
If duplicates are allowed, the result data structure has the form
%data = ( "key1" => [ [ elem_x, elem_y, elem_z ], [ elem_x, elem_y, elem_z ], ... ], "key2" => [ [ elem_x, elem_y, elem_z ], [ elem_x, elem_y, elem_z ], ... ], );
If no duplicates are allowed, %data has the structure
%data
%data = ( "key1" => [ elem_x, elem_y, elem_z ], "key2" => [ elem_x, elem_y, elem_z ], );
hslurp dies with stacktrace if it hits a duplicate key in the index column.
hslurp
jw bargsten, <joachim.bargsten at wur.nl>
<joachim.bargsten at wur.nl>
To install Bio::Gonzales, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Bio::Gonzales
CPAN shell
perl -MCPAN -e shell install Bio::Gonzales
For more information on module installation, please visit the detailed CPAN module installation guide.