BioPerl

 view release on metacpan or  search on metacpan

Bio/SearchIO/waba.pm  view on Meta::CPAN

	  'Hsp_hseq'      =>  'HSP-hit_seq',
	  'Hsp_midline'   =>  'HSP-homology_seq',
	  'Hsp_stateseq'  =>  'HSP-hmmstate_seq',
	  'Hsp_align-len' =>  'HSP-hsp_length',
	  
	  'Hit_id'        => 'HIT-name',
	  'Hit_accession' => 'HIT-accession',

	  'WABAOutput_program'  => 'RESULT-algorithm_name',
	  'WABAOutput_version'  => 'RESULT-algorithm_version',
	  'WABAOutput_query-def'=> 'RESULT-query_name',
	  'WABAOutput_query-db' => 'RESULT-query_database',
 	  'WABAOutput_db'       => 'RESULT-database_name',
	  );
}


use base qw(Bio::SearchIO);

=head2 new

 Title   : new
 Usage   : my $obj = Bio::SearchIO::waba->new();
 Function: Builds a new Bio::SearchIO::waba object 
 Returns : Bio::SearchIO::waba
 Args    : see Bio::SearchIO

=cut

sub _initialize {
    my ($self,@args) = @_;
    $self->SUPER::_initialize(@args);
    $self->_eventHandler->register_factory('result', Bio::Search::Result::ResultFactory->new(-type => 'Bio::Search::Result::WABAResult'));

    $self->_eventHandler->register_factory('hsp', Bio::Search::HSP::HSPFactory->new(-type => 'Bio::Search::HSP::WABAHSP'));
}


=head2 next_result

 Title   : next_result
 Usage   : my $hit = $searchio->next_result;
 Function: Returns the next Result from a search
 Returns : Bio::Search::Result::ResultI object
 Args    : none

=cut

sub next_result{
    my ($self) = @_;
    local $/ = "\n";
    local $_;
    
    my ($curquery,$curhit);
    my $state = -1;
    $self->start_document();
    my @hit_signifs;
    while( defined ($_ = $self->_readline )) { 
	
	if( $state == -1 ) {
	    my ($qid, $qhspid,$qpercent, $junk,
		$alnlen,$qdb,$qacc,$qstart,$qend,$qstrand,
		$hitdb,$hacc,$hstart,$hend,
		$hstrand) =
		    ( /^(\S+)\.(\S+)\s+align\s+ # get the queryid
		      (\d+(\.\d+)?)\%\s+     # get the percentage
		      of\s+(\d+)\s+  # get the length of the alignment
		      (\S+)\s+           # this is the query database
		      (\S+):(\-?\d+)\-(\-?\d+) # The accession:start-end for query
		      \s+([\-\+])        # query strand
		      \s+(\S+)\.         # hit db
		      (\S+):(\-?\d+)\-(\-?\d+) # The accession:start-end for hit
		      \s+([\-\+])\s*$    # hit strand
		      /ox );
	    
	    # Curses.  Jim's code is 0 based, the following is to readjust
	    if( $hstart < 0 ) { $hstart *= -1}
	    if( $hend   < 0 ) { $hend   *= -1}
	    if( $qstart < 0 ) { $qstart *= -1}
	    if( $qend   < 0 ) { $qend   *= -1}
	    $hstart++; $hend++; $qstart++; $qend++;
	    if( ! defined $alnlen ) {
		$self->warn("Unable to parse the rest of the WABA alignment info for: '$_'");
		last;
	    }
	    $self->{'_reporttype'} = 'WABA'; # hardcoded - only 
	                                     # one type of WABA AFAIK	    
	    if( defined $curquery && 
		$curquery ne $qid ) { 
		$self->end_element({'Name' => 'Hit'});
		$self->_pushback($_);
		$self->end_element({'Name' => 'WABAOutput'});
		return $self->end_document();
	    } 
	    
	    if( defined $curhit &&
		$curhit ne $hacc) {
		# slight duplication here -- keep these in SYNC
		$self->end_element({'Name' => 'Hit'});
		$self->start_element({'Name' => 'Hit'});
		$self->element({'Name' => 'Hit_id',
				'Data' => $hacc});
		$self->element({'Name' => 'Hit_accession',
				'Data' => $hacc});

	    } elsif ( ! defined $curquery ) {
		$self->start_element({'Name' => 'WABAOutput'});
		$self->{'_result_count'}++;
		$self->element({'Name' => 'WABAOutput_query-def',
				'Data' => $qid });
		$self->element({'Name' => 'WABAOutput_program',
				'Data' => 'WABA'});
		$self->element({'Name' => 'WABAOutput_query-db',
				'Data' => $qdb});
		$self->element({'Name' => 'WABAOutput_db',
				'Data' => $hitdb});
		
		# slight duplication here -- keep these N'SYNC ;-)
		$self->start_element({'Name' => 'Hit'});
		$self->element({'Name' => 'Hit_id',
				'Data' => $hacc});
		$self->element({'Name' => 'Hit_accession',
				'Data' => $hacc});
	    }

	    



( run in 0.767 second using v1.01-cache-2.11-cpan-39bf76dae61 )