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.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|