grunwaldlab / metacoder

Parsing, Manipulation, and Visualization of Metabarcoding/Taxonomic data
http://grunwaldlab.github.io/metacoder_documentation
Other
135 stars 28 forks source link

Using MetacodeR with Sourmash LCA output #246

Closed shigdon closed 6 years ago

shigdon commented 6 years ago

Hello @zachary-foster,

I have microbial classification data that was generated using Sourmash, and now I would like to visualize with metacoder. I am struggling to read in the taxmap object file based on the input csv file format. The data I am trying to read in as a taxmap object has the following format (sample_id, superkingdom, phylum, class, order, family, genus, species).

Here are two example lines within my output file:

172,Bacteria,Proteobacteria,Gammaproteobacteria,Enterobacterales,Enterobacteriaceae,,
173,Bacteria,Proteobacteria,Gammaproteobacteria,Enterobacterales,Enterobacteriaceae,,

What I wish to do is count the number of observations for each level of taxonomic classification across all of my samples and visualize the number of observations for each classification level within my population of sequenced microbial isolates.

I have been trying to learn by following your https://cran.r-project.org/web/packages/metacoder/vignettes/introduction.html, but my data does not seem to be in the same format as the hmp_otus file.

Is there a way to use metacoder and taxa to parse the sourmash classification data I have described to generate counts that can be visualized as a heat tree, or do I need to somehow generate counts first?

zachary-foster commented 6 years ago

HEllo @shigdon,

Try this:

library(metacoder)
library(readr)

raw_data <- read_csv(file = "my/file/path")

obj <- parse_tax_data(raw_data, class_cols = 2:8)

n_obs(obj, "tax_data") # Count number of rows in table for each taxon

heat_tree(obj,
          node_label = taxon_names,
          node_size = n_obs,
          node_color = n_obs)

Let me know if you have problems

shigdon commented 6 years ago

Thank you very much @zachary-foster ! I now have a beautiful starting point for the plot. I will continue to use and explore the features of this package!

zachary-foster commented 6 years ago

Great, thanks!