#!/usr/bin/perl

$stroot = "RNA2";
$shortLab = "RNAseq spleen Sept2023";
$longLab = "RNAseq Normalized Depth Tracks - spleen Sept2023";

$prio = 200;

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

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

@gts = ("MTA1-KO","MTA1-WT","MTA3-KO","MTA3-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 Genotypes"; 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=replicate 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:25:11\n";
print OUT "   viewLimits\t0:3\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$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 spleen ($str)\n";
  print OUT "      longLabel\t$id RPM-normalized depth [spleen] ($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);
