BioPerl-Run

 view release on metacpan or  search on metacpan

lib/Bio/Tools/Run/StandAloneBlastPlus.pm  view on Meta::CPAN

	$f =~ s/\..*$//; # ignore extensions
	$db_path = File::Spec->catfile($d||'.',$f);
    }
    else {
	$db_path = $self->db_path;
    }
    if ( $db_path ) {
	$self->{_factory} = $bp_class->new( -command => 'blastdbcmd',
					    -info => 1,
					    -db => $db_path );
#	$DB::single=1;
	$self->factory->no_throw_on_crash(1);
	$self->factory->_run();
	$self->factory->no_throw_on_crash(0);
	return 0 if ($self->factory->stderr =~ /No alias or index file found/);
	return 1;
    }
    return;
}

=head2 no_throw_on_crash()

 Title   : no_throw_on_crash
 Usage   : $fac->no_throw_on_crash($newval)
 Function: set to prevent an exeception throw on a failed 
           blast program execution
 Example : 
 Returns : value of no_throw_on_crash (boolean)
 Args    : on set, new value (boolean)

=cut

sub no_throw_on_crash {
    my $self = shift;
    
    return $self->{'no_throw_on_crash'} = shift if @_;
    return $self->{'no_throw_on_crash'};
}


=head1 Internals

=head2 _fastize()

 Title   : _fastize
 Usage   : 
 Function: convert a sequence collection to a temporary
           fasta file (sans gaps)
 Returns : fasta filename (scalar string)
 Args    : sequence collection 

=cut

sub _fastize {
    my $self = shift;
    my $data = shift;
    for ($data) {
	!ref && do {
	    # suppose a fasta file name
	    $self->throw('Sequence file not found') unless -e $data;
	    my $guesser = Bio::Tools::GuessSeqFormat->new(-file => $data);
	    $self->throw('Sequence file not in FASTA format') unless
		$guesser->guess eq 'fasta';
	    last;
	};
	(ref eq 'ARRAY') && (ref $$data[0]) &&
	    ($$data[0]->isa('Bio::Seq') || $$data[0]->isa('Bio::PrimarySeq'))
	    && do {
		my $fh = File::Temp->new(TEMPLATE => 'DBDXXXXX', 
					 UNLINK => 0, 
					 DIR => $self->db_dir,
					 SUFFIX => '.fas');
		my $fname = $fh->filename;
		$fh->close;
		$self->_register_temp_for_cleanup($fname);
		my $fasio = Bio::SeqIO->new(-file=>">$fname", -format=>"fasta")
		   or $self->throw("Can't create temp fasta file");
		for (@$data) {
		    my $s = $_->seq;
		    my $a = $_->alphabet;
		    $s =~ s/[$Bio::PrimarySeq::GAP_SYMBOLS]//g;
		    $_->seq( $s );
		    $_->alphabet($a);
		    $fasio->write_seq($_);
		}
		$fasio->close;
		$data = $fname;
		last;
	};
	ref && do { # some kind of object
	    my ($fmt) = ref($data) =~ /.*::(.*)/;
	    if ($fmt eq 'fasta') {
		$data = $data->file; # use the fasta file directly
	    }
	    else {
		# convert
		my $fh = File::Temp->new(TEMPLATE => 'DBDXXXXX', 
					 UNLINK => 0, 
					 DIR => $self->db_dir,
					 SUFFIX => '.fas');
		my $fname = $fh->filename;
		$fh->close;
		$self->_register_temp_for_cleanup($fname);
		my $fasio = Bio::SeqIO->new(-file=>">$fname", -format=>"fasta") 
		    or $self->throw("Can't create temp fasta file");
		require Bio::PrimarySeq;
		if ($data->isa('Bio::AlignIO')) {
		    my $aln = $data->next_aln;
		    for ($aln->each_seq) {
			# must de-gap
			my $s = $_->seq;
			my $a = $_->alphabet;
			$s =~ s/[$Bio::PrimarySeq::GAP_SYMBOLS]//g;
			$_->seq( $s );
			$_->alphabet($a);
			$fasio->write_seq($_) 
		    }
		}
		elsif ($data->isa('Bio::SeqIO')) {
		    while (local $_ = $data->next_seq) {
			my $s = $_->seq;
			my $a = $_->alphabet;
			$s =~ s/[$Bio::PrimarySeq::GAP_SYMBOLS]//g;



( run in 2.879 seconds using v1.01-cache-2.11-cpan-75ffa21a3d4 )