t/AlignIO/AlignIO.t: fix number of tests in plan (fixup c523e6bed866)
[bioperl-live.git] / Bio / Tools / TargetP.pm
blob89e2bb440512d2d21476a9bc107a262fac41fefe
2 # Bioperl module for TargetP
4 # Please direct questions and support issues to <bioperl-l@bioperl.org>
6 # Cared for by Emmanuel Quevillon <emmanuel.quevillon@versailles.inra.fr>
8 # You may distribute this module under the same terms as perl itself
10 # POD documentation - main docs before the code
12 =head1 NAME
14 Bio::Tools::TargetP - Results of one TargetP run
16 =head1 SYNOPSIS
18 use Bio::Tools::TargetP;
20 #filename for TargetP result :
21 $targetp = Bio::Tools::TargetP->new(-file => 'targetp.out');
23 # filehandle for TargetP :
24 $targetp = Bio::Tools::TargetP->new( -fh => \*INPUT );
26 ### targetp v1.1 prediction results ##################################
27 #Number of query sequences: 11
28 #Cleavage site predictions included.
29 #Using NON-PLANT networks.
31 #Name Len mTP SP other Loc RC TPlen
32 #----------------------------------------------------------------------
33 #swall|Q9LIP3|C72Y_AR 500 0.245 0.935 0.009 S 2 22
34 #swall|Q52813|AAPQ_RH 400 0.170 0.462 0.577 _ 5 -
35 #swall|O86459|AAT_RHI 400 0.346 0.046 0.660 _ 4 -
39 # parse the results
40 while($feature = $targetp->next_prediction()) {
42 #$feature is a Bio::SeqFeature::Generic object
43 my $method = $targetp->analysis_method();
44 my $vesion = $targetp->analysis_method_version() || $feature->source();
45 my $seqid = $feature->seq_id();
46 # ...
49 # essential if you gave a filename at initialization (otherwise the file
50 # will stay open)
51 $targetp->close();
53 =head1 DESCRIPTION
55 TargetP modules will provides parsed information about protein
56 localization. It reads in a targetp output file. It parses the
57 results, and returns a Bio::SeqFeature::Generic object for each
58 seqeunces found to have a subcellular localization
60 =head1 FEEDBACK
62 =head2 Mailing Lists
64 User feedback is an integral part of the evolution of this and other
65 Bioperl modules. Send your comments and suggestions preferably to
66 the Bioperl mailing list. Your participation is much appreciated.
68 bioperl-l@bioperl.org - General discussion
69 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
71 =head2 Support
73 Please direct usage questions or support issues to the mailing list:
75 I<bioperl-l@bioperl.org>
77 rather than to the module maintainer directly. Many experienced and
78 reponsive experts will be able look at the problem and quickly
79 address it. Please include a thorough description of the problem
80 with code and data examples if at all possible.
82 =head2 Reporting Bugs
84 Report bugs to the Bioperl bug tracking system to help us keep track
85 of the bugs and their resolution. Bug reports can be submitted via
86 the web:
88 https://github.com/bioperl/bioperl-live/issues
90 =head1 AUTHORS - Emmanuel Quevillon
92 Email emmanuel.quevillon@versailles.inra.fr
94 Describe contact details here
96 =head1 APPENDIX
98 The rest of the documentation details each of the object methods.
99 Internal methods are usually preceded with a _
101 =cut
104 # Let the code begin...
107 package Bio::Tools::TargetP;
108 use strict;
109 use Bio::Tools::AnalysisResult;
110 use Bio::SeqFeature::Generic;
111 use Data::Dumper;
113 use base qw(Bio::Tools::AnalysisResult);
116 #Definition of 'Loc' field according to http://www.cbs.dtu.dk/services/TargetP/output.php
117 my $MAPLOC = {
118 'S' => 'Secretory pathway',
119 'M' => 'Mitochondrion',
120 'C' => 'Chloroplast',
121 '_' => 'Any other',
122 '*' => 'Unknown',
123 '?' => 'Unknown',
127 =head1 analysis_method
129 Usage : $self->analysis_method();
130 Purpose : Inherited method. Overridden to ensure that the name matches
131 Returns : String
132 Argument : n/a
134 =cut
136 sub analysis_method {
138 my ($self, $method) = @_;
140 if($method && ($method !~ /TargetP/i)) {
141 $self->throw("method $method not supported in " . ref($self));
144 return $self->SUPER::analysis_method($method);
147 =head1 network
149 Title : network
150 Usage : $self->network($network)
151 Function: This method Get/Set the network used for the analysis (PLANT or NON-PLANT)
152 Example :
153 Returns : string
154 Arguments: On set, the network used
156 =cut
158 sub network {
160 my($self, $net) = @_;
162 if(defined($net)){
163 $self->{'_network'} = $net;
166 return $self->{'_network'};
171 =head1 cleavage
173 Title : cleavage
174 Usage : $self->cleavage($cleavage)
175 Function : This method Get/Set if SignalP program was used to run TargetP
176 Example :
177 Returns : 1 or 0
178 Arguments: On set, the cleavage used or not
180 =cut
182 sub cleavage {
184 my($self, $cleavage) = @_;
186 if(defined($cleavage)){
187 $self->{'_cleavage'} = $cleavage =~ /not included/ ? '0' : '1';
190 return $self->{'_cleavage'};
195 =head1 next_prediction
197 Usage : $targetp->next_prediction()
198 Purpose : Returns the next TargetP prediction
199 Returns : A Bio::SeqFeature::Generic object
200 Arguments: n/a
202 =cut
204 sub next_prediction {
206 my($self) = @_;
208 unless($self->_parsed()){
209 $self->_parse_results();
210 $self->_parsed(1);
213 return shift @{$self->{'_features'}} || undef;
216 =head1 create_feature
218 Title : create_feature
219 Usage : $self->create_feature(\%hash);
220 Function : This method creates a new Bio::SeqFeature::Generic object
221 Example :
222 Returns : Bio::SeqFeature::Generic
223 Arguments : hash reference
225 =cut
227 sub create_feature {
229 my($self, $feat) = @_;
231 $self->throw("Need a reference to hash table") unless($feat && ref($feat) eq 'HASH');
233 my $feature = Bio::SeqFeature::Generic->new(
234 -seq_id => $feat->{seqid},
235 -source_tag => $self->analysis_method(),
236 -primary_tag => 'signal_peptide', #Sequence Ontology compliant
237 -strand => '+',
240 if(defined($feat->{seqlen})){
241 $feature->start(1);
242 $feature->end($feat->{seqlen});
244 $feature->add_tag_value('location', $MAPLOC->{$feat->{loc}}) if(exists($MAPLOC->{$feat->{loc}}));
245 $feature->add_tag_value('chloroplastCutOff', $feat->{cTP}) if(defined($feat->{cTP}));
246 $feature->add_tag_value('mitochondrionCutOff', $feat->{mTP}) if(defined($feat->{mTP}));
247 $feature->add_tag_value('signalPeptideCutOff', $feat->{SP}) if(defined($feat->{SP}));
248 $feature->add_tag_value('otherCutOff', $feat->{other}) if(defined($feat->{other}));
249 $feature->add_tag_value('reliabilityClass', $feat->{RC}) if(defined($feat->{RC}));
250 $feature->add_tag_value('signalPeptideLength', $feat->{TPLen}) if(defined($feat->{TPLen}));
252 $feature->add_tag_value('network', $self->network());
254 return $feature;
259 =head2 PRIVATE METHODS
261 =cut
263 =head2 _initialize_state
265 Title : _initialize_state
266 Usage : n/a; usually called by _initialize() itself called by new()
267 Function: This method is supposed to reset the state such that any 'history'
268 is lost. State information that does not change during object
269 lifetime is not considered as history, e.g. parent, name, etc shall
270 not be reset. An inheriting object should only be concerned with
271 state information it introduces itself, and for everything else
272 call SUPER::_initialize_state(@args).
274 The argument syntax is the same as for new() and _initialize(),
275 i.e., named parameters following the -name=>$value convention.
276 The following parameters are dealt with by the implementation
277 provided here:
278 -INPUT, -FH, -FILE
279 (tags are case-insensitive).
280 Example :
281 Returns :
282 Args :
284 =cut
286 sub _initialize_state {
288 my ($self,@args,) = @_;
289 # first call the inherited method!
290 $self->SUPER::_initialize_state(@args);
292 # our private state variables
293 $self->{'_features'} = [ ];
294 $self->{'_parameters'} = undef;
295 $self->{'_format'} = undef;
296 $self->{'_network'} = undef;
297 $self->{'_cleavage'} = undef;
298 $self->{'_parsed'} = 0;
300 $self->analysis_method('TargetP');
302 return 1;
305 =head2 _predictions
307 Usage : $targetp->_prediction()
308 Purpose : Returns the number of TargetP predictions
309 Returns : A scalar (number)
310 Arguments: n/a
312 =cut
314 sub _predictions {
316 my($self) = @_;
318 return scalar(@{$self->{'_features'}}) || 0;
322 =head2 _parsed
324 Title : _parsed
325 Usage : $targetp->_parsed(1)
326 Function : This method is used to know if the output result is parsed or not
327 For internal use only
328 Example :
329 Returns : 1/0
330 Arguments : 1/0 for setting
332 =cut
334 sub _parsed {
336 my($self, $value) = @_;
338 if(defined($value)){
339 $self->{'_parsed'} = $value;
342 return $self->{'_parsed'};
347 =head2 _parse_results
349 Title : _parse_results
350 Usage : $self->_parse_results()
351 Function : This method parses a TargetP output
352 For internal use only
353 Example :
354 Returns : n/a
355 Arguments: none
357 =cut
359 sub _parse_results {
361 my($self) = @_;
364 ### targetp v1.1 prediction results ##################################
365 #Number of query sequences: 11
366 #Cleavage site predictions included.
367 #Using NON-PLANT networks.
369 #Name Len mTP SP other Loc RC TPlen
370 #----------------------------------------------------------------------
371 #swall|Q9LIP3|C72Y_AR 500 0.245 0.935 0.009 S 2 22
372 #swall|Q52813|AAPQ_RH 400 0.170 0.462 0.577 _ 5 -
373 #swall|O86459|AAT_RHI 400 0.346 0.046 0.660 _ 4 -
376 while(defined(my $line = $self->_readline())){
378 if($line =~ /targetp (v[\d\.]+)/){
380 $self->analysis_method_version($1);
382 }elsif($line =~ /Cleavage site predictions (.*)/){
384 $self->cleavage($1);
386 }elsif($line =~ /Using (\S+) networks/){
388 $self->network($1);
390 }elsif($line =~ /^Name/){
392 #We skip the next line which is '------------------'
393 $self->_readline();
395 my $hash = { };
397 while(defined(my $line = $self->_readline())){
399 last if($line =~ /^----/);
401 my $hash = $self->_parse_line($line);
403 my $new_feature = $self->create_feature($hash);
405 $self->_add_feature($new_feature);
410 return;
413 =head2 _parse_line
415 Title : _parse_line
416 Usage : $self->_parse_line($line)
417 Function : This method parses the line result
418 For internal use only
419 Example :
420 Returns : Hash reference
421 Arguemnts: line to parse
423 =cut
425 sub _parse_line {
427 my($self, $line) = @_;
429 $self->throw("No line to parse given") unless($line);
431 my $hash = { };
432 my ($seqid, $seqlen, $cTP, $mTP, $SP, $other, $loc, $RC, $TPlen);
434 if($self->network() eq 'NON-PLANT'){
436 ($seqid, $seqlen, $mTP, $SP, $other, $loc, $RC, $TPlen) = split(/\s+/, $line);
438 }else{
440 ($seqid, $seqlen, $cTP, $mTP, $SP, $other, $loc, $RC, $TPlen) = split(/\s+/, $line);
444 $hash->{seqid} = $seqid;
445 $hash->{seqlen} = $seqlen;
446 $hash->{cTP} = $cTP || undef;
447 $hash->{mTP} = $mTP;
448 $hash->{SP} = $SP;
449 $hash->{other} = $other;
450 $hash->{loc} = $loc;
451 $hash->{RC} = $RC;
452 $hash->{TPLen} = ($TPlen && $TPlen =~ /\d+/) ? $TPlen : undef;
454 return $hash;
458 =head2 _add_feature
460 Title : _add_feature
461 Usage : $self->_add_feature($feature)
462 Function : This method stores a feature object
463 For internal use only
464 Example :
465 Returns : n/a
466 Arguments: Bio::SeqFeature::Generic
468 =cut
470 sub _add_feature {
472 my($self, $feature) = @_;
474 $self->throw("Need a Bio::SeqFeature::Generic object") unless $feature->isa("Bio::SeqFeature::Generic");
476 push(@{$self->{'_features'}}, $feature);
478 return;
482 =head2 _toString_location
484 Title : _toString_location
485 Usage : $self->_toString_location($key)
486 Function : This method convert the 'one letter code' location to
487 the corresponding definition
488 For internal use only
489 Example :
490 Returns : Location or undef
491 Arguments: String
493 =cut
495 sub _toString_location {
497 my($self, $key) = @_;
499 if($key && exists($MAPLOC->{$key})){
500 return $MAPLOC->{$key};
503 return;