Skip to content

Commit

Permalink
some POD for NameHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
rbuels committed Feb 3, 2012
1 parent d4c2829 commit a14bbd7
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions lib/NameHandler.pm
Original file line number Diff line number Diff line change
@@ -1,3 +1,26 @@
=head1 NAME
NameHandler - create JSON indices of feature names
=head1 SYNOPSIS
# instantiate with a callback that gives the directory to use for a
# given reference sequence
my $nameHandler = NameHandler->new(
sub { "$trackDir/" . $_[0] . "/" . $track->{"track"}; };
);
for my $name ( @feature_names ) {
$nameHandler->addName( $name );
}
# write out the finished names index
$nameHandler->finish;
=head1 METHODS
=cut

package NameHandler;

use strict;
Expand All @@ -16,6 +39,14 @@ our $chromIndex = 3;

my $nameFile = "names.json";

=head1 new( \&directory_callback )
Make a new NameHandler. Takes a subroutine reference that should take
a reference sequence name as an argument and return the path to the
directory that should contain the name index we generate.
=cut

sub new {
my ($class, $trackDirForChrom) = @_;

Expand All @@ -28,6 +59,13 @@ sub new {
return $self;
}

=head1 addName( \@name_record )
Name record (an arrayref) to add to the names index. Generated by the
BioperlFlattener.
=cut

sub addName {
my ($self, $nameArr) = @_;
my $chrom = $nameArr->[$chromIndex];
Expand All @@ -47,6 +85,14 @@ sub addName {
or die "couldn't write to file for $chrom: $!";
}

=head1 newChrom( $refSeqName )
Given the name of the reference sequence, returns a filehandle to the
proper name index file. Makes a new directory to hold the file if
necessary.
=cut

sub newChrom {
my ($self, $chrom) = @_;
my $chromDir = $self->{trackDirForChrom}->($chrom);
Expand All @@ -60,6 +106,12 @@ sub newChrom {
return $fh;
}

=head1 finish
Finalize and flush to disk any currently open name index.
=cut

sub finish {
my ($self) = @_;
foreach my $chrom (keys %{$self->{nameFiles}}) {
Expand Down

0 comments on commit a14bbd7

Please sign in to comment.