blib/lib/Bio/Tools/Run/Alignment/Gmap.pm

filter: Statementstmt 38.1% 29 / 76 Branchbran 9.0% 2 / 22 Conditioncond 0.0% 0 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 56.2% 9 / 16 Podpod 100% 8 / 8 totaltotal 37.5% 48 / 128 CC 15 SCAR 23.2
CC
15
Cov
30%
_build_fasta_input_file
30.0
_run
20.0
version
6.0
CRAP 10.2
« blib/lib/Bio/Tools/Run/Alignment/Exonerate.pm ↑ Summary blib/lib/Bio/Tools/Run/Seg.pm »
1 # $Id$
2 #
3 # BioPerl module for Bio::Tools::Run::Alignment::Gmap
4 #
5 # Cared for by George Hartzell <hartzell@alerce.com>
6 #
7 # Copyright George Hartzell
8 #
9 # You may distribute this module under the same terms as perl itself
10  
11 # POD documentation - main docs before the code
12  
13 =head1 NAME
14  
15 Bio::Tools::Run::Alignment::Gmap - Wrapper for running gmap.
16  
17 =head1 SYNOPSIS
18  
19 use Bio::Tools::Run::Alignment::Gmap;
20 use Bio::SeqIO;
21  
22 my $sio = Bio::SeqIO->new(-file=>$filename ,-format=>'fasta');
23 my @seq;
24 while(my $seq = $sio->next_seq()){
25 push @seq,$seq;
26 }
27 my $mapper =Bio::Tools::Run::Gmap->new();
28 my $result = $mapper->run(\@seq);
29  
30  
31 =head1 DESCRIPTION
32  
33 Bioperl-run wrapper around gmap. See
34 L<http://www.gene.com/share/gmap/> for information about gmap.
35  
36 It requires a reference to an array of bioperl SeqI objects and
37 returns a reference to a filehandle from which the gmap output can be
38 read.
39  
40 One can explicitly set the name of the genome database (defaults to
41 NHGD_R36) using the 'genome_db()' method. One can also explicitly set
42 the flags that are passed to gmap (defaults to '-f 9 -5 -e') using the
43 'flags()' method.
44  
45 The name of the gmap executable can be overridden using the
46 program_name() method and the directory in which to find that
47 executable can be overridden using the program_dir() method.
48  
49 =head1 FEEDBACK
50  
51 =head2 Mailing Lists
52  
53 User feedback is an integral part of the evolution of this and other
54 Bioperl modules. Send your comments and suggestions preferably to
55 the Bioperl mailing list. Your participation is much appreciated.
56  
57 bioperl-l@bioperl.org - General discussion
58 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
59  
60 =head2 Reporting Bugs
61  
62 Report bugs to the Bioperl bug tracking system to help us keep track
63 of the bugs and their resolution. Bug reports can be submitted via
64 the web:
65  
66 http://redmine.open-bio.org/projects/bioperl/
67  
68 =head1 AUTHOR - George Hartzell
69  
70 Email hartzell@alerce.com
71  
72 Describe contact details here
73  
74 =head1 CONTRIBUTORS
75  
76 Additional contributors names and emails here
77  
78 =head1 APPENDIX
79  
80 The rest of the documentation details each of the object methods.
81 Internal methods are usually preceded with a _
82  
83 =cut
84  
85  
86 # Let the code begin...
87  
88 # TODO handle stderr output from gmap.
89  
90 package Bio::Tools::Run::Alignment::Gmap;
91 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
92 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
93  
94 # Object preamble - inherits from Bio::Root::Root
95  
96 1 ▶use Bio::Root::Root;
Subroutine BEGIN: called CC=1 SCAR=0.0
97 1 ▶use Bio::SeqIO;
Subroutine BEGIN: called CC=1 SCAR=0.0
98  
99  
100 1 use base qw(Bio::Root::Root Bio::Tools::Run::WrapperBase
101 1 ▶ Bio::Factory::ApplicationFactoryI);
Subroutine BEGIN: called CC=1 SCAR=0.0
102  
103 =head2 new
104  
105 Title : new
106 Usage : my $obj = new Bio::Tools::Run::Alignment::Gmap();
107 Function: Builds a new Bio::Tools::Run::Alignment::Gmap object
108 Returns : an instance of Bio::Tools::Run::Alignment::Gmap
109 Args :
110  
111  
112 =cut
113  
114 sub new {
115 1 ▶ my($class,@args) = @_;
Subroutine new: called CC=1 SCAR=0.0
Pod documented
116  
117 1 my $self = $class->SUPER::new(@args);
118 1 $self->{_program_name} = 'gmap';
119 1 return $self;
120 }
121  
122 =head2 version
123  
124 Title : version
125 Usage : print "gmap version: " . $mapper->version() . "\n";
126 Function: retrieves and returns the version of the gmap package.
127 Example :
128 Returns : scalar string containing the version number. Probably looks
129 like YYYY-MM-DD.
130 Args : none.
131  
132  
133 =cut
134  
135 sub version {
136 0 ▶ my ($self,@args) = @_;
Subroutine version: not called CC=2 SCAR=17.9
Pod documented
137 0 my $version;
138  
139 0 my $str = $self->executable;
140 0 $str .= ' --version';
141 0 $self->debug("gmap version command = $str\n");
142  
143 0 ▶ open(GMAPRUN, "$str |") || $self->throw($@);
Branch: 1 branch
BranchTrueFalseTotal
open GMAPRUN, "$str |" or $self->throw($@) 0 0 0
144  
145 {
146 0 local $/ = undef;
147 0 my $result = <GMAPRUN>;
148 0 ($version) = ($result =~ m|.*Part of GMAP package, version (.*).*|);
149 }
150  
151 0 return($version);
152  
153 }
154  
155 =head2 program_name
156  
157 Title : program_name
158 Usage : $mapper->program_name('gmap-dev');
159 my $pname = $mapper->program_name();
160 Function: sets/gets the name of the program to run.
161 Returns : string representing the name of the executable.
162 Args : [optional] string representing the name of the executable
163 to set.
164  
165 =cut
166  
167 sub program_name {
168 6 ▶ my $self = shift;
Subroutine program_name: called CC=2 SCAR=7.1
Pod documented
169  
170 6 ▶ $self->{_program_name} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 6 6
171 6 return $self->{_program_name};
172 }
173  
174 =head2 program_dir
175  
176 Title : program_dir
177 Usage : $mapper->program_dir('/usr/local/sandbox/gmap/bin');
178 my $pdir = $mapper->program_dir();
179 Function: sets/gets the directory path in which
180 to find the gmap executable.
181 Returns : string representing the path to the directory.
182 Args : [optional] string representing the directory path to set.
183  
184 =cut
185  
186 sub program_dir {
187 3 ▶ my $self = shift;
Subroutine program_dir: called CC=2 SCAR=7.1
Pod documented
188  
189 3 ▶ $self->{_program_dir} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 3 3
190 3 return $self->{_program_dir};
191 }
192  
193 =head2 input_file
194  
195 Title : input_file
196 Usage : $mapper->input_file('/tmp/moose.fasta');
197 my $filename = $mapper->input_file();
198 Function: sets/gets the name of a file containing sequences
199 to be mapped.
200 Returns : string containing the name of the query sequence.
201 Args : [optional] string representing the directory path to set.
202  
203 =cut
204  
205 sub input_file {
206 0 ▶ my $self = shift;
Subroutine input_file: not called CC=2 SCAR=17.9
Pod documented
207  
208 0 ▶ $self->{_input_file} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
209 0 return $self->{_input_file};
210 }
211  
212 =head2 genome_db
213  
214 Title : genome_db
215 Usage : $mapper->genome_db('NHGD_R36');
216 my $genome_db = $mapper->genome_db();
217 Function: sets/gets the name of the genome database, this will be
218 passed to gmap using its '-d' flag.
219 Returns : name of the genome database.
220 Args : [optional] string representing the genome db to set.
221  
222 =cut
223  
224 sub genome_db {
225 0 ▶ my $self = shift;
Subroutine genome_db: not called CC=2 SCAR=17.9
Pod documented
226  
227 0 ▶ $self->{_genome_db} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
228 0 return $self->{_genome_db};
229 }
230  
231 =head2 flags
232  
233 Title : flags
234 Usage : $mapper->flags('-A -e -5');
235 my $flags = $mapper->flags();
236 Function: sets/gets the flags that will be passed to gmap.
237 Returns : the current value of the flags that will be passed to gmap.
238 Args : [optional] the flags to set.
239  
240 =cut
241  
242 sub flags {
243 0 ▶ my $self = shift;
Subroutine flags: not called CC=2 SCAR=17.9
Pod documented
244  
245 0 ▶ $self->{_flags} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
246 0 return $self->{_flags};
247 }
248  
249 =head2 run
250  
251 Title : run
252 Usage : $mapper->run()
253 Function: runs gmap
254 Example :
255 Returns : a file handle, opened for reading, for gmap's output.
256 Args : An array of references query sequences (as Bio::Seq objects)
257  
258  
259 =cut
260  
261 sub run {
262 0 ▶ my $self = shift;
Subroutine run: not called CC=2 SCAR=17.9
Pod documented
263  
264 0 ▶ $self->input_file( $self->_build_fasta_input_file(@_) ) if(@_);
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
265  
266 0 my $result = $self->_run();
267  
268 0 return $result;
269 }
270  
271 =head2 _build_fasta_input_file
272  
273 Title : _build_fasta_input_file
274 Usage : my $seq_file = $self->_build_fasta_input_file(@_);
275 Function:
276 Example :
277 Returns : The name of the temporary file that contains the sequence.
278 Args : A reference to an array of Bio::Seq objects.
279  
280 =cut
281  
282 1 ▶use File::Temp;
Subroutine BEGIN: called CC=1 SCAR=0.0
283  
284 sub _build_fasta_input_file {
285 0 ▶ my $self = shift;
Subroutine _build_fasta_input_file: not called CC=5 SCAR=34.0
286 0 my $seqs = shift;
287 0 my $seq_count = 0;
288  
289 # the object returned by File::Temp->new() is magic. Used normally
290 # it behaves as a filehandle opened onto the temporary file. Used
291 # as a string it behaves as a string that is the name of the
292 # temporary file.
293 # It is up to the user to remove the when finished with it.
294 0 my $file_tmp = File::Temp->new( TEMPLATE => 'mvp-gmap-tempfile-XXXXXX',
295 TMPDIR => 1,
296 UNLINK => 0,
297 );
298 0 my $seqio = Bio::SeqIO->new( -fh => $file_tmp, -format => 'Fasta' );
299  
300 0 ▶ if (ref($seqs) =~ /ARRAY/i) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref($seqs) =~ /ARRAY/i) 0 0 0
301 0 foreach my $seq (@$seqs) {
302 0 ▶ throw
Branch: 1 branch
BranchTrueFalseTotal
unless $seq->isa("Bio::PrimarySeqI") 0 0 0
303 Bio::Root::BadParameter(-text =>
304 "sequence args must be a Bio::SeqI subclass.",
305 )
306 unless ($seq->isa("Bio::PrimarySeqI"));
307  
308 0 $seqio->write_seq($seq);
309 0 $seq_count++;
310 }
311 }
312 0 ▶ if ($seq_count == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($seq_count == 0) 0 0 0
313 0 throw
314 Bio::Root::BadParameter(-text => <<EOM
315 You must supply a reference to an array of Bio::SeqI objects.
316 EOM
317 );
318 }
319  
320 # pass back the filename of the temporary file (see above)
321 0 return ("$file_tmp");
322 }
323  
324  
325 sub _run {
326 0 ▶ my $self = shift;
Subroutine _run: not called CC=4 SCAR=30.0
327  
328 0 my $str = $self->executable;
329 0 ▶ $str .= ' -d' . ($self->genome_db() || 'NHGD_R36');
Condition0%0/2
$self->genome_db || 'NHGD_R36'
l!l
00
MC/DC0%0/1
$self->genome_db || 'NHGD_R36'
$self->genome_db
Truth table0%0/2
A
A= $self->genome_db
Aresult
11
00
330 0 ▶ $str .= ' ' . ($self->flags() || '-f 9 -5 -e');
Condition0%0/2
$self->flags || '-f 9 -5 -e'
l!l
00
MC/DC0%0/1
$self->flags || '-f 9 -5 -e'
$self->flags
Truth table0%0/2
A
A= $self->flags
Aresult
11
00
331 0 $str .= ' ' . $self->input_file();
332 0 $str .= ' 2> /dev/null';
333 0 $str .= '; rm -f ' . $self->input_file();
334 0 $self->debug("gmap command = $str\n");
335  
336 0 ▶ open(GMAPRUN, "$str |") || $self->throw("Can't open gmap (command = \"$str\"): $!");
Branch: 1 branch
BranchTrueFalseTotal
open GMAPRUN, "$str |" or $self->throw(qq[Can't open gmap (command = "$str"): $!]) 0 0 0
337  
338 0 return (\*GMAPRUN);
339 }
340  
341 1 1;
« blib/lib/Bio/Tools/Run/Alignment/Exonerate.pm ↑ Summary blib/lib/Bio/Tools/Run/Seg.pm »