cafferychen777 / MicrobiomeStat

Track, Analyze, Visualize: Unravel Your Microbiome's Temporal Pattern with MicrobiomeStat
https://www.microbiomestat.wiki/
31 stars 5 forks source link

calculating alpha diversity pr feature, not sample #7

Closed mariamaseng closed 1 year ago

mariamaseng commented 1 year ago

Helllo,

I used the function "mSTAT_convert_phyloseq_to_data_obj" to convert from phyloseq to ms-object. This works well. However, when I am exploring alpha diversity, by mStat_calculate_alpha_diveristy, it by defaults calcluate by feature, not sample. Testing the other alpha_div functions doesnt work, and I am suspecting it to be because of this.

It becomes correct if I do: msdata_rare.alpha = mStat_calculate_alpha_diversity(t(msdata_rare$feature.tab), "shannon").

cafferychen777 commented 1 year ago

Hello @mariamaseng ,

Thank you for sharing your experience with the functions I've designed for phylogenetic sequencing data analysis. I appreciate your engagement and the opportunity to clarify how these functions work.

To address your concerns, the function mStat_calculate_alpha_diversity is actually designed to calculate alpha diversity based on samples, not features. In fact, I'm not sure what would entail calculating alpha diversity by features.

If you've obtained diversity metrics based on features, it may indicate that an issue occurred during the data conversion step. I would recommend using the mStat_validate_data function to ensure that your data object is in the appropriate format.

For your reference, you might find the example code below useful. This example demonstrates that the function calculates alpha diversity based on samples.

# Create example OTU table
otu.tab <- matrix(data = rpois(100, 5), nrow = 10, ncol = 10)
rownames(otu.tab) <- paste0("Taxon_", 1:10)
colnames(otu.tab) <- paste0("Sample_", 1:10)

# Calculate alpha diversity indices
alpha.obj <- mStat_calculate_alpha_diversity(x = otu.tab, alpha.name = c("shannon", "simpson", "observed_species", "chao1", "ace", "pielou"))

By running this example, you should be able to confirm that the function is working as intended for calculating alpha diversity based on samples.

I hope this clears up any confusion. If you have further questions, please don't hesitate to ask.

Best regards, Chen YANG

mariamaseng commented 1 year ago

Thank you! Using mStat_validate_data solved it, and the features-tab is interpreted correctly. Thank you!

mariamaseng commented 1 year ago

Btw - despite the feature-tab being interpreted corretly with mStat_validate_data, all the info in meta.dat are then transformed into NA and therefore lost.

cafferychen777 commented 1 year ago

Hi @mariamaseng ,

Thank you for reaching out about the issue. In order to assist you effectively, it would be really helpful if you could provide more context. When submitting a problem, please include the relevant code, details about your dataset, and the step-by-step process you followed to build it. This will allow me to better understand your situation and provide a more accurate solution.

You can take a look at well-structured questions in the ggpicrust2 repository’s issues section to understand what constitutes a good question and how to present your issue in a way that helps others assist you more effectively.

Looking forward to your next submission with more context!

Best regards, Chen YANG

mariamaseng commented 1 year ago

Yes, I understand and will try my best. As I am working within TSD, I cannot export the data, but will do my best. Thank you for your patience with all my questions.

image image

image

Running the simplest alpha diversity on the "ms_rare", it calculates alpha diversity pr feature, not sample. image

cafferychen777 commented 1 year ago

Actually the building of mStat Object is not right. You can check the figure and the wiki. image

mariamaseng commented 1 year ago

OK, thanks for this. I will try :)