http://qs321.pair.com?node_id=1131307


in reply to Random shuffling

As hexcoder says, you only need to read two lines at a time. Rather than using C-style loops to move along the sequence shuffling as you go you could use unpack and map; as BrowserUk has observed, there seems to be no point in shuffling more than once.

use strict; use warnings; use List::Util qw{ shuffle }; my $inFile = shift; open my $inFH, q{<}, $inFile or die qq{open: < $inFile: $!\n}; my $outFile = $inFile . q{_shuffled.fasta}; open my $outFH, q{>}, $outFile or die qq{open: > $outFile: $!\n}; my $window = 10; while ( not eof $inFH ) { my( $id, $seq ) = map { chomp; $_ } map { scalar <$inFH> } 1 .. 2; my $shuffled = join q{}, map { join q{}, shuffle split m{} } unpack qq{(a$window)*}, $seq; print $outFH qq{$id\n$shuffled\n}; } close $inFH or die $!; close $outFH or die $!;

I hope this is of interest.

Update: Corrected cut'n'paste error in script, I was erroneously unpacking $shuffled instead of $seq.

Cheers,

JohnGG