So I'm working with a kmer project and I needed to generate a 4**21 by 197 matrix to record the information I need for each kmer since I'm doing 21mer right now. However, it shows out of memory when I try to generate the matrix. Is there any way I can get around with it?
Here is the script I wrote:
#!/usr/bin/perl
use strict;
use warnings;
#initialize matrix
my @matrix;
my $i; #column
my $j; #roll
my @sum;
for ($i=0; $i<197; $i++){
for ($j=0; $j<4**21; $j++){
$matrix[$i][$j]=0;
if($i==0)
{
$sum[$j]=0;
}
}
}
#inport file names
my $fn = $ARGV[0];
chomp $fn;
unless (open(FILE, $fn)){
print "Can't open file \"$fn\"\n\n";
exit;
}
chomp(my @line = <FILE>);
my $n;
for ($n=0; $n<scalar @line; $n++){
#open each kmer file
unless (open(KMER, $line[$n])){
print "Can't open file \"$line[$n]\"\n\n";
exit;
}
my @kmers = <KMER>;
my @all_kmer;
my $kmer;
foreach $kmer (@kmers){
my @split = split(/\s+/,$kmer); #obtain kmer reference
+ number
$matrix[$n][$split[0]] = 1;
#print OUT "$matrix[$n][$split[0]]\t";
$sum[$split[0]]=$sum[$split[0]]+1;
}
close $line[$n];
}
close $fn;
#creat outfile
my $outfile = $ARGV[1];
unless(open OUT, '>' .$outfile){
die "\nUnable to create $outfile\n";
}
#sum up
for ($j=0; $j<4**21; $j++){
print OUT "$sum[$j]\n";
}
-
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.
|