Juba has asked for the wisdom of the Perl Monks concerning the following question:
The infile looks like this with hundreds of thousands of repeats#!/usr/bin/perl -w #This code joins randomly haplotypes two by two from the output given +by Eli's program with an arbitrary number of populations. It needs a +2 allele output. It is the infile for R calculation. if ( @ARGV != 1 ) { print "incorrect usage ---- TYPE IN COMMAND LINE: perl eli+.pl inf +ile\n"; exit(); } print "What's the OUTFILE?\n"; $OUTFILE = <STDIN>; open (OUT, ">$OUTFILE") or die "could not create $OUTFILE\n"; open (IN, $ARGV[0]); #open the first argument #transform the input list in an array of arrays @total = (); @haplotypes=(); $currentPop = 0; $sampleSize={}; # This will hold the sample size for each population + while(<IN>) { chomp; if (/^(\-{0,1}\d+\t-{0,1}\d+)/) { $sampleSize{$currentPop}++; @temp = split; push @{$haplotypes{$currentPop}}, [@temp]; }elsif (/segsites: (\d+)/) { @{$TempList{$currentPop}}=(); while(@{$haplotypes{$currentPop}}) { push(@{$TempList{$currentPop}}, + splice(@{$haplotypes{$currentPop}}, rand(@{$haplotypes{$currentPop}}), 1)) + } @{$haplotypes{$currentPop}} = @{$TempList{$currentPop}}; push @total, $currentPop; $currentPop++; + } + } foreach $_ (@total) { print "Population $_\n"; print OUT "Population $_\n"; print "$sampleSize{$_}\n"; for($i = 0; $i < $sampleSize{$_}/2; $i++) { @pair =(); @pair = splice @{$haplotypes{$_}}, 0, 2; print "$pair[0][0]\t$pair[1][0]\t$pair[0][1]\t$pair[1][1]\t\n"; print OUT "$pair[0][0]\t$pair[1][0]\t$pair[0][1]\t$pair[1][1]\t\n"; + } + } print "$currentPop\n";
segsites: 2 tMRCA: 0.6398829 Fsense 1 founders: 2 -4 0 -4 0 -1 1 -4 0 -segsites: 2 tMRCA: 0.3395337 Fsense 1 founders: 2 0 0 0 0 -3 -1 0 0
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: still memory leak
by BrowserUk (Patriarch) on Aug 05, 2004 at 02:12 UTC | |
by Juba (Initiate) on Aug 05, 2004 at 11:17 UTC |