It's your fault :)
In your original post, you showed the input as LOWER CASE. Your actual data file has input in UPPER CASE.
Here's a version that handles upper case.
#!/usr/bin/perl # 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 $inputfile = shift // 'd.1228191'; my $outputfile = shift // 'd.out.1228191'; open my $in, '<', $inputfile or die "$! opening $inputfile"; open my $out, '>', $outputfile or die "$! opening $outputfile"; 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 $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;
In reply to Re^9: Reduce RAM required
by tybalt89
in thread Reduce RAM required
by onlyIDleft
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |