Something like this?
#!/usr/bin/perl # https://perlmonks.org/?node_id=1228191 use strict; use warnings; my $window = 1e6; my $A = my $C = my $G = my $T = my $all = 0; my (@sizes, $tmp, $start); sub letter { my $n = rand $all--; $n < $A ? ($A--, return 'a') : $n < $A + $C ? ($C--, return 'c') : $n < $A + $C + $G ? ($G--, return 'g') : ($T--, return 't'); } sub output { for my $count ( @sizes ) { print ">ID", $start++, "\n"; print map(letter(), 1 .. $count), "\n"; } @sizes = (); } while( <DATA> ) { $start //= s/\D+//gr; $_ = <DATA>; $A += tr/a//; $C += tr/c//; $G += tr/g//; $T += tr/t//; $all += $tmp = tr/acgt//; push @sizes, $tmp; $all >= $window and output(); } $all and output(); __DATA__ >ID1 atgagcagctag >ID2 tggacgagctgaca >ID3 tgactagacggacatac
In reply to Re: Reduce RAM required
by tybalt89
in thread Reduce RAM required
by onlyIDleft
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |