/usr/share/perl5/Bio/Tools/Run/Alignment/StandAloneFasta.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 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 | #StandAloneFasta.pm v1.00 2002/11/01
#
#Bioperl module for Bio::Tools::Run::Alignment::StandAloneFasta
#
# Written by Tiequan Zhang
# Please direct questions and support issues to <bioperl-l@bioperl.org>
#
# Cared for by Shawn Hoon
# Copyright Tiequan Zhang
#
# 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::StandAloneFasta - Object for the local
execution of the Fasta3 programs ((t)fasta3, (t)fastx3, (t)fasty3
ssearch3)
=head1 SYNOPSIS
#!/usr/bin/perl
use Bio::Tools::Run::Alignment::StandAloneFasta;
use Bio::SeqIO;
use strict;
my @arg=(
'b' =>'15',
'O' =>'resultfile',
'H'=>'',
'program'=>'fasta34'
);
my $factory=Bio::Tools::Run::Alignment::StandAloneFasta->new(@arg);
$factory->ktup(1);
$factory->library('p');
#print result file name
print $factory->O;
my @fastreport=$factory->run($ARGV[0]);
foreach (@fastreport) {
print "Parsed fasta report:\n";
my $result = $_->next_result;
while( my $hit = $result->next_hit()) {
print "\thit name: ", $hit->name(), "\n";
while( my $hsp = $hit->next_hsp()) {
print "E: ", $hsp->evalue(), "frac_identical: ",
$hsp->frac_identical(), "\n";
}
}
}
#pass in seq objects
my $sio = Bio::SeqIO->new(-file=>$ARGV[0],-format=>"fasta");
my $seq = $sio->next_seq;
my @fastreport=$factory->run($ARGV[0]);
=head1 DESCRIPTION
This wrapper works with version 3 of the FASTA program package (see
W. R. Pearson and D. J. Lipman (1988), "Improved Tools for Biological
Sequence Analysis", PNAS 85:2444-2448 (Pearson and Lipman, 1988);
W. R. Pearson (1996) "Effective protein sequence comparison"
Meth. Enzymol. 266:227-258 (Pearson, 1996); Pearson et. al. (1997)
Genomics 46:24-36 (Zhang et al., 1997); Pearson, (1999) Meth. in
Molecular Biology 132:185-219 (Pearson, 1999). Version 3 of the FASTA
packages contains many programs for searching DNA and protein
databases and one program (prss3) for evaluating statistical
significance from randomly shuffled sequences.
Fasta is available at ftp://ftp.virginia.edu/pub/fasta
=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 one
of the Bioperl mailing lists. Your participation is much appreciated.
bioperl-l@bioperl.org - General discussion
http://bioperl.org/wiki/Mailing_lists - About the mailing lists
=head2 Support
Please direct usage questions or support issues to the mailing list:
I<bioperl-l@bioperl.org>
rather than to the module maintainer directly. Many experienced and
reponsive experts will be able look at the problem and quickly
address it. Please include a thorough description of the problem
with code and data examples if at all possible.
=head2 Reporting Bugs
Report bugs to the Bioperl bug tracking system to help us keep track
the bugs and their resolution. Bug reports can be submitted via the
web:
http://redmine.open-bio.org/projects/bioperl/
=head1 AUTHOR - Tiequan Zhang
Adapted for bioperl by Shawn Hoon
Enhanced by Jason Stajich
Email tqzhang1973@yahoo.com
shawnh@fugu-sg.org
jason-at-bioperl.org
=head1 Appendix
The rest of the documendation details each of the object
methods. Internal methods are preceded with a underscore
=cut
package Bio::Tools::Run::Alignment::StandAloneFasta;
use vars qw ($AUTOLOAD @ISA $library %parameters
$ktup @FASTA_PARAMS %OK_FIELD @OTHER_PARAMS);
use strict;
use Bio::Root::Root;
use Bio::Root::IO;
use Bio::Seq;
use Bio::SeqIO;
use Bio::SearchIO;
use Bio::Tools::Run::WrapperBase;
BEGIN {
@FASTA_PARAMS=qw(a A b c E d f g h H i j l L M m n O o p Q q r R s S w x y z);
@OTHER_PARAMS =qw(program output database);
foreach my $att (@FASTA_PARAMS, @OTHER_PARAMS) {$OK_FIELD{$att}++;}
$ktup=2;
%parameters=('H' => '',
'q' => '',
'm' =>'1', 'O' =>'');
}
@ISA = qw(Bio::Root::Root Bio::Tools::Run::WrapperBase);
sub new {
my ($caller,@args)=@_;
#chained new
my $self = $caller->SUPER::new(@args);
while(@args){
my $attr = shift @args;
my $value = shift @args;
next if ($attr=~/^-/ || ! $attr);
$self->$attr($value);
}
return $self;
}
sub AUTOLOAD {
my $self = shift;
my $attr = $AUTOLOAD;
$attr =~ s/.*:://;
$self->throw("Unallowed parameter: $attr !") unless $OK_FIELD{$attr};
$self->{$attr} = shift if @_;
return $self->{$attr};
}
=head2 program_name
Title : program_name
Usage : $factory->program_name()
Function: holds the program name
Returns: string
Args : None
=cut
sub program_name {
my ($self) = shift;
return $self->program(@_);
}
=head2 executable
Title : executable
Usage : my $exe = $blastfactory->executable('blastall');
Function: Finds the full path to the 'codeml' executable
Returns : string representing the full path to the exe
Args : [optional] name of executable to set path to
[optional] boolean flag whether or not warn when exe is not found
=cut
sub executable {
my ($self, $exename, $exe,$warn) = @_;
$exename = 'fasta34' unless defined $exename;
if( defined $exe && -x $exe ) {
$self->{'_pathtoexe'}->{$exename} = $exe;
}
unless( defined $self->{'_pathtoexe'}->{$exename} ) {
my $f = $self->program_path($exename);
$exe = $self->{'_pathtoexe'}->{$exename} = $f if(-e $f && -x $f );
# This is how I meant to split up these conditionals --jason
# if exe is null we will execute this (handle the case where
# PROGRAMDIR pointed to something invalid)
unless( $exe ) { # we didn't find it in that last conditional
if( ($exe = $self->io->exists_exe($exename)) && -x $exe ) {
$self->{'_pathtoexe'}->{$exename} = $exe;
} else {
$self->warn("Cannot find executable for $exename") if $warn;
$self->{'_pathtoexe'}->{$exename} = undef;
}
}
}
return $self->{'_pathtoexe'}->{$exename};
}
=head2 program_dir
Title : program_dir
Usage : $factory->program_dir(@params)
Function: returns the program directory, obtained from ENV variable.
Returns: string
Args :
=cut
sub program_dir {
return Bio::Root::IO->catfile($ENV{FASTADIR}) if $ENV{FASTADIR};
}
=head2 run
Title : run
Usage : my @fasta_object = $factory->($input,$onefile);
where $factory is the name of executable FASTA program;
$input is file name containing the sequences in the format
of fasta or Bio::Seq object or array of Bio::Seq object;
$onefile is 0 if you want to save the outputs to different files
default: outputs are saved in one file
Function: Attempts to run an executable FASTA program
and return array of fasta objects containing the fasta report
Returns : aray of fasta report object
If the user specify the output file(s),
the raw fasta report will be saved
Args : sequence object OR array reference of sequence objects
filename of file containing fasta formatted sequences
=cut
sub run {
my ($self,$input,$onefile)=@_;
local * FASTARUN;
$self->io->_io_cleanup;
my $program = $self->executable($self->program_name) ||
$self->throw("FASTA program not found or not executable.\n");
# You should specify a library file
$self->throw("You didn't choose library.\n") unless ( $library);
my @seqs = $self->_setinput($input);
return 0 unless (@seqs);
my @fastobj;
my ($fhout, $tempoutfile)=$self->io->tempfile(-dir=>$self->tempdir);
my $outfile=$self->O();
# The outputs from executable FASTA program will
# be saved into different files if $onefile is 0,
# else will be concatenated into one file
my $onfile = (!defined $onefile || $onefile =~ /^0$/);
unless( $onfile ) {
my $count=0;
# do some fancy stuff here to test if we are running fasta34
# with mlib so we just pass in a single file rather than
# running fasta N times
# (not implemented yet)
foreach my $seq (@seqs){
$count++;
# Decide if the output will be saved into a temporary file
if( $outfile ) {
$self->O(sprintf("%s_%d",$outfile,$count));
}
my ($fhinput,$teminputfile)=
$self->io->tempfile(-dir=>$self->tempdir);
my $temp = Bio::SeqIO->new(-fh=>$fhinput, '-format'=>'Fasta');
$temp->write_seq($seq);
$temp->close();
close $fhinput;
undef $fhinput;
my $para= $self->_setparams;
$para .=" $teminputfile $library $ktup";
$para ="$program $para";
my $object;
unless( $outfile ) {
open(FASTARUN, "$para |") || $self->throw($@);
$object = Bio::SearchIO->new(-fh=>\*FASTARUN,
-format=>"fasta");
} else {
if ( $self->verbose() < 0) {
my $null = ($^O =~ m/mswin/i) ? 'NUL' : '/dev/null';
$para .= " >$null 2>$null";
} else {
$self->debug("Going to execute: $para");
}
my $status = system($para);
$self->throw("$para crashed: $?\n" )unless ($status==0);
$object = Bio::SearchIO->new(-file=>$self->O,
-format=>"fasta");
}
push @fastobj, $object;
}
} else {
if ($outfile){
open (FILE, ">$outfile") or $self->throw("can't use $outfile:$!");
close(FILE);
}
foreach my $seq (@seqs){
my ($fhinput,$teminputfile)=$self->io->tempfile(-dir=>$self->tempdir);
my $temp=Bio::SeqIO->new(-fh=>$fhinput, '-format'=>'fasta');
$temp->write_seq($seq);
$temp->close();
close $fhinput;
undef $fhinput;
$self->O($tempoutfile) if( $outfile );
my $para= $self->_setparams;
$para .= " $teminputfile $library $ktup";
$para ="$program $para";
my $object;
unless( $outfile ) {
open(FASTARUN, "$para |") || $self->throw($@);
$object=Bio::SearchIO->new(-fh=>\*FASTARUN,
-format=>"fasta");
} else {
if ( $self->verbose() < 0) {
my $null = ($^O =~ m/mswin/i) ? 'NUL' : '/dev/null';
$para .= " >$null 2>$null";
} else {
$self->debug("Going to execute: $para");
}
my $status = system($para);
$self->throw("$para crashed: $?\n" )unless ($status==0);
$object = Bio::SearchIO->new(-file=>$self->O,
-format=>"fasta");
}
push @fastobj, $object;
# The output in the temporary file
# will be saved at the end of $outfile
if($outfile){
open (FHOUT, $tempoutfile) or die("can't open the $tempoutfile file");
open (FH, ">>$outfile") or die("can't use the $outfile file");
print FH (<FHOUT>);
close (FHOUT);
close (FH);
}
}
}
return @fastobj;
}
=head2 library
Title : library
Usage : my $lb = $self->library
Function: Fetch or set the name of the library to search against
Returns : The name of the library
Args : No argument if user wants to fetch the name of library file;
A letter or a string of letter preceded by %;
(e.g. P or %pn, the letter is the character in the third field
of any line of fastlibs file ) or the name of library file
(if environmental variable FASTLIBS is not set);
if user wants to set the name of library file to search against
=cut
sub library {
my($self,$lb)=@_;
return $library if (!defined($lb));
if ( ($lb =~ /^%[a-zA-Z]+$/)||($lb=~ /^[a-zA-Z]$/)){
if(! defined $ENV{'FASTLIBS'} ){
$self->throw("abbrv. list request but FASTLIBS undefined, cannot use $lb");
}
} else {
unless ( -e $lb){
$self->throw("cannot open $lb library");
}
}
return $library=$lb;
}
*database = \&library;
=head2 output
Title : output
Usage : $obj->output($newval)
Function: The output directory if we want to use this
Example :
Returns : value of output (a scalar)
Args : on set, new value (a scalar or undef, optional)
=cut
sub output{
my $self = shift;
return $self->{'output'} = shift if @_;
return $self->{'output'};
}
=head2 ktup
Title : ktup
Usage : my $ktup = $self->ktup
Function: Fetch or set the ktup value for executable FASTA programs
Example :
Returns : The value of ktup if defined, else undef is returned
Args : No argument if user want to fetch ktup value; A integer value between 1-6 if user want to set the
ktup value
=cut
sub ktup {
my($self,$k)=@_;
if(!defined($k)){return $ktup;}
if ($k =~ /^[1-6]$/){
$ktup=$k;
return $ktup
} else {
$self->warn("You should set the ktup value between 1-6. The FASTA program will decide your default ktup value.");
return $ktup= undef;
}
}
=head2 _setinput
Title : _setinput
Usage : Internal function, not to be called directly
Function: Create input file(s) for Blast executable
Example :
Returns : array of Bio::Seq object reference
Args : Seq object reference or input file name
=cut
sub _setinput {
my ($self, $input) = @_;
if( ! defined $input ) {
$self->throw("Calling fasta program with no input");
}
my @seqs;
if( ! ref $input ) {
if( -e $input ) {
my $seqio = Bio::SeqIO->new(-format => 'fasta', -file => $input);
while( my $seq = $seqio->next_seq ) {
push @seqs, $seq;
}
} else {
$self->throw("Input $input was not a valid filename");
}
} elsif( ref($input) =~ /ARRAY/i ) {
foreach ( @$input ) {
if( ref($_) && $_->isa('Bio::PrimarySeqI') ) {
push @seqs, $_;
} else {
$self->warn("Trying to add a " . ref($_) ." but expected a Bio::PrimarySeqI");
}
}
if( ! @seqs) {
$self->throw("Did not pass in valid input -- no sequence objects found");
}
} elsif( $input->isa('Bio::PrimarySeqI') ) {
push @seqs, $input;
}
return @seqs;
}
=head2 _exist
Title : _exist
Usage : Internal function, not to be called directly
Function: Determine whether a executable FASTA program can be found
Cf. the DESCRIPTION section of this POD for how to make sure
for your FASTA installation to be found. This method checks for
existence of the blastall executable in the path.
Returns : 1 if FASTA program found at expected location, 0 otherwise.
Args : none
=cut
sub _exist {
my $exe = shift @_;
return 0 unless($exe =~ /fast|ssearch/);
$exe .='.exe' if ($^O =~ /mswin/i);
my $f;
return ($f=Bio::Root::IO->exists_exe($exe))&&(-x $f);
}
=head2 _setparams
Title : _setparams
Usage : Internal function, not to be called directly
Function: Create parameter inputs for FASTA executable
Returns : part of parameter string to be passed to FASTA program
Args : none
=cut
sub _setparams {
my ($self,$attr,$value);
$self = shift;
my $para = "";
foreach my $attr(@FASTA_PARAMS) {
$value = $self->$attr();
next unless (defined $value);
$para .=" -$attr $value";
}
$para .= " -q ";
return $para;
}
1;
__END__
|