| Summary | Package variables | Synopsis | Description | General documentation | Methods |
| Summary | Top |
| Clair::Bio::GeneRIF - Perl module for parsing GeneRIF files |
| Package variables | Top |
| No package variables defined. |
| Included modules | Top |
| Fcntl |
| MLDBM qw ( DB_File ) |
| strict |
| Synopsis | Top |
use Clair::Bio::GeneRIF; |
| Description | Top |
| This module is used to parse GeneRIFs files. A GeneRIF file has the following format: the first line is meta-data that labels each tab-delimited field, and the rest of the lines are those fields. The parsed file is saved into a DBM file after being parsed. The module will look for a DBM file before attempting to parse the text file, unless the 'reload' parameter is passed with a true value to the constructor. Access to the data is done by passing a gene_id value to the get_records_from_id method, which returns a list of all the GeneRIFs with the given gene_id. Additionaly, you may access all GeneRIF entries at once using the get_all_records method. This will most likely be a large hash, backed by a DBM, so it would be best to use the each() function to iterate over its keys and values. This module uses DB_File to store nested data structures. |
| Methods | Top |
| _convert_to_dbm | No description | Code |
| _dbm_exists | No description | Code |
| _open_records | No description | Code |
| _read_fields | No description | Code |
| get_all_records | Description | Code |
| get_fields | Description | Code |
| get_records_from_id | Description | Code |
| get_total_records | Description | Code |
| new | Description | Code |
| get_all_records | code | next | Top |
my @all_records = $generif->get_all_records();Returns all records from the GeneRIF file as a hashref mapping gene_ids to |
| get_fields | code | prev | next | Top |
my @field_names = $generif->get_fields();Returns a list of the field names. These are the keys in each record. |
| get_records_from_id | code | prev | next | Top |
my @records = $generif->get_records_from_id($gene_id);Returns a list of records with the given gene_id. Each record is an array |
| get_total_records | code | prev | next | Top |
my $total = $generif->get_total_records();Returns the total number of records. |
| new | code | prev | next | Top |
|
| _convert_to_dbm | description | prev | next | Top |
sub _convert_to_dbm
{
my $self = shift;
my $key_index = 1;
my %records = ();
if (-e $self->{dbm}) {
unlink($self->{dbm}) or die "Couldn't remove $self->{dbm}: $!";
}
tie (%records, "MLDBM", $self->{dbm}, O_CREAT|O_RDWR, 0666)
or die "Couldn't open DBM: $!";
my @field_names = $self->_read_fields();
open FILE, "< $self->{path}" or die "Couldn't open $self->{path}: $!";
# Get rid of first line} |
| _dbm_exists | description | prev | next | Top |
sub _dbm_exists
{ my $self = shift;
return glob("$self->{dbm}*");} |
| _open_records | description | prev | next | Top |
sub _open_records
{ my $self = shift;
my %records = ();
tie (%records, "MLDBM", $self->{dbm}, O_RDONLY, 0444)
or die "Couldn't open $self->{dbm}: $!";
$self->{records} =\% records;
$self->_read_fields();} |
| _read_fields | description | prev | next | Top |
sub _read_fields
{ my $self = shift;
open FILE, "< $self->{path}" or die "Couldn't open $self->{path}: $!";
my @field_names;
my $line = <FILE>;
chomp $line;
if ($line =~ /^#/) {
$line =~ s/^#\s*//g;
@field_names = split /\t/, $line;
} else {
die "Unexpected format: first line must begin with # followed by "
. "field names";
}
close FILE;
$self->{fields} =\@ field_names;
return @field_names;} |
| get_all_records | description | prev | next | Top |
sub get_all_records
{ my $self = shift;
return $self->{records};} |
| get_fields | description | prev | next | Top |
sub get_fields
{ my $self = shift;
return @{$self->{fields}};} |
| get_records_from_id | description | prev | next | Top |
sub get_records_from_id
{ my $self = shift;
my $id = shift;
my $listref = $self->{records}->{$id} || [];
return @{ $listref };} |
| get_total_records | description | prev | next | Top |
sub get_total_records
{ my $self = shift;
my %records = %{$self->{records}};
unless (defined $self->{total}) {
$self->{total} = 0;
while (my ($key, $listref) = each %records) {
$self->{total} += @$listref;
}
}
return $self->{total};} |
| new | description | prev | next | Top |
sub new
{ my $class = shift;
my %params = @_;
die "'path' is a required parameter" unless defined $params{path};
my $dbm = $params{path} . ".dbm";
$params{dbm} = $dbm;
my $self = bless\% params, $class;
# See if the dbm already exists} |
| AUTHOR | Top |
| Tony Fader, afader@umich.edu |