JPRED-2 Current state of the SVN trank
[jpred.git] / jpred / lib / Sequence / File.pm
index 77b64da..188966c 100644 (file)
@@ -14,12 +14,13 @@ Returns all records so far found in the file.
 =cut
 
 sub get_entries {
-       my ($self) = @_;
+  my ($self) = @_;
 
-       if (exists $self->{__PACKAGE__."entries"}) {
-               return @{ $self->{__PACKAGE__."entries"} };
-       }
-       else { return undef; }
+  if ( exists $self->{ __PACKAGE__ . "entries" } ) {
+    return @{ $self->{ __PACKAGE__ . "entries" } };
+  } else {
+    return undef;
+  }
 }
 
 =head2 $file->get_entry(@positions);
@@ -29,12 +30,13 @@ Retrieves the @position's'th record found in the file or undef if there is no su
 =cut
 
 sub get_entry {
-       my ($self, @offsets) = @_;
+  my ( $self, @offsets ) = @_;
 
-       if (exists $self->{__PACKAGE__."entries"} and @offsets) {
-               return @{ $self->{__PACKAGE__."entries"} }[@offsets];
-       }
-       else { return undef }
+  if ( exists $self->{ __PACKAGE__ . "entries" } and @offsets ) {
+    return @{ $self->{ __PACKAGE__ . "entries" } }[@offsets];
+  } else {
+    return undef;
+  }
 }
 
 =head2 $self->add_entries(@entries)
@@ -44,29 +46,29 @@ Adds more entries to the object. Returns the number of entries added to the obje
 =cut
 
 sub add_entries {
-       my ($self, @entries) = @_;
-       return unless @entries;
-
-       for (@entries) {
-               croak "Adding non Sequence object" unless isa $_, "Sequence";
-               $self->_ids($_->id);
-               push @{ $self->{__PACKAGE__."entries"} }, $_;
-       }
-
-#      my $max = $self->get_max_entries;
-#      if (defined $max) {
-#              my $exist_size = @{ $self->{__PACKAGE__."entries"} };
-#              if ($exist_size > $max) { return 0 }
-#              elsif ($exist_size + @entries > $max) {
-#                      return push @{ $self->{__PACKAGE__."entries"} }, @entries[0..$max - $exist_size];
-#              }
-#              else {
-#                      return push @{ $self->{__PACKAGE__."entries"} }, @entries;
-#              }
-#      }
-#      else {
-#              return push @{ $self->{__PACKAGE__."entries"} }, @entries;
-#      }
+  my ( $self, @entries ) = @_;
+  return unless @entries;
+
+  for (@entries) {
+    croak "Adding non Sequence object" unless isa $_, "Sequence";
+    $self->_ids( $_->id );
+    push @{ $self->{ __PACKAGE__ . "entries" } }, $_;
+  }
+
+  #    my $max = $self->get_max_entries;
+  #    if (defined $max) {
+  #            my $exist_size = @{ $self->{__PACKAGE__."entries"} };
+  #            if ($exist_size > $max) { return 0 }
+  #            elsif ($exist_size + @entries > $max) {
+  #                    return push @{ $self->{__PACKAGE__."entries"} }, @entries[0..$max - $exist_size];
+  #            }
+  #            else {
+  #                    return push @{ $self->{__PACKAGE__."entries"} }, @entries;
+  #            }
+  #    }
+  #    else {
+  #            return push @{ $self->{__PACKAGE__."entries"} }, @entries;
+  #    }
 }
 
 =head2 $file->get_entry_by_id(/regex/);
@@ -77,35 +79,37 @@ Returns all of those entries which have id's that match the regex.
 
 # Cache of sequence IDs for fast grepping
 sub _ids {
-       my ($self, $id) = @_;
-       if ($id) { push @{ $self->{__PACKAGE__."ids"} }, $id }
-       else { return @{ $self->{__PACKAGE__."ids"} } }
+  my ( $self, $id ) = @_;
+  if ($id) { push @{ $self->{ __PACKAGE__ . "ids" } }, $id }
+  else     { return @{ $self->{ __PACKAGE__ . "ids" } } }
 }
 
 sub get_entry_by_id {
-       my ($self, $id) = @_;
-       croak "No id passed" unless defined $id;
+  my ( $self, $id ) = @_;
+  croak "No id passed" unless defined $id;
 
-       #return grep { $_->id =~ /$id/ } $self->get_entries;
+  #return grep { $_->id =~ /$id/ } $self->get_entries;
 
-       {
-               my @ids = $self->_ids;
-               my @indices = grep { $ids[$_] =~ /$id/ } 0..$#ids;
-               return $self->get_entry(@indices);
-       }
+  {
+    my @ids = $self->_ids;
+    my @indices = grep { $ids[$_] =~ /$id/ } 0 .. $#ids;
+    return $self->get_entry(@indices);
+  }
 }
 
 =head2 $file->set_max_entries($size);
 
-Limits the storing of $size records. Will prevent the addition of more records, but won't delete existing records in the object if there are already more than $size entries.
+Limits the storing of $size records. Will prevent the addition of more records, 
+but won't delete existing records in the object if there are already more than 
+$size entries.
 
 =cut
 
 sub set_max_entries {
-       my ($self, $size) = @_;
+  my ( $self, $size ) = @_;
 
-       $self->{__PACKAGE__."max_size"} = $size;
-       return $size;
+  $self->{ __PACKAGE__ . "max_size" } = $size;
+  return $size;
 }
 
 =head2 $file->get_max_entries
@@ -115,8 +119,8 @@ Accessor for set_max_entries().
 =cut
 
 sub get_max_entries {
-       my ($self) = @_;
-       return $self->{__PACKAGE__."max_size"};
+  my ($self) = @_;
+  return $self->{ __PACKAGE__ . "max_size" };
 }
 
 =head2 
@@ -124,19 +128,19 @@ sub get_max_entries {
 =cut
 
 sub sub_seq {
-       my ($self, $start, $end) = @_;
+  my ( $self, $start, $end ) = @_;
 
-       croak "Not passed start and end arguments" unless 2 == grep { defined } $start, $end;
+  croak "Not passed start and end arguments" unless 2 == grep { defined } $start, $end;
 
-       # Produce a new version of myself, in the right namespace
-       my ($new_self) = (ref $self)->new;
+  # Produce a new version of myself, in the right namespace
+  my ($new_self) = ( ref $self )->new;
 
-       for ($self->get_entries) {
-               my ($seq) = $_->sub_seq($start, $end);
-               $new_self->add_entries($seq);
-       }
+  for ( $self->get_entries ) {
+    my ($seq) = $_->sub_seq( $start, $end );
+    $new_self->add_entries($seq);
+  }
 
-       return $new_self;
+  return $new_self;
 }
 
 1;