Open main menu

Biolecture.org β

Changes

N50 N90 calculation using Perl code

745 bytes added, 19:41, 8 November 2010
Created page with "<p><span style="font-family: Courier New">#/usr/bin/perl -w<br /> use strict;<br /> my ($len,$total)=(0,0);<br /> my @x;<br /> while(<>){<br /> if(/^[\>\@]/){<br /> if($..."
<p><span style="font-family: Courier New">#/usr/bin/perl -w<br />
use strict;<br />
my ($len,$total)=(0,0);<br />
my @x;<br />
while(&lt;&gt;){<br />
if(/^[\&gt;\@]/){<br />
if($len&gt;0){<br />
$total+=$len;<br />
push @x,$len;<br />
}<br />
$len=0;<br />
}<br />
else{<br />
s/\s//g;<br />
$len+=length($_);<br />
}<br />
}<br />
if ($len&gt;0){<br />
$total+=$len;<br />
push @x,$len;<br />
}<br />
@x=sort{$b&lt;=&gt;$a} @x; <br />
my ($count,$half)=(0,0);<br />
for (my $j=0;$j&lt;@x;$j++){<br />
$count+=$x[$j];<br />
if (($count&gt;=$total/2)&amp;&amp;($half==0)){<br />
print &quot;N50: $x[$j]\n&quot;;<br />
$half=$x[$j]<br />
}elsif ($count&gt;=$total*0.9){<br />
print &quot;N90: $x[$j]\n&quot;;<br />
exit;<br />
}<br />
}</span></p>