| 1 | |||||||||||||||||||||||||||||
| 2 | =head1 NAME | ||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | Bio::Tools::PrositeScan - Parser for ps_scan result | ||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | use Bio::Tools::PrositeScan; | ||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | my $factory = Bio::Tools::PrositeScan->new( | ||||||||||||||||||||||||||||
| 11 | -file => 'out.PrositeScan', | ||||||||||||||||||||||||||||
| 12 | -format => 'fasta' | ||||||||||||||||||||||||||||
| 13 | ); | ||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | while(my $match = $factory->next_prediction){ | ||||||||||||||||||||||||||||
| 16 | # $match is a Bio::SeqFeature::FeaturePair | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | # Sequence ID | ||||||||||||||||||||||||||||
| 19 | my $seq_id = $match->seq_id; | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | # PROSITE accession number | ||||||||||||||||||||||||||||
| 22 | my $psac = $match->hseq_id; | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | # Coordinates | ||||||||||||||||||||||||||||
| 25 | my @coords = ( $match->start, $match->end ); | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | # Subsequence | ||||||||||||||||||||||||||||
| 28 | my $seq = $match->feature1->seq; | ||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | This is a parser of the output of the ps_scan program. It takes either a file | ||||||||||||||||||||||||||||
| 34 | handle or a file name, and returns a L<Bio::SeqFeature::FeaturePair> object. | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | Note that the current implementation parses the entire file at once. | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | Juguang Xiao, juguang@tll.org.sg | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | =head1 SEE ALSO | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | =over | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | =item * L<ps_scan software|ftp://ftp.expasy.org/databases/prosite/ps_scan> | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | =item * L<PROSITE User Manual|http://prosite.expasy.org/prosuser.html> | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | =back | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | =cut | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | # Let the code begin... | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | package Bio::Tools::PrositeScan; | ||||||||||||||||||||||||||||
| 57 | 2 | $Bio::Tools::PrositeScan::VERSION = '1.7.8'; | |||||||||||||||||||||||||||
| 58 | 2 | ▶ | use vars qw(@FORMATS); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 59 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 60 | 2 | ▶ | use Bio::Seq; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 61 | 2 | ▶ | use Bio::SeqFeature::Generic; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 62 | 2 | ▶ | use Bio::SeqFeature::FeaturePair; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 2 | ▶ | use base qw(Bio::Root::Root Bio::Root::IO); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 65 | 2 | @FORMATS = qw(SCAN FASTA PSA MSA PFF MATCHLIST); | |||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | =head2 new | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | Title : new | ||||||||||||||||||||||||||||
| 70 | Usage : Bio::Tools::PrositeScan->new(-file => 'out.PrositeScan'); | ||||||||||||||||||||||||||||
| 71 | Bio::Tools::PrositeScan->new(-fh => \*FH); | ||||||||||||||||||||||||||||
| 72 | Returns : L<Bio::Tools::PrositeScan> | ||||||||||||||||||||||||||||
| 73 | Args : -format => string representing the format type for the | ||||||||||||||||||||||||||||
| 74 | ps_scan output, REQUIRED | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | The C<-format> argument must currently be set to C<fasta> since this is the | ||||||||||||||||||||||||||||
| 77 | only parser implemented. This corresponds with using the ps_scan arguments | ||||||||||||||||||||||||||||
| 78 | C<-o fasta>. | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | =cut | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 1 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=3 SCAR=11.3
Pod
documented
| |||||||||||||||||||||||||||||
| 83 | 1 | my ($class, @args) = @_; | |||||||||||||||||||||||||||
| 84 | 1 | my $self = $class->SUPER::new(@args); | |||||||||||||||||||||||||||
| 85 | 1 | $self->_initialize_io(@args); | |||||||||||||||||||||||||||
| 86 | 1 | my ($format) = $self->_rearrange([qw(FORMAT)], @args); | |||||||||||||||||||||||||||
| 87 | 1 | ▶ | $format || $self->throw("format needed"); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 88 | 1 | ▶ | if(grep /^$format$/i, @FORMATS){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 89 | 1 | $self->format($format); | |||||||||||||||||||||||||||
| 90 | }else{ | ||||||||||||||||||||||||||||
| 91 | 0 | $self->throw("Invalid format, [$format]"); | |||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||
| 93 | 1 | return $self; | |||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | 1 | ▶ | sub format { | ||||||||||||||||||||||||||
|
Subroutine
format: called CC=2 SCAR=8.1
Pod
documented
| |||||||||||||||||||||||||||||
| 97 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 98 | 1 | ▶ | return $self->{_format} = shift if(@_); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 99 | 0 | return $self->{_format}; | |||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | =head2 next_prediction | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | Title : new | ||||||||||||||||||||||||||||
| 105 | Usage : | ||||||||||||||||||||||||||||
| 106 | while($result = $factory->next_prediction){ | ||||||||||||||||||||||||||||
| 107 | ; | ||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | Returns : a Bio::SeqFeature::FeaturePair object where | ||||||||||||||||||||||||||||
| 111 | feature1 is the matched subsequence and | ||||||||||||||||||||||||||||
| 112 | feature2 is the PROSITE accession number. | ||||||||||||||||||||||||||||
| 113 | See <http://prosite.expasy.org/prosuser.html#conv_ac>. | ||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | =cut | ||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | 0 | ▶ | sub next_prediction { | ||||||||||||||||||||||||||
|
Subroutine
next_prediction: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 118 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 119 | 0 | ▶ | unless($self->_parsed){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 120 | 0 | $self->_parse; | |||||||||||||||||||||||||||
| 121 | 0 | $self->_parsed(1); | |||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||
| 123 | 0 | return shift @{$self->{_matches}}; | |||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | 0 | ▶ | sub next_result { | ||||||||||||||||||||||||||
|
Subroutine
next_result: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 127 | 0 | return shift->next_prediction; | |||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | 0 | ▶ | sub _parsed { | ||||||||||||||||||||||||||
|
Subroutine
_parsed: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 131 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 132 | 0 | ▶ | return $self->{_parsed} = 1 if @_ && $_[0]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
@_ and $_[0]
MC/DC0%0/2
@_ and $_[0]
@_
$_[0]
Truth table0%0/3
A and B
A= @_B= $_[0]
| |||||||||||||||||||||||||||||
| 133 | 0 | return $self->{_parsed}; | |||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | 0 | ▶ | sub _parse { | ||||||||||||||||||||||||||
|
Subroutine
_parse: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 137 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 138 | 0 | my $format = $self->format; | |||||||||||||||||||||||||||
| 139 | 0 | ▶ | if($self->format =~ /^fasta$/){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 140 | 0 | $self->_parse_fasta; | |||||||||||||||||||||||||||
| 141 | }else{ | ||||||||||||||||||||||||||||
| 142 | 0 | $self->throw("the [$format] parser has not been written"); | |||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | 0 | ▶ | sub _parse_fasta { | ||||||||||||||||||||||||||
|
Subroutine
_parse_fasta: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||
| 147 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 148 | 0 | my @matches; | |||||||||||||||||||||||||||
| 149 | my $fp; | ||||||||||||||||||||||||||||
| 150 | 0 | my $seq; | |||||||||||||||||||||||||||
| 151 | 0 | ▶ | while(defined($_ = $self->_readline)){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 152 | 0 | chop; | |||||||||||||||||||||||||||
| 153 | 0 | ▶ | if(/^\>([^>]+)/){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 154 | 0 | my $fasta_head = $1; | |||||||||||||||||||||||||||
| 155 | 0 | ▶ | if($fasta_head =~ /([^\/]+)\/(\d+)\-(\d+)(\s+)\:(\s+)(\S+)/){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 156 | 0 | my $q_id = $1; | |||||||||||||||||||||||||||
| 157 | 0 | my $q_start = $2; | |||||||||||||||||||||||||||
| 158 | 0 | my $q_end = $3; | |||||||||||||||||||||||||||
| 159 | 0 | my $h_id = $6; | |||||||||||||||||||||||||||
| 160 | 0 | ▶ | if(defined $fp){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 161 | 0 | $self->_attach_seq($seq, $fp); | |||||||||||||||||||||||||||
| 162 | 0 | push @matches, $fp; | |||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||
| 164 | 0 | $fp = Bio::SeqFeature::FeaturePair->new( | |||||||||||||||||||||||||||
| 165 | -feature1 => Bio::SeqFeature::Generic->new( | ||||||||||||||||||||||||||||
| 166 | -seq_id => $q_id, | ||||||||||||||||||||||||||||
| 167 | -start => $q_start, | ||||||||||||||||||||||||||||
| 168 | -end => $q_end | ||||||||||||||||||||||||||||
| 169 | ), | ||||||||||||||||||||||||||||
| 170 | -feature2 => Bio::SeqFeature::Generic->new( | ||||||||||||||||||||||||||||
| 171 | -seq_id => $h_id, | ||||||||||||||||||||||||||||
| 172 | -start => 0, | ||||||||||||||||||||||||||||
| 173 | -end => 0 | ||||||||||||||||||||||||||||
| 174 | ) | ||||||||||||||||||||||||||||
| 175 | ); | ||||||||||||||||||||||||||||
| 176 | 0 | $seq = ''; | |||||||||||||||||||||||||||
| 177 | }else{ | ||||||||||||||||||||||||||||
| 178 | 0 | $self->throw("ERR:\t\[$_\]"); | |||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||
| 180 | }else{ # sequence lines, ignored | ||||||||||||||||||||||||||||
| 181 | 0 | $seq .= $_; | |||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||
| 183 | } | ||||||||||||||||||||||||||||
| 184 | 0 | ▶ | if(defined $fp){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 185 | 0 | $self->_attach_seq($seq, $fp); | |||||||||||||||||||||||||||
| 186 | 0 | push @matches, $fp; | |||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||
| 188 | 0 | push @{$self->{_matches}}, @matches; | |||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||
| 191 | 0 | ▶ | sub _attach_seq { | ||||||||||||||||||||||||||
|
Subroutine
_attach_seq: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 192 | 0 | my ($self, $seq, $fp) = @_; | |||||||||||||||||||||||||||
| 193 | 0 | ▶ | if(defined $fp){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 194 | 0 | my $whole_seq = 'X' x ($fp->start-1); | |||||||||||||||||||||||||||
| 195 | 0 | $whole_seq .= $seq; | |||||||||||||||||||||||||||
| 196 | 0 | $fp->feature1->attach_seq( | |||||||||||||||||||||||||||
| 197 | Bio::Seq->new(-seq => $whole_seq) | ||||||||||||||||||||||||||||
| 198 | ); | ||||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||
| 202 | 2 | 1; | |||||||||||||||||||||||||||