clear all;
close all;
clc;

indir = 'b37/';
outfile = [ indir '/gc.ps' ];

fontSz = 8;
winSz = 100;

firstPage = 1;
for chrNo = 1 : 23

	disp(chrNo)

	if chrNo < 23
		infile = [ indir '/' num2str(chrNo) '_1k.txt' ];
	else
		infile = [ indir '/X_1k.txt' ];
	end
	
	[startPos, endPos, gc] = textread(infile, '%n %n %n');
	gc_s = medfilt1(gc, winSz);
	
	pos = 0.5*(startPos + endPos)/1e6;
	
	pos_min = min(pos);
	pos_max = max(pos);
	
	n = length(gc);
	randloc = randperm(n);
	randloc = randloc(1:30000);
	randloc = sort(randloc);
	
	figure(1); clf;
	hold on;
	plot(pos(randloc), gc(randloc), 'k.');
	plot(pos(randloc), gc_s(randloc), 'r.');
	set(gca, 'Box', 'On', 'FontSize', fontSz);
	xlim([pos_min pos_max]);
	ylim([0 100]);
	xlabel('Position / Mb', 'FontSize', fontSz+2);
	ylabel('Local GC Content %', 'FontSize', fontSz+2);
	title(['Chr' num2str(chrNo)], 'FontSize', fontSz+2);
	
	if firstPage
		print('-dpsc2', '-r300', outfile); 
		firstPage = 0;
	else
		print('-dpsc2', '-r300', '-append', outfile);
	end

end

gzip(outfile);
delete(outfile);