Permalink
Browse files

properly removing tempfiles

svn path=/bioperl-run/trunk/; revision=12937
  • Loading branch information...
1 parent 4881281 commit b6657d01bd6c386cddc3c32d8fd3eeccdf03def5 @hyphaltip hyphaltip committed Feb 28, 2001
Showing with 17 additions and 24 deletions.
  1. +13 −10 Bio/Tools/Run/Alignment/Clustalw.pm
  2. +4 −14 t/Clustalw.t
View
23 Bio/Tools/Run/Alignment/Clustalw.pm
@@ -307,7 +307,7 @@ methods. Internal methods are usually preceded with a _
package Bio::Tools::Run::Alignment::Clustalw;
use vars qw($AUTOLOAD @ISA $DEBUG $PROGRAM $PROGRAMDIR
- $TMPOUTFILE @CLUSTALW_SWITCHES @CLUSTALW_PARAMS
+ $TMPDIR $TMPOUTFILE @CLUSTALW_SWITCHES @CLUSTALW_PARAMS
@OTHER_SWITCHES %OK_FIELD);
use strict;
use Bio::Seq;
@@ -365,7 +365,8 @@ sub new {
}
my ($attr, $value);
- (undef,$TMPOUTFILE) = $self->tempfile();
+ (undef,$TMPDIR) = $self->tempdir(CLEANUP=>1);
+ (undef,$TMPOUTFILE) = $self->tempfile(-dir => $TMPDIR);
while (@args) {
$attr = shift @args;
$value = shift @args;
@@ -563,8 +564,9 @@ sub _setinput {
# $input may be an array of BioSeq objects...
if (ref($input) eq "ARRAY") {
# Open temporary file for both reading & writing of BioSeq array
- ($tfh,$infilename) = $self->tempfile();
- $temp = Bio::SeqIO->new(-fh=>$tfh, '-format' =>'Fasta');
+ ($tfh,$infilename) = $self->tempfile(-dir=>$TMPDIR);
+ $temp = Bio::SeqIO->new('-fh'=>$tfh,
+ '-format' =>'Fasta');
# Need at least 2 seqs for alignment
unless (scalar(@$input) > 1) {return 0;}
@@ -574,21 +576,23 @@ sub _setinput {
{return 0;}
$temp->write_seq($seq);
}
+ $temp->close();
return $infilename;
}
# $input may be a SimpleAlign object.
- if (ref($input) eq "Bio::SimpleAlign") {
+ elsif (ref($input) eq "Bio::SimpleAlign") {
# Open temporary file for both reading & writing of SimpleAlign object
- ($tfh,$infilename) = $self->tempfile() if ($suffix ==1 ||
-$suffix== 2 );
- $temp = Bio::AlignIO->new(-fh=> $tfh,
+ if ($suffix ==1 || $suffix== 2 ) {
+ ($tfh,$infilename) = $self->tempfile(-dir=>$TMPDIR);
+ }
+ $temp = Bio::AlignIO->new('-fh'=> $tfh,
'-format' => 'Fasta');
$temp->write_aln($input);
return $infilename;
}
# or $input may be a single BioSeq object (to be added to a previous alignment)
- if (ref($input) && $input->isa("Bio::PrimarySeqI") && $suffix==2) {
+ elsif (ref($input) && $input->isa("Bio::PrimarySeqI") && $suffix==2) {
# Open temporary file for both reading & writing of BioSeq object
($tfh,$infilename) = $self->tempfile();
$temp = Bio::SeqIO->new(-fh=> $tfh, '-format' =>'Fasta');
@@ -598,7 +602,6 @@ $suffix== 2 );
return 0;
}
-
=head2 _setparams()
Title : _setparams
View
18 t/Clustalw.t
@@ -22,8 +22,7 @@ ok(1);
my @params = ('ktuple' => 2, 'matrix' => 'BLOSUM');
my $factory = Bio::Tools::Run::Alignment::Clustalw->new(@params);
-ok $factory->isa('Bio::Tools::Run::Alignment::Clustalw');#
-
+ok $factory->isa('Bio::Tools::Run::Alignment::Clustalw');
my $ktuple = 3;
$factory->ktuple($ktuple);
@@ -41,7 +40,6 @@ $factory->quiet($bequiet); # Suppress clustal messages to terminal
my $inputfilename = Bio::Root::IO->catfile("t","cysprot.fa");
my $aln;
-
my $clustal_present = Bio::Tools::Run::Alignment::Clustalw->exists_clustal();
unless ($clustal_present) {
warn "Clustalw program not found. Skipping tests 5 to 9.\n";
@@ -57,23 +55,18 @@ $aln = $factory->align($inputfilename);
ok ($aln->{order}->{'0'}, 'CATH_HUMAN-1-335',
"failed clustalw alignment using input file");
-
-my $str = Bio::SeqIO->new(-file=> Bio::Root::IO->catfile("t","cysprot.fa"), '-format' => 'Fasta');
+my $str = Bio::SeqIO->new(-file=> Bio::Root::IO->catfile("t","cysprot.fa"),
+ '-format' => 'Fasta');
my @seq_array =();
while ( my $seq = $str->next_seq() ) {
push (@seq_array, $seq) ;
}
-my $seq_array_ref = \@seq_array;
-
-$aln = $factory->align($seq_array_ref);
+$aln = $factory->align(\@seq_array);
ok ($aln->{order}->{'0'}, 'CATH_HUMAN-1-335',
"failed clustalw alignment using BioSeq array ");
-
-
-
my $profile1 = Bio::Root::IO->catfile("t","cysprot1a.msf");
my $profile2 = Bio::Root::IO->catfile("t","cysprot1b.msf");
@@ -82,7 +75,6 @@ $aln = $factory->profile_align($profile1,$profile2);
ok( $aln->{order}->{'1'}, 'CATH_HUMAN-1-335',
" failed clustalw profile alignment using input file" );
-
my $str1 = Bio::AlignIO->new(-file=> Bio::Root::IO->catfile("t","cysprot1a.msf"));
my $aln1 = $str1->next_aln();
my $str2 = Bio::AlignIO->new(-file=> Bio::Root::IO->catfile("t","cysprot1b.msf"));
@@ -92,8 +84,6 @@ $aln = $factory->profile_align($aln1,$aln2);
ok($aln->{order}->{'1'}, 'CATH_HUMAN-1-335',
"failed clustalw profile alignment using SimpleAlign input ");
-
-
$str1 = Bio::AlignIO->new(-file=> Bio::Root::IO->catfile("t","cysprot1a.msf"));
$aln1 = $str1->next_aln();
$str2 = Bio::SeqIO->new(-file=> Bio::Root::IO->catfile("t","cysprot1b.fa"));

0 comments on commit b6657d0

Please sign in to comment.