in reply to Re^3: Reduce RAM required
in thread Reduce RAM required

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!

Replies are listed 'Best First'.
Re^5: Reduce RAM required
by tybalt89 (Monsignor) on Jan 09, 2019 at 19:16 UTC

    Does your input file have leading whitespace?

    Also, program state is altered by the print statement, you can't have two of them.

      head -n1 Ath_orig.fa >Chr1

      Doesn't appear to have any leading whitespace

      About the print statement, even if I comment out the first one, the output file is still empty

      Conversely, if I comment out the second one, I do not see the output on screen as STDOUT

      If you would like to replicate the same behavior with my input file, you can download it from here -

      https://www.filehosting.org/file/details/774814/Ath_orig.fa

      Thanks a lot!

        Just post about 20 lines here, enclosed in a code block, instead of using a posting service that requires an email address.

        Try adding an error message as an "else" part to the "if" test to see if there are any invalid lines in the input file.