# Running calculate\_unifrac.R ignores first sample

**URL:** <https://forum.biobakery.org/t/running-calculate-unifrac-r-ignores-first-sample/1600>\
**Category:** MetaPhlAn\
**Created:** [January 22, 2021, 11:25pm UTC](https://forum.biobakery.org/t/running-calculate-unifrac-r-ignores-first-sample/1600 "2021-01-22T23:25:04Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![david-castillo](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.biobakery.org/david-castillo/32/440_2.png) [@david-castillo](https://forum.biobakery.org/u/david-castillo)\
**Post date:** [January 22, 2021, 11:25pm UTC](https://forum.biobakery.org/t/running-calculate-unifrac-r-ignores-first-sample/1600/1 "2021-01-22T23:25:04Z")

</div>

I was running the calculate\_unifrac.R script ([MetaPhlAn/calculate\_unifrac.R at master · biobakery/MetaPhlAn · GitHub](https://github.com/biobakery/MetaPhlAn/blob/master/metaphlan/utils/calculate_unifrac.R)) and observed it ignored the first of the samples from the input merged MetaPhlAn file.  
After reviewing the code it seems the problem comes from this line (line 44):  
`mpa_table <- mpa_table[grep('s__',mpa_table[,1]),-2]`  
after substituting this line with this:  
`mpa_table <- mpa_table[grep('s__',mpa_table[,1]),]`  
the problem was solved. Just for you guys to know.  
Best regards

---

<div class="post-metadata">

**Author:** ![fbeghini](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.biobakery.org/fbeghini/32/81_2.png) [@fbeghini](https://forum.biobakery.org/u/fbeghini)\
**Post date:** [January 29, 2021, 4:14pm UTC](https://forum.biobakery.org/t/running-calculate-unifrac-r-ignores-first-sample/1600/2 "2021-01-29T16:14:16Z")

</div>

That’s weird, the first 2 columns of the `merge_metaphlan_tables.py` output are the taxonomy string and the NCBI taxonomy ID of each clade, so `-2` should discard both these columns.

Are you using the last version of `merge_metaphlan_tables.py`?
