alpha_plot.R and beta_plot.R - juanravm/MicroSeqProfiler GitHub Wiki

Alpha and beta diversity plot and statistical analysis (alpha_plot.R and beta_plot.R)

After calculating diversity metrics, this two scripts performs Kruskal-Wallis statistical test in alpha diversity metrics and PERMANOVA statistical test in beta diversity metrics to determine if there are significant differences between metadata groups. This script returns a .csv format file with a table of the pairwise comparisons between groups and their significance. Finally, they make a boxplot for alpha diversity metrics and a PCoA plot for beta diversity metrics with ggplot2 R package.

It is necesary to deactivate qiime2 conda enviroment prior to execute these scripts with the following command, as the R packages instalation must be performed in the base enviroment:

conda deactivate

alpha_plot.R

You can run the alpha_plot.R as shown below:

Rscript /file_path/alpha_plot.R \
--shannon_fp /file_path/diversity/alpha/shannon.tsv \
--evenness_fp /file_path/diversity/alpha/evenness_pd.tsv \
--faith_fp /file_path/diversity/alpha/faith_pd.tsv \
--metadata_fp /file_path/metadata.tsv \
--col Comparison \
--output_dir /directory_path/diversity/alpha/Visualizations

Specifying the variables:

  • --shannon_fp - shannon.tsv file path. It should be automatically generated in diversity/alpha directory by diversity.sh script
  • --evenness_fp - evenness_pd.tsv file path. It should be automatically generated in diversity/alpha directory by diversity.sh script
  • --faith_fp - faith_pd.tsv file path. It should be automatically generated in diversity/alpha directory by diversity.sh script
  • --metadata_fp - metadata.tsv file path
  • --col - Metadata column with the groups to compare their alpha diversity
  • --output_dir - Visualizations directory path generated automatically in diversity/alpha by diversity.sh script

This script returns:

  • evenness_pval.csv and pielou_evenness.png - Pielou Evenness boxplot comparing groups and their Kruskal-Wallis statistical analysis in .csv format
  • faith_pval.csv and faith_pd.png - Faith Phylogenetic Diversity boxplot comparing groups and their Kruskal-Wallis statistical analysis in .csv format
  • shannon_pval.csv and shannon.png - Shannon Index boxplot comparing groups and their Kruskal-Wallis statistical analysis in .csv format

beta_plot.R

Also, you can run the beta_plot.R script as shown below:

 Rscript /file_path/beta_plot.R \
--metadata_fp /file_path/metadata.tsv \
--col Comparison \
--bray_fp /file_path/diversity/beta/bray_curtis.tsv \
--unweighted_fp /file_path/diversity/beta/unweighted.tsv \
--weigthed_fp /file_path/diversity/beta/weighted.tsv \
--jaccard_fp /file_path/diversity/beta/jaccard.tsv \
--output_dir /file_path/diversity/beta/Visualizations

Specifying the variables:

  • --metadata_fp - metadata.tsv file path
  • --col - Metadata column with the groups to compare their beta diversity
  • --bray_fp - bray_curtis.tsv file path. It should be automatically generated in diversity/beta directory by diversity.sh script
  • --unweighted_fp - unweighted.tsv file path. It should be automatically generated in diversity/beta directory by diversity.sh script
  • --weigthed_fp - weighted.tsv file path. It should be automatically generated in diversity/beta directory by diversity.sh script
  • --jaccard_fp - jaccard.tsv file path. It should be automatically generated in diversity/beta directory by diversity.sh script
  • --output_dir - Visualizations directory path generated automatically in diversity/beta by diversity.sh script

This script returns:

  • bray_pval.csv and bray_curtis.png - Bray-Curtis PCoA plot comparing groups and their PERMANOVA statistical analysis in .csv format
  • unweighted.csv and unweighted.png - Unweighted UniFrac PCoA plot comparing groups and their PERMANOVA statistical analysis in .csv format
  • weighted.csv and weighted.png - Weighted UniFrac PCoA plot comparing groups and their PERMANOVA statistical analysis in .csv format
  • jaccard.csv and jaccard.png - Jaccard Index PCoA plot comparing groups and their PERMANOVA statistical analysis in .csv format