Dear all,
I have a follow up question to an answer I received from a previous question, which you can see here.
This is a little bit unusual. My program generates all the combinations of
the four DNA bases via the subroutine and saves them to disk. It later calls
the file and reads through it one line at a time with a while loop. With larger
sets of combinations, 5 or more bases long, this works fine but with a smaller
sets, 3 or 4 bases I encounter a strange error. After running the sub routine
the program reopens the file but the file is empty so the program skips the while loop (the file is empty)then quits. Opening the resulting output
of the combination sub routine shows that all the combinations are indeed there.
The file size for 3 base long combinitaions is just 320 bytes.
I have followed this in a debugger and its reproducible. My guess is that the
contents of the file are not been flushed to disk until the program ends. This
happens on both Linux and Win2k. I am also having problems deleting the file
after use. I've never run into this problem before. Ideas anyone?
Here is a script that illustrates the problem.
Try varying the commentating on the two unlink lines to see different effects
and the changing the length of the sequence that is generated
#!/usr/local/bin/perl -w $| = 1; #generate promoters my $Bases = "ACGT"; #my @PromoterLenghts = ($PromoterMinLenght...$PromoterMaxLength); my @PromoterLenghts = (4); my $PromotroListLength = $#PromoterLenghts; $PromotroListLength ++; #unlink 'permute.txt'; my ($currLenght, $permutelist_filename); foreach $currLenght (@PromoterLenghts){ $permutelist_filename = &permute_bases ($currLenght, $Bases); } #print "Sequences file $permutelist_filename\n"; open (PIN, "permute.txt")||die "Can't open file: $!\n"; open (OUTPUT, ">output.txt")||die "Can't open file: $!\n"; while (<PIN>){ $promoter = $_; chomp $promoter; #do intrestering stuff with promoter sequence print OUTPUT "$promoter\n"; } close PIN ||die "Could not close sequences file: $!"; close OUTPUT ||die "Could not close output file: $!"; unlink 'permute.txt'; ###################################################################### +### sub permute_bases { my( $length, $bases )= @_; my @bases= split //, $bases; my @digit= (0) x $length; my $seq= $bases[0] x $length; my $permutelist_filename = "permute.txt"; open (PERMUTEOUT, ">>$permutelist_filename"); while( 1 ) { print PERMUTEOUT $seq,$/; print $seq,$/; my $pos= 0; while( @bases <= ++$digit[$pos] ) { substr( $seq, $pos, 1 )= $bases[ $digit[$pos]= 0 ]; return if $length <= ++$pos; } substr( $seq, $pos, 1 )= $bases[ $digit[$pos] ]; } close PERMUTEOUT ||die "Could not close $permutelist_filename: $!" +; return ($permutelist_filename); }
In reply to Program can not read the contents of a small file that it has recently written! by lostcause
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |