#!/usr/bin/perl

$stroot = "RNA3";
$shortLab = "RNAseq NPC May2024";
$longLab = "RNAseq Normalized Depth Tracks - NPC May2024";

$prio = 130;

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

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

@gts = ("NPC_G3KO","NPC_WT");
@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\trep Replicate"; foreach $r (@reps) { print OUT " $r=$r"; } print OUT "\n";
print OUT "subGroup4\tstr Strand"; foreach $str (@strands) { print OUT " $str=$str"; } print OUT "\n";
print OUT "dimensions\tdimX=gt dimY=rep dimA=str\n";
print OUT "sortOrder\tview=+ gt=+ 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 $r (@reps) { foreach $str (@strands) {
  $id = "$gt"."-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 rep$r 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 gt=$gt rep=$r str=$str\n\n";
} } }

print OUT "\n\n";

close(OUT);
