#!/usr/bin/perl

@A_cell = ("nTC", "Mono", "GR");
@A_chip = ("H3K27ac", "H3K4me1");
@A_strand = ("forward", "reverse");

foreach $cell (@A_cell) {

	foreach $chip (@A_chip) {

		if ($chip =~ /27ac/)   { $color = "0,0,255"; }
		elsif ($chip =~ /me1/) { $color = "255,0,0"; }

		$txt = qq {track $cell.$chip
type bigWig
container multiWig
shortLabel $cell.$chip
longLabel $cell.$chip
visibility full
aggregate stacked
autoScale on
showSubtrackColorOnUi on
maxHeightPixels 100:48:8
priority 1
};
		print $txt;

		my @A_files;
		@A_files1 = </home/tkwan/webroot/hg19/chip_seq/gs/project/mugqic/epigenome/pipelines/chip_seq/v_1/EMC_BluePrint/hg19/wiggle_tracks/*$cell*$chip*bigwig>;
		@A_files2 = </home/tkwan/webroot/hg19/chip_seq/gs/project/apk-861-ab/mugqic/finalBam_ChIPSeq.bigwig/*$cell*$chip*bigwig>;
		foreach $file (@A_files1) { push (@A_files, $file); }
		foreach $file (@A_files2) { push (@A_files, $file); }

		foreach $file (@A_files) {
			$file =~ s/\/home\/tkwan\/webroot\///;

			if ($file =~ /wiggle/)   { ($sample) = $file =~ /wiggle_tracks\/(.*)\.bigwig/;           }
			if ($file =~ /finalBam/) { ($sample) = $file =~ /finalBam_ChIPSeq.bigwig\/(.*)\.bigwig/; }
			
			$txt = qq {
track $sample
bigDataUrl http://pastinenlab.gqinnovationcenter.com/$file
shortLabel $sample
longLabel $sample
parent $cell.$chip
type bigWig
autoScale on
color $color
};
			print "$txt\n";
		}
	}

	foreach $strand (@A_strand) {
		$txt = qq{track $cell.$strand
type bigWig
container multiWig
shortLabel $cell.$strand
longLabel $cell.$strand
visibility full
aggregate stacked
autoScale on
showSubtrackColorOnUi on
maxHeightPixels 100:48:8
priority 1
};
		print $txt;

		@A_files = </home/tkwan/webroot/hg19/rna_seq/gs/project/apk-861-ab/mugqic/finalBam_RNASeq.bigwig/*$cell*$strand*bigwig>;
		foreach $file (@A_files) {
			$file =~ s/\/home\/tkwan\/webroot\///;
			($sample) = $file =~ /finalBam_RNASeq.bigwig\/(.*)\.bigwig/;

			$txt = qq {
track $sample
bigDataUrl http://pastinenlab.gqinnovationcenter.com/$file
shortLabel $sample
longLabel $sample
parent $cell.$strand
type bigWig
autoScale on
color 0,0,0
};
			print "$txt\n";
		}
	}
}


