telling FileCoordinator;
getNumberOfTaxas;
Integer.numTaxas *It;
decrement.numTaxas;  [if only one, don't do anything (should explain why, but doesn't yet)]
ifNot *Integer.numTaxas;
	alert 'Macro "s by depth" can''t be run with this file because there is only one set of taxa';
endIf;
if *Integer.numTaxas;
	alert 'This macro calculates Slatkin and Maddison''s "s" value for gene trees within an available species tree, for varying branch lengths';
	getTaxas;
	Object.taxas *It;
	newAssistant  'Tree values';
	tell It;
		suspendCalculations;
		queryListNumber *Object.taxas 'Which set of taxa represents genes?';
		Integer.taxa *It;
		setTaxa *Integer.taxa; [needs to ask for taxa]
		queryString 'Name of results file?';
		String.fileName *It;
		queryNumber 'Initial branch length (in generations)';
		Number.initial *It;  
		queryNumber 'Increment in branch length';
		Number.lengthIncrement *It;  
		queryInteger 'Number of different branch lengths';
		Integer.numIncrements *It;
		queryInteger 'Number of gene trees sampled for each species branch length';
		Integer.sampleSize *It;


		getCharter 'Item values chart';
		Object.chartModule *It;
		tell *Object.chartModule;
			getWindow;
			Object.chartWindow *It;
			tell *Object.chartWindow;
				setSize 400 400;
				setLocation 60 10;
				setFont SanSerif;
				setFontSize 10;
				onInfoBar;
				setChartType  'Histogram';
				tell It;
					showAverageToggle off;
					setMode 0;
					toggleSizeToFit on;
				endTell;
				toggleOrientation off;
				toggleColorItems off;
				setNumberItems *Integer.sampleSize;
			endTell;
		endTell;
		
		[setNumberTrees *Integer.sampleSize;]
		setCalculator  's of Slatkin & Maddison';
		setTreeSource  'Simulated Trees';
		tell It;
			setTreeSimulator  'Contained Coalescence';
			Object.coalescer *It;
		endTell;
		setChartVisible;
		doCounts;
		resumeCalculations;
		showWindow;
		tell *Object.coalescer;
			getSpeciesTree;
			Object.speciesTree *It;
		endTell;
		saveMessageToFile *String.fileName 'Results of simulations of gene tree coalescence within species';
		appendReturnToFile *String.fileName;
		Number.bL *Number.initial;
		for *Integer.numIncrements;
			Number.bL +*Number.lengthIncrement;
		endFor;
		appendLiteralToFile *String.fileName 'Branch lengths from ';
		appendMessageToFile *String.fileName *Number.initial;
		appendLiteralToFile *String.fileName ' through ';
		appendMessageToFile *String.fileName *Number.bL;
		appendReturnToFile *String.fileName;
		appendMessageToFile *String.fileName '================================';
		appendReturnToFile *String.fileName;
		appendReturnToFile *String.fileName;
		Number.branchLength *Number.initial;
		for *Integer.numIncrements;
			appendLiteralToFile *String.fileName 'Results when all branch lengths in species tree set to ';
			appendMessageToFile *String.fileName *Number.branchLength;
			appendReturnToFile *String.fileName;
			appendReturnToFile *String.fileName;
			tell *Object.speciesTree;
				setAllBranchLengths *Number.branchLength;
			endTell;
			tell *Object.chartWindow;
				appendTextToFile *String.fileName;
			endTell;
			Number.branchLength +*Number.lengthIncrement;
		endFor;
		tell *Object.chartWindow;
			closeWindow;
		endTell;
	endTell;
	showFile *String.fileName;
endIf;
