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