Skip to content

Example usage

Mike Lee edited this page Jun 6, 2019 · 100 revisions

This page demonstrates two examples from start-to-finish. The data files, run log, and results for all examples are packaged with GToTree in the noted sub-directories.


Alteromonas example

The code and files for this example are in the GToTree/example_run/ sub-directory.

The setup

During my PhD I had the privilege of working on a really cool, nitrogen-fixing, marine cyanobacterium called Trichodesmium. This bug seems to only live in perpetual association with a consortium of other microorganisms – there are no pure (axenic) cultures of Trichodesmium by itself, it just doesn't seem to be happy without its buddies. One of the highly conserved organisms (here meaning consistently present to some extent across all Trichodesmium samples, but not in non-Trichodesmium "controls") that came out of this work was an Alteromonas metagenome-assembled genome (MAG) – work on this is presented in this paper (https://www.nature.com/articles/ismej201749).

Here we are going to use GToTree to place this "new" Alteromonas MAG into a phylogenomic tree of all the Alteromonas genomes available in NCBI's RefSeq database.

Generating inputs

Genomes

The inputs will be: 1) the fasta file of our "new" MAG; 2) a list of accessions of Alteromonas genomes from NCBI's RefSeq; and 3) an Alphaproteobacteria to serve as a root.

1) We can download the MAG fasta file from NCBI and decompress it like such:

curl ftp://ftp.ncbi.nlm.nih.gov/genomes/all/GCA/002/271/865/GCA_002271865.1_ASM227186v1/GCA_002271865.1_ASM227186v1_genomic.fna.gz | gunzip - > GCA_002271865.1.fa

2) We can search NCBI's assembly database on their website to get the accessions for all RefSeq Alteromonas genomes with the following search string: Alteromonas[ORGN] AND "latest refseq"[filter] AND "complete genome"[filter] (when this was put together on 1-Jan-2019, this returned 31 hits). You can download a summary file by selecting "Send to:" at the top right, and setting the options as shown here:

Clicking create file will download these as "assembly_result.txt". Here we are using the RefSeq assembly accessions (those that start with "GCF_...", but GToTree also handles GenBank assembly accessions (those that start with "GCA_"). For us here we are going to take the RefSeq accessions from the 3rd column, but if you are following this and want to work with genomes available in GenBank but not in RefSeq, you would want to take the first column.

In our case here, we can take just the RefSeq accessions with the following:

tail -n +2 assembly_result.txt | cut -f3 > alteromonas_refseq_accessions.txt

If you're unfamiliar with this line of code, and want to get to know working at the command line better, a good place to start is here :)


NOTE: This part of the process (generating the accessions list of the reference genomes we want) can actually be done completely at the command line. Entrez-Direct is a command-line tool for accessing NCBI's databases. It can have a bit of a learning curve, but is definitely worthwhile if you use information from NCBI databases frequently. It is also installable through conda with conda install -c bioconda entrez-direct. With Entrez-Direct, (as shown in the "run_log.txt" file in the example_run sub-directory), this accessions file could be created at the command line as such: esearch -query 'Alteromonas[ORGN] AND "latest refseq"[filter] AND "complete genome"[filter] AND (latest[filter] AND all[filter] NOT anomalous[filter])' -db assembly | esummary | xtract -pattern DocumentSummary -def "NA" -element AssemblyAccession > alteromonas_refseq_accessions.txt.


3) And to have an outgroup to root the tree with, and to incorporate a GenBank file which GToTree can handle as input as well, we'll take an alphaproteobacterium:

curl ftp://ftp.ncbi.nlm.nih.gov/genomes/all/GCF/000/011/365/GCF_000011365.1_ASM1136v1/GCF_000011365.1_ASM1136v1_genomic.gbff.gz | gunzip - > GCF_000011365.1.gbff

Mapping file for labeling specific genomes

Often it is helpful to have specific labels for specific genomes in a tree. In this case we may want to have our "new" MAG labeled as "Our_Alteromonas_MAG", instead of just "GCA_002271865.1", and we may want to label our root as "Alpha_root" instead of "GCF_000011365.1". GToTree uses TaxonKit to add lineage information to any genomes that have such information associated with them (whether provided as NCBI accessions or GenBank files), but we can also swap labels of specific genomes we know we care about and want to be able to find more easily.

To do that we just need to provide a 2-column, tab-delimited file that has the initial genome ID in the first column (this will be either the NCBI accession or the file name (depending on how the genome was provided). Here's how ours looks in this case:

cat genome_to_id_map.tsv
GCA_002271865.1.fa	Our_Alteromonas_MAG
GCF_000011365.1.gbff	GCF_000011365.1_Alpha_Outgroup

NOTE: User-provided labels given to genomes listed in this mapping file (passed to the program with the -m flag) will always take precedence over any automated lineage swapping.


Running GToTree

The accessions file can be provided as-is, but to tell GToTree which fasta and genbank files to work on, we need to put their names (or paths) into files. In the case here, this will get the job done:

ls *.fa > fasta_files.txt
ls *.gbff > genbank_files.txt

Now we are set to run GToTree :)

We can check which single-copy gene HMM profiles are available by running gtt-hmms, and since Alteromonas is within the Gammaproteobacteria, we will use that one:

Note: If you're not familiar with seeing things like the codeblock just below, you can ignore the backslashes (\) in here. They are only there to "escape" the return characters so this can all be seen at once (instead of one long line you'd have to scroll), and so it can be copy-and-pasted if wanted 😊

GToTree -a alteromonas_refseq_accessions.txt -g genbank_files.txt \
        -f fasta_files.txt -H Gammaproteobacteria \
        -t -L Species,Strain -m genome_to_id_map.tsv -j 4 \
        -o Alteromonas_example

Code Breakdown:

  • -a – the file with the list of accessions
  • -g – the file holding the genbank paths
  • -f – the file holding the fasta paths
  • -H – the desired HMM profiles to use (can view all default available with gtt-hmms)
  • -t – specifies to use TaxonKit to add labels with lineage information to the tree
  • -L – specifies the ranks to add when adding lineage information to the tree, since here we are working with all Alteromonas, we don't really need more than the Species (or "specific name", which in NCBI includes the Genus) and Strain (if available)
  • -m – the mapping file specifying specific labels for specific input genomes
  • -j – the number of jobs to run in parallel when possible
  • -o – the output prefix for primary output files

Viewing/Editing the tree

The output tree file "Alteromonas_aligned_SCGs_mod_names.tre" is in newick format and can be viewed/edited with any general tree program. A good one for large trees that I have installed on my laptop and use regularly is Dendroscope. And a good web-based one is the Interactive Tree of Life.

If we go to the Interactive Tree of Life upload page, we can upload the tree file we just created. After rooting at our alpha outgroup and coloring our "new" MAG blue, we can see it's among the Alteromonas macleodii references:

And taking a closer look, based on these 172 gammaproteobacterial SCGs it is most closely related to reference strain Te101:

ToL Example

The code and files for this example are in the GToTree/ToL_example/ sub-directory.

Run log:

# getting accessions for all refseq, complete, representative genomes (search originally performed on 20-Dec-2018)
esearch -query '"latest refseq"[filter] AND "complete genome"[filter] AND "representative genome"[filter] AND all[filter] NOT anomalous[filter]' -db assembly | esummary | xtract -pattern DocumentSummary -def "NA" -element AssemblyAccession > GToTree_ToL_accessions

# running GToTree:
time GToTree -a GToTree_ToL_accessions -H Universal_Hug_et_al -t -j 4 -o ToL -G 0.4

NOTE: This took about 60 minutes on my late 2013 MacBook Pro.

Taking the output tree file "ToL_aligned_SCGs_mod_names.tre" from that and loading it into a tree viewer/editor such as the web-hosted Interactive Tree of Life gives us this view:

The iToL is a pretty stellar program for viewing/editing trees. I also use Dendroscope pretty regularly.

Visualization of gene presence/absence across the bacterial domain


Distribution of flagellar protein FliT across the bacterial domain.

The setup

Depending on the scope of the question being pursued, it can sometimes be useful to visualize a trait or characteristic across an entire domain or large clade, as this may reveal patterns about its evolutionary distribution. The presence or absence of a particular trait in a given genome can be acquired in any fashion – e.g., using annotations already available, using a program to identify a specific antibiotic resistance marker if that's your thing, etc. GToTree includes a program for another way to do this using hidden Markov Model (HMM) searches performed with HMMER3 and HMM profiles available from Pfam. It's in a program called GToTree-pfam-search. Here we will use that to search for the presence of flagellar protein FliT (PF05400.13) in all complete bacterial genomes available from NCBI’s RefSeq. After identifying the presence or absence of the gene(s) we care about, then the only required inputs for GToTree are: 1) a list of the NCBI accessions searched; and 2) a tab-separated mapping file that allows us to append something to the label of each genome in which the gene of interest was identified (this makes them easily searchable and colorable on the final tree).

Note: This is not a particularly quick example because it is done at a large scale, so while it may not be great for following allowing executing the code, it shows the full process I use to visualize the distribution of things across a domain. Things can be done the same way on any smaller subset of organisms with any PFam targets (or with any other metric for a characteristic, as discussed below). If you'd like to run a quick example of the GToTree-pfam-search program, you can in the "test_data" directory that comes with GToTree as shown in the "test_pfam_search_run_log.txt" file there.

Getting accessions

The included accessions from NCBI's RefSeq were attained with the following search string on NCBI's website "bacteria"[filter] AND "latest refseq"[filter] AND ("reference genome"[filter] OR "representative genome"[filter]), as shown above in the Alteromonas example – and can be retrieved entirely from the command also as demonstrated above in the same example above. When performed on 3-June-2019, this returned 5,550 genomes.

Searching for genes of interest

For this example I just picked the flagellar protein FliT (PF05400.13), but we could search for as many as we'd like. So for good measure let's add another one to the list, a ribosomal protein (PF00238.19).

Now are target PFam accessions are stored in a file, here called "targets.txt", e.g.:

head targets.txt
PF00238.19
PF05400.13

And our assembly accessions stored in "accessions.txt", e.g.:

head accessions.txt
GCF_000765805.2
GCF_000763135.2
GCF_000762875.2
GCF_000765745.2
GCF_000765905.2
GCF_002075285.3
GCF_000158095.2
GCF_000974685.2
GCF_001687475.2
GCF_000953855.2

Note: Just as with the main GToTree program, we could provide any combination of NCBI accessions, GenBank, fasta, or amino acid files here, though we're just using accessions now.

And now we're ready to run the search:

GToTree-pfam-search -a accessions.txt -p targets.txt

This downloads and concatenates the needed PFam HMMs, then downloads each genome and searches them for the targets. The main outputs include: 1) a table with each genome, how many total genes it had, and how many hits there were to each target; and 2) fasta files holding the amino acid sequences of each hit for each target.

Note: Currently this is not yet parallelizable (so it takes ~50 minutes with this many genomes), nor can it be run at the same time as the main GToTree program. But I'll work on adding those soon.

Making mapping file for GToTree

Now for this example we just need a mapping file so we can append some identifier to the labels of genomes that possess the gene we care about (or whatever characteristic you want to visualize). The GToTree mapping file can hold 3 columns: 1) the genome ID you want to change; 2) what you want to change it to if you want to replace it completely; and/or 3) what you want to append to the label. Here we want to keep the starting label, but just append something to it. So our mapping file will hold the assembly ID in column 1, nothing in column 2, and "FliT" in column 3.

One way we can make this mapping file is with the bash one-liner below, working with the file we just created with GToTree-pfam-search:

tail -n +2 pfam_search_output/All_genomes_Pfam_target_counts.tsv | awk -F $'\t' ' $5 > 0 { print $1 } ' | sed 's/$/  /' | tr " " "\t" | sed 's/$/FliT/' > mapping_file.tsv

Note: If you're new to bash, I recommend getting to know it better if you're going to be getting into bioinformatics. A good place to start is here 😊 For a quick breakdown of what's going on here: the tail is skipping the first line as the file has a header; the awk command is printing out the assembly ID (first column) of any row where the 5th column (holding counts of our FliT gene) is greater than 0; the first sed command is adding two blank spaces to the end of the assembly IDs we just pulled out, this is so that we can turn them into tab characters with the tr command, as that's the format needed for our mapping file (sed does not play well with tab characters, so this is just a workaround); then the final sed command adds the "FilT" text to the 3rd column. Isn't bash glorious??

Running GToTree

Now we're all set to run GToTree (note the inclusion of the -t flag to add lineage information, without this, our tree would just have accessions on it and no lineage information):

GToTree -a accessions.txt -H Universal -m mapping_file.tsv -j 4 -t -o FliT_bacterial_tree

Note: I used the Universal SCG-set with just 15 targets to save time just for this example. But in general, it's best to use the SCG-set that is most specific to the breadth of organisms you are treeing, and here that would be the Bacteria SCG-set with has 74 targets. You can see all available SGC-sets that come with GToTree by running gtt-hmms.

Visualizing and editing the tree

Great, now we have our tree. The way I got it to look like the picture above involved two more programs: coloring the branches blue and the removing all labels in Dendroscope; and then putting the on finishing touches (groupings and major taxa names) in a figure-editing program.

Here I'll lay out the exact steps I took in Dendroscope (v.3.5.10) to color all the appropriate branches blue and remove all labels: 1) clicked the "draw tree or network as radial phylogram" in the top toolbar; 2) clicked the binoculars icon in the same toolbar to open the "Find" window; 3) typed in "FilT" (the label we appended for those with hits to it) and clicked "All" to select all of them; 4) pulled down the "Select" menu, then in the "Advanced Selection" side-menu I chose "Select Induced Network" - which selects all the branches connecting our genomes that hold our gene of interest; 5) then pulled down the "Edit" menu and selected "Format" at the bottom; 6) with the "Line color" box already selected at the right, I chose a blue color in the middle, then exited that formatting window; 7) selected all by pulling down the "Select" menu and choosing "Select All" (or shortcut keys cmd + a or ctrl + a); 8) re-opened the "Format" window from the "Edit menu, unchecked "Show labels" to remove all labels, then de-select all from the "Select" menu, or with shortcut keys cmd + shift + a or ctrl + shift + a.

Then I exported the tree from Dendroscope and added the lines grouping major taxa and their names in a figure-editing program :) – I use Affinity Designer, which has a one-time purchase fee of $50, but Inkscape is a free and open-source alternative.

And that's how we end up with this:


Distribution of flagellar protein FliT across the bacterial domain.

Again, here we just used some flagellar protein for an example, but it can be done with any sort of binary characteristic of genomes in a similar fashion, just by making the mapping file appropriately. And although I've added the 'GToTree-pfam-search` program to GToTree, that's only one way to go about it. The trait(s) of interest can come from anything 😊

Using the alignment and partitions file with another program

Some tree-building programs allow for the incorporation of mixed models – meaning they will treat each gene differently rather than all the same. GToTree generates a partitions file that is compatible with most of these. If you wanted to do this, you might want to run GToTree in alignment-only mode (by adding the -N flag when running), and then take the alignment and partitions file into a stellar program like iqtree – which has excellent documentation here. While iqtree is installed with GToTree by default, running it within GToTree is doing things in a very standard, generic way. As discussed on the Things to Consider page, you have to sacrifice some level of control as you broaden out to an entire workflow. So GToTree gives you the alignment and partitions file so if you'd like you can take them into something like iqtree and take advantage of all their functionality. If you're looking specifically for their information on mixed-model analysis, a good place to start is their advanced documentation here.

Here is an example of one way you might do this with iqtree using the alignment and partitions outputs from the Alteromonas example above.

iqtree -s Alteromonas_example/Aligned_SCGs_mod_names.faa \
       -spp Alteromonas_example/Partitions.txt \
       -m MFP -bb 1000 -nt 4 -pre iqtree_out

Code Breakdown:

  • -s – the alignment file we got from GToTree
  • -spp – the partitions file we got from GToTree
  • -m – telling iqtree which model-finder settings to use
  • -bb – number of "ultrafast" bootstraps we want
  • -nt – number of threads we want to use
  • -pre – the prefix of the output files generated

Clone this wiki locally