grunwaldlab / metacoder

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

Error in check_element_length #306

Closed mr2raccoon closed 3 years ago

mr2raccoon commented 3 years ago

Hey, I followed the workshop (https://grunwaldlab.github.io/metacoder_documentation) and then tried to replicate what was done with my own data. Please note: I am still very much a beginner to programming and R in general.

I tried to create a heat tree and I receive the following error message: library(metacoder) heat_tree(exobj, node_label=7:13, node_size= reads, node_color= reads) Error in check_element_length(c("node_size", "edge_size", "node_label_size", : Length of argument'node_size' must be a factor of the length of 'taxon_id'

For note labels I used columns 7:13 stored in the object, from superkingdom to species. The column "reads" stores the number of reads from Illumina-sequencing for this one sample.

Creating "exobj" I did as follows:

`otu_data <- read.csv("mb5_2020_ill_OTU_counts.csv") tax_data <- read.csv("mb5_2020_ill_tax.csv")

com_data <- left_join(otu_data,tax_data, by=c("taxon_id"="taxon_id"))

exobj <- parse_tax_data(com_data, class_cols=7:13)`

Thank you in advance!

zachary-foster commented 3 years ago

Greetings Mr. Raccoon II,

The node_label option for heat_tree must take a character vector of length equal to the number of taxa in exobj. exobj probably already has the taxon names if it was produced correctly, and these can be accessed in the heat_tree function using taxon_names. Does this work?

heat_tree(exobj, node_label=taxon_names, node_size= reads, node_color= reads)

You might also want to look at the examples in the function documentation by typing ?heat_tree

mr2raccoon commented 3 years ago

Thanks for getting back to me. I tried parsing my data from a phyloseq object now. I am still having trouble. I think it did not create the taxon names correctly. My taxmap object looks like this: `> metaphy

221 taxa: ab. Eukaryota, ac. Bacteria, ad. unclassified ... ji. Clostridium sp. C105KSO15, jj. Olsenella sp. Marseille-P3256 221 edges: NA->ab, NA->ac, NA->ad, ab->ae, ab->ai, ae->aj, ae->ak, ae->al, ab->an ... gx->jc, gy->jd, fz->je, gz->jf, ha->jg, hb->jh, hc->ji, hd->jj 2 data sets: otu_table: # A tibble: 58 x 4 taxon_id otu_id reads_mb5_ill reads_mb6_ill 1 he 293939 22266 175 2 hf 5606 12168 4164 3 hg 5341 8232 3789 # … with 55 more rows tax_data: # A tibble: 58 x 10 taxon_id otu_id superkingdom kingdom phylum class order family genus species 1 he 293939 Eukaryota Fungi Ascomycota Eurotiomycetes Eurotiales Aspergillaceae Aspergillus Aspergillus lentulus 2 hf 5606 Eukaryota Fungi Ascomycota NA NA NA Saitoella Saitoella complicata 3 hg 5341 Eukaryota Fungi Basidiomycota Agaricomycetes Agaricales Agaricaceae Agaricus Agaricus bisporus # … with 55 more rows` Already when I parse I get the following error message `The following 22 of 58 (37.9%) input indexes have `NA` in their classifications: 2, 7, 14, 15, 18, 19, 20, 29, 31, 32, 34, 36, 39, 45, 46, 47, 49, 51, 52, 55, 57, 58` Which is correct way for metacoder to read NA in the "tax_data"? One more question: in my taxmap object I have two samples "MB5" and "MB6". Is it possible to draw the heat tree for only one of the two? Thanks for your time!
mr2raccoon commented 3 years ago

@zachary-foster Nevermind my last post I managed to draw the heat_tree now. I simply had to change "NA" to chr-value "unclassified". I managed to filter to show only "Fungi" even.

Two questions remian

  1. How can I draw one heat tree per sample? I assume now it plots a heat tree for both samples together?

  2. The n_obs does not seem to take the reads stored in the OTU-table but count the rows for observation. How can I assign n_obs correctly ?

metaobj <- parse_phyloseq(physeq_nano) metaobj%>% filter_taxa(taxon_names == "Fungi", subtaxa = TRUE) %>% heat_tree( node_label = taxon_names, node_size = n_obs, node_color = n_obs)

` 1069 taxa: aab. Eukaryota, aac. Bacteria, aad. Viruses ... bpc. Oscillatoriales cyanobacterium USR001, bpd. Singulisphaera sp. GP187 1069 edges: NA->aab, NA->aac, NA->aad, NA->aae, aab->aaf, aac->aag, aab->aah ... bcb->boy, bcc->boz, baj->bpa, bcd->bpb, bce->bpc, bcf->bpd

2 data sets:

otu_table:
  # A tibble: 336 x 4
    taxon_id otu_id  MB5_2020_nano MB6_2020_nano
    <chr>    <chr>           <dbl>         <dbl>
  1 bcg      1873960        178089         49468
  2 bch      574774          41123         12172
  3 bci      5606            34803          8956
  # … with 333 more rows

tax_data:

  # A tibble: 336 x 10
    taxon_id otu_id  superkingdom kingdom phylum     class           order        family             genus            species                   
    <chr>    <chr>   <chr>        <chr>   <chr>      <chr>           <chr>        <chr>              <chr>            <chr>                     
  1 bcg      1873960 Eukaryota    Fungi   Ascomycota Dothideomycetes Capnodiales  Mycosphaerellaceae Pseudocercospora Pseudocercospora fijiensis
  2 bch      574774  Eukaryota    Fungi   Ascomycota Dothideomycetes unclassified Gloniaceae         Glonium          Glonium stellatum         
  3 bci      5606    Eukaryota    Fungi   Ascomycota unclassified    unclassified unclassified       Saitoella        Saitoella complicata      
  # … with 333 more rows

0 functions:`

image