Created
September 10, 2014 18:11
-
-
Save rhallPB/7275c48d6f166e1410df to your computer and use it in GitHub Desktop.
Coverage bed to csv file to be used in CeleraToGephi script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
print "Name,MedianCoverage,ReferenceLength,MapsTo\n"; | |
use List::Util qw(sum max); | |
open FBed, $ARGV[0]; | |
open Fnuc, $ARGV[1]; | |
while(<FBed>){ | |
if (!/^track/){ | |
chomp; | |
split; | |
$length{$_[0]} = $_[2]; | |
push(@{$coverageArray{$_[0]}},$_[4]); | |
} | |
} | |
while(<Fnuc>){ | |
if(/^ +[0-9]+/){ | |
split; | |
$contig = $_[12]; | |
$ref = $_[11]; | |
@out = split(/\|/,$_[12]); | |
$map{$out[0]} = $_[11]; | |
} | |
} | |
foreach $contig (sort keys %length){ | |
$medianCov = median(@{$coverageArray{$contig}}); | |
print $contig.','.$medianCov.','.$length{$contig}.",".$map{$contig}."\n"; | |
} | |
sub mean | |
{ | |
return sum(@_)/@_;; | |
} | |
sub median | |
{ | |
my @vals = sort {$a <=> $b} @_; | |
my $len = @vals; | |
if($len%2) #odd? | |
{ | |
return $vals[int($len/2)]; | |
} | |
else #even | |
{ | |
return ($vals[int($len/2)-1] + $vals[int($len/2)])/2; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment