use strict; use warnings; use List::Util 'shuffle'; # Idea from http://www.perlmonks.org/?node_id=199901 my $input = shift @ARGV; open(IN, '<', $input) or die "Can't read multifasta input genomic DNA file $input : $!\n"; my $window = 1000000; # hard coded for shuffle window to be 1MB i.e 10^6 my (@IDsSeqs,$seq_id, $seq, @output); while () { chomp; push @IDsSeqs, $_; } my $index = 0; while ($index <= $#IDsSeqs) { $seq_id = $IDsSeqs[$index]; $seq = $IDsSeqs[$index+1]; my $final_seq; for (my $i = 1; $i <= length $seq; $i=$i+$window ) { my $s = substr ($seq, $i - 1, $window); my @temp_seq_array = split //, $s; my $rep = 1; while($rep <=10) { @temp_seq_array = shuffle @temp_seq_array; # using the List::Util module AND Shuffles EACH windown 10 times!!! $rep++; } my $rand_shuffled_seq = join ('', @temp_seq_array,); $final_seq = $final_seq.$rand_shuffled_seq; # concatenates the shuffled DNA seq to the 3' end of the previous 1MB fragment } push @output, $seq_id, "\n",$final_seq,"\n"; $index = $index + 2; # process every alternate line with ID (and its corresponding sequence in next line) } my $destination = $input."_1MBWindow_ListUtilshuffle.fasta"; open(OUT, '>', $destination) or die "Can't write to file $destination: $!\n"; print OUT @output; close OUT;