#!/usr/bin/perl

$usecolorIP = "0,0,153";
$usecolorInput = "102,102,102";

open(OUT, ">trackDb.ChIP.txt");
$prio = 200;

### write composite track header
print OUT "track\tdataChIPseq\n";
print OUT "compositeTrack\ton\n";
print OUT "shortLabel\tChIPseq\n";
print OUT "longLabel\tChIPseq data\n";
print OUT "priority\t$prio\n";
print OUT "subGroup1\tview View COV=depth PK=peak\n";
print OUT "subGroup2\tSample Sample N274=N274 N293=N293 I=I\n";
print OUT "subGroup3\tIP IP PR=PR ER=ER input=input\n";
print OUT "dimensions\tdimX=IP dimY=Sample\n";
print OUT "sortOrder\tSample=+ IP=+ view=+\n";
print OUT "configurable\ton\n";
print OUT "type\tbed 3\n\n";

### write header for depth tracks
print OUT "   track\tdataChIPseq_ViewDepth\n";
print OUT "   parent\tdataChIPseq\n";
print OUT "   shortLabel\tChIPseq Depth\n";
print OUT "   longLabel\tChIP-seq normalized depth\n";
print OUT "   view\tCOV\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:40\n";
print OUT "   showSubtrackColorOnUi\ton\n";
print OUT "   viewUi\ton\n\n";

### write depth tracks
# PR & ER
@ids = ("N274-PR","N293-PR","N274-ER","N293-ER");
foreach $id (@ids) {
  ($sample, $ip) = split/\-/, $id;
  $bwfile = "data/$id.hg19.bwt.rmdup.ext200.norm20M.bigWig";
  unless (-e $bwfile) { print "WARNING: Did not find $bwfile.\n"; exit; }
  $prio++;
  print OUT "      track\t$id.ChIPd\n";
  print OUT "      parent\tdataChIPseq_ViewDepth\n";
  print OUT "      bigDataUrl\t$bwfile\n";
  print OUT "      shortLabel\t$id depth\n";
  print OUT "      longLabel\tnormalized ChIP-seq depth: $id\n";
  print OUT "      type\tbigWig\n";
  print OUT "      color\t$usecolorIP\n";
  print OUT "      priority\t$prio\n";
  print OUT "      visibility\thide\n";
  print OUT "      subGroups\tSample=$sample IP=$ip view=COV\n\n";
}
# inputs
@ids = ("N274-input","N293-input","pooled-input");
foreach $id (@ids) {
  $bwfile = "data/$id.hg19.bwt.rmdup.ext200.norm20M.bigWig";
  unless (-e $bwfile) { print "WARNING: Did not find $bwfile.\n"; exit; }
  $prio++;
  print OUT "      track\t$id.ChIPd\n";
  print OUT "      parent\tdataChIPseq_ViewDepth\n";
  print OUT "      bigDataUrl\t$bwfile\n";
  print OUT "      shortLabel\t$id depth\n";
  print OUT "      longLabel\tnormalized ChIP-seq depth: $id\n";
  print OUT "      type\tbigWig\n";
  print OUT "      color\t$usecolorInput\n";
  print OUT "      priority\t$prio\n";
  print OUT "      visibility\thide\n";
  print OUT "      subGroups\tSample=I IP=input view=COV\n\n";
}
print OUT "\n\n";


### write header for peak tracks
print OUT "   track\tdataChIPseq_ViewDepthPeaks\n";
print OUT "   parent\tdataChIPseq\n";
print OUT "   shortLabel\tChIP-seq Peaks\n";
print OUT "   longLabel\tChIP-seq Peaks\n";
print OUT "   view\tPK\n";
print OUT "   visibility\tdense\n";
print OUT "   type\tbigBed 3\n";
print OUT "   allButtonPair\ton\n";
print OUT "   centerLabelsDense\ton\n";
print OUT "   dragAndDrop\ton\n";
print OUT "   showSubtrackColorOnUi\ton\n";
print OUT "   viewUi\ton\n\n";

### write peak tracks
@ids = ("N274-PR","N293-PR","N274-ER","N293-ER");
foreach $id (@ids) {
  ($sample, $ip) = split/\-/, $id;
  $prio++;
  print OUT "       track\t$id.ChIPp\n";
  print OUT "       parent\tdataChIPseq_ViewDepthPeaks\n";
  print OUT "       bigDataUrl\tdata/$id.homer-peakcalls.FDRe-5_F4.300bp.bigBed\n";
  print OUT "       shortLabel\t$id peaks\n";
  print OUT "       longLabel\tHOMER peak calls: $id peaks\n";
  print OUT "       type\tbigBed 3\n";
  print OUT "       color\t$usecolorIP\n";
  print OUT "       priority\t$prio\n";
  print OUT "       visibility\tdense\n";
  print OUT "       subGroups\tSample=$sample IP=$ip view=PK\n\n";
}

print OUT "\n\n";
close(OUT);
