# How can I get lefse output for a single taxonomy level (e.g. species) only?

**URL:** <https://forum.biobakery.org/t/how-can-i-get-lefse-output-for-a-single-taxonomy-level-e-g-species-only/800>\
**Category:** LEfSe\
**Created:** [July 30, 2020, 5:44pm UTC](https://forum.biobakery.org/t/how-can-i-get-lefse-output-for-a-single-taxonomy-level-e-g-species-only/800 "2020-07-30T17:44:32Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![DEEPCHANDA7](https://avatars.discourse-cdn.com/v4/letter/d/eb9ed0/32.png) [@DEEPCHANDA7](https://forum.biobakery.org/u/DEEPCHANDA7)\
**Post date:** [July 30, 2020, 5:44pm UTC](https://forum.biobakery.org/t/how-can-i-get-lefse-output-for-a-single-taxonomy-level-e-g-species-only/800/1 "2020-07-30T17:44:32Z")

</div>

Hi community!!! @sma @franzosa @sagunmaharjann  
I am using MetaPhlAn output data as input for lefse in **Galaxy**. But, I am seeing that a single output graph shows various taxa level within it. [This is my output](https://ibb.co/qWndrkb). But I want only a single taxa level (e.g. only species) to be shown in a single plot. How can I get that? Am I doing anything wrong?

Thanks,  
dc

---

<div class="post-metadata">

**Author:** ![sma](https://avatars.discourse-cdn.com/v4/letter/s/dec6dc/32.png) [@sma](https://forum.biobakery.org/u/sma)\
**Post date:** [July 31, 2020, 4:49pm UTC](https://forum.biobakery.org/t/how-can-i-get-lefse-output-for-a-single-taxonomy-level-e-g-species-only/800/2 "2020-07-31T16:49:12Z")

</div>

Hi dc -

LEfSe automatically goes up the taxonomy to test for features at all levels. Given your input is MetaPhlAn (so should have features at all taxonomy levels to begin with?), here is what I’d suggest:

1. First, filter your MetaPhlAn table so that it only contains species level features.
2. “Trick” LEfSe to not test features at all taxonomy levels. You can achieve this by manipulating the species names. You can either remove all the other taxa levels preceding the species name, e.g, “k\_\_Bacteria|p\_\_Actinobacteria|c\_\_Actinobacteria|o\_\_Actinomycetales|f\_\_Corynebacteriaceae|g\_\_Corynebacterium|s\_\_Corynebacterium\_matruchotii” -\> “s\_\_Corynebacterium\_matruchotii”. Alternatively, replace the taxon separator “|” with something LEfSe won’t recognize, such as “;”, e.g., -\> “k\_\_Bacteria;p\_\_Actinobacteria;c\_\_Actinobacteria;o\_\_Actinomycetales;f\_\_Corynebacteriaceae;g\_\_Corynebacterium;s\_\_Corynebacterium\_matruchotii”. The latter might be simpler to do, but gives you less pretty feature names (the full name will appear instead of just s\_\_Corynebacterium\_matruchotii).

Let me know if you’d need help on any of this.  
Best,  
Siyuan

---

<div class="post-metadata">

**Author:** ![DEEPCHANDA7](https://avatars.discourse-cdn.com/v4/letter/d/eb9ed0/32.png) [@DEEPCHANDA7](https://forum.biobakery.org/u/DEEPCHANDA7)\
**Post date:** [July 31, 2020, 4:52pm UTC](https://forum.biobakery.org/t/how-can-i-get-lefse-output-for-a-single-taxonomy-level-e-g-species-only/800/3 "2020-07-31T16:52:44Z")

</div>

Hi @sma I have already tested the first option. It did not work. I have seen that the first step (“format data for lefse”) was successfully completed. But, the second step (“LDA Effect size”) was failed.  
Thanks,  
dc

---

<div class="post-metadata">

**Author:** ![Kelsey\_Thompson](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.biobakery.org/kelsey_thompson/32/65_2.png) [@Kelsey\_Thompson](https://forum.biobakery.org/u/Kelsey_Thompson)\
**Post date:** [July 31, 2020, 4:57pm UTC](https://forum.biobakery.org/t/how-can-i-get-lefse-output-for-a-single-taxonomy-level-e-g-species-only/800/4 "2020-07-31T16:57:26Z")

</div>

Hi dc-  
You can also run something like:  
for MetaPhlAn3 output on the command line

```auto
$ grep -E "s __|clade" merged_abundance_table.txt | sed 's/^.*s__ //g' | cut -f1,3-8 | sed -e 's/clade_name/body_site/g' > merged_abundance_table_species.txt

```

or  
For MetaPhlAn2 output

```auto
$ grep -E "(s__)|(^ID)" merged_abundance_table.txt | grep -v "t__" | sed 's/^.*s__//g' > merged_abundance_table_species.txt

```

To produce feature tables that only have the species level results. Both commands are from the MetaPhlAn tutorials: [https://github.com/biobakery/biobakery/wiki/metaphlan2;](https://github.com/biobakery/biobakery/wiki/metaphlan2;) [https://github.com/biobakery/biobakery/wiki/metaphlan3](https://github.com/biobakery/biobakery/wiki/metaphlan3) - this will give you more information on what exactly those commands are doing.

---

<div class="post-metadata">

**Author:** ![DEEPCHANDA7](https://avatars.discourse-cdn.com/v4/letter/d/eb9ed0/32.png) [@DEEPCHANDA7](https://forum.biobakery.org/u/DEEPCHANDA7)\
**Post date:** [July 31, 2020, 5:02pm UTC](https://forum.biobakery.org/t/how-can-i-get-lefse-output-for-a-single-taxonomy-level-e-g-species-only/800/5 "2020-07-31T17:02:03Z")

</div>

Hi @Kelsey_Thompson !!! This is the command I have used to generate species level merged abundance file:  
grep -E “(s\_\_)|(^clade\_name)” merged\_abundance\_table.txt | grep -v “t\_\_” | sed ‘s/^.\*s\_\_//g’ \> merge\_abundance\_species.txt

```
here is a reproducible part from my data:
|type|highbp|control|control|
|---|---|---|---|
|clade_name|ERR185652_profile|ERR298068_profile|ERR321205_profile|
|Actinobaculum_sp_oral_taxon_183|0|0|0|
|Actinomyces_graevenitzii|0|0|0|
|Actinomyces_naeslundii|0|0|0|
|Actinomyces_odontolyticus|0|0|0.00341|
|Actinomyces_oris|0|0|0|
|Actinomyces_sp_HMSC035G02|0|0|0|
|Actinomyces_sp_HPA0247|0|0|0|
|Actinomyces_sp_ICM47|0|0|0.0042|
|Actinomyces_sp_S6_Spd3|0|0|0|
|Actinomyces_sp_oral_taxon_181|0|0|0|
|Actinomyces_sp_oral_taxon_414|0|0|0|
|Actinomyces_turicensis|0|0|0|
|Varibaculum_cambriense|0|0|0|
|Aeriscardovia_aeriphila|0.00454|0|0|
|Alloscardovia_omnicolens|0|0|0|
|Bifidobacterium_adolescentis|0.26989|0.21046|0|
|Bifidobacterium_animalis|0|0.03512|0|
|Bifidobacterium_bifidum|0|0.07668|0|
|Bifidobacterium_breve|0|0|0|
|Bifidobacterium_catenulatum|0|0.06641|0|
|Bifidobacterium_dentium|0|0|0|
|Bifidobacterium_longum|2.46071|1.68152|0|
|Bifidobacterium_pseudocatenulatum|0|0|0|
|Bifidobacterium_pullorum|0|0|0|
|Gardnerella_vaginalis|0|0|0|

```

Thanks,  
dc

---

<div class="post-metadata">

**Author:** ![DEEPCHANDA7](https://avatars.discourse-cdn.com/v4/letter/d/eb9ed0/32.png) [@DEEPCHANDA7](https://forum.biobakery.org/u/DEEPCHANDA7)\
**Post date:** [August 1, 2020, 12:37pm UTC](https://forum.biobakery.org/t/how-can-i-get-lefse-output-for-a-single-taxonomy-level-e-g-species-only/800/6 "2020-08-01T12:37:15Z")

</div>

Hi @sma I also have replaced “|” with “;”. But, it didn’t help. Even the first step is failed in this case. Please tell me what to do now?

Thanks,  
dc

---

<div class="post-metadata">

**Author:** ![sma](https://avatars.discourse-cdn.com/v4/letter/s/dec6dc/32.png) [@sma](https://forum.biobakery.org/u/sma)\
**Post date:** [August 3, 2020, 2:35am UTC](https://forum.biobakery.org/t/how-can-i-get-lefse-output-for-a-single-taxonomy-level-e-g-species-only/800/7 "2020-08-03T02:35:18Z")

</div>

Hi -

Would you mind sharing your input table with us? It’s a bit difficult to see what the issue might be without the file. You can reach me at siyuanma@g.harvard.edu to share the file.

Best,  
Siyuan

---

<div class="post-metadata">

**Author:** ![DEEPCHANDA7](https://avatars.discourse-cdn.com/v4/letter/d/eb9ed0/32.png) [@DEEPCHANDA7](https://forum.biobakery.org/u/DEEPCHANDA7)\
**Post date:** [August 3, 2020, 7:08am UTC](https://forum.biobakery.org/t/how-can-i-get-lefse-output-for-a-single-taxonomy-level-e-g-species-only/800/8 "2020-08-03T07:08:41Z")

</div>

Hi @sma I have sent the data to your mail. Please have a look at it. My mail Id is [deepchanda771992@gmail.com](mailto:deepchanda771992@gmail.com)

Thanks,  
dc
