Metaphlan4 calculate_diversity.R error

Hello! I am trying to calculate alpha and beta diversity using the script calculate_diversity.R which is present in the packages of Metaphlan4. I run the command in the conda environment where I installed Metaphlan4, but it does not work.

The command I used to calculate beta diversity:
Rscript calculate_diversity.R -f merged_metaphlan_samples.tsv -d beta -m bray-curtis

Fatal Error:
Cannot open file ‘calculate_diversity.R’: No such file or directory

Any input will be appreciated.

Hi @angel
Have you try to call the script using the absolute path to it?
Rscript /absolute_path/calculate_diversity.R -f merged_metaphlan_samples.tsv -d beta -m bray-curtis

1 Like

Hi @aitor.blancomiguez

Thanks for the suggestion. Using the absolute path fixed the issue.

Hi! I am encountering the same issue but am having trouble finding the absolute path. I used the path to the directory where I created the metaphlan environment, but I get the same error.

For example, these were the commands I used to create and activate the environment:

cd /workdir/slg/diet_manip/metaphlan4_v2
conda install -c conda-forge -c bioconda metaphlan
conda create --name mpa -c conda-forge -c bioconda python=3.7 metaphlan
conda update -n base -c defaults conda
conda activate mpa

And this is how I am trying to calculate diversity after getting my merged table:

Rscript /workdir/slg/diet_manip/metaphlan4_v2/calculate_diversity.R -f merged_abundance_table.txt -d alpha -m jaccard

I don’t see a utils folder anywhere

Any help is appreciated. Thank you!

Hi @samanthagoldman
Running metaphlan --help will provide you the path where the MetaPhlAn scripts are installed. If you look at the default value of the --bowtie2db , e.g:

Mapping arguments:                                                                                                                                                                                                 
  --force               Force profiling of the input file by removing the bowtie2out file                                                                                                                          
  --bowtie2db METAPHLAN_BOWTIE2_DB                                                                                                                                                                                 
                        Folder containing the MetaPhlAn database. You can specify the location by exporting the DEFAULT_DB_FOLDER variable in the shell.[default /etc/anaconda3/e

Your metaphlan and utils script will be in the parent folder of the databases. E.g in my case will be