Tye,

Thanks for the alternative piece of code, I ran into the very problem you described and was quite amazed to discover that a 10MB hash took up so much RAM.
The new solution, of course, brings up a new problem This is a little bit unusual. My program generates all the combinations of the 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 combination's, 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 continues not doing my stuff with each sequence then quits. Opening the resulting output of the combination sub routine shows that all the combinations are indeed there. The file size 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 Re: (tye)Re: Generate all possibilities by lostcause
in thread Generate all possibilities by lostcause

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.