hsgweon / pipits

Automated pipeline for analyses of fungal ITS from the Illumina
GNU General Public License v3.0
30 stars 16 forks source link

Not able to import phylotype table using phyloseq #43

Closed kunstner closed 3 years ago

kunstner commented 3 years ago

Hi,

I have an issue importing the phylotype table using the phyloseq package. I tried phylotype table from different pipits runs. All show the same behavior (see below).

ps <- import_biom(BIOMfilename = "data/20056_ITS/phylotype_table.biom") Error in dimnames(x) <- dn : length of 'dimnames' [2] not equal to array extent In addition: There were 50 or more warnings (use warnings() to see the first 50)

The normal biom file (otu_tabke.biom) just works fine.

Any suggestings to get rid off this error?

Thanks a lot!

Best, Axel

hsgweon commented 3 years ago

Hi Axel @kunstner

The phylotype table has a different structure from OTU table because each OTU is now a taxonomic classification unlike in OTU tables where you had OTU IDs AND taxonomic classifications. This might be the reason causing the issue (I don't use phyloseq by the way).

One way to resolve this is by not using the phylotype file at all but importing the OTU table and then phylotyping it by yourself in R. And, this is how I would do it:

otu = read.csv("otu_table.txt", row.names = 1, sep = "\t", skip = 1)
otu = otu %>% select(-taxonomy)

tax = read.csv("assigned_taxonomy_reformatted_filtered.txt", sep = "\t", header = FALSE)
colnames(tax) = c("OTU", "taxonomy", "threshold")
tax = tax %>% separate(taxonomy, into = c("Kingdom","Phylum", "Class", "Order", "Family", "Genus", "Species"), sep = "; ")

And now you can aggregate into phylotypes at different levels by:

otu_k = aggregate(otu, tax[1:1], FUN = sum)
otu_p = aggregate(otu, tax[1:2], FUN = sum)
otu_c = aggregate(otu, tax[1:3], FUN = sum)
otu_o = aggregate(otu, tax[1:4], FUN = sum)
otu_f = aggregate(otu, tax[1:5], FUN = sum)
otu_g = aggregate(otu, tax[1:6], FUN = sum)
otu_s = aggregate(otu, tax[1:7], FUN = sum)

Let me know if this works?

kunstner commented 3 years ago

Hi @hsgweon,

thanks for the quick reply! It works!

Best, Axel

hsgweon commented 3 years ago

Perfect!