How to calculate alpha diversity using many different metrics in one command?

Hello,

Does anyone know how to calculate alpha diversity using several different metrics in one command please?

I tried following the advice given on How to compute several alpha-diversity rarefaction plots, but it gave me an error.

My command:

qiime diversity alpha
–i-table Ar2_raw_PairedEnd_table_deblur.qza
–p-metric ‘observed_otus’
–p-metric ‘shannon’
–p-metric ‘dominance’
–p-metric ‘osd’
–p-metric ‘chao1’
–p-metric ‘strong’
–p-metric ‘goods_coverage’
–p-metric ‘lladser_pe’
–p-metric ‘mcintosh_d’
–p-metric ‘brillouin_d’
–p-metric ‘ace’
–p-metric ‘michaelis_menten_fit’
–p-metric ‘enspie’
–p-metric ‘fisher_alpha’
–p-metric ‘kempton_taylor_q’
–p-metric ‘lladser_ci’
–p-metric ‘berger_parker_d’
–p-metric ‘esty_ci’
–p-metric ‘gini_index’
–p-metric ‘simpson_e’
–p-metric ‘doubles’
–p-metric ‘menhinick’
–p-metric ‘singles’
–p-metric ‘heip_e’
–p-metric ‘mcintosh_e’
–p-metric ‘chao1_ci’
–p-metric ‘margalef’
–p-metric ‘pielou_e’
–p-metric ‘simpson’
–p-metric ‘robbins’
–o-alpha-diversity Ar2_raw_PairedEnd_alpha_diversity_observed_otus.qza

And this is the error I got:

              There were some problems with the command:                  

(1/10?) Option ‘–p-metric’ was specified multiple times in the command.
(2/10?) Option ‘–p-metric’ was specified multiple times in the command.
(3/10?) Option ‘–p-metric’ was specified multiple times in the command.
(4/10?) Option ‘–p-metric’ was specified multiple times in the command.
(5/10?) Option ‘–p-metric’ was specified multiple times in the command.
(6/10?) Option ‘–p-metric’ was specified multiple times in the command.
(7/10?) Option ‘–p-metric’ was specified multiple times in the command.
(8/10?) Option ‘–p-metric’ was specified multiple times in the command.
(9/10?) Option ‘–p-metric’ was specified multiple times in the command.
(10/10?) Option ‘–p-metric’ was specified multiple times in the command.

I would really appreciate your advice… Many thanks!

Hi @fgara,

Welcome to the :qiime2: forum.

At the moment, it's not possible to do this in one command in QIIME 2. You could build a for-loop (I'd recommend the python API for that but if you have some bash-foo, you could probably put together a loop on the command line or via a snakemake pipeline. You could alos check and see if core-diversity will let you change the list of metrics.

Otherwise, this might be a good development suggestion.

Best,
Justine

2 Likes

Thank you!
I will try a for-loop in that case.
And yes, if it’s possible to enable this as one command in QIIME2, that would be great!

Thanks again

1 Like

Hi,

Sorry for asking again.

Following your suggestion I tried the following, but it gave me error.

for i in shannon observed_otus dominance
do
qiime diversity alpha
–i-table Ar2_raw_PairedEnd_table_deblur.qza
-–p-metric “’$i’”
–o-alpha-diversity Ar2_raw_PairedEnd_alpha_diversity
done

Error message:
Error: Detected invalid character in: -–p-metric
Verify the correct quotes or dashes (ASCII) are being used.

I have tried various combinations of quotes, such as “”, ‘’, “’’”,… all gave me the same error message.

Do you know how to correctly pass on a bash variable to a QIIME command please?

Thank you so much once again

HI @fgara,

I think you can just try

for i in shannon observed_otus dominance
do
qiime diversity alpha
–i-table Ar2_raw_PairedEnd_table_deblur.qza
-–p-metric $i
–o-alpha-diversity Ar2_raw_PairedEnd_alpha_diversity
done

But, bash is not my best language.

Best,
Justine

2 Likes

Dear Justine,

I’ve tried your suggestion, and still got the same error:
Error: Detected invalid character in: -–p-metric, –-o-alpha-diversity
Verify the correct quotes or dashes (ASCII) are being used.

But don’t worry, I’ll try to figure it out.
Thanks again for your kindness!

Hi @fgara,

Again, bash isn’t my language, but maybe try

for i in 'shannon' 'observed_otus' 'dominance'
do
echo $i
qiime diversity alpha
--i-table Ar2_raw_PairedEnd_table_deblur.qza
--p-metric $i
--o-alpha-diversity $i.qza
done

I also think you want to direct your output path more clearly. Like, you’ll re-write the filepath if you do it this way.

So, a wonderful collegue pointed out that you might also have an issue with your fancy dashes. Try typing directly on the command line or using a text editor to format

Best,
Justine

1 Like

Hi, @fgara
I have some ideas for your problem.

If you have a metada file, you can try ‘qiime diversity core-metrics’ or ’ qiime diversity core-metrics-phylogenetic ’ to calculate alpha diversity, and you will get some of the alpha diversity you listed (see the command documentation for details).

There’s also a very silly way. Your code will print out the qiime2 commands. If you want q2 to run these commands, you can try the following:

Create a blank ’ .txt ’ file, write the qiime2 command with a different ’ --p-metric ’ parameter by line through the loop or manually, then, change the file suffix to ’ .sh ', like this:

qiime diversity --i-table table.qza --p-metric shannon --o-alpha-diversity output.qza
qiime diversity --i-table table.qza --p-metric observed_otus --o-alpha-diversity output.qza

and run it on the terminal using the ‘nohup sh your_file_name.sh &’ command.

Hope the above can help you.

1 Like

Dear both,

Thanks so much for your kind replies.
Unfortunately, I’ve tried all sorts of different dashes, quotation marks etc but nothing worked.
So I decided to write all of the commands in a bash file script.

Many thanks once again

1 Like

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.