qiime2 to LEfSe

I am trying to run LEfSe analysis. Can someone provide qiime2 coding to convert table.qza to something compatible for LEfSe. I found an old posting (from June 2018), but it seems not working (outdated?). Thanks!!

Welcome to :qiime2: @hjeong1!

Aside from the content outlined here:

I've often made use of qiime2R and then feed the phyloseq object to phyloseq2lefse.R. You'll have to perform some minor edits to the resulting table, e.g. move excess rows of metadata. But I've used this approach several times quite successfully.



I have never been able to use any tool to do this!!
I do it manually. Export your table of taxonomically attributed ASV (using qiime taxa collapse, ex. at L6). Then export to BIOM and then to text format (using the -‘to-tsv’ from the biom module).
Once you have exported the table to text format (L6_table.txt), you merge it with the metadata (i use Excell ! since there is not too much data at that point). Then flip around, sort, merge SampleID with metadata, keep only the needed lines in the header and change the ‘;’ to ‘|’. And you are all set!
Just have a good look at an example sample sheet. Like on the galaxy server.
I like this way to go as you look at the table when manipulating it.

Good luck with that and have a great one, -JA


Hi all,

Just to clarify, the R wrapper I reference only prepares a data table for you in R and does not require that you have LEfSe installed. Obviously, it does require phyloseq. :slight_smile:

If you’d like to be able to run LEfSe locally, you may want to try the approach outlined below. I have not tried this recently, but it did work when I installed last September.

conda update conda
conda create -n lefse -c conda-forge python=2.7.15
conda activate lefse
conda install -c bioconda -c conda-forge lefse
conda update lefse

Then you can:

conda activate lefse

lefse-format_input.py \
      tax-otu-table.txt \
      tax-otu-table-form.txt \
      -c 1 -u 2 -o 1000000

run_lefse.py \
    tax-otu-table-form.txt \

lefse-plot_res.py \
    tax-otu-table-result.txt \
    tax-otu-table-diffabund.pdf \

lefse-plot_cladogram.py \
     tax-otu-table-result.txt \
     tax-otu-table-cladogram.pdf \


-I hope this helps! If anyone has other or better solutions please let us know.


Hi SoilRotifer,
Thanks for the nice advice. I followed the method you mentioned above: creating a Phyloseq Object with qiime2R; and then transfer the phyloseq object to the lefse input format. But there were some errors happened. 1. the taxonomic level seems contain only genus, but not all the levels from phylum to genus as the example file. Besides, NA values appeared in some samples. Have you ever had these problems before?


Hi @11131, welcome to :qiime2:!

I am not sure what is happening here. When do these NAs appear? During import into R or when formatting for LEfSe? Perhaps contact the developers of the either of the R tools?


Hi SoilRotifer,
These NAs appear in the lefse input file that created with the physeq2lefse.R. I just checked the physeq file created by the qiime2R with the otu_table function, and found that the table was correct, meaning that the physeq file was built correctly. So I think the problem was associate with the phyloseq2lefse.R code.
Besides, only the genus level was tested when you perform the lefse?
Thanks! !

1 Like

Hmm interesting.

In that case, you may have to try making the LEfSe input manually. :confused:

If you made the conda lefse environment that I highlighted above, then you might try the hidden lefse script qiime2lefse.py. It appears that you can provide it with your feature-table and your metadata file and it will make a lefse compatable input file. Perhaps give this a try? Note, that this appears to take old QIIME 1 formatted data.

Run qiime2lefse.py -h to see the help options.


1 Like

Hi Mike,
Thank you so much for your reply!
I jsut found a R package microbiomeMarker that could perform the lefse analysis with the phyloseq object built by qiime2R. This is more convenient!


Thank you for letting us know about this R package @11131! :slight_smile:


hi,Bin,could you share the way to performed lefse?


I have tried the abovementioned package this way:
I write pseudocode below,
In addition I read that this function is suitable for more than 2-classes comparison


rank_names(phyle) # phyle is my phyloseq object, please construct the phyloseq object

taxa.name <- as.character(c("Kingdom", "Phylum", "Class", "Order", "Family", "Genus", "Species")) # I chaneg the colnames because I have "Rank2", ...

colnames(tax_table(phyle)) <- taxa.name 

lefse.full <- lefse(ps = phyle,class = "outcome") # here I run lefse

head(marker_table(lefse.full))# I see the marker table

# plots
write.xlsx(marker_table(lefse.full),file = "marker_full.xlsx",rowNames=TRUE)# I write the table

pdf("abundance.pdf",width = 10,height = 7)
microbiomeMarker::plot_abundance(lefse.full,group_var = "abundance",label_level = 0)

pdf(file = "lefse.pdf",width = 10)
plot_ef_bar(lefse.full, label_level = 0) +
  scale_fill_manual(values = c("0" = "dodgerblue2", "1" = "firebrick2"))

pdf("cladogram_.pdf",width = 10, height = 10)
microbiomeMarker::plot_cladogram(lefse.full,color = c("dodgerblue2","firebrick2"))
dev.off() # this should be tuned to have a beautiful picture

I saw an additional option to run lefse:

however, as far as I know it performs only two-class analysis,
and it is based on ``SummarizedExperiment` classand not on phyloseq


1 Like