#!/usr/bin/perl

@A_proj = ("EMC_Mitochondrial_Disease", "EMC_Bone", "ULaval_Obesity.IA", "ULaval_Obesity.SC");
@A_dir  = ("forward", "reverse");

foreach $proj (@A_proj) {

	foreach $dir (@A_dir) {

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

	$cnt = 0;

	$val = 150;

	$proj2 = $proj;
	if ($proj =~ /ULaval/) { $proj2 = "ULaval_Obesity"; }

	my @A_files;
	@A_files = </mnt/www/webroot/hg19/rna_seq/v_2/$proj2/hg19/wiggle_tracks/*forward.bigwig>;

	foreach $file (@A_files) {

		($sample) = $file =~ /wiggle_tracks\/(.*)\.forward\.bigwig/;
		next if ($sample !~ /IA/ && $proj eq "ULaval_Obesity.IA");
		next if ($sample !~ /SC/ && $proj eq "ULaval_Obesity.SC");
		
		foreach $dir (@A_dir) {
			if ($dir eq "forward") { $color = "0,0,$val"; }
			else                   { $color = "$val,0,0"; }

			$txt = qq{
track $sample.$dir
bigDataUrl http://pastinenlab.genome.mcgill.ca/hg19/rna_seq/v_2/$proj2/hg19/wiggle_tracks/$sample.$dir.bigwig
shortLabel $sample.$dir
longLabel $sample.$dir
parent $proj.$dir
type bigWig
autoScale on
color $color
};
			print "$txt\n";
			$val += 25;
		}
		last if ($cnt > 5);
	}
}

# WGBS
@A_proj = ("EMC_Mature_Adipocytes", "EMC_Mitochondrial_Disease", "EMC_Bone");
foreach $proj (@A_proj) {

	$txt = qq {
track $proj.WGBS
type bigWig
container multiWig
shortLabel $proj.WGBS
longLabel $proj.WGBS
visibility full
aggregate stacked
autoScale on
showSubtrackColorOnUi on
maxHeightPixels 100:48:8
priority 1
};
	print $txt;
	$val = 0;
	my @A_files = </mnt/www/webroot/hg19/wgb_seq/$proj/*.bigwig>;
	foreach $file (@A_files) {
		($sample) = $file =~ /wgb_seq\/.*\/(.*)\.bigwig/;
		
		$txt = qq{
track $sample
bigDataUrl http://pastinenlab.genome.mcgill.ca/hg19/wgb_seq/$proj/$sample.bigwig
shortLabel $sample
longLabel $sample
parent $proj.WGBS
type bigWig
autoScale on
color 0,0,$val
};
		print "$txt\n";
		$val += 75;
	}
}

@A_bone = ("trabecular", "Cortical");
foreach $bone (@A_bone) {

	$val = 255;

        $txt = qq {
track $bone
type bigWig
container multiWig
shortLabel $bone
longLabel $bone
visibility full
aggregate stacked
autoScale on
showSubtrackColorOnUi on
maxHeightPixels 100:48:8
priority 1
};
        print $txt;
        my @A_files = </mnt/www/webroot/hg19/scRNA/bone_fluidigm/*bigwig>;
        foreach $file (@A_files) {
                ($sample) = $file =~ /bone_fluidigm\/(.*)\.bam\.bigwig/;

print "$file\t$sample\n";
                $txt = qq{
track $sample
bigDataUrl http://pastinenlab.genome.mcgill.ca/hg19/scRNA/bone_fluidigm/$sample.bam.bigwig
shortLabel $sample
longLabel $sample
parent $bone
type bigWig
autoScale on
color 0,0,$val
};
                print "$txt\n";
                $val -= 2;
        }
}

