# Unable to merge virus profile.txt files into table

**URL:** https://forum.biobakery.org/t/unable-to-merge-virus-profile-txt-files-into-table/6848
**Category:** MetaPhlAn
**Created:** [March 26, 2024, 1:32am UTC](https://forum.biobakery.org/t/unable-to-merge-virus-profile-txt-files-into-table/6848 "2024-03-26T01:32:51Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![young\_doktor](https://avatars.discourse-cdn.com/v4/letter/y/dc4da7/32.png) [@young\_doktor](https://forum.biobakery.org/u/young_doktor)
#### Post date: [March 26, 2024, 1:32am UTC](https://forum.biobakery.org/t/unable-to-merge-virus-profile-txt-files-into-table/6848/1 "2024-03-26T01:32:51Z")

</div>

I am using metaphlan4 with mpa\_vJun23\_CHOCOPhlAnSGB\_202307

I obtained profiled.vsc files for virus using this command:  
SampleName.r1.fastq --input\_type fastq --bowtie2out SampleName.r1.bowtie2.bz2 --profile\_vsc --vsc\_out profiled\_Sample Name.vsc.txt

 ![image](https://canada1.discourse-cdn.com/flex027/uploads/biobakery/original/2X/4/49f75d260a35f3bcce63473794d08b3ca2226de6.png)

I am running this command

merge\_metaphlan\_tables.py profiled\_\*.txt \> -o merged\_abundance\_table.txt

I am getting this error:  
Traceback (most recent call last):  
File “MYPATH/.conda/envs/metaphlan4/lib/python3.10/site-packages/pandas/core/indexes/base.py”, line 3805, in get\_loc  
return self.\_engine.get\_loc(casted\_key)  
File “index.pyx”, line 167, in pandas.\_libs.index.IndexEngine.get\_loc  
File “index.pyx”, line 196, in pandas.\_libs.index.IndexEngine.get\_loc  
File “pandas/\_libs/hashtable\_class\_helper.pxi”, line 7081, in pandas.\_libs.hashtable.PyObjectHashTable.get\_item  
File “pandas/\_libs/hashtable\_class\_helper.pxi”, line 7089, in pandas.\_libs.hashtable.PyObjectHashTable.get\_item  
KeyError: ‘relative\_abundance’

The above exception was the direct cause of the following exception:

Traceback (most recent call last):  
File “MYPATH/.conda/envs/metaphlan4/bin/merge\_metaphlan\_tables.py”, line 10, in   
sys.exit(main())  
File “MYPATH/.conda/envs/metaphlan4/lib/python3.10/site-packages/metaphlan/utils/merge\_metaphlan\_tables.py”, line 73, in main  
merge(args.aistms, open(args.o, ‘w’) if args.o else sys.stdout, args.gtdb\_profiles)  
File “MYPATH/.conda/envs/metaphlan4/lib/python3.10/site-packages/metaphlan/utils/merge\_metaphlan\_tables.py”, line 36, in merge  
profiles\_list.append(pd.Series(data=iIn[‘relative\_abundance’], index=iIn.index,  
File “MYAPTH/.conda/envs/metaphlan4/lib/python3.10/site-packages/pandas/core/frame.py”, line 4090, in **getitem**  
indexer = self.columns.get\_loc(key)  
File “MYPATH/.conda/envs/metaphlan4/lib/python3.10/site-packages/pandas/core/indexes/base.py”, line 3812, in get\_loc  
raise KeyError(key) from err  
KeyError: ‘relative\_abundance’

Any thoughts of how I can troubleshoot this?

Thanks!

---

<div class="post-metadata">

### Author: ![young\_doktor](https://avatars.discourse-cdn.com/v4/letter/y/dc4da7/32.png) [@young\_doktor](https://forum.biobakery.org/u/young_doktor)
#### Post date: [March 26, 2024, 11:56pm UTC](https://forum.biobakery.org/t/unable-to-merge-virus-profile-txt-files-into-table/6848/2 "2024-03-26T23:56:42Z")

</div>

I found this tutorial: [MetaPhlAn 4.1 · biobakery/biobakery Wiki · GitHub](https://github.com/biobakery/biobakery/wiki/MetaPhlAn-4.1#3-metaphlan-viral-module-tutorial)

However, the code provided: ```

# Merge multiple tables

merge\_vsc\_tables.py -o OUT.vsc.txt \*\_vsc.txt

```auto

Did not work.

I tried modeling the code after how the merge command is written for relative abundance. This is what worked for me: 

merge_vsc_tables.py profiled_*.txt > OUT.vsc.txt
```

---

<div class="post-metadata">

### Author: ![fconstancias](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.biobakery.org/fconstancias/32/190_2.png) [@fconstancias](https://forum.biobakery.org/u/fconstancias)
#### Post date: [November 24, 2025, 8:37pm UTC](https://forum.biobakery.org/t/unable-to-merge-virus-profile-txt-files-into-table/6848/3 "2025-11-24T20:37:38Z")

</div>

Hello,

I am also facing an error when trying to merge the VSC tables:

merge\_vsc\_tables.py X204SC250\*/S\_\*/\*\*\_vsc\_metagenome.txt -o merged\_vsc\_tables.txt

Traceback (most recent call last):  
File “/work/FAC/FBM/DBC/slehtine/stool\_sampling/tools/mpa4.2.2/bin/merge\_vsc\_tables.py”, line 10, in  
sys.exit(main())  
^^^^^^  
File “/work/FAC/FBM/DBC/slehtine/stool\_sampling/tools/mpa4.2.2/lib/python3.12/site-packages/metaphlan/utils/merge\_vsc\_tables.py”, line 99, in main  
merge(args.aistms, fout, options)  
File “/work/FAC/FBM/DBC/slehtine/stool\_sampling/tools/mpa4.2.2/lib/python3.12/site-packages/metaphlan/utils/merge\_vsc\_tables.py”, line 69, in merge  
out\_table = pd.pivot\_table(  
merged\_tables,  
index=indexes\_for\_pivot,  
columns=‘sampleID’,  
values=groupby\_field  
)  
File “/work/FAC/FBM/DBC/slehtine/stool\_sampling/tools/mpa4.2.2/lib/python3.12/site-packages/pandas/core/reshape/pivot.py”, line 102, in pivot\_table  
table = \_\_internal\_pivot\_table(  
File “/work/FAC/FBM/DBC/slehtine/stool\_sampling/tools/mpa4.2.2/lib/python3.12/site-packages/pandas/core/reshape/pivot.py”, line 172, in \_\_internal\_pivot\_table  
grouped = data.groupby(keys, observed=observed\_bool, sort=sort, dropna=dropna)  
File “/work/FAC/FBM/DBC/slehtine/stool\_sampling/tools/mpa4.2.2/lib/python3.12/site-packages/pandas/core/frame.py”, line 9190, in groupby  
return DataFrameGroupBy(  
File “/work/FAC/FBM/DBC/slehtine/stool\_sampling/tools/mpa4.2.2/lib/python3.12/site-packages/pandas/core/groupby/groupby.py”, line 1329, in **init**  
grouper, exclusions, obj = get\_grouper(  
File “/work/FAC/FBM/DBC/slehtine/stool\_sampling/tools/mpa4.2.2/lib/python3.12/site-packages/pandas/core/groupby/grouper.py”, line 1043, in get\_grouper  
raise KeyError(gpr)  
KeyError: ‘Annotation’

(/work/FAC/FBM/DBC/slehtine/stool\_sampling/tools/mpa4.2.2) metaphlan --version  
MetaPhlAn version 4.2.2 (4 Jun 2025)

Any help would be appreciated !

---

<div class="post-metadata">

### Author: ![lindacova](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.biobakery.org/lindacova/32/3218_2.png) [@lindacova](https://forum.biobakery.org/u/lindacova)
#### Post date: [November 27, 2025, 10:00am UTC](https://forum.biobakery.org/t/unable-to-merge-virus-profile-txt-files-into-table/6848/4 "2025-11-27T10:00:49Z")

</div>

Hi @fconstancias ,

I think there was a bug in the `merge_vsc_tables` script in MetaPhlAn version 4.2.2, which has been fixed in the newer versions.

You can either update the whole MetaPhlAn package or find the fixed script for merging vsc tables here: [https://github.com/biobakery/MetaPhlAn/blob/master/metaphlan/utils/merge\_vsc\_tables.py](https://github.com/biobakery/MetaPhlAn/blob/master/metaphlan/utils/merge_vsc_tables.py)

Hope this was helpful!

Linda
