BioPerl

 view release on metacpan or  search on metacpan

Bio/Search/HSP/ModelHSP.pm  view on Meta::CPAN


=cut

sub frac_conserved {
    my $self = shift;
    $self->warn('$hsp->frac_conserved not implemented for Model-based searches');
    return;
}

=head2 matches

=cut

sub matches {
    my $self = shift;
    $self->warn('$hsp->matches not implemented for Model-based searches');
    return;
}

=head2 num_conserved

=cut

sub num_conserved {
    my $self = shift;
    $self->warn('$hsp->num_conserved not implemented for Model-based searches');
    return;
}

=head2 num_identical

=cut

sub num_identical {
    my $self = shift;
    $self->warn('$hsp->num_identical not implemented for Model-based searches');
    return;
}

=head2 cigar_string

=cut


sub cigar_string {
    my $self = shift;
    $self->warn('$hsp->cigar_string not implemented for Model-based searches');
    return;
}

=head2 generate_cigar_string

=cut

sub generate_cigar_string {
    my $self = shift;
    $self->warn('$hsp->generate_cigar_string not implemented for Model-based searches');
    return;    
}

=head2 percent_identity

=cut

sub percent_identity {
    my $self = shift;
    $self->warn('$hsp->percent_identity not implemented for Model-based searches');
    return;
}

############## PRIVATE ##############

# the following method postprocesses HSP data in cases where the sequences
# aren't complete (which can trigger a validation error)

{
	my $SEQ_REGEX = qr/\*\[\s*(\d+)\s*\]\*/;
    my $META_REGEX = qr/(~+)/;

sub _postprocess_hsp {
	my ($self, $hsp) = @_;
	$self->throw('Must pass a hash ref for HSP processing') unless ref($hsp) eq 'HASH';
	my @ins;
	for my $type (qw(query hit meta)) {
        $hsp->{$type} =~ s{\s+$}{};
		my $str = $hsp->{$type};
		my $regex = $type eq 'meta' ? $META_REGEX : $SEQ_REGEX;
		my $ind = 0;		
		while ($str =~ m{$regex}g) {
			$ins[$ind]->{$type} = {pos => pos($str) - length($1), str => $1};
            $ind++;
		}
	}
	for my $chunk (reverse @ins) {
        my ($max, $min) = ($chunk->{hit}->{str} >= $chunk->{query}->{str}) ?
            ('hit', 'query') : ('query', 'hit');
        my %rep;
        $rep{$max} = 'N' x $chunk->{$max}->{str};
        $rep{$min} = 'N' x $chunk->{$min}->{str}.
            ('-'x($chunk->{$max}->{str}-$chunk->{$min}->{str}));
        $rep{'meta'} = '~' x $chunk->{$max}->{str};
        $rep{'midline'} = ' ' x $chunk->{$max}->{str};
        for my $t (qw(hit query meta midline)) {
            substr($hsp->{$t}, $chunk->{meta}->{pos}, length($chunk->{meta}->{str}) , $rep{$t});
        }
	}
}

}

1;



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