G'day azheid,
Cutting your code down to a skeleton where I think your two biggest problems are:
if(!($permute)){
open(SEQ,'<',$sequence_fname)||die "Cannot open sequence file\n";
while (my @line=split (/\t/,<SEQ>)){
...
}
...
{
else{
for (...) {
...
open(SEQ,'<',$sequence_fname)||die "Cannot open sequence file\
+n";#open the sequence file
while (my @line=split (/\t/,<SEQ>)){#for each sequence record
+the nmer information
...
}
close SEQ;
open(OUT,">>$out")||die "Cannot open $out\n";
foreach my $key(keys %ktc){
...
print OUT ...
...
}
close OUT;
}
}
You open the SEQ file, read the data from disk, and parse it multiple times: you only need to do this once.
Also, you open and close the OUT file for appending multiple times: you only need to do this once.
Without making changes to your coding style, I suspect this, which does only open those files once, would be substantially faster:
my @seq_data;
open(SEQ,'<',$sequence_fname)||die "Cannot open sequence file\n";
while (<SEQ>) {
push @seq_data, [split /\t/];
}
close SEQ;
if(!($permute)){
for (@seq_data) {
my @line = @$_;
...
}
...
{
else{
open(OUT,">>$out")||die "Cannot open $out\n";
for (...) {
...
for (@seq_data) {
my @line = @$_;
...
}
foreach my $key(keys %ktc){
...
print OUT ...
...
}
}
close OUT;
}
There may be other areas where substantial gains could be made, but I haven't looked beyond the two I/O ones at this point.
-
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.