#!/usr/bin/perl

$datadir = "DATA/rna_adrenal-Dec2020";
$trackname = "trackDb.JAZF1-adrenal-Dec2020.txt";
$stroot = "RNA04";
$shortLab = "JAZF1-adrenal";

@grps = ("mouseAG-JAZF1-KO-F","mouseAG-JAZF1-KO-M","mouseAG-JAZF1-WT-F","mouseAG-JAZF1-WT-M");
%grp2short = ("mouseAG-JAZF1-KO-F" => "KO-F", "mouseAG-JAZF1-KO-M" => "KO-M", "mouseAG-JAZF1-WT-F" => "WT-F", "mouseAG-JAZF1-WT-M" => "WT-M");
@reps = (1,2,3,4);

$prio = 250;

$useColor = "0,0,0";
#$useColor = "0,0,204";


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 RNAseq\n";
print OUT "longLabel\t$shortLab RNA-seq data (normalized depth)\n";
print OUT "priority\t$prio\n";
print OUT "subGroup1\tview View NORM=normDepth\n";
print OUT "subGroup2\tGroup Group"; foreach $grp (@grps) { print OUT " $grp2short{$grp}=$grp2short{$grp}"; } print OUT "\n";
print OUT "subGroup3\tRep Rep"; foreach $r (@reps) { print OUT " $r=$r"; } print OUT "\n";
print OUT "dimensions\tdimX=Group dimY=Rep\n";
print OUT "sortOrder\tGroup=+ Rep=+\n";
print OUT "type\tbigWig\n\n";

# write header for depth tracks
print OUT "   track\tdata$stroot\_ViewDepth\n";
print OUT "   parent\tdata$stroot\n";
print OUT "   shortLabel\t$shortLab RNAseq\n";
print OUT "   longLabel\t$shortLab RNA-seq data (normalized depth)\n";
print OUT "   view\tNORM\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:30:11\n";
print OUT "   viewLimits\t0:500\n";
print OUT "   showSubtrackColorOnUi\ton\n";
print OUT "   viewUi\ton\n\n";

# write depth tracks
foreach $grp (@grps) { foreach $r (@reps) {
  $id = "$grp\-$r";
  $idlab = "$shortLab $grp2short{$grp}"."$r";
  $bwfile = "$datadir/$id.depthNorm.bw";
  unless (-e $bwfile) { print "WARNING: Did not find $bwfile.\n"; next; }
  $prio++;
  print OUT "      track\t$id.$stroot\n";
  print OUT "      parent\tdata$stroot\_ViewDepth\n";
  print OUT "      bigDataUrl\t$bwfile\n";
  print OUT "      shortLabel\t$idlab RNAseq\n";
  print OUT "      longLabel\tnormalized RNA-seq depth: $idlab\n";
  print OUT "      type\tbigWig\n";
  print OUT "      color\t$useColor\n";
  print OUT "      priority\t$prio\n";
  print OUT "      visibility\thide\n";
  print OUT "      subGroups\tGroup=$grp2short{$grp} Rep=$r view=NORM\n\n";
} }
print OUT "\n\n";


close(OUT);
