#!/usr/bin/perl

$stroot = "MT";
$shortLab = "Takaku";
$longLab = "Takaku Normalized Depth Tracks";

$prio = 250;

##############################################################

$datadir = "data/Takaku";
$trackname = "trackDb.$stroot.txt";

##############################################################

open(OUT, ">$trackname");

##### normalized depth #####
# write header supertrack header
print OUT "track\tdata$stroot\n";
print OUT "compositeTrack\ton\n";
print OUT "shortLabel\t$shortLab\n";
print OUT "longLabel\t$longLab\n";
print OUT "priority\t$prio\n";
print OUT "subGroup1\tview View RNA=RNA ChIP=ChIP\n";
print OUT "subGroup2\tStrand Strand plus=plus minus=minus NA=NA\n";
#print OUT "dimensions\tdimX=Antibody dimY=Treatment\n";
print OUT "sortOrder\tView=+\n";
print OUT "type\tbigWig\n\n";

# write header for RNAseq tracks
print OUT "   track\tdata$stroot\_ViewDepthRNA\n";
print OUT "   parent\tdata$stroot\n";
print OUT "   shortLabel\t$shortLab-RNA\n";
print OUT "   longLabel\t$longLab (RNA)\n";
print OUT "   view\tRNA\n";
print OUT "   visibility\tfull\n";
print OUT "   type\tbigWig\n";
print OUT "   allButtonPair\ton\n";
print OUT "   centerLabelsDense\ton\n";
print OUT "   dragAndDrop\ton\n";
print OUT "   alwaysZero\ton\n";
print OUT "   graphTypeDefault\tbar\n";
print OUT "   maxHeightPixels\t150:25:11\n";
print OUT "   viewLimits\t0:30\n";
print OUT "   showSubtrackColorOnUi\ton\n";
print OUT "   viewUi\ton\n\n";

# write RNAseq depth tracks
@trts = ("Veh","PR");
%trtKey = ("Veh" => "Veh", "PR" => "P4");
@reps = (1,2,3);
@strands = ("plus","minus");
foreach $trt (@trts) { foreach $r (@reps) { foreach $str (@strands) {
  $id = "T47D_$trt"."-$r";
  $useID = "T47D_$trtKey{$trt}"."-$r";
  $ss = uc(substr($str, 0, 1));
  $bwfile = "$datadir/$id.depthRPM.$str.bw";
  unless (-e $bwfile) { print "WARNING: Did not find \'$bwfile\'.\n"; next; }
  $prio++;
  print OUT "      track\t$useID.RNA-$ss.$stroot\n";
  print OUT "      parent\tdata$stroot\_ViewDepthRNA\n";
  print OUT "      bigDataUrl\t$bwfile\n";
  print OUT "      shortLabel\t$useID RNA ($str)\n";
  print OUT "      longLabel\t$useID RPM-normalized depth ($str)\n";
  print OUT "      type\tbigWig\n";
  print OUT "      color\t0,0,0\n";
  print OUT "      priority\t$prio\n";
  print OUT "      visibility\thide\n";
  print OUT "      subGroups\tview=RNA Strand=$str\n\n";
} } }

# write header for ChIPseq tracks
print OUT "   track\tdata$stroot\_ViewDepthChIP\n";
print OUT "   parent\tdata$stroot\n";
print OUT "   shortLabel\t$shortLab-ChIP\n";
print OUT "   longLabel\t$longLab (ChIP)\n";
print OUT "   view\tChIP\n";
print OUT "   visibility\tfull\n";
print OUT "   type\tbigWig\n";
print OUT "   allButtonPair\ton\n";
print OUT "   centerLabelsDense\ton\n";
print OUT "   dragAndDrop\ton\n";
print OUT "   alwaysZero\ton\n";
print OUT "   graphTypeDefault\tbar\n";
print OUT "   maxHeightPixels\t150:25:11\n";
print OUT "   viewLimits\t0:30\n";
print OUT "   showSubtrackColorOnUi\ton\n";
print OUT "   viewUi\ton\n\n";

# write ChIPseq depth tracks
$prio++;
$bwfile = "$datadir/T47D_P4_PR.hg38.bwt2.MAPQ5-PP.rmdup.singlefrag.norm10M.bigWig";
unless (-e $bwfile) { print "ERROR: Did not find $bwfile; exiting.\n"; exit; }
print OUT "      track\tMT_P4_PR.ChIP.$stroot\n";
print OUT "      parent\tdata$stroot\_ViewDepthChIP\n";
print OUT "      bigDataUrl\t$bwfile\n";
print OUT "      shortLabel\tT47D_P4_PR depth\n";
print OUT "      longLabel\tnormalized depth (T47D_P4_PR)\n";
print OUT "      type\tbigWig\n";
print OUT "      color\t0,0,0\n";
print OUT "      priority\t$prio\n";
print OUT "      visibility\thide\n";
print OUT "      subGroups\tview=ChIP Strand=NA\n\n";

$prio++;
$bwfile = "$datadir/T47D_P4_input.hg38.bwt2.MAPQ5-PP.rmdup.singlefrag.norm10M.bigWig";
unless (-e $bwfile) { print "ERROR: Did	not find $bwfile; exiting.\n"; exit; }
print OUT "      track\tMT_P4_input.ChIP.$stroot\n";
print OUT "      parent\tdata$stroot\_ViewDepthChIP\n";
print OUT "      bigDataUrl\t$bwfile\n";
print OUT "      shortLabel\tT47D_P4_input depth\n";
print OUT "	 longLabel\tnormalized depth (T47D_P4_input)\n";
print OUT "      type\tbigWig\n";
print OUT "      color\t102,102,102\n";
print OUT "      priority\t$prio\n";
print OUT "      visibility\thide\n";
print OUT "      subGroups\tview=ChIP Strand=NA\n\n";

print OUT "\n\n";

close(OUT);
