#!/usr/bin/perl -w 


$firstn=1;
$minreadsum = 10;
$minspliceraw = 0;

@dirs = qw(
hs1B
hs1D
);
$ndirs = scalar(@dirs);

for($i=0;$i<$ndirs;$i++){
$d = $dirs[$i];

system("ls $d/*_splicingValues.txt > filelist");

open(IF,"filelist");

while($a=<IF>){
chomp($a);
$tgene = $a;
$tgene =~ s/$d\///;
$tgene =~ s/_splicingValues.txt//;
$tn=0;
open(SV,"$a");
$b=<SV>;
while($b = <SV>){
chomp($b);
#relPos	readSum	splicingValueRaw	splicingValueNorm
#-100	6	0	0
($relpos,$readsum,$spliceraw,$splicenorm) = split(/\t/,$b);
if($relpos > 0 && $readsum > $minreadsum && $spliceraw > $minspliceraw){
if($tn<$firstn){  $info{$d}{$tgene} .= "$relpos"; if($firstn>1){$info{$d}{$tgene} .= ";";}}
$tn++;
$genes{$tgene}++;
}
}
}
}


print "gene";
for($i=0;$i<$ndirs;$i++){$d = $dirs[$i];print "\t$d";}
print "\n";

foreach $gene (sort keys %genes){
print "$gene";
for($i=0;$i<$ndirs;$i++){
$d = $dirs[$i];
if(exists $info{$d}{$gene}){ print "\t$info{$d}{$gene}";}
else{print "\tNA";}
}
print "\n";
}


