#!/usr/bin/perl

# NOTE: I've not included input tracks here. Can be added later if desired.

$stroot = "COV";
$shortLab = "Depth";
$longLab = "Normalized Depth Tracks";

$prio = 100;

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

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

## in the hub, label as HC/WV instead of E/C/I/A

@abs = ("K9-WV","K9-HC","K27-WV","K27-HC");
@trts = ("V", "P");
@reps = (1,2,3,4,5);
%abKey = ("K9-WV" => "E", "K9-HC" => "CST", "K27-WV" => "I", "K27-HC" => "AB");
%trtKey = ("P" => "PR", "V" => "V");
%repKey = (1 => "Dec2020", 2 => "Jan2021", 3 => "Feb2021", 4 => "Mar2021", 5 => "Apr2021");

%useColors = ("P-K9-WV" => "0,153,0",       # green [WV]
              "V-K9-WV" => "0,0,204",       # blue  [WV]
              "P-K27-WV" => "255,128,0",    # orange [WV]
              "V-K27-WV" => "255,215,0",    # gold [WV]
              "V-K9-HC" => "153,51,255",    # purple [HC]
              "V-K27-HC" => "153,0,0");      # dark red [HC]
#              "input" => "102,102,102");    # gray -- not included for now

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

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 NORM=normDepth\n";
print OUT "subGroup2\tAntibody Antibody"; foreach $ab (@abs) { print OUT " $ab=$ab"; } print OUT "\n";
print OUT "subGroup3\tTreatment Treatment"; foreach $trt (@trts) { print OUT " $trt=$trt"; } print OUT "\n";
print OUT "subGroup4\tRep Rep"; foreach $r (@reps) { print OUT " $r=$r"; } print OUT "\n";
print OUT "dimensions\tdimX=Antibody dimY=Treatment\n";
print OUT "sortOrder\tAntibody=+ Treatment=+ 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\n";
print OUT "   longLabel\t$longLab\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:25:11\n";
print OUT "   viewLimits\t0:30\n";
print OUT "   showSubtrackColorOnUi\ton\n";
print OUT "   viewUi\ton\n\n";

# write depth tracks
foreach $ab (@abs) { foreach $trt (@trts) { foreach $r (@reps) {
  $useID = "$trt-$ab-rep$r";
  $bwfile = "$datadir/$trtKey{$trt}-$abKey{$ab}-$repKey{$r}.PE.hg19.singlefrag.norm10M.bigWig";
  unless (-e $bwfile) { print "Skipping $useID (no bigWig file found as \'$bwfile\').\n"; next; }
  $trt_ab = "$trt-$ab";
  $thiscolor = $useColors{$trt_ab};
  if ($thiscolor eq "") { print "ERROR: Did not find color assignment for \'$trt_ab\'.\n"; exit; }
  $prio++;
  print OUT "      track\t$useID.$stroot\n";
  print OUT "      parent\tdata$stroot\_ViewDepth\n";
  print OUT "      bigDataUrl\t$bwfile\n";
  print OUT "      shortLabel\t$useID depth\n";
  print OUT "      longLabel\tnormalized depth ($useID)\n";
  print OUT "      type\tbigWig\n";
  print OUT "      color\t$thiscolor\n";
  print OUT "      priority\t$prio\n";
  print OUT "      visibility\thide\n";
  print OUT "      subGroups\tAntibody=$ab Treatment=$trt Rep=$r view=NORM\n\n";
} } }
print OUT "\n\n";

close(OUT);
