#!/usr/bin/perl -w 

open(IF,"ares_sc3_isoformst.bed");
while($a=<IF>){
chomp($a);
#chrI	87285	87752	SNC1	0	+	87285	87752	0	2	102,252,	0,215,
@b=split(/\t/,$a);
$n=$b[9];
$chrom=$b[0];
if($n>1){

@sizes = split(/,/,$b[10]);
@starts = split(/,/,$b[11]);
for($i=0;$i<$n;$i++){
$tstart = $b[1] + $starts[$i];
$tend = $tstart + $sizes[$i];
$bedhash{"$chrom $tstart $tend"}= $b[3];
print "$chrom $tstart $tend\n";
}
}}


print "<pre>\n";

use DBI; 

$db_user = "donohue"; 
$db_passwd = ""; 
$database = "DBI:mysql:one_sacCer3"; 
$mdb = DBI->connect($database, $db_user, $db_passwd) || die ("couldn't connect to database"); 
$cnt=0;
$q1uery = "select annName,chrom,start,end,strand,type,start_pos,end_pos from clean_span where type=2 ;";
$h1andle = $mdb->prepare($q1uery); 
$h1andle->execute; 
while( ($ann,$chrom,$justart,$juend,$strand,$type,$jusp,$juep) = $h1andle->fetchrow) {
$pos = "$chrom:$justart-$juend";
$length = $juend-$justart;
$l = $justart+1;
$r = $juend-1;
$ll = $l-4;
$rr = $r+4;
$npos = "$chrom:$ll-$rr";

$q2uery = "select annName,chrom,start,end,strand,type,start_pos,end_pos from clean_span where annName = '$ann' and  type=0  and end_pos = $juep;";
$h2andle = $mdb->prepare($q2uery); 
$h2andle->execute; 
($ann,$chrom,$exstart,$exend,$strand,$type,$start_pos,$end_pos) = $h2andle->fetchrow ;

$tintron = "$ann.$jusp.$juep";
$key = "$chrom $exstart $exend";
if($bedhash{$key}){
#great
}
else{$tt = $exend - $exstart ;  print "<a href=\"http://exon.ucsc.edu/cgi-bin/hgTracks?genome=sacCer3&position=$chrom:$exstart-$exend\">not in gtf $key $tt $ann</a>\n";}


#log2((INa x EXb)/(INb x EX a))  (for IAI)

}

