How to represent OTU abundance in heat trees

98 views
Skip to first unread message

sanchezarr...@gmail.com

unread,
Oct 9, 2017, 12:38:51 PM10/9/17
to metacoder

Hello, 

I just discovered metacoder and I found it really cool to display the relative abundance of different eukaryotic groups depending on the sampling site, size fraction, depth in the water column, etc. I want to try to do the heat trees and compare them.

The problem is that I don't know how to plot the abundance (amount of reads of each OTU) instead of richness (number of OTUs). 

My initial file looks like this (I trimmed the sequences, so it's easy to see). 

>OTU_3 65123 Root;Stramenopiles;Ochrophyta;Chrysophyceae_Synurophyceae;Synurales;Synurales_X
CCAGCACCCGCGGTAATTCCAGCTCCAATAGCGTATACTAAAG
>OTU_6 82891 Root;Alveolata;Ciliophora;Spirotrichea;Choreotrichia;Tintinnidiidae
CCAGCACCCGCGGTAATTCCAGCTCCAATAGCGTATATTAAAGTTGTT
>OTU_4 2375 Root;Stramenopiles;Ochrophyta;Bacillariophyta;Bacillariophyta_X;Radial_Coscinodiscophyceae
CCAGCACCCGCGGTAATTCCAGCTCCAATAGCGTATATTAAAGTTGTT
>OTU_1 7365 Root;Cryptophyta;Cryptophyta;Cryptophyceae;Cryptophyceae_X;Cryptomonadales
CCAGCACCCGCGGTAATTCCAGCTCTAATAGCATATATTAAAGT

The second column is the abundance of each OTU and this is the value I want to plot as node_color. 

My code right now is like this: 

prueba <- file.path("EukSeqs_prueba.fa")
seqs.prueba <- ape::read.FASTA(prueba)
data.prueba <- extract_taxonomy(seqs.prueba, regex = "^(.*)\\t(.*)\\t(.*)", key = c(id = "obs_id", "obs_info", "class"), class_sep = ";")
heat_tree(data.prueba, node_size = n_obs, node_label = name, node_color = obs_info, overlap_avoidance = 0.5)

But an error pops up "Error in eval(expr, envir, enclos) : object 'obs_info' not found'

I checked the data.prueba and it has two tables (taxon_data and obs_data), but I don't know how to use the obs_info from the obs_data table and the name and n_obs from the taxon_data table... 

Any help? 
Thank you so much, and congratulations for the package. It's great!!


Alicia

Zachary Foster

unread,
Oct 9, 2017, 8:36:30 PM10/9/17
to metacoder
Hello Alicia,

Thanks!

The main issue is that you need per-taxon values, but you have per-OTU values. Since each taxon might have zero or more OTUs associated with it, you have to identify which OTUs apply to each taxon and sum their counts. The `obs` or `obs_apply` functions to get OTU info for each taxon, but there the `calc_taxon_abund` function in the development version of `metacoder` that will do this for you.
 
I took your example dataset and made an exaple of how to do this. Attached is an R project with an Rmd file that has the code and notes. The PDF attached is its output.

Take a look and let me know if you have questions.

Best,

-Zach
2017_10_09--alicia--otu_abundance.zip
example.pdf

Niklaus Grünwald

unread,
Oct 9, 2017, 10:06:27 PM10/9/17
to Zachary Foster, metacoder
Zach, well done!

Cheers,
Nik


--
You received this message because you are subscribed to the Google Groups "metacoder" group.
To unsubscribe from this group and stop receiving emails from it, send an email to metacoder-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/metacoder-discussions/599c2937-23c7-4605-8b48-06e27d647434%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
<2017_10_09--alicia--otu_abundance.zip><example.pdf>

sanchezarr...@gmail.com

unread,
Oct 10, 2017, 12:02:34 PM10/10/17
to metacoder

Thank you so much, Zach!!

Yes, it worked perfectly fine :) This package is super useful, I love it. Thanks again


A. 

Zachary Foster

unread,
Oct 10, 2017, 12:51:05 PM10/10/17
to metacoder
No problem! I am glad it worked out. Thanks!

-Zach

marm...@gmail.com

unread,
Nov 29, 2017, 3:23:44 AM11/29/17
to metacoder
Hi Zach,

I was following the code you provided to Alicia and running line 57 (heat_tree calling) produced the following error:

Error in ggrepel:::repel_boxes(data_points = as.matrix(text_data[movable, :  
 argument
"hjust" is absent, without value ...  

I was using ggrepel  (0.7.1 2017-11-18). Then saw on github they just added some changes to justification, So I downgraded ggrepel to 0.7.0 (2017-09-08 ) and it did the trick.
Hope this helps.

Thanks for those examples!

Miguel

Zachary Foster

unread,
Nov 29, 2017, 12:40:18 PM11/29/17
to metacoder
Hello Miguel,

Thanks for figuring that out! I will look into that.

-Zach
Reply all
Reply to author
Forward
0 new messages