BioPerl-Run

 view release on metacpan or  search on metacpan

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

    my $param_string = $self->_setparams();

    # run probalign
    return &_run($self, $infilename, $param_string);
}

=head2  _run

 Title   :  _run
 Usage   :  Internal function, not to be called directly
 Function:  makes actual system call to probalign program
 Example :
 Returns : nothing; probalign output is written to a
           temporary file OR specified output file
 Args    : Name of a file containing a set of unaligned fasta sequences
           and hash of parameters to be passed to probalign


=cut

sub _run {
    my ($self,$infilename,$params) = @_;
    my $commandstring = $self->executable." $infilename $params";

    $self->debug( "probalign command = $commandstring \n");

    my $status = system($commandstring);
    my $outfile = $self->outfile_name(); 

    if( !-e $outfile || -z $outfile ) {
	$self->warn( "Probalign call crashed: $? [command $commandstring]\n");
	return undef;
    }

    my $in  = Bio::AlignIO->new('-file'   => $outfile, 
				'-format' => $self->aformat);
    my $aln = $in->next_aln();
    return $aln;
}


=head2  _setinput

 Title   :  _setinput
 Usage   :  Internal function, not to be called directly	
 Function:  Create input file for probalign program
 Example :
 Returns : name of file containing probalign data input AND
 Args    : Arrayref of Seqs or input file name


=cut

sub _setinput {
    my ($self,$input) = @_;
    my ($infilename, $seq, $temp, $tfh);
    if (! ref $input) {
	# check that file exists or throw
	$infilename = $input;
	unless (-e $input) {return 0;}
	# let's peek and guess
	open(IN,$infilename) || $self->throw("Cannot open $infilename");
	my $header;
	while( defined ($header = <IN>) ) {
	    last if $header !~ /^\s+$/;
	}
	close(IN);
	if ( $header !~ /^>\s*\S+/ ){
	    $self->throw("Need to provide a FASTA format file to probalign!");
	} 
	return ($infilename);
    } elsif (ref($input) =~ /ARRAY/i ) { #  $input may be an
	#  array of BioSeq objects...
        #  Open temporary file for both reading & writing of array
	($tfh,$infilename) = $self->io->tempfile();
	if( ! ref($input->[0]) ) {
	    $self->warn("passed an array ref which did not contain objects to _setinput");
	    return undef;
	} elsif( $input->[0]->isa('Bio::PrimarySeqI') ) {
	    $temp =  Bio::SeqIO->new('-fh' => $tfh,
				     '-format' => 'fasta');
	    my $ct = 1;
	    foreach $seq (@$input) {
		return 0 unless ( ref($seq) && 
				  $seq->isa("Bio::PrimarySeqI") );
		if( ! defined $seq->display_id ||
		    $seq->display_id =~ /^\s+$/) {
		    $seq->display_id( "Seq".$ct++);
		} 
		$temp->write_seq($seq);
	    }
	    $temp->close();
	    undef $temp;
	    close($tfh);
	    $tfh = undef;
	} else { 
	    $self->warn( "got an array ref with 1st entry ".
			 $input->[0].
			 " and don't know what to do with it\n");
	}
	return ($infilename);
    } else { 
	$self->warn("Got $input and don't know what to do with it\n");
    }
    return 0;
}


=head2  _setparams

 Title   :  _setparams
 Usage   :  Internal function, not to be called directly	
 Function:  Create parameter inputs for probalign program
 Example :
 Returns : parameter string to be passed to probalign
           during align or profile_align
 Args    : name of calling object

=cut

sub _setparams {



( run in 1.295 second using v1.01-cache-2.11-cpan-39bf76dae61 )