1 package Sequence::File;
7 #use UNIVERSAL qw(isa);
8 use base qw(Root Read Write);
10 =head2 $file->get_entries
12 Returns all records so far found in the file.
19 if ( exists $self->{ __PACKAGE__ . "entries" } ) {
20 return @{ $self->{ __PACKAGE__ . "entries" } };
26 =head2 $file->get_entry(@positions);
28 Retrieves the @position's'th record found in the file or undef if there is no such sequence.
33 my ( $self, @offsets ) = @_;
35 if ( exists $self->{ __PACKAGE__ . "entries" } and @offsets ) {
36 return @{ $self->{ __PACKAGE__ . "entries" } }[@offsets];
42 =head2 $self->add_entries(@entries)
44 Adds more entries to the object. Returns the number of entries added to the object. This may be less than those passed if set_max_entries() has been called.
49 my ( $self, @entries ) = @_;
50 return unless @entries;
54 # croak "Adding non Sequence object" unless isa $_, "Sequence";
55 $self->_ids( $_->id );
56 push @{ $self->{ __PACKAGE__ . "entries" } }, $_;
60 =head2 $file->get_entry_by_id(/regex/);
62 Returns all of those entries which have id's that match the regex.
66 # Cache of sequence IDs for fast grepping
68 my ( $self, $id ) = @_;
69 if ($id) { push @{ $self->{ __PACKAGE__ . "ids" } }, $id }
70 else { return @{ $self->{ __PACKAGE__ . "ids" } } }
74 my ( $self, $id ) = @_;
75 croak "No id passed" unless defined $id;
77 #return grep { $_->id =~ /$id/ } $self->get_entries;
80 my @ids = $self->_ids;
81 my @indices = grep { $ids[$_] =~ /$id/ } 0 .. $#ids;
82 return $self->get_entry(@indices);
86 =head2 $file->set_max_entries($size);
88 Limits the storing of $size records. Will prevent the addition of more records,
89 but won't delete existing records in the object if there are already more than
95 my ( $self, $size ) = @_;
97 $self->{ __PACKAGE__ . "max_size" } = $size;
101 =head2 $file->get_max_entries
103 Accessor for set_max_entries().
107 sub get_max_entries {
109 return $self->{ __PACKAGE__ . "max_size" };
117 my ( $self, $start, $end ) = @_;
119 croak "Not passed start and end arguments" unless 2 == grep { defined } $start, $end;
121 # Produce a new version of myself, in the right namespace
122 my ($new_self) = ( ref $self )->new;
124 for ( $self->get_entries ) {
125 my ($seq) = $_->sub_seq( $start, $end );
126 $new_self->add_entries($seq);