#!/usr/bin/perl

$datadir = "data/NS51527_NS20113_mock_hg38";
$trackname = "trackDb.MB231-mock_hg38.Dec2024.txt";
$stroot = "RNA06";
$shortLab = "MDA-MB231-wtG3-FOXA1 [mock hg38]";

@samples = ("MB231-PM19-clone1","MB231-PM20-clone2","MB231-PM21-clone3","MB231-PM22-clone4","MB231-PM23-clone9","MB231-PM28-clone4","MB231-PM29-clone23");
@strands = ("plus","minus");

$prio = 160;

$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 RNAseq (normalized depth)\n";
print OUT "priority\t$prio\n";
print OUT "subGroup1\tview View NORM=normDepth\n";
print OUT "subGroup2\tSample Sample"; foreach $s (@samples) { print OUT " $s=$s"; } print OUT "\n";
print OUT "subGroup3\tSeqRun SeqRun NS51527=NS51527 NS20113=NS20113\n";
print OUT "subGroup4\tStrand Strand"; foreach $str (@strands) { print OUT " $str=$str"; } print OUT "\n";
print OUT "dimensions\tdimX=Sample dimA=Strand\n";
print OUT "sortOrder\tSample=+ SeqRun=+ 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 RNAseq 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:40:11\n";
print OUT "   autoScale\tgroup\n";
#print OUT "   viewLimits\t0:4\n";
print OUT "   showSubtrackColorOnUi\ton\n";
print OUT "   viewUi\ton\n\n";

# write depth tracks
foreach $s (@samples) { foreach $str (@strands) {
  $ss = uc(substr($str,0,1));
  $id = $s;
  $idZ = "$s.$ss";
  $bwfile = "$datadir/$id.depthRPM.$str.bw";
  unless (-e $bwfile) { print "WARNING: Did not find $bwfile.\n"; next; }
  if ($id eq "MB231-PM28-clone4" || $id eq "MB231-PM29-clone23") { $sr = "NS20113"; } else { $sr = "NS51527"; }
  $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$id ($str) [mock hg38]\n";
  print OUT "      longLabel\tnormalized RNA-seq depth: $id ($str) [mock hg38]\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\tSample=$s SeqRun=$sr Strand=$str view=NORM\n\n";
} }
print OUT "\n\n";


close(OUT);
