view NEUMA-1.2.1/calculate_gEUMA.pl @ 0:c44c43d185ef draft default tip

NEUMA-1.2.1 Uploaded
author chawhwa
date Thu, 08 Aug 2013 00:46:13 -0400
parents
children
line wrap: on
line source

#!/usr/bin/perl
# Compute gEUMA for each gene from the gUtable file and insertlendis file and print out only genes whose gEUMA is larger than 0.

if(@ARGV<3) { print "usage: $0 gUtable_file insertlendis_file READLENGTH\n"; exit; }

my ($gUtable_file,$insertlendis_file,$READLENGTH) = @ARGV;

open GUTABLE, $gUtable_file or die "Can't open gUtable file $gUtable_file\n";
chomp($header = <GUTABLE>); 
@distances = split/\t/,$header;
shift @distances;   #'gene'
while(<GUTABLE>){
 chomp;
 my @line = split/\t/;
 my $gene = shift @line;
 for my $i (0..$#distances){
   $gUtable{$gene}{"$distances[$i]"}=$line[$i];
 }
}
close GUTABLE;


my $totalfreq=0;
open LENDIS, $insertlendis_file or die "Can't open insertlendis file $insertlendis_file\n";
while(<LENDIS>){
 chomp;
 my ($insert_size, $freq) = split/\t/;
 $insertlendis{"$insert_size"}=$freq;
 $totalfreq+=$freq;
}
close LENDIS;

print "gene\tgEUMA\n";  #header
for my $gene (sort keys %gUtable){
  my $EUMA=0;
  for my $d (keys %{$gUtable{$gene}}){
    $pUMA = $gUtable{$gene}{$d} * ($insertlendis{$d}/$totalfreq) ;
    $EUMA += $pUMA;
  }
  if($EUMA>=0.005) { printf "$gene\t%.2f\n",$EUMA; }  # use >=0.005  instead of >0, because I'm plotting two decimals after point. (in bp)
}