Skip to content

Commit

Permalink
Implement write_feature() in FeatureIO::ptt
Browse files Browse the repository at this point in the history
  • Loading branch information
bosborne committed Jun 22, 2011
1 parent 2d0c41b commit 29f1f4b
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 5 deletions.
40 changes: 36 additions & 4 deletions Bio/FeatureIO/ptt.pm
Expand Up @@ -190,19 +190,51 @@ sub next_feature {
return $feat;
}

=head2 write_feature (NOT IMPLEMENTED)
=head2 write_feature
Title : write_feature
Usage : $io->write_feature($feature)
Function: write a Bio::SeqFeatureI object in PTT format
Function: write a Bio::SeqFeature object in PTT format with no header
Example :
Args : Bio::SeqFeatureI object
Args : Bio::SeqFeature object
Returns :
=cut

sub write_feature {
shift->throw_not_implemented;
my($self,$feat) = @_;

# Example, with header:
# Location Strand Length PID Gene Synonym Code COG Product
# 190..255 + 21 16763391 thrL STM0001 - - thr operon leader peptide

$self->throw("Only Bio::SeqFeature::Generic or Bio::SeqFeature::Annotated objects are writeable")
unless ( $feat->isa('Bio::SeqFeature::Generic') || $feat->isa('Bio::SeqFeature::Annotated') );

# Could be a problematic condition since it assumes all proteins have a
# primary tag of 'CDS' as in the Genbank files from NCBI
if ( $feat->primary_tag eq 'CDS' ) {

# Default
my ($len,$pid,$gene,$synonym,$code,$cog,$product) = qw(- - - - - - -);

my $start = $feat->start;
my $end = $feat->end;
my $loc = "$start..$end";

my $strand = $feat->strand == 1 ? '+' : '-';

$len = int(($end - $start)/3);

$product = join ' ',$feat->get_tag_values("product") if ($feat->has_tag("product"));
$pid = join ' ',$feat->get_tag_values("protein_id") if ($feat->has_tag("protein_id"));
$code = join ' ',$feat->get_tag_values("codon_start") if ($feat->has_tag("codon_start"));

$self->_print(join("\t",($loc,$strand,$len,$pid,$gene,$synonym,$code,$cog,$product)) . "\n");

$self->write_feature($_) foreach $feat->get_SeqFeatures();

}
}

=head2 description
Expand Down
2 changes: 1 addition & 1 deletion t/SeqFeature/FeatureIO.t
Expand Up @@ -203,7 +203,7 @@ is($f->seq_id, "chr1");

################################################################################
#
# use FeatureIO::gff to read a PTT file.
# use FeatureIO::ptt to read a PTT file.
#
$fcount = 0;

Expand Down

0 comments on commit 29f1f4b

Please sign in to comment.