Skip to content

Tutorial 4: Format conversions

Trevor Bedford edited this page Oct 25, 2013 · 4 revisions

The directory conversion contains Ruby scripts to convert BEAST output into Phylowood compatible NEXUS.

Discrete location mapping

The file conversion/h5n1_mcc.trees contains a maximum clade credibility tree of influenza H5N1 from Lemey et al. (2009). This MCC tree can be obtained following the "Discrete phylogeographic diffusion models" of the BEAST tutorials website.

In the MCC trees file, nodes are labeled with inferred locations, via the following format 23[&location="HongKong"]. The ruby conversion script beast-to-nhx-phylowood-discrete.rb scans the NEWICK tree for these assignments and converts this to Phylowood's preferred 23[&area_pp={0,0,0,0,0,1,0}] format.

From the conversion directory, running ruby beast-to-nhx-phylowood-discrete.rb h5n1_mcc.trees will print a .nhx file to standard ouput. Save this to the file h5n1.nhx by running:

ruby beast-to-nhx-phylowood-discrete.rb h5n1_mcc.trees > h5n1.nhx

The output file h5n1.nhx starts with default Phylowood parameters in the phylowood block:

Begin phylowood;
	drawtype	pie
	modeltype	phylogeography
	areatype	discrete
	maptype	clean
	pieslicestyle	full
	piefillstyle	outwards
	timestart	0.0
	timeunit	yr
	markerradius	200.0
	minareaval	0.0
	description	Discrete phylogeography (default settings)
End;

These can be modified to change the visualization. However, in order to run this display, we need to specify latitude and longitudes of each region (which are not contained in the MCC trees file). The geo block is output as:

Begin geo;
	Dimensions ngeo=7;
	Coords
		Fujian [LATITUDE] [LONGITUDE],
		Guangdong [LATITUDE] [LONGITUDE],
		Guangxi [LATITUDE] [LONGITUDE],
		Hebei [LATITUDE] [LONGITUDE],
		Henan [LATITUDE] [LONGITUDE],
		HongKong [LATITUDE] [LONGITUDE],
		Hunan [LATITUDE] [LONGITUDE]
	;
End;

The [LATITUDE] and [LONGITUDE] placeholders need to be fixed before it will run. In the file examples/h5n1.nhx this has been revised to:

Begin geo;
	Dimensions ngeo=7;
	Coords
		Fujian 25.93 118.25,
		Guangdong 22.87 113.00,
		Guangxi 23.64 108.27,
		Hebei 39.32 116.70,
		Henan 33.88 113.49,
		HongKong 22.25 114.57,
		Hunan 27.38 111.53
	;
End;

Copying and pasting this entire file into the text input area in Phylowood will run the resulting visualization.

Continuous location mapping

The file conversion/rabies_mcc.trees contains the MCC tree of rabies virus from Lemey et al. (2010). Instructions for obtaining this tree can be found in the "Continuous phylogeographic diffusion models" section of the BEAST tutorials site.

In this case, phylogeny nodes are directly labeled with estimated latitude and longitude locations, via the attributes "location1" and "location2". To convert the file into Phylowood format run:

ruby beast-to-nhx-phylowood-continuous.rb rabies_mcc.trees > rabies.nhx

The contents of file rabies.nhx can then be pasted directly into the Phylowood text field.