Writing a narrative
The following will walk you through writing a Nextstrain narrative. We’ll start with a basic 2-slide narrative and then gradually add further slides with the intention of describing the functionality of narratives. The aim is for you to feel comfortable with the technical aspects of creating and troubleshooting narratives.
This tutorial will rely on the new Narratives Debugger which allows you to drag & drop the Markdown files we’ll introduce here and see an instant summary of the narrative.
Sections in this document
This guide uses the narratives debugger on nextstrain.org; while you can also use this by running Auspice on your computer there are some differences - see below for more details.
In order to make sense of this tutorial we are going to need:
A (basic) understanding of writing Markdown (here is good introduction).
Familiarity with the general concept of Nextstrain Narratives (see Communicating Results Using Narratives to get started).
Be comfortable editing a Markdown file on your computer (in your editor of choice) and then dragging that file onto the browser.
The Narratives Debugger open in a separate browser window
The aim is to author your own narratives, so we suggest adapting the Markdown files introduced below to form your own narrative once you’ve worked through the tutorial. For this you’ll need:
The content of a narrative is all within a single Markdown file, and this file contains nextstrain.org URLs from which the interactive visualisations are sourced. We’ll introduce the basic functionality via an example Markdown file below, which describes three slides:
The title slide (the section surrounded by
A slide showing the latest available monkeypox phylogeny
A slide looking back at the rise and fall of Influenza clades over the past 12 years
--- title: Introduction to narratives authors: Nextstrain authorLinks: "https://nextstrain.org" date: "2022-11-01" dataset: "https://nextstrain.org/monkeypox/hmpxv1?d=map&p=full&c=region" abstract: " 3-slide narrative to introduce how to write narratives. This narrative is intended to be used as part out the [Writing a Narrative](https://docs.nextstrain.org/en/latest/tutorials/narratives-how-to-write.html) tutorial. This opening slide is looking at monkeypox genomes focusing on the current outbreak. This view into the data is taken from the associated URL: https://nextstrain.org/monkeypox/hmpxv1?d=map&p=full&c=region " --- # [Monkeypox](https://nextstrain.org/monkeypox/hmpxv1?d=tree&p=full&c=region) We've now changed the view from the map to the phylogenic tree. This was achieved by changing the dataset URL to indicate that the display panel should change from the map to the tree. ``` Title slide: monkeypox/hmpxv1?d=map This slide: monkeypox/hmpxv1?d=tree ^^^^ ``` In practice, you don't need to remember the URL syntax, rather you can manipulate the visualization (on nextstrain.org) and then simply copy & paste the URL once you are happy with the current view into the data. P.S. The B.1 clade is the main outbreak clade & we can see a distinct comb-like appearance, with limited clustering of samples. This structure is typical of new, fast-spreading outbreaks. The tree is colored by region & we can see that the outbreak clade is dominated by samples from Europe and the Americas, whereas the basal (older) cases were typically from Africa. # [The rise and fall of Influenza clades](https://nextstrain.org/flu/seasonal/h3n2/ha/12y?d=tree,frequencies&p=full) We switch now to a completely different viral phylogeny - that of Influenza H3N2 over 12 years. This switch was made by defining a different dataset in the URL associated with this slide (https://nextstrain.org/flu/seasonal/h3n2/ha/12y?d=tree,frequencies&p=full). It is this URL which specifies that we should view both the tree & the frequencies panel 👉 P.S. This phylogenetic structure is very different, more latter-like than comb like, a phenomena which is linked to antigenic evolution ([Bedford, Rambaut & Pascual, 2012](https://bmcbiol.biomedcentral.com/articles/10.1186/1741-7007-10-38)).
This tutorial will make use of our narratives debugger, which is available at nextstrain.org/edit/narratives.
To introduce this functionality, let’s copy / download the above Markdown to a file on your computer (the filename doesn’t matter, as long as it finishes with
We can then drag the Markdown file onto the Narrative Debugger page and you should see something like the top half of this figure:
We can see the titles of the three slides & their associated datasets (see the following section for details on how titles are defined), and hovering over these should show you the full appearance of the slide. To the right of the titles are their associate datasets, each with a series of icons next to them representing the main + sidecar JSONs associated with this dataset. The icons represent whether the dataset exists on nextstrain.org – in this case, they are all green (success) or grey (not attempted). When debugging a narrative it’s easy to make syntax errors resulting in datasets which don’t load – you could try changing the URLs in the Markdown file and dragging the file back onto the debugger to see this. Clicking on the title of a slide will jump into the narrative at that slide, or you can click the “View Narrative” button to start from the beginning.
The narrative file you drag onto the debugger remains within your browser and is not sent to the Nextstrain server. The datasets it specifies must be accessible through nextstrain.org and are fetched (downloaded) when you are testing a narrative; these can include private Nextstrain Groups assuming you are logged into nextstrain.org & can access those private datasets.
Hopefully the above section gives you enough to get started writing your own narratives. There are more technical details to follow, but if you want to get started we encourage trying it out! There are plenty of ways to approach the task, but we find the following workflow tends to work well:
In the future we plan to add more and more editing capability into the debugger, but for now any changes to the narrative must be made in the Markdown file itself. When you are happy with the end result, see below for how to publish it on nextstrain.org.
The opening (title) slide is defined in the Markdown file by an opening YAML frontmatter block, which is the part between the two
--- lines in the above example.
This defines a number of key-value pairs which we transform into the slide you see, all of which are optional except
The possible content which can be rendered is listed below, in the order they would appear on screen:
The main title is taken from the
The authors are then listed; these can be provided via
authorsLinkswhich should either both be strings or both be arrays of the same length. The
authorsLinksis optional but recommended!
Any translators are then listed, encoded in the same format as the authors but using keys
The abstract, defined by
abstractis a string which will be rendered as Markdown 1.
When the narrative was first created (
date) and when it was most recently updated (
updated) is then displayed.
Finally, any applicable license is shown, as defined by
datasetis required and defines the data view in the right hand side of screen (see see below).
The rest of the Markdown file defines one or more slides, where each slide is defined by a level 1 heading which is also a link to a dataset on nextstrain.org 2 and a section of Markdown which represents the slide’s content:
# [slide title here](nextstrain.org dataset URL here, including (optional) query params) Markdown content of the slide
As a real example (taken from above), we have:
# [The rise and fall of Influenza clades](https://nextstrain.org/flu/seasonal/h3n2/ha/12y?d=tree,frequencies&p=full) We switch now to a completely different viral phylogeny - that of Influenza H3N2 over 12 years.
The dataset URL is detailed below and defines the view into the data shown to the right of the rendered Markdown content.
It’s possible to replace the right-hand side view into the data with a full page Markdown rendering, which is useful for adding a large image in a narrative etc. This is done via a specific code fence within the Markdown content of a slide:
# [slide title](dataset URL) Slide content rendered in the left-hand sidebar (as normal) ```auspiceMainDisplayMarkdown Markdown content rendered in the right-hand pane of the display, where the dataset would normally be. _Note that the dataset URL is still required, although unused._ ```
Publicaly accessible images can be embedded using normal Markdown syntax, for example using this SEM photo of Yersinia Pestis:
### Here's a SEM photo of Y. pestis ![Y pestis SEM](https://upload.wikimedia.org/wikipedia/commons/thumb/d/d0/Yersinia_pestis.jpg/800px-Yersinia_pestis.jpg)
It’s possible to run a local instance of Auspice (the phylogenetic visualisation app used in nextstrain.org) and view narratives locally, however there are some differences between this and nextstrain.org which are really easy to get tripped up on!
Specifically the hostname is not used 2 – only the pathname is used, and the way the dataset pathname is interpreted is different: Auspice can only access datasets on your computer (in the directory you supply via
--datasetDir) whereas nextstrain.org accesses data from a range of places.
The following example of a narrative slide may make this difference clearer:
# [Which dataset is this?](https://nextstrain.org/community/inrb-drc/ebola-nord-kivu) The dataset displayed here differs if you run it on localhost (auspice) or through nextstrain.org. When viewed on nextstrain.org this dataset is sourced from [this GitHub repository](https://github.com/inrb-drc/ebola-nord-kivu) as it is using our [community sharing functionality](https://docs.nextstrain.org/en/latest/guides/share/community-builds.html). To work when running on auspice locally, we would need to have a dataset with the following filename: `community_inrb-drc_ebola-nord-kivu.json`.
This complexity encouraged us to build the interactive debugger we have used in this tutorial and we encourage to use that approach rather than developing your narratives using Auspice locally & then trying to share them through nextstrain.org!
All of the narratives written by the core Nextstrain team are available in this GitHub repo.
The app used to test narratives is in its infancy. We hope to incrementally add features such as Markdown editing, changing the dataset view settings, and the ability to publish the narrative to Nextstrain Groups. The eventual aim is to be able to write & publish an entire narrative from within the app, without needing to know any specifics of the Markdown language behind it.
The provided string is actually rendered as
### <abstract>, so the first line will appear as a h3 heading! Multiple line strings are possible in YAML and we suggest using these.
In practice, the URL path component is what is used to access the dataset relative to the current hostname, however for historical reasons the protocol and hostname must be either
This isn’t great from a file-size point of view, and the Markdown file isn’t nice to look at itself, but it gets around the problem of where to store images by embedding them in the file itself.