#!/usr/bin/perl

$stroot = "RNA";
$shortLab = "RNAseq";
$longLab = "RNAseq Normalized Depth Tracks";

$prio = 100;

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

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

@gts = ("wt","ta1");
@inds = ("dox","ctrl");
@reps = (1,2,3);
@strands = ("plus","minus");

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

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\n";
print OUT "subGroup2\tgt Genotype"; foreach $gt (@gts) { print OUT " $gt=$gt"; } print OUT "\n";
print OUT "subGroup3\tind IfInduced"; foreach $ind (@inds) { print OUT " $ind=$ind"; } print OUT "\n";
print OUT "subGroup4\trep Replicate"; foreach $r (@reps) { print OUT " $r=$r"; } print OUT "\n";
print OUT "subGroup5\tstr Strand"; foreach $str (@strands) { print OUT " $str=$str"; } print OUT "\n";
print OUT "dimensions\tdimX=gt dimY=ind dimA=str\n";
print OUT "sortOrder\tview=+ gt=+ ind=+ rep=+ str=+\n";
print OUT "configurable\ton\n";
print OUT "type\tbigWig\n\n";

# write header for RNAseq tracks
print OUT "   track\tdata$stroot\_ViewDepth\n";
print OUT "   parent\tdata$stroot\n";
print OUT "   shortLabel\t$shortLab\n";
print OUT "   longLabel\t$longLab\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:40:11\n";
print OUT "   autoScale\tgroup\n";
#print OUT "   viewLimits\t0:5\n";
print OUT "   showSubtrackColorOnUi\ton\n";
print OUT "   viewUi\ton\n\n";

# write RNAseq depth tracks
foreach $gt (@gts) { foreach $ind (@inds) { foreach $r (@reps) { foreach $str (@strands) {
  $id = "rna.$gt.$ind.rep$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$id.$ss\n";
  print OUT "      parent\tdata$stroot\_ViewDepth\n";
  print OUT "      bigDataUrl\t$bwfile\n";
  print OUT "      shortLabel\t$id ($str)\n";
  print OUT "      longLabel\t$gt/$ind rep$r RPM-normalized depth (RNAseq $str strand)\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 gt=$gt ind=$ind rep=$r str=$str\n\n";
} } } }

print OUT "\n\n";

close(OUT);
