File Coverage

blib/lib/Bio/Tools/Run/Profile.pm
Criterion Covered Total %
statement 46 93 49.4
branch 4 20 20.0
condition n/a
subroutine 13 18 72.2
pod 5 5 100.0
total 68 136 50.0


line stmt bran cond sub pod time code
1             # BioPerl module for Profile
2             # Copyright Balamurugan Kumarasamy
3             #
4             # You may distribute this module under the same terms as perl itself
5             # POD documentation - main docs before the code
6              
7             =head1 NAME
8              
9             Bio::Tools::Run::Profile
10              
11             =head1 SYNOPSIS
12              
13             Build a Profile factory
14             # $paramfile is the full path to the seg binary file
15              
16             my @params = ('DB',$dbfile,'PROGRAM',$paramfile);
17             my $factory = Bio::Tools::Run::Profile->new($param);
18              
19             # Pass the factory a Bio::PrimarySeqI object
20             # @feats is an array of Bio::SeqFeature::Generic objects
21             my @feats = $factory->run($seq);
22              
23             =head1 DESCRIPTION
24              
25             Wrapper module for the pfscan program
26              
27             =head1 FEEDBACK
28              
29             =head2 Mailing Lists
30              
31             User feedback is an integral part of the evolution of this and other
32             Bioperl modules. Send your comments and suggestions preferably to one
33             of the Bioperl mailing lists. Your participation is much appreciated.
34              
35             bioperl-l@bioperl.org - General discussion
36             http://bioperl.org/wiki/Mailing_lists - About the mailing lists
37              
38             =head2 Support
39              
40             Please direct usage questions or support issues to the mailing list:
41              
42             I
43              
44             rather than to the module maintainer directly. Many experienced and
45             reponsive experts will be able look at the problem and quickly
46             address it. Please include a thorough description of the problem
47             with code and data examples if at all possible.
48              
49             =head2 Reporting Bugs
50              
51             Report bugs to the Bioperl bug tracking system to help us keep track
52             the bugs and their resolution. Bug reports can be submitted via the
53             web:
54              
55             http://redmine.open-bio.org/projects/bioperl/
56              
57             =head1 AUTHOR - Balamurugan Kumarasamy
58              
59             Email: fugui@worf.fugu-sg.org
60              
61             =head1 APPENDIX
62              
63             The rest of the documentation details each of the object
64             methods. Internal methods are usually preceded with a _
65              
66             =cut
67              
68             package Bio::Tools::Run::Profile;
69              
70 1         63 use vars qw($AUTOLOAD @ISA $PROGRAM $PROGRAMDIR
71             $PROGRAMNAME @PROFILE_PARAMS
72 1     1   100782 %OK_FIELD);
  1         2  
73 1     1   3 use strict;
  1         1  
  1         14  
74 1     1   453 use Bio::SeqIO;
  1         38449  
  1         26  
75 1     1   6 use Bio::Root::Root;
  1         2  
  1         13  
76 1     1   3 use Bio::Root::IO;
  1         1  
  1         12  
77 1     1   394 use Bio::Factory::ApplicationFactoryI;
  1         98  
  1         17  
78 1     1   441 use Bio::Tools::Profile;
  1         42635  
  1         26  
79 1     1   386 use Bio::Tools::Run::WrapperBase;
  1         2  
  1         46  
80              
81              
82             @ISA = qw(Bio::Root::Root Bio::Tools::Run::WrapperBase);
83              
84             BEGIN {
85 1     1   2 @PROFILE_PARAMS=qw(DB PROGRAM VERBOSE);
86 1         2 foreach my $attr ( @PROFILE_PARAMS)
87 3         513 { $OK_FIELD{$attr}++; }
88             }
89              
90             =head2 program_name
91              
92             Title : program_name
93             Usage : $factory>program_name()
94             Function: holds the program name
95             Returns: string
96             Args : None
97              
98             =cut
99              
100             sub program_name {
101 6     6 1 24 return 'pfscan';
102             }
103              
104             =head2 program_dir
105              
106             Title : program_dir
107             Usage : $factory->program_dir(@params)
108             Function: returns the program directory, obtained from ENV variable.
109             Returns: string
110             Args :
111              
112             =cut
113              
114             sub program_dir {
115 3 50   3 1 13 return Bio::Root::IO->catfile($ENV{PROFILEDIR}) if $ENV{PROFILEDIR};
116             }
117              
118             sub AUTOLOAD {
119 1     1   2 my $self = shift;
120 1         2 my $attr = $AUTOLOAD;
121 1         4 $attr =~ s/.*:://;
122 1         2 $attr = uc $attr;
123 1 50       14 $self->throw("Unallowed parameter: $attr !") unless $OK_FIELD{$attr};
124 1 50       4 $self->{$attr} = shift if @_;
125 1         3 return $self->{$attr};
126             }
127              
128             =head2 new
129              
130             Title : new
131             Usage : my $factory= Bio::Tools::Run::Profile->new($param);
132             Function: creates a new Profile factory
133             Returns: Bio::Tools::Run::Profile
134             Args :
135              
136             =cut
137              
138             sub new {
139 1     1 1 93 my ($class,@args) = @_;
140 1         12 my $self = $class->SUPER::new(@args);
141 1         41 $self->io->_initialize_io();
142            
143 1         19 my ($attr, $value);
144 1         2 while (@args) {
145 1         2 $attr = shift @args;
146 1         1 $value = shift @args;
147 1 50       4 next if( $attr =~ /^-/ ); # don't want named parameters
148 1         9 $self->$attr($value);
149             }
150 1         2 return $self;
151             }
152              
153             =head2 predict_protein_features
154              
155             Title : predict_protein_features
156             Usage : DEPRECATED. Use $factory->run($seq) instead.
157             Function: Runs Profile and creates an array of featrues
158             Returns : An array of L objects
159             Args : A Bio::PrimarySeqI
160              
161             =cut
162              
163             sub predict_protein_features{
164 0     0 1   return shift->run(@_);
165             }
166              
167             =head2 run
168              
169             Title : run
170             Usage : my @feats = $factory->run($seq)
171             Function: Runs Profile
172             Returns : An array of L objects
173             Args : A Bio::PrimarySeqI
174              
175             =cut
176              
177             sub run{
178 0     0 1   my ($self,$seq) = @_;
179 0           my @feats;
180              
181 0 0         if (ref($seq) ) {
182            
183 0 0         if (ref($seq) =~ /GLOB/) {
184 0           $self->throw("cannot use filehandle");
185             }
186            
187 0           my $display_id = $seq->display_id;
188            
189 0           my $infile1 = $self->_writeSeqFile($seq);
190            
191 0           $self->_input($infile1);
192            
193 0           @feats = $self->_run($display_id);
194 0           unlink $infile1;
195            
196             }
197             else {
198             #The clone object is not a seq object but a file.
199             #Perhaps should check here or before if this file is fasta format...if not die
200             #Here the file does not need to be created or deleted. Its already written and may be used by other runnables.
201              
202 0           $self->_input($seq);
203              
204 0           @feats = $self->_run();
205            
206             }
207            
208 0           return @feats;
209              
210             }
211              
212             =head2 _input
213              
214             Title : _input
215             Usage : $factory->_input($seqFile)
216             Function: get/set for input file
217             Returns :
218             Args :
219              
220             =cut
221              
222             sub _input() {
223 0     0     my ($self,$infile1) = @_;
224 0 0         if(defined $infile1){
225 0           $self->{'input'}=$infile1;
226             }
227 0           return $self->{'input'};
228             }
229              
230             =head2 _run
231              
232             Title : _run
233             Usage : $factory->_run()
234             Function: Makes a system call and runs pfscan
235             Returns : An array of L objects
236             Args :
237              
238             =cut
239              
240             sub _run {
241 0     0     my ($self,$display_id)= @_;
242 0           my ($tfh,$outfile) = $self->io->tempfile(-dir=>$self->tempdir());
243 0           close($tfh);
244 0           undef $tfh;
245 0           my $str =$self->executable.' -fz '.$self->_input." ".$self->DB." > ".$outfile;
246 0           my $status = system($str);
247 0 0         $self->throw( "Profile call ($str) crashed: $? \n") unless $status==0;
248            
249 0           my $filehandle;
250 0 0         if (ref ($outfile) !~ /GLOB/) {
251 0 0         open (PROFILE, "<".$outfile) or $self->throw ("Couldn't open file ".$outfile.": $!\n");
252 0           $filehandle = \*PROFILE;
253             }
254             else {
255 0           $filehandle = $outfile;
256             }
257 0           my $profile_parser = Bio::Tools::Profile->new(-fh=>$filehandle);
258              
259 0           my @profile_feat;
260              
261 0           while(my $profile_feat = $profile_parser->next_result){
262              
263 0           $profile_feat->seq_id($display_id);
264 0           push @profile_feat, $profile_feat;
265             }
266            
267 0           $self->cleanup();
268            
269 0           unlink $outfile;
270 0           return @profile_feat;
271              
272             }
273              
274              
275             =head2 _writeSeqFile
276              
277             Title : _writeSeqFile
278             Usage : $factory->_writeSeqFile($seq)
279             Function: Creates a file from the given seq object
280             Returns : A string(filename)
281             Args : Bio::PrimarySeqI
282              
283             =cut
284              
285             sub _writeSeqFile{
286 0     0     my ($self,$seq) = @_;
287 0           my ($tfh,$inputfile) = $self->io->tempfile(-dir=>$self->tempdir());
288 0           my $in = Bio::SeqIO->new(-fh => $tfh , '-format' => 'fasta');
289 0           $in->write_seq($seq);
290 0           $in->close();
291 0           undef $in;
292 0           close($tfh);
293 0           undef $tfh;
294 0           return $inputfile;
295              
296             }
297             1;