Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Bio::SearchIO::hmmer: Add a hmmer2/3 compatibility module

Add back a Bio::SearchIO::hmmer module that decides which of the hmmer
parsers to instantiate based on the second line of input.
  • Loading branch information...
commit 2d4816f1d67880c69948b2ce529fdeb52e0d843f 1 parent 59ce452
@kblin authored
View
2  Bio/SearchIO.pm
@@ -54,7 +54,7 @@ A list of module names and formats is below:
waba WABA output
axt AXT format
sim4 Sim4
- hmmer HMMER hmmpfam and hmmsearch
+ hmmer HMMER2 hmmpfam and hmmsearch or HMMER3 hmmscan and hmmsearch
exonerate Exonerate CIGAR and VULGAR format
blastxml NCBI BLAST XML
wise Genewise -genesf format
View
164 Bio/SearchIO/hmmer.pm
@@ -0,0 +1,164 @@
+#
+# BioPerl module for Bio::SearchIO::hmmer
+#
+# Please direct questions and support issues to <bioperl-l@bioperl.org>
+#
+# Cared for by Kai Blin <kai.blin@biotech.uni-tuebingen.de>
+#
+# Copyright Kai Blin
+#
+# You may distribute this module under the same terms as perl itself
+#
+# POD documentation - main docs before the code
+
+=head1 NAME
+
+Bio::SearchIO::hmmer - A parser for HMMER2 and HMMER3 output (hmmscan, hmmsearch, hmmpfam)
+
+=head1 SYNOPSIS
+
+ # do not use this class directly it is available through Bio::SearchIO
+ use Bio::SearchIO;
+ my $in = Bio::SearchIO->new(-format => 'hmmer',
+ -file => 't/data/L77119.hmmer');
+ while( my $result = $in->next_result ) {
+ # this is a Bio::Search::Result::HMMERResult object
+ print $result->query_name(), " for HMM ", $result->hmm_name(), "\n";
+ while( my $hit = $result->next_hit ) {
+ print $hit->name(), "\n";
+ while( my $hsp = $hit->next_hsp ) {
+ print "length is ", $hsp->length(), "\n";
+ }
+ }
+ }
+
+=head1 DESCRIPTION
+
+This object implements a parser for HMMER output. It works with both HMMER2 and HMMER3
+
+=head1 FEEDBACK
+
+=head2 Mailing Lists
+
+User feedback is an integral part of the evolution of this and other
+Bioperl modules. Send your comments and suggestions preferably to
+the Bioperl mailing list. Your participation is much appreciated.
+
+ bioperl-l@bioperl.org - General discussion
+ http://bioperl.org/wiki/Mailing_lists - About the mailing lists
+
+=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
+with code and data examples if at all possible.
+
+=head2 Reporting Bugs
+
+Report bugs to the Bioperl bug tracking system to help us keep track
+of the bugs and their resolution. Bug reports can be submitted via the
+web:
+
+ http://bugzilla.open-bio.org/
+
+=head1 AUTHOR - Kai Blin
+
+Email kai.blin-at-biotech.uni-tuebingen.de
+
+=head1 APPENDIX
+
+The rest of the documentation details each of the object methods.
+Internal methods are usually preceded with a _
+
+=cut
+
+# Let the code begin...
+
+package Bio::SearchIO::hmmer;
+
+use strict;
+
+use Bio::Factory::ObjectFactory;
+
+use base qw(Bio::SearchIO);
+
+sub new {
+ my ( $caller, @args ) = @_;
+ my $class = ref($caller) || $caller;
+
+ if( $class =~ /Bio::SearchIO::hmmer(\d)/ ) {
+ my ($self) = $class->SUPER::new(@args);
+ $self->_initialize(@args);
+ return $self;
+ } else {
+ #FIXME: There's got to be a better way to do this:
+ my $format;
+ my $fh;
+ my $fh_needs_close = 0;
+ my %param = @args;
+
+ @param{ map { lc $_ } keys %param } = values %param; # lowercase keys
+
+ if (defined($param{"-fh"})) {
+ $fh = $param{"-fh"};
+ } elsif (defined($param{"-file"})) {
+ open($fh, $param{"-file"}) || return;
+ $fh_needs_close = 1;
+ }
+
+ # read second line of the file
+ <$fh>;
+ $_ = <$fh>;
+
+ if ( m/HMMER\s3/ ) {
+ $format = "hmmer3";
+ } else {
+ $format = "hmmer2";
+ }
+
+ if ($fh_needs_close) {
+ close($fh);
+ } else {
+ seek($fh, 0, 0);
+ }
+
+ return unless( $class->_load_format_module($format) );
+ return "Bio::SearchIO::${format}"->new(@args);
+ }
+}
+
+sub _initialize {
+ my ( $self, @args ) = @_;
+ $self->SUPER::_initialize(@args);
+ my $handler = $self->_eventHandler;
+ $handler->register_factory(
+ 'result',
+ Bio::Factory::ObjectFactory->new(
+ -type => 'Bio::Search::Result::HMMERResult',
+ -interface => 'Bio::Search::Result::ResultI'
+ )
+ );
+
+ $handler->register_factory(
+ 'hit',
+ Bio::Factory::ObjectFactory->new(
+ -type => 'Bio::Search::Hit::HMMERHit',
+ -interface => 'Bio::Search::Hit::HitI'
+ )
+ );
+
+ $handler->register_factory(
+ 'hsp',
+ Bio::Factory::ObjectFactory->new(
+ -type => 'Bio::Search::HSP::HMMERHSP',
+ -interface => 'Bio::Search::HSP::HSPI'
+ )
+ );
+}
+
+1;
View
26 Bio/SearchIO/hmmer2.pm
@@ -88,7 +88,7 @@ use Bio::Factory::ObjectFactory;
use vars qw(%MAPPING %MODEMAP
);
-use base qw(Bio::SearchIO);
+use base qw(Bio::SearchIO::hmmer);
BEGIN {
@@ -152,30 +152,6 @@ BEGIN {
sub _initialize {
my ( $self, @args ) = @_;
$self->SUPER::_initialize(@args);
- my $handler = $self->_eventHandler;
- $handler->register_factory(
- 'result',
- Bio::Factory::ObjectFactory->new(
- -type => 'Bio::Search::Result::HMMERResult',
- -interface => 'Bio::Search::Result::ResultI'
- )
- );
-
- $handler->register_factory(
- 'hit',
- Bio::Factory::ObjectFactory->new(
- -type => 'Bio::Search::Hit::HMMERHit',
- -interface => 'Bio::Search::Hit::HitI'
- )
- );
-
- $handler->register_factory(
- 'hsp',
- Bio::Factory::ObjectFactory->new(
- -type => 'Bio::Search::HSP::HMMERHSP',
- -interface => 'Bio::Search::HSP::HSPI'
- )
- );
$self->{'_hmmidline'} = 'HMMER 2.2g (August 2001)';
}
View
26 Bio/SearchIO/hmmer3.pm
@@ -80,7 +80,7 @@ use strict;
use Data::Dumper;
use Bio::Factory::ObjectFactory;
use vars qw(%MAPPING %MODEMAP);
-use base qw(Bio::SearchIO);
+use base qw(Bio::SearchIO::hmmer);
BEGIN {
@@ -144,30 +144,6 @@ BEGIN {
sub _initialize {
my( $self,@args ) = @_;
$self->SUPER::_initialize(@args);
- my $handler = $self->_eventHandler;
- $handler->register_factory(
- 'result',
- Bio::Factory::ObjectFactory->new(
- -type => 'Bio::Search::Result::HMMERResult',
- -interface => 'Bio::Search::Result::ResultI'
- )
- );
-
- $handler->register_factory(
- 'hit',
- Bio::Factory::ObjectFactory->new(
- -type => 'Bio::Search::Hit::HMMERHit',
- -interface => 'Bio::Search::Hit::HitI'
- )
- );
-
- $handler->register_factory(
- 'hsp',
- Bio::Factory::ObjectFactory->new(
- -type => 'Bio::Search::HSP::HMMERHSP',
- -interface => 'Bio::Search::HSP::HSPI'
- )
- );
$self->{'_hmmidline'} = 'HMMER 3.0b placeholder';
$self->{'_alnreport'} = 1; #does report include alignments
}
View
18 t/SearchIO/hmmer.t
@@ -12,7 +12,7 @@ BEGIN {
use_ok('Bio::SearchIO');
}
-my $searchio = Bio::SearchIO->new(-format => 'hmmer2',
+my $searchio = Bio::SearchIO->new(-format => 'hmmer',
-file => test_input_file('hmmpfam.out'));
while( my $result = $searchio->next_result ) {
@@ -75,7 +75,7 @@ while( my $result = $searchio->next_result ) {
last;
}
}
-$searchio = Bio::SearchIO->new(-format => 'hmmer2',
+$searchio = Bio::SearchIO->new(-format => 'hmmer',
-file => test_input_file('hmmsearch.out'));
while( my $result = $searchio->next_result ) {
is(ref($result),'Bio::Search::Result::HMMERResult', 'Check for the correct result reference type');
@@ -103,7 +103,7 @@ while( my $result = $searchio->next_result ) {
is($hsp->hit->seq_id(), 'Q91581', 'Check for hit seq_id');
}
-$searchio = Bio::SearchIO->new(-format => 'hmmer2',
+$searchio = Bio::SearchIO->new(-format => 'hmmer',
-file => test_input_file('L77119.hmmer'));
while( my $result = $searchio->next_result ) {
@@ -146,7 +146,7 @@ while( my $result = $searchio->next_result ) {
}
-$searchio = Bio::SearchIO->new(-format => 'hmmer2',
+$searchio = Bio::SearchIO->new(-format => 'hmmer',
-file => test_input_file('cysprot1b.hmmsearch'));
@@ -189,7 +189,7 @@ while( my $result = $searchio->next_result ) {
}
# test for bug 2632 - CS lines should get ignored without breaking the parser
-$searchio = Bio::SearchIO->new(-format => 'hmmer2', -file => test_input_file('hmmpfam_cs.out'));
+$searchio = Bio::SearchIO->new(-format => 'hmmer', -file => test_input_file('hmmpfam_cs.out'));
my $result = $searchio->next_result;
my $hit = $result->next_hit;
my $hsp = $hit->next_hsp;
@@ -198,7 +198,7 @@ is($hsp->seq_str, 'CGV-GFIADVNNVANHKIVVQALEALTCMEHRGACSADRDSGDGAGITTAIPWNLFQKSLQ
# Tests for hmmer3 output here
-$searchio = Bio::SearchIO->new(-format => 'hmmer3',
+$searchio = Bio::SearchIO->new(-format => 'hmmer',
-file => test_input_file('hmmscan.out'),
-verbose => 1);
@@ -236,7 +236,7 @@ while( my $result = $searchio->next_result ) {
}
}
-$searchio = Bio::SearchIO->new(-format => 'hmmer3',
+$searchio = Bio::SearchIO->new(-format => 'hmmer',
-file => test_input_file('hmmsearch3.out'),
-verbose => 1);
while( my $result = $searchio->next_result ) {
@@ -253,7 +253,7 @@ while( my $result = $searchio->next_result ) {
}
}
-$searchio = Bio::SearchIO->new(-format => 'hmmer3',
+$searchio = Bio::SearchIO->new(-format => 'hmmer',
-file => test_input_file('hmmscan_multi_domain.out'),
-verbose => 1);
@@ -300,7 +300,7 @@ while( my $result = $searchio->next_result ) {
}
}
-$searchio = Bio::SearchIO->new(-format => 'hmmer3',
+$searchio = Bio::SearchIO->new(-format => 'hmmer',
-file => test_input_file('hmmscan_sec_struct.out'),
-verbose => 1);
Please sign in to comment.
Something went wrong with that request. Please try again.