Bio-FeatureIO

 view release on metacpan or  search on metacpan

lib/Bio/FeatureIO/ptt.pm  view on Meta::CPAN

  my($self,%arg) = @_;

  $self->SUPER::_initialize(%arg);

  if ($self->mode eq 'r') {
    # Line 1
    my $desc = $self->_readline();
    chomp $desc;
    $self->description($desc);
    # Line 2
    my $line = $self->_readline();
    $line =~ m/^(\d+) proteins/ or $self->throw("Invalid protein count");
    $self->protein_count($1);
    # Line 3
    $self->_readline();
  }
}

=head2 next_feature

 Title   : next_feature
 Usage   : $io->next_feature()
 Function: read the next feature from the PTT file
 Example : 
 Args    : 
 Returns : Bio::SeqFeatureI object

=cut

sub next_feature {
  my $self = shift;
  $self->mode eq 'r' || return; # returns if can't read next_feature when we're in write mode
  
  my $line = $self->_readline() or return; # returns if end of file, no more features?
  chomp $line;
  my @col = split m/\t/, $line;
  @col==$NUM_COL or $self->throw("Too many columns for PTT line");

  $col[0] =~ m/(\d+)\.\.(\d+)/ or $self->throw("Invalid location (column 1)");
  my $feat = Bio::SeqFeature::Generic->new(-start=>$1, -end=>$2, -primary=>'CDS');
  $col[1] =~ m/^([+-])$/ or $self->throw("Invalid strand (column 2)");
  $feat->strand($1 eq '+' ? +1 : -1);
  for my $i (2 .. $NUM_COL-1) {
    $feat->add_tag_value($NAME_OF{$i}, $col[$i]) if $col[$i] ne '-';
  }
  return $feat;
}

=head2 write_feature (NOT IMPLEMENTED)

 Title   : write_feature
 Usage   : $io->write_feature($feature)
 Function: write a Bio::SeqFeatureI object in PTT format
 Example : 
 Args    : Bio::SeqFeatureI object
 Returns : 

=cut

sub write_feature {
  shift->throw_not_implemented;
}

=head2 description

 Title   : description
 Usage   : $obj->description($newval)
 Function: set/get the PTT file description for/from line one
 Example : 
 Returns : value of description (a scalar)
 Args    : on set, new value (a scalar or undef, optional)

=cut

sub description {
  my $self = shift;
  return $self->{'description'} = shift if @_;
  return $self->{'description'};
}

=head2 protein_count

 Title   : protein_count
 Usage   : $obj->protein_count($newval)
 Function: set/get the PTT protein count for/from line two
 Example : 
 Args    : on set, new value (a scalar or undef, optional)
 Returns : value of protein_count (a scalar)

=cut

sub protein_count {
  my $self = shift;
  return $self->{'protein_count'} = shift if @_;
  return $self->{'protein_count'};
}

1;



( run in 0.934 second using v1.01-cache-2.11-cpan-e1769b4cff6 )