Zika tutorial

Following on from the zika install

Get the NextStrain zika tutorial | https://github.com/nextstrain/zika-tutorial

Prepare the Sequences

A Nextstrain build typically starts with a collection of pathogen sequences in a single FASTA file and a corresponding table of metadata describing those sequences in a tab-delimited text file. For this tutorial, we will use an example data set with a subset of 34 viruses.

Each example virus sequence record looks like the following, with the virus’s strain id as the sequence name in the header line followed by the virus sequence.


Each sequence record’s virus strain id links to the tab-delimited metadata file by the latter’s strain field. The metadata file contains a header of column names followed by one row per virus strain id in the sequences file. An example metadata file looks like the following.


A metadata file must have the following columns:

  • strain
  • virus
  • date

Builds using published data should include the following additional columns, as shown in the example above:

  • accession (e.g., NCBI GenBank, EMBL EBI, etc.)
  • authors
  • url
  • title
  • journal
  • paper_url

Start Nextstrain shell

Filter the Sequences

Filter the parsed sequences and metadata to exclude strains from subsequent analysis and subsample the remaining strains to a fixed number of samples per group.

Make results directory

Use augur to filter sequences

* Paste as is and execute.

Align the Sequences

Create a multiple alignment of the sequences using a custom reference. After this alignment, columns with gaps in the reference are removed. Additionally, the –fill-gaps flag fills gaps in non-reference sequences with “N” characters. These modifications force all sequences into the same coordinate space as the reference sequence.

Get a Time-Resolved Tree

Augur can also adjust branch lengths in this tree to position tips by their sample date and infer the most likely time of their ancestors, using TreeTime. Run the refine command to apply TreeTime to the original phylogenetic tree and produce a “time tree”.

In addition to assigning times to internal nodes, the refine command filters tips that are likely outliers and assigns confidence intervals to inferred dates. Branch lengths in the resulting Newick tree measure adjusted nucleotide divergence. All other data inferred by TreeTime is stored by strain or internal node name in the corresponding JSON file.

Annotate the Phylogeny

Reconstruct Ancestral Traits

TreeTime can also infer ancestral traits from an existing phylogenetic tree and metadata annotating each tip of the tree. The following command infers the region and country of all internal nodes from the time tree and original strain metadata. As with the refine command, the resulting JSON output is indexed by strain or internal node name.

Infer Ancestral Sequences

Infer the ancestral sequence of each internal node and identify any nucleotide mutations on the branches leading to any node in the tree.

Identify Amino-Acid Mutations

Identify amino acid mutations from the nucleotide mutations and a reference sequence with gene coordinate annotations. The resulting JSON file contains amino acid mutations indexed by strain or internal node name and by gene name. To export a FASTA file with the complete amino acid translations for each gene from each node’s sequence, specify the –alignment-output parameter in the form of results/aligned_aa_%GENE.fasta.

Export the Results

Finally, collect all node annotations and metadata and export it all in auspice’s JSON format. The resulting tree and metadata JSON files are the inputs to the auspice visualization tool.

Visualize the Results

If you entered the Nextstrain build environment using nextstrain shell at the beginning of this tutorial, leave it now using the exit command and then use nextstrain view to visualize the Zika build output in auspice/*.json.

# Leave the shell you entered earlier.

# View results in your auspice/ directory.

If you’re not using the Nextstrain CLI shell, then copy the auspice/*.json files into the data directory of your local auspice installation and start auspice from there. You can use the commands below (adjusted if necessary), or copy them using a graphical file explorer.

# Copy files into auspice data directory. Adjust
# paths if auspice isn’t installed in ~/src/auspice/.

Then enter your auspice directry and start auspice.

# Navigate into auspice.

# Start auspice.

When auspice is running, navigate to http://localhost:4000/local/zika in your browser to view the results.

To stop auspice and return to the command line when you are done viewing your data, press CTRL+C.

Automate the Build with Snakemake

While it is instructive to run all of the above commands manually, it is more practical to automate their execution with a single script. Nextstrain implements these automated pathogen builds with Snakemake by defining a Snakefile like the one in the Zika repository you downloaded.

First delete the output from the manual steps above. (Be sure to navigate into the zika-tutorial/ directory first.)

Then, if you’re using the Nextstrain CLI tool, run:

to run the automated pathogen build.

If you’re not using the Nextstrain CLI tool, run:

The automated build runs all of the manual steps above up through the auspice export. View the results the same way you did before to confirm it produced the same Zika build you made manually.

Note that automated builds will only re-run steps when the data changes. This means builds will pick up where they left off if they are restarted after being interrupted. If you want to force a re-run of the whole build, first remove any previous output with nextstrain build . clean or snakemake clean.

Snakemake file