Bio::Tools PrositeScan
SummaryIncluded librariesPackage variablesSynopsisDescriptionGeneral documentationMethods
Toolbar
WebCvs
Summary
Bio::Tools::PrositeScan - Parser for ps_scan result
Package variables
No package variables defined.
Included modules
Bio::Seq
Bio::SeqFeature::FeaturePair
Bio::SeqFeature::Generic
Inherit
Bio::Root::IO Bio::Root::Root
Synopsis
  use Bio::Tools::PrositeScan;
my $factory = Bio::Tools::PrositeScan->new( -file => 'out.PrositeScan' ); while(my $match = $factory->next_prediction){ # $match is of Bio::SeqFeature::FeaturePair my $q_id = $fatch->feature1->seq_id; my $h_id = $fatch->feature2->seq_id; }
Description
This is the parser of the output of ps_scan program. It takes either a file
handler or a file name, and returns a Bio::SeqFeature::FeaturePair object.
Methods
newDescriptionCode
format
No description
Code
next_predictionDescriptionCode
next_result
No description
Code
_parsed
No description
Code
_parse
No description
Code
_parse_fasta
No description
Code
_attach_seq
No description
Code
Methods description
newcode    nextTop
  Title   : new
Usage : Bio::Tools::PrositeScan->new(-file => 'out.PrositeScan');
Bio::Tools::PrositeScan->new(-fh => \*FH);
Returns : Bio::Tools::PrositeScan
next_predictioncodeprevnextTop
  Title   : new
Usage :
while($result = $factory->next_prediction){
;
}
Returns : a Bio::SeqFeature::FeaturePair object
Methods code
newdescriptionprevnextTop
sub new {
    my ($class, @args) = @_;
    my $self = $class->SUPER::new(@args);
    $self->_initialize_io(@args);
    my ($format) = $self->_rearrange([qw(FORMAT)], @args);
    $format || $self->throw("format needed");
    if(grep /^$format$/i, @FORMATS){
        $self->format($format);
    }else{
        $self->throw("Invalid format, [$format]");
    }
    return $self;
}
formatdescriptionprevnextTop
sub format {
    my $self = shift;
    return $self->{_format} = shift if(@_);
    return $self->{_format};
}
next_predictiondescriptionprevnextTop
sub next_prediction {
    my ($self) = @_;
    unless($self->_parsed){
        $self->_parse;
        $self->_parsed(1);
    }
    return shift @{$self->{_matches}};
}
next_resultdescriptionprevnextTop
sub next_result {
    return shift->next_prediction;
}
_parseddescriptionprevnextTop
sub _parsed {
    my $self = shift;
    return $self->{_parsed} = 1 if @_ && $_[0];
    return $self->{_parsed};
}
_parsedescriptionprevnextTop
sub _parse {
    my $self = shift;
    my $format = $self->format;
    if($self->format =~ /^fasta$/){
        $self->_parse_fasta;
    }else{
        $self->throw("the [$format] parser has not been written");
    }
}
_parse_fastadescriptionprevnextTop
sub _parse_fasta {
    my ($self) = @_;
    my @matches;
    my $fp;
    my $seq;
    while(defined($_ = $self->_readline)){
        chop;
        if(/^\>([^>]+)/){
            my $fasta_head = $1;
            if($fasta_head =~ /([^\/]+)\/(\d+)\-(\d+)(\s+)\:(\s+)(\S+)/){
                my $q_id = $1;
                my $q_start = $2;
                my $q_end = $3;
                my $h_id = $6;
                if(defined $fp){
                    $self->_attach_seq($seq, $fp);
                    push @matches, $fp;
                }
                $fp = Bio::SeqFeature::FeaturePair->new(
                    -feature1 => Bio::SeqFeature::Generic->new(
                        -seq_id => $q_id,
                        -start => $q_start,
                        -end => $q_end
                    ),
                    -feature2 => Bio::SeqFeature::Generic->new(
                        -seq_id => $h_id,
                        -start => 0,
                        -end => 0
                    )
                );
                $seq = '';
            }else{
                $self->throw("ERR:\t\[$_\]");
            }
        }else{ # sequence lines, ignored
$seq .= $_; } } if(defined $fp){ $self->_attach_seq($seq, $fp); push @matches, $fp; } push @{$self->{_matches}}, @matches;
}
_attach_seqdescriptionprevnextTop
sub _attach_seq {
    my ($self, $seq, $fp) = @_;
    if(defined $fp){
        my $whole_seq = 'X' x ($fp->start-1);
        $whole_seq .= $seq;
        $fp->feature1->attach_seq(
            Bio::Seq->new(-seq => $whole_seq)
        );
    }
}

1;
}
General documentation
AUTHORTop
Juguang Xiao, juguang@tll.org.sg