Skip to content
This repository
Browse code

properly removing tempfiles

svn path=/bioperl-run/trunk/; revision=12937
  • Loading branch information...
commit b6657d01bd6c386cddc3c32d8fd3eeccdf03def5 1 parent 4881281
Jason Stajich authored February 28, 2001
23  Bio/Tools/Run/Alignment/Clustalw.pm
@@ -307,7 +307,7 @@ methods. Internal methods are usually preceded with a _
307 307
 package Bio::Tools::Run::Alignment::Clustalw;
308 308
 
309 309
 use vars qw($AUTOLOAD @ISA $DEBUG $PROGRAM $PROGRAMDIR
310  
-	    $TMPOUTFILE @CLUSTALW_SWITCHES @CLUSTALW_PARAMS 
  310
+	    $TMPDIR $TMPOUTFILE @CLUSTALW_SWITCHES @CLUSTALW_PARAMS 
311 311
 	    @OTHER_SWITCHES %OK_FIELD);
312 312
 use strict;
313 313
 use Bio::Seq;
@@ -365,7 +365,8 @@ sub new {
365 365
     }
366 366
     
367 367
     my ($attr, $value);
368  
-    (undef,$TMPOUTFILE) = $self->tempfile();
  368
+    (undef,$TMPDIR) = $self->tempdir(CLEANUP=>1);
  369
+    (undef,$TMPOUTFILE) = $self->tempfile(-dir => $TMPDIR);
369 370
     while (@args)  {
370 371
 	$attr =   shift @args;
371 372
 	$value =  shift @args;
@@ -563,8 +564,9 @@ sub _setinput {
563 564
     #  $input may be an array of BioSeq objects...
564 565
     if (ref($input) eq "ARRAY") {
565 566
         #  Open temporary file for both reading & writing of BioSeq array
566  
-	($tfh,$infilename) = $self->tempfile();
567  
-	$temp =  Bio::SeqIO->new(-fh=>$tfh, '-format' =>'Fasta');
  567
+	($tfh,$infilename) = $self->tempfile(-dir=>$TMPDIR);
  568
+	$temp =  Bio::SeqIO->new('-fh'=>$tfh, 
  569
+				 '-format' =>'Fasta');
568 570
 
569 571
 	# Need at least 2 seqs for alignment
570 572
 	unless (scalar(@$input) > 1) {return 0;} 
@@ -574,21 +576,23 @@ sub _setinput {
574 576
 	    {return 0;}
575 577
 	    $temp->write_seq($seq);
576 578
 	}
  579
+	$temp->close();
577 580
 	return $infilename;
578 581
     }
579 582
 #  $input may be a SimpleAlign object.
580  
-    if (ref($input) eq "Bio::SimpleAlign") {
  583
+   elsif (ref($input) eq "Bio::SimpleAlign") {
581 584
 	#  Open temporary file for both reading & writing of SimpleAlign object
582  
-	($tfh,$infilename) = $self->tempfile() if ($suffix ==1 ||
583  
-$suffix== 2 );
584  
-	$temp =  Bio::AlignIO->new(-fh=> $tfh,
  585
+	if ($suffix ==1 || $suffix== 2 ) {
  586
+	    ($tfh,$infilename) = $self->tempfile(-dir=>$TMPDIR);
  587
+	}
  588
+	$temp =  Bio::AlignIO->new('-fh'=> $tfh,
585 589
 				   '-format' => 'Fasta');
586 590
 	$temp->write_aln($input);
587 591
 	return $infilename;
588 592
     }
589 593
 
590 594
 #  or $input may be a single BioSeq object (to be added to a previous alignment)
591  
-    if (ref($input) && $input->isa("Bio::PrimarySeqI") && $suffix==2) {
  595
+    elsif (ref($input) && $input->isa("Bio::PrimarySeqI") && $suffix==2) {
592 596
         #  Open temporary file for both reading & writing of BioSeq object
593 597
 	($tfh,$infilename) = $self->tempfile();
594 598
 	$temp =  Bio::SeqIO->new(-fh=> $tfh, '-format' =>'Fasta');
@@ -598,7 +602,6 @@ $suffix== 2 );
598 602
     return 0;
599 603
 }
600 604
 
601  
-
602 605
 =head2  _setparams()
603 606
 
604 607
  Title   :  _setparams
18  t/Clustalw.t
@@ -22,8 +22,7 @@ ok(1);
22 22
 my @params = ('ktuple' => 2, 'matrix' => 'BLOSUM');
23 23
 my  $factory = Bio::Tools::Run::Alignment::Clustalw->new(@params);
24 24
 
25  
-ok $factory->isa('Bio::Tools::Run::Alignment::Clustalw');# 
26  
-
  25
+ok $factory->isa('Bio::Tools::Run::Alignment::Clustalw');
27 26
 
28 27
 my $ktuple = 3;
29 28
 $factory->ktuple($ktuple);
@@ -41,7 +40,6 @@ $factory->quiet($bequiet);  # Suppress clustal messages to terminal
41 40
 my $inputfilename = Bio::Root::IO->catfile("t","cysprot.fa");
42 41
 my $aln;
43 42
 
44  
-
45 43
 my $clustal_present = Bio::Tools::Run::Alignment::Clustalw->exists_clustal();
46 44
 unless ($clustal_present) {
47 45
 	warn "Clustalw program not found. Skipping tests 5 to 9.\n";
@@ -57,23 +55,18 @@ $aln = $factory->align($inputfilename);
57 55
 ok ($aln->{order}->{'0'}, 'CATH_HUMAN-1-335', 
58 56
     "failed clustalw alignment using input file");
59 57
 
60  
-
61  
-my $str = Bio::SeqIO->new(-file=> Bio::Root::IO->catfile("t","cysprot.fa"), '-format' => 'Fasta');
  58
+my $str = Bio::SeqIO->new(-file=> Bio::Root::IO->catfile("t","cysprot.fa"), 
  59
+			  '-format' => 'Fasta');
62 60
 my @seq_array =();
63 61
 
64 62
 while ( my $seq = $str->next_seq() ) {
65 63
 	push (@seq_array, $seq) ;
66 64
     }
67 65
 
68  
-my $seq_array_ref = \@seq_array;
69  
-
70  
-$aln = $factory->align($seq_array_ref);
  66
+$aln = $factory->align(\@seq_array);
71 67
 	
72 68
 ok ($aln->{order}->{'0'}, 'CATH_HUMAN-1-335', 
73 69
     "failed clustalw alignment using BioSeq array ");
74  
-
75  
-
76  
-
77 70
 	
78 71
 my $profile1 = Bio::Root::IO->catfile("t","cysprot1a.msf");
79 72
 my $profile2 = Bio::Root::IO->catfile("t","cysprot1b.msf");
@@ -82,7 +75,6 @@ $aln = $factory->profile_align($profile1,$profile2);
82 75
 ok( $aln->{order}->{'1'}, 'CATH_HUMAN-1-335', 
83 76
     " failed clustalw profile alignment using input file" );
84 77
 
85  
-
86 78
 my $str1 = Bio::AlignIO->new(-file=> Bio::Root::IO->catfile("t","cysprot1a.msf"));
87 79
 my $aln1 = $str1->next_aln();
88 80
 my $str2 = Bio::AlignIO->new(-file=> Bio::Root::IO->catfile("t","cysprot1b.msf"));
@@ -92,8 +84,6 @@ $aln = $factory->profile_align($aln1,$aln2);
92 84
 ok($aln->{order}->{'1'}, 'CATH_HUMAN-1-335', 
93 85
    "failed clustalw profile alignment using SimpleAlign input ");
94 86
 
95  
-
96  
-
97 87
 $str1 = Bio::AlignIO->new(-file=> Bio::Root::IO->catfile("t","cysprot1a.msf"));
98 88
 $aln1 = $str1->next_aln();
99 89
 $str2 = Bio::SeqIO->new(-file=> Bio::Root::IO->catfile("t","cysprot1b.fa"));

0 notes on commit b6657d0

Please sign in to comment.
Something went wrong with that request. Please try again.