microeco icon indicating copy to clipboard operation
microeco copied to clipboard

plot alpha error

Open apoosakkannu opened this issue 2 years ago • 12 comments

Hi, i try to plot the alpha diversity by_group and found problem with significant code.

Please check the following code.

#calculate and plot the alpha diversity t_country <- trans_alpha$new(dataset = dataset2, group = "Country", by_group = "Host_taxa") t_country$cal_diff(method = "wilcox") t_country$plot_alpha(measure = "Chao1") t_country$plot_alpha(measure = "Shannon")

image image

apoosakkannu avatar Jan 31 '23 10:01 apoosakkannu

Hi. Could you please send me your dataset2 to check it? Please use save function to save the data (https://chiliubio.github.io/microeco_tutorial/notes.html#save-function). I am not sure how it hapened now.

ChiLiubio avatar Feb 02 '23 01:02 ChiLiubio

dataset.rdata.zip https://drive.google.com/file/d/1QI_OcO4Q8TtJXMrQaSEiVhutseYKfaW3/view?usp=drive_web

pls find the dataset attached!

On Thu, Feb 2, 2023 at 3:48 AM Chi Liu @.***> wrote:

Hi. Could you please send me your dataset2 to check it? Please use save function to save the data ( https://chiliubio.github.io/microeco_tutorial/notes.html#save-function). I am not sure how it hapened now.

— Reply to this email directly, view it on GitHub https://github.com/ChiLiubio/microeco/issues/177#issuecomment-1413033699, or unsubscribe https://github.com/notifications/unsubscribe-auth/AMC3WZUFZGS274HHSDRDJ4TWVMG5LANCNFSM6AAAAAAUMIXVYE . You are receiving this because you authored the thread.Message ID: @.***>

apoosakkannu avatar Feb 02 '23 04:02 apoosakkannu

Please drag the data in the Github issue page. I can not open the upper link via the email.

ChiLiubio avatar Feb 02 '23 10:02 ChiLiubio

Thanks, check the following link, https://drive.google.com/file/d/1QI_OcO4Q8TtJXMrQaSEiVhutseYKfaW3/view?usp=drive_web

apoosakkannu avatar Feb 02 '23 11:02 apoosakkannu

It can not be opened for me. Please directly send the data to my email ([email protected]). Thanks.

ChiLiubio avatar Feb 03 '23 05:02 ChiLiubio

Hi. I found the weird result comes from the incorrect factor assignment in the 'Host_taxa ' of sample_table. If you print dataset2$sample_table$Host_taxa, you can find there are 5 factors, not 4. Removing the factors can solve this issue.

library(magrittr)
dataset2$sample_table$Host_taxa %<>% as.character
t_country <- trans_alpha$new(dataset = dataset2, group = "Country", by_group = "Host_taxa")
t_country$cal_diff(method = "wilcox")
t_country$plot_alpha(measure = "Chao1")

ChiLiubio avatar Feb 07 '23 08:02 ChiLiubio

Thanks, it worked. It seems that when I do the subset, a factor still remains even after tidying the dataset.

On Tue, Feb 7, 2023 at 10:56 AM Chi Liu @.***> wrote:

Hi. I found the weird result comes from the incorrect factor assignment in the 'Host_taxa ' of sample_table. If you print dataset2$sample_table$Host_taxa, you can find there are 5 factors, not 4. Removing the factors can solve this issue.

library(magrittr) dataset2$sample_table$Host_taxa %<>% as.character t_country <- trans_alpha$new(dataset = dataset2, group = "Country", by_group = "Host_taxa") t_country$cal_diff(method = "wilcox") t_country$plot_alpha(measure = "Chao1")

— Reply to this email directly, view it on GitHub https://github.com/ChiLiubio/microeco/issues/177#issuecomment-1420413470, or unsubscribe https://github.com/notifications/unsubscribe-auth/AMC3WZTZ4UQ5PKKVA74U5XTWWIE43ANCNFSM6AAAAAAUMIXVYE . You are receiving this because you authored the thread.Message ID: @.***>

apoosakkannu avatar Feb 07 '23 09:02 apoosakkannu

dataset <- mpa2meco("buglist_clean.tsv", sample_table =metadata1) test <- dataset$merge_taxa(taxa = "Genus") test$cal_alphadiv(PD = FALSE) t2 <- trans_alpha$new(dataset = test, group = "group",by_group="time") t2$cal_diff(method = "wilcox") I also check the "group" and "time" as.character but Error in wilcox.test.formula(formu, data = table_compare, ...) : grouping factor must have exactly 2 levels KW_genus_leveL_TIME.pdf

milyzhou avatar Mar 04 '24 02:03 milyzhou

Hi. Could you please attach your dataset or test object so that I can reproduce your issue? To save it, please follow the steps in the tutorial (https://chiliubio.github.io/microeco_tutorial/notes.html#save-function) and attach the compressed object.

ChiLiubio avatar Mar 04 '24 12:03 ChiLiubio

test_data.zip Thank you!

milyzhou avatar Mar 05 '24 00:03 milyzhou

Hi @milyzhou , I found the reason is there is NaN in "ACE" index in the alpha diversity table, i.e. test$alpha_diversity. The temporary solution is to filter ACE or directly use Shannon metric.

test <- dataset$merge_taxa(taxa = "Genus")
test$cal_alphadiv(PD = FALSE)
test$alpha_diversity %<>% .[, !grepl("ACE", colnames(.))]
t2 <- trans_alpha$new(dataset = test, group = "group",by_group="time")
t2$cal_diff(method = "wilcox")

or

test <- dataset$merge_taxa(taxa = "Genus")
test$cal_alphadiv(PD = FALSE)
t2 <- trans_alpha$new(dataset = test, group = "group",by_group="time")
t2$cal_diff(method = "wilcox", measure = "Shannon")

I will add a filtering step in the trans_alpha class in the next version to delete the index with NaN. Thanks!

Best, Chi

ChiLiubio avatar Mar 05 '24 02:03 ChiLiubio

Thanks! It work!Thank you again!

milyzhou avatar Mar 05 '24 08:03 milyzhou