joey711 / phyloseq

phyloseq is a set of classes, wrappers, and tools (in R) to make it easier to import, store, and analyze phylogenetic sequencing data; and to reproducibly share that data and analysis with others. See the phyloseq front page:
http://joey711.github.io/phyloseq/
584 stars 187 forks source link

Heatmap with dendogram-grouping and display by genus level??? #970

Open emankhalaf opened 6 years ago

emankhalaf commented 6 years ago

Hello, I have used two different methods to generate a heatmap with dendogram. The first and easiest one using Phyloseq tutorial: heatmap(otu_table(physeq)) print.pdf

The second using the following code:

Extract abundance matrix from phyloseq object

OTU = as(otu_table(physeq), "matrix")


#Transpose if necessary
if(taxa_are_rows(physeq)){OTU <- t(OTU)}

coerce to data frame

OTUdf = as.data.frame(OTU)

transform the raw counts of reads to proportions

OTUdf.prop <- OTUdf/rowSums(OTUdf) OTUdf.prop[1:3, 1:3] heatmap(as.matrix(OTUdf.prop), Rowv = NA, Colv = NA, col = scaleyellowred)

# determine the maximum relative abundance for each column
maxab <- apply(OTUdf.prop, 2, max)
head(maxab)

heatmap(as.matrix(OTUdf.prop), Rowv = NA, Colv = NA, col = scaleyellowred, margins = c(10, 2))

# calculate the Bray-Curtis dissimilarity matrix on the full dataset:
OTUdf.dist <- vegdist(OTUdf.prop, method = "bray")

row.clus <- hclust(OTUdf.dist, "aver")


# make the heatmap with Rowv = as.dendrogram(row.clus)
heatmap(as.matrix(OTUdf.prop), Rowv = as.dendrogram(row.clus), Colv = NA, col = scaleyellowred, margins = c(10, 3))

add a column dendrogram to cluster the genera that occur more often together

OTUdf.dist.g <- vegdist(t(OTUdf.prop), method = "bray") col.clus <- hclust(OTUdf.dist.g, "aver")


# make the heatmap with Rowv = as.dendrogram(row.clus)
heatmap(as.matrix(OTUdf.prop), Rowv = as.dendrogram(row.clus), Colv = as.dendrogram(col.clus), col = scaleyellowred, margins = c(11, 5), trace = "none", density.info = "none", xlab = "Features", ylab = "Samples", main = "Hierarchical clustering heatmap", lhei = c(2, 8))

but as shown in the attached graph, the otus are displayed by their IDs and I would like to show them by their taxonomic classification (genus level).

One more question, I don't know how to group variables in the regular heatmap (pathogen-treated together and control samples together)?

Thanks in advance Eman

AndreaQ7 commented 5 years ago

Thank you for your suggestion with Heatmap but what does it means "scaleyellowred" thanks

nataliagaeta29 commented 5 years ago

emankhalaf I am having the same issue.... OTU IDs instead of taxonomic classification.

Does someone know how to solve it????

Thanks!

emankhalaf commented 5 years ago

I added the taxonomy (at genus level) manually. If you came up with a solution, please pass it to the forum! Thanks

On Fri, Oct 4, 2019 at 3:01 PM nataliagaeta29 notifications@github.com wrote:

emankhalaf I am having the same issue.... OTU IDs instead of taxonomic classification.

Does someone know how to solve it????

Thanks!

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/joey711/phyloseq/issues/970?email_source=notifications&email_token=AGJ2WVY6DPDLLUMXJBRRCLDQM6OH7A5CNFSM4FLMNFJKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEAMXUWQ#issuecomment-538540634, or mute the thread https://github.com/notifications/unsubscribe-auth/AGJ2WVYUUJWAHORBOVREJIDQM6OH7ANCNFSM4FLMNFJA .

-- Eman M Khalaf (PhD) Post doctoral fellow, University of Guelph, ON, Canada. Lecturer of Microbiology, Faculty of Pharmacy Damanhour University, Egypt e.mail: eimanpharmacist@gmail.com Cell Phone: 002-01005043084

nataliagaeta29 commented 5 years ago

Hi!

I found a code that worked for me! (Using a top20 phyloseq object)

Initially I had the same problem using the following code:

plot_heatmap(top20_phyloseq_object, species.lable="Genus", sample.label = "V4")

image

But, this one: plot_heatmap(physeq_top20_object, taxa.label = "Genus", sample.label = "V4") worked.

(Apparently, my problem was the absence of "taxa.label")

image

I hope it works for you too!

emankhalaf commented 5 years ago

Sorry, it is okay for the heatmap, I am using the following: p1 <- plot_heatmap(rhizo.gen_top50r, "NMDS", "bray", "Treatment", "Genus", taxa.order="Genus", sample.order="Treatment", low="#FFFFCC", high="#000033", na.value="white") print(p1) + theme(legend.position = "right", legend.direction = "vertical")

I assume you mean relative abundance bar charts??

On Fri, Oct 4, 2019 at 3:29 PM nataliagaeta29 notifications@github.com wrote:

Hi!

I found a code that worked for me! (Using a top20 phyloseq object)

Initially I had the same problem using the following code:

plot_heatmap(top20_phyloseq_object, species.lable="Genus", sample.label = "V4")

[image: image] https://user-images.githubusercontent.com/54448811/66236941-c2a23e00-e6c1-11e9-85ae-a305f0a91eea.png

But, this one: plot_heatmap(physeq_top20_object, taxa.label = "Genus", sample.label = "V4") worked.

(Apparently, my problem was the absence of "taxa.label")

[image: image] https://user-images.githubusercontent.com/54448811/66237401-fd58a600-e6c2-11e9-8b5d-b8e871fabf91.png

I hope it works for you too!

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/joey711/phyloseq/issues/970?email_source=notifications&email_token=AGJ2WV52NRLKEEGPV34SKF3QM6RQXA5CNFSM4FLMNFJKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEAMZUJY#issuecomment-538548775, or mute the thread https://github.com/notifications/unsubscribe-auth/AGJ2WV6YX2IBRP5SUGMZL3DQM6RQXANCNFSM4FLMNFJA .

-- Eman M Khalaf (PhD) Post doctoral fellow, University of Guelph, ON, Canada. Lecturer of Microbiology, Faculty of Pharmacy Damanhour University, Egypt e.mail: eimanpharmacist@gmail.com Cell Phone: 002-01005043084