Skip to content

Commit

Permalink
forgot handler and parent class
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Fields committed Apr 14, 2012
1 parent f62817d commit 48cc553
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 26 deletions.
20 changes: 9 additions & 11 deletions lib/Bio/FeatureIO.pm
Expand Up @@ -47,7 +47,7 @@ An I/O iterator subsystem for genomic sequence features. This set of parsers
can be used on many levels:
1) Simple parsing: the next_dataset() method returns hash-refs containing
both the data parsed and
both the data parsed and
Bio::FeatureIO is a handler module for the formats in the FeatureIO set (eg,
Bio::FeatureIO::GFF). It is the officially sanctioned way of getting at the
Expand Down Expand Up @@ -227,15 +227,15 @@ Your participation is much appreciated.
bioperl-l@bioperl.org - General discussion
http://bioperl.org/wiki/Mailing_lists - About the mailing lists
=head2 Support
=head2 Support
Please direct usage questions or support issues to the mailing list:
I<bioperl-l@bioperl.org>
rather than to the module maintainer directly. Many experienced and
reponsive experts will be able look at the problem and quickly
address it. Please include a thorough description of the problem
rather than to the module maintainer directly. Many experienced and
reponsive experts will be able look at the problem and quickly
address it. Please include a thorough description of the problem
with code and data examples if at all possible.
=head2 Reporting Bugs
Expand Down Expand Up @@ -336,7 +336,7 @@ sub _initialize {
$format ||= 'GFF3';
$handler_args ||= {};
(ref($handler_args) eq 'HASH') ||
$self->throw("-handler_args must be a hash reference");
$self->throw("-handler_args must be a hash reference");
$handler ||= Bio::FeatureIO::Handler::GenericFeatureHandler->new(
-verbose => $self->verbose,
-fh => $self->_fh,
Expand All @@ -345,7 +345,7 @@ sub _initialize {
$seq && $self->seq( $seq);

$self->_init_stream();
$self->handler($handler);
$self->handler($handler);
}

=head2 newFh
Expand Down Expand Up @@ -508,12 +508,12 @@ END
sub _guess_format {
my $class = shift;
return unless $_ = shift;
return 'gff' if /\.gff3?$/i;
return 'gff3' if /\.gff3$/i;
return 'gff' if /\.gtf$/i;
return 'bed' if /\.bed$/i;
return 'ptt' if /\.ptt$/i;

return 'gff'; #the default
return 'gff3'; #the default
}

sub _init_stream {
Expand Down Expand Up @@ -551,5 +551,3 @@ sub PRINT {
1;

__END__
42 changes: 27 additions & 15 deletions lib/Bio/FeatureIO/Handler/GenericFeatureHandler.pm
Expand Up @@ -6,24 +6,26 @@ use strict;
use warnings;
use Bio::Factory::ObjectFactory;
use Bio::SeqIO;
use Data::Dumper;
use feature qw(say);

my $ct = 0;
my %GFF3_RESERVED_TAGS = map {$_ => $ct++ }
qw(ID Name Alias Parent Target Gap
Derives_from Note Dbxref Ontology_term Index);

my %HANDLERS = (
# GFF3-specific
'directive' => \&directives,

# BED-specific
'track_definition' => \&track_definition,

# generic
'comment' => \&comment,
'feature' => \&seqfeature,
'sequence' => \&sequence,

# defaults (none for now)
#'default' => \&default
);
Expand All @@ -47,7 +49,7 @@ sub data_handler {
my $method = (exists $HANDLERS{$nm}) ? ($HANDLERS{$nm}) :
(exists $HANDLERS{'_DEFAULT_'}) ? ($HANDLERS{'_DEFAULT_'}) :
undef;

if ($method && ref $method eq 'CODE') {
return $self->$method($data);
} else {
Expand Down Expand Up @@ -153,12 +155,22 @@ sub seqfeature {
my ($handler, $data) = @_;
# TODO: Optionally type check ontology here, preferably prior to expending
# unnecessary energy/time on creating objects (Robert Bradbury rules)
return $handler->feature_factory->create_object(%{$data->{DATA}});
return $handler->feature_factory->create_object(
start => $data->{DATA}{start},
end => $data->{DATA}{end},
strand => $data->{DATA}{strand},
source => $data->{DATA}{source},
seq_id => $data->{DATA}{seq_id},
score => $data->{DATA}{score},
phase => $data->{DATA}{phase},
primary_tag => $data->{DATA}{type},
primary_id => exists $data->{DATA}{attributes}{ID} ? $data->{DATA}{attributes}{ID}[0] : undef,
);
}

sub directives {
my ($handler, $data) = @_;
my $directive = $data->{DATA}->{type};
my $directive = $data->{DATA}->{directive};
if ($directive eq 'sequence') {
my $fh = $handler->file_handle;
$handler->throw("Handler doesn't have a set file handle") if !$fh;
Expand All @@ -172,7 +184,7 @@ sub directives {
-start => $sf_data->{start},
-end => $sf_data->{end},
-strand => 1,
-seq_id => $sf_data->{id},
-seq_id => $sf_data->{seq_id},
-primary_tag => 'region');
} else {
# defaults for other directives?
Expand All @@ -182,15 +194,15 @@ sub directives {

sub sequence {
my ($handler, $data) = @_;

# So, at this point we have to decide whether to indicate this is the start
# of a sequence stream (i.e. grab the file handle and create a SeqIO), or
# allow further sequence data to be passed in. We punt and do the easy thing
# for now, but we should allow flexibility here, so maybe something
# configurable?

# Note this relies on having knowledge of the specific place in the stream

my ($start, $len) = @{$data}{qw(START LENGTH)};
my $fh = $handler->file_handle;
$handler->throw("Handler doesn't have a set file handle") if !$fh;
Expand Down Expand Up @@ -290,12 +302,12 @@ BioPerl mailing lists. Your participation is much appreciated.
Patches are always welcome.
=head2 Support
=head2 Support
Please direct usage questions or support issues to the mailing list:
L<bioperl-l@bioperl.org>
rather than to the module maintainer directly. Many experienced and reponsive
experts will be able look at the problem and quickly address it. Please include
a thorough description of the problem with code and data examples if at all
Expand Down

0 comments on commit 48cc553

Please sign in to comment.