#!/usr/bin/perl

$datadir = "DATA/G1KO_aged_testes";
$trackname = "trackDb.G1KO_aged_testes_Aug2021.txt";
$stroot = "RNA03";
$shortLab = "aged testes G1KO";
$shortLabID = "aged testes";  # prepend to grp2short for full ID

@grps = ("aged-testes-G1KO","aged-testes-G1WT");
%grp2short = ("aged-testes-G1KO" => "G1KO", "aged-testes-G1WT" => "G1WT");
@reps = (1,2,3,4,5);
@strands = ("plus","minus");

$prio = 200;

$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\tGenotype Genotype"; foreach $grp (@grps) { print OUT " $grp=$grp"; } print OUT "\n";
print OUT "subGroup3\tRep Rep"; foreach $r (@reps) { print OUT " $r=$r"; } print OUT "\n";
print OUT "subGroup4\tStrand Strand"; foreach $str (@strands) { print OUT " $str=$str"; } print OUT "\n";
print OUT "dimensions\tdimX=Genotype dimY=Rep dimA=Strand\n";
print OUT "sortOrder\tGenotype=+ Rep=+ Strand=+\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:600\n";
print OUT "   showSubtrackColorOnUi\ton\n";
print OUT "   viewUi\ton\n\n";

# write depth tracks
foreach $grp (@grps) { foreach $r (@reps) { foreach $str (@strands) {
  $id = "$grp\-rep$r";
  $idlab = "$shortLabID $grp2short{$grp}"."-$r ($str)";
  $idZ = "$grp2short{$grp}"."$r.$str";
  $bwfile = "$datadir/$id.depthNorm.$str.bw";
  unless (-e $bwfile) { print "WARNING: Did not find $bwfile.\n"; next; }
  $prio++;
  print OUT "      track\t$idZ.$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 testes\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\tGenotype=$grp Rep=$r Strand=$str view=NORM\n\n";
} } }
print OUT "\n\n";


close(OUT);
