In your modified script, I hard coded the input and output file names as follows:

my $inputfile = 'Ath_orig.fa'; my $outputfile = 'Ath_tybalt_shuffle.fa';

the specified output file was created, BUT it was empty.

So I tried to modify your script very slightly to file handle syntax I am most familiar with, as follows, but here too the output file specified was empty. Not sure what I am doing wrong....

#!/usr/bin/perl #tybalt89_DNAfreq_Random_Generator.pl # https://perlmonks.org/?node_id=1228191 use strict; use warnings; my $window = 1e6; my $A = my $C = my $G = my $all = 0; my (@sizes, $tmp, $start); my $in = shift @ARGV; my $out = shift @ARGV; print $in, "\n"; print $out, "\n"; open IN, '<', $in or die "$! opening $in"; open OUT, '>', $out or die "$! opening $out"; sub letter { my $n = int rand $all--; $n < $A ? ($A--, return 'a') : $n < $A + $C ? ($C--, return 'c') : $n < $A + $C + $G ? ($G--, return 'g') : return 't'; } sub output { for my $count ( @sizes ) { print ">ID", $start++, "\n", map(letter(), 1 .. $count), "\n"; print OUT ">ID", $start++, "\n", map(letter(), 1 .. $count), "\n"; } @sizes = (); } while( <IN> ) { if( /^>/ ) { $start //= s/\D+//gr; } elsif( /^[acgt]/ ) { $A += tr/a//; $C += tr/c//; $G += tr/g//; $all += $tmp = tr/acgt//; push @sizes, $tmp; $all >= $window and output(); } } $all and output(); close IN; close OUT;

Execution syntax was simply:

 perl tybalt89_DNAfreq_Random_Generator.pl Ath_orig.fa Ath_tybalt_shuffle.fa

Thanks a lot!


In reply to Re^4: Reduce RAM required by onlyIDleft
in thread Reduce RAM required by onlyIDleft

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.